summaryrefslogtreecommitdiff
path: root/src/mov_encoder_thread.cc
diff options
context:
space:
mode:
authordeva <deva>2005-09-12 15:34:25 +0000
committerdeva <deva>2005-09-12 15:34:25 +0000
commit701608f39c59b530f6cede66ec24e9ddda8beae6 (patch)
treee974077734a45e0e6bb5b487b230922656834bed /src/mov_encoder_thread.cc
parent84e9873f846478476487d5cd2587e5879a0be8ea (diff)
*** empty log message ***
Diffstat (limited to 'src/mov_encoder_thread.cc')
-rw-r--r--src/mov_encoder_thread.cc51
1 files changed, 30 insertions, 21 deletions
diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc
index cfa6071..dc3581d 100644
--- a/src/mov_encoder_thread.cc
+++ b/src/mov_encoder_thread.cc
@@ -34,8 +34,16 @@ MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
info = i;
info->info("MovEncoderThread");
- outputqueue = new FramePriorityQueue();
+ // Queues
inputqueue = new FrameVectorQueue();
+ video_outputqueue = new FramePriorityQueue();
+ audio_outputqueue = new FramePriorityQueue();
+
+ // Queue mutexes
+ pthread_mutex_init (&input_mutex, NULL);
+ pthread_mutex_init (&video_output_mutex, NULL);
+ pthread_mutex_init (&audio_output_mutex, NULL);
+
block = new FrameVector();
num_frames_in_block = config->readString("frame_sequence")->length();
@@ -46,28 +54,26 @@ MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
// Thread stuff
sem_init(&in_sem, 0, 0);
- sem_init(&out_sem, 0, 0);
+ sem_init(&video_out_sem, 0, 0);
+ sem_init(&audio_out_sem, 0, 0);
sem_init(&read_sem, 0, 0);
for(int cnt = 0; cnt < threads; cnt++) sem_post(&read_sem);
- pthread_mutex_init (&input_mutex, NULL);
- pthread_mutex_init (&output_mutex, NULL);
-
- writer = new MovEncoderWriter(cpr, outputqueue, &out_sem, &output_mutex, info);
+ writer = new MovEncoderWriter(cpr,
+ video_outputqueue, &video_output_mutex, &video_out_sem,
+ audio_outputqueue, &audio_output_mutex, &audio_out_sem,
+ info);
writer->run();
- // writer_tid = new pthread_t;
- //pthread_create (writer_tid, NULL, thread_run, writer);
for(int cnt = 0; cnt < threads; cnt++) {
MovEncoder *movenc = new MovEncoder(&read_sem,
inputqueue, &in_sem, &input_mutex,
- outputqueue, &out_sem, &output_mutex,
+ video_outputqueue, &video_output_mutex, &video_out_sem,
+ audio_outputqueue, &audio_output_mutex, &audio_out_sem,
info);
movenc->run();
encs.push_back(movenc);
- // tids.push_back(new pthread_t);
- // pthread_create (tids[cnt], NULL, thread_run, encs[cnt]);
}
frame_number = 0;
@@ -80,9 +86,10 @@ MovEncoderThread::~MovEncoderThread()
// These should not be deleted here... its done elsewhere.
// inputqueue = NULL;
- sem_post(&out_sem);
+ sem_post(&video_out_sem);
+ sem_post(&audio_out_sem);
- // Stop the encoding threads.
+ // Tell the encoding threads to stop.
for(int cnt = 0; cnt < threads; cnt++) {
encs[cnt]->running = false;
}
@@ -94,27 +101,29 @@ MovEncoderThread::~MovEncoderThread()
// They should be exited now, so we can delete them.
for(int cnt = 0; cnt < threads; cnt++) {
- // pthread_join(*tids[cnt], NULL);
+ // Wait for it to stop
+ encs[cnt]->wait_stop();
+ // Delete it
delete encs[cnt];
- // delete tids[cnt];
}
// Tell the writer to stop
writer->running = false;
// Kick it to make it stop.
- sem_post(&out_sem);
+ sem_post(&video_out_sem);
+ sem_post(&audio_out_sem);
- // Destroy the thread
- // pthread_join(*writer_tid, NULL);
- // delete writer_tid;
+ // Wait for it to stop.
+ writer->wait_stop();
// delete the writer (end thereby close the file)
delete writer;
// Destroy the semaphores.
sem_destroy(&in_sem);
- sem_destroy(&out_sem);
+ sem_destroy(&video_out_sem);
+ sem_destroy(&audio_out_sem);
sem_destroy(&read_sem);
}
@@ -157,5 +166,5 @@ void MovEncoderThread::encode(Frame* frame)
block = new FrameVector;
}
- frame_number += 2;
+ frame_number ++;
}