diff options
author | deva <deva> | 2005-06-16 21:28:57 +0000 |
---|---|---|
committer | deva <deva> | 2005-06-16 21:28:57 +0000 |
commit | e0592745a40dae2e14e5b6d9226f41a293ababc9 (patch) | |
tree | b3640c07fd6af71aa01bed384613ffda6c03bf41 /src/mov_encoder_writer.cc | |
parent | c397f2dcdc399b43cf150f8000e711fc20613deb (diff) |
Rewrote thread object
Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to
growing server queue)
Diffstat (limited to 'src/mov_encoder_writer.cc')
-rw-r--r-- | src/mov_encoder_writer.cc | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc index bd4fb56..a10d671 100644 --- a/src/mov_encoder_writer.cc +++ b/src/mov_encoder_writer.cc @@ -31,6 +31,11 @@ /* * $Log$ + * Revision 1.6 2005/06/16 21:28:57 deva + * Rewrote thread object + * Fixed bug in mov_encoder (pushed read_sem too many times, whihc lead to + * growing server queue) + * * Revision 1.5 2005/06/14 18:58:35 deva * *** empty log message *** * @@ -117,45 +122,76 @@ MovEncoderWriter::~MovEncoderWriter() delete file; } -//#define TEST_SIZE -#ifdef TEST_SIZE - #define BLOCK_SIZE 1024*1024 - #define TIMES 10 - static void *buf = NULL; -#endif - -void MovEncoderWriter::run() +void MovEncoderWriter::thread_main() { info->info("MovEncoderWriter::run"); -#ifdef TEST_SIZE - if(!buf) buf = malloc(BLOCK_SIZE); -#endif - Frame *frame; while(running) { sem_wait(sem); + // Lock output mutex + pthread_mutex_lock(mutex); + frame = queue->top(); + if(frame && frame->number == frame_number) queue->pop(); + pthread_mutex_unlock(mutex); + // Unlock output mutex + + while(frame && (frame->number == frame_number)) { + int ret; + + ret = file->Write(frame->data, frame->size); + + delete frame; + + if(ret == -1) return; + + frame_number++; + + // Lock output mutex + pthread_mutex_lock(mutex); + frame = queue->top(); + if(frame && frame->number == frame_number) queue->pop(); + pthread_mutex_unlock(mutex); + // Unlock output mutex + } + } + + info->info("MovEncoderWriter::stop"); +} + +/* +void MovEncoderWriter::thread_main() +{ + unsigned int howdeep = 0; + info->info("MovEncoderWriter::run"); + + Frame *frame; + + while(running) { + sem_wait(sem); + howdeep++; + + // Lock output mutex pthread_mutex_lock(mutex); if(queue->size() == 0) { - // info->warn("MovEncoderWriter::run() encountered an empty queue."); + info->warn("1MovEncoderWriter encountered an empty queue (This shouldn't happen)."); + // Unlock output mutex pthread_mutex_unlock(mutex); continue; } frame = queue->top(); if(frame->number == frame_number) queue->pop(); pthread_mutex_unlock(mutex); + // Unlock output mutex - while(frame->number == frame_number) { + while((frame->number == frame_number) && howdeep) { + howdeep--; int ret; -#ifdef TEST_SIZE - for(int cnt = 0; cnt < TIMES; cnt++) ret = file->Write(buf, BLOCK_SIZE); -#else ret = file->Write(frame->data, frame->size); -#endif delete frame; @@ -166,9 +202,9 @@ void MovEncoderWriter::run() // Lock output mutex pthread_mutex_lock(mutex); if(queue->size() == 0) { - //info->warn("MovEncoderWriter::run() encountered an empty queue."); + info->warn("2MovEncoderWriter encountered an empty queue (This shouldn't happen)."); pthread_mutex_unlock(mutex); - break; + continue; } frame = queue->top(); if(frame->number == frame_number) queue->pop(); @@ -179,3 +215,4 @@ void MovEncoderWriter::run() info->info("MovEncoderWriter::stop"); } +*/ |