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

time verification and pointer update are now in handoff

parent 25fb8daf
......@@ -39,20 +39,19 @@ StreamRecorder::StreamRecorder(const char* source, int time)
recordTime = nFrames*READSIZE/STREAMRECORDER_SAMPLERATE;
cout << "record time: " << recordTime << endl;
// Required record time
audioFileDuration = time;
strcpy(pluginUri,source);
bufferSize=nFrames*READSIZE*STREAMRECORDER_BYTESPERSAMPLE;
audioBuffer = new unsigned char[bufferSize];
bytesPerSecond= bufferSize/audioFileDuration;
// New buffer
memset(audioBuffer, 0, bufferSize);
audioBufferPosition=audioBuffer;
nBytes=0;
createMainPipeline();
connect();
}
......@@ -195,7 +194,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
switch (error->code)
{
case STREAM_ENOUGH_DATA_ERROR:
/** Last message in errors secuence*/
/** Last message in errors sequence*/
((StreamRecorder*)user_data)->isDisconnected = true;
break;
......@@ -233,6 +232,7 @@ int StreamRecorder::bus_callback (GstBus *bus, GstMessage *message, void *user_d
void StreamRecorder::saveBuffer()
{
compressBuffer();
// Restart buffer configuration
audioBufferPosition=audioBuffer;
memset (audioBuffer, 0, bufferSize);
nBytes=0;
......@@ -248,7 +248,7 @@ void StreamRecorder::saveBuffer()
void StreamRecorder::srcNewPad_callback(GstElement *element, GstPad *pad, void *data)
{
cout << gst_element_get_name(element)<< " adding pad.." << gst_pad_get_name (pad) << endl;
cout << gst_element_get_name(element)<< " adding pad..." << endl;
cout << "Pad Name: " << gst_pad_get_name (pad) << endl;
GstPad *sinkpad;
......@@ -298,7 +298,9 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
//GST_BUFFER_DATA is for gst v0.1
// ((StreamRecorder*)user_data)->addToBuffer((unsigned char*)GST_BUFFER_DATA (buffer));
if(((StreamRecorder*)user_data)->isDisconnected){
// If we come from a disconnection
if(((StreamRecorder*)user_data)->isDisconnected)
{
currentTime = time(NULL);
actualRecordTime = currentTime - ((StreamRecorder*)user_data)->timestamp;
......@@ -313,14 +315,15 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
}
else
{
long int bytesToAdd = actualRecordTime*((StreamRecorder*)user_data)->bytesPerSecond;
unsigned char *newPosition;
long int bytesToAdd = actualRecordTime*STREAMRECORDER_SAMPLERATE*STREAMRECORDER_BYTESPERSAMPLE*NCHANNELS;
printf("Bytes to add: %ld\n", bytesToAdd);
printf("Bytes to add %d\n", bytesToAdd);
// Adjust the bytes to add value to a buffer size divider
bytesToAdd = ceil(bytesToAdd / (STREAMRECORDER_BYTESPERSAMPLE*READSIZE))*STREAMRECORDER_BYTESPERSAMPLE*READSIZE;
printf("Adjusted to: %ld\n", bytesToAdd);
newPosition = ((StreamRecorder*)user_data)->audioBuffer;
newPosition += bytesToAdd;
((StreamRecorder*)user_data)->audioBufferPosition = newPosition;
((StreamRecorder*)user_data)->audioBufferPosition = ((StreamRecorder*)user_data)->audioBuffer;
((StreamRecorder*)user_data)->audioBufferPosition += bytesToAdd;
((StreamRecorder*)user_data)->nBytes = bytesToAdd;
cout << "The pointer has been updated..." << endl;
......@@ -342,9 +345,11 @@ int StreamRecorder::filter_handoff_callback(GstElement* filter, GstBuffer* buffe
* @param length Data length
* @return Bytes writen
*/
int StreamRecorder::addToBuffer(unsigned char* data, int length) {
int StreamRecorder::addToBuffer(unsigned char* data, int length)
{
int bytesRead = length;// READSIZE*STREAMRECORDER_BYTESPERSAMPLE;
bool aux = false;
bool isNewAudioFile;
/** Useful for obtain the filename*/
......@@ -363,10 +368,9 @@ int StreamRecorder::addToBuffer(unsigned char* data, int length) {
{
cout << "New audio stream" << endl;
/** filename */
/** filename and initial record time*/
timestamp = time(NULL);
cout << "Audio filename (timestamp): " << timestamp << endl;
printf("Audio buffer %d\n", audioBuffer);
}
else
{
......
......@@ -23,6 +23,7 @@
#define STREAMRECORDER_SAMPLERATE 44100
#define READSIZE 1152 //For MPEG1, frame_size = 1152 samples/frame
#define STREAMRECORDER_BYTESPERSAMPLE 2
#define NCHANNELS 1
#define ERROR_MSG_SIZE 50
#define DST_URI_SIZE 80
......@@ -52,16 +53,10 @@ class StreamRecorder
/** Audio filename */
long int timestamp = 0;
long int oldTmpTimestamp = 0;
long int newTmpTimestamp = 0;
long int bytesPerSecond = 0;
bool isDisconnected = false;
bool isValidDisconnectedEvent = false;
//char* sourceName;
//GstElement* audioResample;
//GstElement* tempBin;
......
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