diff options
Diffstat (limited to 'src/multiplexer.cc')
-rw-r--r-- | src/multiplexer.cc | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/multiplexer.cc b/src/multiplexer.cc index 323b33c..12e9768 100644 --- a/src/multiplexer.cc +++ b/src/multiplexer.cc @@ -31,6 +31,8 @@ #include <netinet/in.h> #include <math.h> +#include "util.h" + #define SIZEOF(x) (sizeof(x)-1) // Audio index lists @@ -101,9 +103,36 @@ Multiplexer::~Multiplexer() } -int Multiplexer::read_stream(char *buf, unsigned int size, StreamType type) +Frame *Multiplexer::getFrame(StreamType type) { Frame *tmpframe; + Frame *frame = NULL; + + sem_wait(sem[type]); + //if(*running) sem_wait(sem[type]); + + while( frame == NULL ) { + // Lock output mutex + pthread_mutex_lock( mutex[type] ); + tmpframe = queue[type]->top(); + + if(tmpframe && tmpframe->number == frame_number[type] ) { + queue[type]->pop(); + frame = tmpframe; + frame_number[type]++; + read[type] = 0; + } + + pthread_mutex_unlock( mutex[type] ); + // Unlock output mutex + + sleep_1_frame(); + } + return frame; +} + +int Multiplexer::read_stream(char *buf, unsigned int size, StreamType type) +{ unsigned int copied = 0; while( copied < size ) { @@ -115,37 +144,10 @@ int Multiplexer::read_stream(char *buf, unsigned int size, StreamType type) } // If no frame is in the buffer, get one from the queue - while( frame[type] == NULL ) { - - // if(!*running) info->warn("Halt detected!"); - - // If we are not running anymore, just process the last frames as fast as possible! - if(*running) sem_wait(sem[type]); - - // Lock output mutex - pthread_mutex_lock( mutex[type] ); - tmpframe = queue[type]->top(); - - if(tmpframe && tmpframe->number == frame_number[type] ) { - queue[type]->pop(); - frame[type] = tmpframe; - frame_number[type]++; - read[type] = 0; - } - /* - if(*running == false && frame[type] == NULL) { - pthread_mutex_unlock( mutex[type] ); - //info->info("Bailed out early %d!", copied); - return copied; - } - */ - - pthread_mutex_unlock( mutex[type] ); - // Unlock output mutex - } + if(frame[type] == NULL) frame[type] = getFrame(type); // check for end of stream - if( frame[type] == endOfFrameStream ) { + if( frame[type]->endOfFrameStream == true) { info->info("endOfFrameStream in Multiplexer %s-stream.", type==TYPE_VIDEO?"video\0":"audio\0"); return copied; } |