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)
* @param user_data NULL
* @return unimplemented
*/
int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_data)
{
//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
long int actualRecordTime;
long int currentTime = time(NULL);
long int addTime;
long int bytesToAdd;
//cout << "Audio start time (timestamp): " << ((StreamRecorder*)user_data)->timestamp << endl;
//cout << "Actual time (timestamp): " << currentTime << endl;
......@@ -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)
{
cout << "Bytes readed: " << ((StreamRecorder*)user_data)->nBytes << endl;
......@@ -204,7 +207,10 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
else
{
/** 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 << "Actual Bytes number: " << "(" << ((StreamRecorder*)user_data)->nBytes << ") + ";
......@@ -223,7 +229,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
((StreamRecorder*)user_data)->isConnectionLost = false;
/** Try reconnect with the radio stream*/
g_timeout_add(5*1000, reconnectURIStream, user_data);
g_timeout_add(1*1000, reconnectURIStream, user_data);
}
break;
......@@ -237,10 +243,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
g_free (debug);
strcpy(((StreamRecorder*)user_data)->errorMessage,error->message);
/** The message doesn't contains null character*/
((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);
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
/** Not audio stream received */
if(((StreamRecorder*)user_data)->timestamp == 0)
{
g_timeout_add(5*1000, reconnectURIStream, user_data);
g_timeout_add(1*1000, reconnectURIStream, user_data);
}
else
{
long int actualRecordTime;
long int currentTime = time(NULL);
//cout << "Audio start time (timestamp): " << ((StreamRecorder *) user_data)->timestamp << endl;
//cout << "Actual time (timestamp): " << currentTime << endl;
long int addTime;
actualRecordTime = currentTime - ((StreamRecorder *) user_data)->timestamp;
cout << "Actual time (timestamp): " << currentTime << endl;
actualRecordTime = currentTime - ((StreamRecorder *)user_data)->timestamp;
cout << "Record time: " << actualRecordTime << endl;
/** Record time is greater than th required */
......@@ -271,7 +280,11 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
else
{
/** 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 << "Actual Bytes number: " << "(" << ((StreamRecorder *) user_data)->nBytes << ") + ";
......@@ -284,22 +297,25 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
cout << "Result : " << ((StreamRecorder *) user_data)->nBytes << endl;
cout << "Buffer size: " << ((StreamRecorder *) user_data)->bufferSize << endl;
cout << "-------------------------------------" << endl;
}
((StreamRecorder*)user_data)->isConnectionLost = false;
/** Try reconnect with the radio stream*/
g_timeout_add(5*1000, reconnectURIStream, user_data);
g_timeout_add(1*1000, reconnectURIStream, user_data);
}
}
break;
default:
break;
}
return TRUE;
}
//------------------------------------------------------------------------------
void StreamRecorder::saveBuffer(void *user_data)
{
......@@ -392,7 +408,8 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
cout << "Data size: " << bytesRead << endl;
//if(nBytes < bufferSize){
//if(nBytes < bufferSize)
//{
/** Update pointer*/
memcpy((char*)audioBufferPosition, (char*)data, bytesRead);
nBytes+=bytesRead;
......@@ -411,6 +428,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{
currentTime = time(NULL);
oldTmpTimestamp = newTmpTimestamp;
newTmpTimestamp = currentTime;
actualRecordTime = currentTime-timestamp;
cout << "Record time: " << actualRecordTime << endl;
......
......@@ -49,6 +49,8 @@ class StreamRecorder
/** Audio filename */
long int timestamp = 0;
long int oldTmpTimestamp = 0;
long int newTmpTimestamp = 0;
bool isConnectionLost;
......@@ -56,7 +58,6 @@ class StreamRecorder
//GstElement* audioResample;
//GstElement* tempBin;
//GstElement* audioSink;
GstElement* streamSrc;
GstElement* audioConvert;
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