summaryrefslogtreecommitdiff
path: root/src/mov_encoder_writer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mov_encoder_writer.cc')
-rw-r--r--src/mov_encoder_writer.cc77
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");
}
+*/