Commit b8dc7be7 authored by d.basulto's avatar d.basulto

solve bug related to segmentation core

parent af6a6793
...@@ -166,6 +166,7 @@ gboolean StreamRecorder::reconnectURIStream(void* instance) ...@@ -166,6 +166,7 @@ gboolean StreamRecorder::reconnectURIStream(void* instance)
* @param user_data NULL * @param user_data NULL
* @return unimplemented * @return unimplemented
*/ */
int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_data) int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_data)
{ {
//printf("StreamRecorder got %s message\n", GST_MESSAGE_TYPE_NAME (message)); //printf("StreamRecorder got %s message\n", GST_MESSAGE_TYPE_NAME (message));
...@@ -187,6 +188,8 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -187,6 +188,8 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
long int actualRecordTime; long int actualRecordTime;
long int currentTime = time(NULL); long int currentTime = time(NULL);
long int addTime;
long int bytesToAdd;
//cout << "Audio start time (timestamp): " << ((StreamRecorder*)user_data)->timestamp << endl; //cout << "Audio start time (timestamp): " << ((StreamRecorder*)user_data)->timestamp << endl;
//cout << "Actual time (timestamp): " << currentTime << endl; //cout << "Actual time (timestamp): " << currentTime << endl;
...@@ -195,7 +198,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -195,7 +198,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
/** Record time is greater than th required */ /** The calculated record time is greater? */
if(actualRecordTime >= ((StreamRecorder*)user_data)->audioFileDuration) if(actualRecordTime >= ((StreamRecorder*)user_data)->audioFileDuration)
{ {
cout << "Bytes readed: " << ((StreamRecorder*)user_data)->nBytes << endl; cout << "Bytes readed: " << ((StreamRecorder*)user_data)->nBytes << endl;
...@@ -204,7 +207,10 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -204,7 +207,10 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
else else
{ {
/** Moves the pointer to the position corresponding to the difference of the timestamps */ /** Moves the pointer to the position corresponding to the difference of the timestamps */
long int bytesToAdd = actualRecordTime*READSIZE*STREAMRECORDER_BYTESPERSAMPLE*10; addTime = currentTime - ((StreamRecorder *) user_data)->oldTmpTimestamp;
cout << "Time to add: " << addTime << endl;
bytesToAdd = addTime*READSIZE*STREAMRECORDER_BYTESPERSAMPLE*10;
cout << "-------------------------------------" << endl; cout << "-------------------------------------" << endl;
cout << "Actual Bytes number: " << "(" << ((StreamRecorder*)user_data)->nBytes << ") + "; cout << "Actual Bytes number: " << "(" << ((StreamRecorder*)user_data)->nBytes << ") + ";
...@@ -223,7 +229,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -223,7 +229,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
((StreamRecorder*)user_data)->isConnectionLost = false; ((StreamRecorder*)user_data)->isConnectionLost = false;
/** Try reconnect with the radio stream*/ /** Try reconnect with the radio stream*/
g_timeout_add(5*1000, reconnectURIStream, user_data); g_timeout_add(1*1000, reconnectURIStream, user_data);
} }
break; break;
...@@ -237,10 +243,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -237,10 +243,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
g_free (debug); g_free (debug);
strcpy(((StreamRecorder*)user_data)->errorMessage,error->message); strcpy(((StreamRecorder*)user_data)->errorMessage,error->message);
/** The message doesn't contains null character*/ /** The message doesn't contains null character*/
((StreamRecorder*)user_data)->errorMessage[ERROR_MSG_SIZE-1] = '\0'; ((StreamRecorder*)user_data)->errorMessage[ERROR_MSG_SIZE-1] = '\0';
cerr << "Error: "<< ((StreamRecorder*)user_data)->errorMessage << endl; //cerr << "Error: "<< ((StreamRecorder*)user_data)->errorMessage << endl;
g_error_free (error); g_error_free (error);
if(strcmp(((StreamRecorder*)user_data)->errorMessage, "Stream doesn't contain enough data.") == 0) if(strcmp(((StreamRecorder*)user_data)->errorMessage, "Stream doesn't contain enough data.") == 0)
...@@ -249,17 +256,19 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -249,17 +256,19 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
/** Not audio stream received */ /** Not audio stream received */
if(((StreamRecorder*)user_data)->timestamp == 0) if(((StreamRecorder*)user_data)->timestamp == 0)
{ {
g_timeout_add(5*1000, reconnectURIStream, user_data); g_timeout_add(1*1000, reconnectURIStream, user_data);
} }
else else
{ {
long int actualRecordTime; long int actualRecordTime;
long int currentTime = time(NULL); long int currentTime = time(NULL);
//cout << "Audio start time (timestamp): " << ((StreamRecorder *) user_data)->timestamp << endl; long int addTime;
//cout << "Actual time (timestamp): " << currentTime << endl;
actualRecordTime = currentTime - ((StreamRecorder *) user_data)->timestamp; cout << "Actual time (timestamp): " << currentTime << endl;
actualRecordTime = currentTime - ((StreamRecorder *)user_data)->timestamp;
cout << "Record time: " << actualRecordTime << endl; cout << "Record time: " << actualRecordTime << endl;
/** Record time is greater than th required */ /** Record time is greater than th required */
...@@ -271,7 +280,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -271,7 +280,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
else else
{ {
/** Moves the pointer to the position corresponding to the difference of the timestamps */ /** Moves the pointer to the position corresponding to the difference of the timestamps */
long int bytesToAdd = actualRecordTime * READSIZE * STREAMRECORDER_BYTESPERSAMPLE * 10;
addTime = currentTime - ((StreamRecorder *) user_data)->oldTmpTimestamp;
cout << "Time to add: " << 1 << endl;
long int bytesToAdd = 1*READSIZE*STREAMRECORDER_BYTESPERSAMPLE*10;
cout << "-------------------------------------" << endl; cout << "-------------------------------------" << endl;
cout << "Actual Bytes number: " << "(" << ((StreamRecorder *) user_data)->nBytes << ") + "; cout << "Actual Bytes number: " << "(" << ((StreamRecorder *) user_data)->nBytes << ") + ";
...@@ -284,22 +297,25 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d ...@@ -284,22 +297,25 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
cout << "Result : " << ((StreamRecorder *) user_data)->nBytes << endl; cout << "Result : " << ((StreamRecorder *) user_data)->nBytes << endl;
cout << "Buffer size: " << ((StreamRecorder *) user_data)->bufferSize << endl; cout << "Buffer size: " << ((StreamRecorder *) user_data)->bufferSize << endl;
cout << "-------------------------------------" << endl; cout << "-------------------------------------" << endl;
} }
((StreamRecorder*)user_data)->isConnectionLost = false; ((StreamRecorder*)user_data)->isConnectionLost = false;
/** Try reconnect with the radio stream*/ /** Try reconnect with the radio stream*/
g_timeout_add(5*1000, reconnectURIStream, user_data); g_timeout_add(1*1000, reconnectURIStream, user_data);
} }
} }
break; break;
default: default:
break; break;
} }
return TRUE; return TRUE;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void StreamRecorder::saveBuffer(void *user_data) void StreamRecorder::saveBuffer(void *user_data)
{ {
...@@ -392,7 +408,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) { ...@@ -392,7 +408,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
cout << "Data size: " << bytesRead << endl; cout << "Data size: " << bytesRead << endl;
//if(nBytes < bufferSize){ //if(nBytes < bufferSize)
//{
/** Update pointer*/ /** Update pointer*/
memcpy((char*)audioBufferPosition, (char*)data, bytesRead); memcpy((char*)audioBufferPosition, (char*)data, bytesRead);
nBytes+=bytesRead; nBytes+=bytesRead;
...@@ -411,6 +428,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) { ...@@ -411,6 +428,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{ {
currentTime = time(NULL); currentTime = time(NULL);
oldTmpTimestamp = newTmpTimestamp;
newTmpTimestamp = currentTime;
actualRecordTime = currentTime-timestamp; actualRecordTime = currentTime-timestamp;
cout << "Record time: " << actualRecordTime << endl; cout << "Record time: " << actualRecordTime << endl;
......
...@@ -49,6 +49,8 @@ class StreamRecorder ...@@ -49,6 +49,8 @@ class StreamRecorder
/** Audio filename */ /** Audio filename */
long int timestamp = 0; long int timestamp = 0;
long int oldTmpTimestamp = 0;
long int newTmpTimestamp = 0;
bool isConnectionLost; bool isConnectionLost;
...@@ -56,7 +58,6 @@ class StreamRecorder ...@@ -56,7 +58,6 @@ class StreamRecorder
//GstElement* audioResample; //GstElement* audioResample;
//GstElement* tempBin; //GstElement* tempBin;
//GstElement* audioSink; //GstElement* audioSink;
GstElement* streamSrc; GstElement* streamSrc;
GstElement* audioConvert; GstElement* audioConvert;
GstElement* filterCaps; GstElement* filterCaps;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment