summaryrefslogtreecommitdiff
path: root/src/mov_encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mov_encoder.cc')
-rw-r--r--src/mov_encoder.cc67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index 118a338..9212e5a 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -43,7 +43,7 @@
#include "debug.h"
-MovEncoder::MovEncoder(sem_t *r_sem,
+MovEncoder::MovEncoder(volatile bool *r, sem_t *r_sem,
FrameVectorQueue *in, sem_t *in_sem, pthread_mutex_t *in_mutex,
FramePriorityQueue *v_out, pthread_mutex_t *v_out_mutex, sem_t *v_out_sem,
FramePriorityQueue *a_out, pthread_mutex_t *a_out_mutex, sem_t *a_out_sem,
@@ -52,7 +52,7 @@ MovEncoder::MovEncoder(sem_t *r_sem,
info = i;
info->info("MovEncoder");
- running = true;
+ running = r;
// Queues
inputqueue = in;
@@ -86,8 +86,8 @@ void MovEncoder::thread_main()
int a_outsize = 0;
int insize = 0;
- // Run with slightly lower priority than MovEncoderWriter
- nice(1);
+ // Run with slightly lower priority than MovEncoderWriter AND AudioEncoder
+ nice(2);
FrameVector *item;
Frame *in_frame;
@@ -95,23 +95,16 @@ void MovEncoder::thread_main()
Frame *out_a_frame;
LibFAMEWrapper fame(info);
- // LibLAMEWrapper lame(info);
- // Make a new instance for every frame sequence (usually 5) to ensure no
- // frame dependencies are broken when running multithreaded.
- LibLAMEWrapper lame(info);
-
- while(running) {
+ // Process until running == false and the queue is empty
+ while(*running || ((*running == false) && (insize > 0))) {
sem_wait(input_sem);
-
// Lock inout mutex
pthread_mutex_lock(input_mutex);
item = inputqueue->front();
inputqueue->pop();
-
insize = inputqueue->size();
-
pthread_mutex_unlock(input_mutex);
// Unlock input mutex
@@ -119,45 +112,45 @@ void MovEncoder::thread_main()
for(unsigned int cnt = 0; cnt < item->size(); cnt++) {
in_frame = item->at(cnt);
- // Encode video
- //out_v_frame = new Frame(in_frame->data, in_frame->size);
- //out_v_frame->number = in_frame->number;
- out_v_frame = fame.encode(in_frame);
- out_v_frame->number = in_frame->number;
-
- // Encode audio
- //out_a_frame = new Frame(in_frame->data, in_frame->size);
- //out_a_frame->number = in_frame->number;
- out_a_frame = lame.encode(in_frame);
- out_a_frame->number = in_frame->number;
-
- // Last frame - we need to close LAME
- // if(cnt == item->size() - 1) out_a_frame = lame.close(out_a_frame);
-
- delete in_frame;
-
+ // Check for end of stream
+ if(in_frame == endOfFrameStream) {
+ info->info("endOfFrameStream in MovEncoder");
+
+ out_v_frame = in_frame;
+
+ // Stop running
+ *running = false;
+ } else {
+ // Encode video
+ out_v_frame = fame.encode(in_frame);
+ out_v_frame->number = in_frame->number;
+ }
+ // Create audio frame
+ out_a_frame = in_frame;
+
// Lock output mutex
pthread_mutex_lock(video_output_mutex);
video_outputqueue->push(out_v_frame);
v_outsize = video_outputqueue->size();
pthread_mutex_unlock(video_output_mutex);
// Unlock output mutex
-
+
// Kick multiplexer (video)
sem_post(video_output_sem);
-
+
// Lock output mutex
pthread_mutex_lock(audio_output_mutex);
audio_outputqueue->push(out_a_frame);
a_outsize = audio_outputqueue->size();
pthread_mutex_unlock(audio_output_mutex);
// Unlock output mutex
-
- // Kick multiplexer (audio)
+
+ // Kick audio encoder
sem_post(audio_output_sem);
}
delete item;
+ item = NULL;
test++;
if(test % (25 * 24) == 0)
@@ -169,7 +162,11 @@ void MovEncoder::thread_main()
}
}
- // Kick multiplexer (audio)
+ info->info("Input pool size: %d, video output pool size: %d, audio output pool size: %d",
+ insize, v_outsize, a_outsize);
+
+
+ // Kick audio encoder
sem_post(audio_output_sem);
// Kick multiplexer (video)