summaryrefslogtreecommitdiff
path: root/src/mov_encoder.cc
diff options
context:
space:
mode:
authordeva <deva>2005-06-16 21:28:57 +0000
committerdeva <deva>2005-06-16 21:28:57 +0000
commite0592745a40dae2e14e5b6d9226f41a293ababc9 (patch)
treeb3640c07fd6af71aa01bed384613ffda6c03bf41 /src/mov_encoder.cc
parentc397f2dcdc399b43cf150f8000e711fc20613deb (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.cc')
-rw-r--r--src/mov_encoder.cc75
1 files changed, 69 insertions, 6 deletions
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index d422f87..908e857 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -39,6 +39,11 @@
/*
* $Log$
+ * Revision 1.30 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.29 2005/06/14 18:58:35 deva
* *** empty log message ***
*
@@ -143,7 +148,9 @@ MovEncoder::MovEncoder(sem_t *r_sem,
/////////LIBFAME STUFF///////////
// Allocate the output buffer.
- fame_buffer = new unsigned char [FAME_BUFFER_SIZE];
+
+// fame_buffer = new unsigned char [FAME_BUFFER_SIZE];
+
/*
// Open output file
f=fopen(filename, "wb");
@@ -272,7 +279,7 @@ MovEncoder::~MovEncoder()
fclose(f);
}
*/
- delete [] fame_buffer;
+ // delete [] fame_buffer;
delete [] yuv.y;
delete [] yuv.u;
delete [] yuv.v;
@@ -370,7 +377,54 @@ void MovEncoder::encode_audio(Frame *dvframe)
}
// this runs in a thread
-void MovEncoder::run()
+void MovEncoder::thread_main()
+{
+ info->info("MovEncoder::run");
+
+ FrameVector *item;
+ Frame *in_frame;
+ Frame *out_frame;
+
+ while(running) {
+ sem_wait(input_sem);
+
+ // Lock inout mutex
+ pthread_mutex_lock(input_mutex);
+ item = inputqueue->front();
+ inputqueue->pop();
+ pthread_mutex_unlock(input_mutex);
+ // Unlock input mutex
+
+ if(item) {
+ for(unsigned int cnt = 0; cnt < item->size(); cnt++) {
+ in_frame = item->at(cnt);
+ out_frame = encode(in_frame);
+ out_frame->number = in_frame->number;
+
+ delete in_frame;
+
+ // Lock output mutex
+ pthread_mutex_lock(output_mutex);
+ outputqueue->push(out_frame);
+ pthread_mutex_unlock(output_mutex);
+ // Unlock output mutex
+
+ // Kick frame writer
+ sem_post(output_sem);
+ }
+
+ delete item;
+
+ // Kick reader
+ sem_post(read_sem);
+ }
+ }
+
+ info->info("MovEncoder::stop");
+}
+
+/*
+void MovEncoder::thread_main()
{
info->info("MovEncoder::run");
@@ -384,8 +438,10 @@ void MovEncoder::run()
// Lock inout mutex
pthread_mutex_lock(input_mutex);
if(inputqueue->size() == 0) {
- info->error("Dammit... Empty queue in MovEncoder.");
+ info->warn("Empty queue in MovEncoder (This should not happen).");
pthread_mutex_unlock(input_mutex);
+ // Kick reader
+ sem_post(read_sem);
continue;
}
item = inputqueue->front();
@@ -394,7 +450,9 @@ void MovEncoder::run()
// Unlock input mutex
if(!item) {
- info->warn("Empty block detected.");
+ info->warn("Empty block detected (This should not happen).");
+ // Kick reader
+ sem_post(read_sem);
continue;
}
@@ -410,13 +468,18 @@ void MovEncoder::run()
outputqueue->push(out_frame);
pthread_mutex_unlock(output_mutex);
// Unlock output mutex
+
+ // Kick frame writer
+ sem_post(output_sem);
}
delete item;
+ // Kick reader
sem_post(read_sem);
- sem_post(output_sem);
}
info->info("MovEncoder::stop");
}
+
+ */