diff options
author | deva <deva> | 2005-05-19 14:10:22 +0000 |
---|---|---|
committer | deva <deva> | 2005-05-19 14:10:22 +0000 |
commit | d74c7a00c417cffdc93a82efa2841e23d823bea6 (patch) | |
tree | ea7f7b69ccbd0dc1df1ea5e05dd59cfafa194f25 /src/mov_encoder.cc | |
parent | a597454b7ce1b931e3e4117e6fed509cc22517ff (diff) |
Multithreading rulez?R0_2_2
Diffstat (limited to 'src/mov_encoder.cc')
-rw-r--r-- | src/mov_encoder.cc | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index 172051d..7bffc50 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -39,6 +39,10 @@ /* * $Log$ + * Revision 1.23 2005/05/19 14:10:22 deva + * + * Multithreading rulez? + * * Revision 1.22 2005/05/17 19:16:26 deva * * Made new mpeg writer work, with proper file permissions. @@ -104,8 +108,8 @@ MovEncoder::MovEncoder() { // FIXME: Hmmm... should this be detected somewhere?! - static int w = 720; - static int h = 576; + int w = 720; + int h = 576; // Initialize yuv strucutre. yuv.w = w; @@ -207,6 +211,13 @@ MovEncoder::MovEncoder() fame_init(fame_context, &fame_par, fame_buffer, FAME_BUFFER_SIZE); + + + // Thread stuff + sem_init(&sem, 0, 0); + sem_init(&done, 0, 0); + + running = true; } MovEncoder::~MovEncoder() @@ -314,3 +325,60 @@ void MovEncoder::encode_audio(Frame *dvframe) { // TODO: Do some audio stuff here sometime! } + +void MovEncoder::encodeSequence(Queue<Frame> *queue) +{ + // set input queue + inputqueue = queue; + + // unlock semaphore + sem_post(&sem); +} + + +// this runs in a thread +void MovEncoder::run() +{ + fprintf(stderr, "Encoder Ready\n"); fflush(stderr); + + while(running) { + // wait for semaphore + // lock semaphore + sem_wait(&sem); + if(inputqueue == NULL) continue; + + fprintf(stderr, "."); fflush(stderr); + + // allocate new output queue + outputqueue = new Queue<Frame>(); + // while input queue.pop + Frame *fi, *fo; + while(inputqueue->length() > 0) { + fi = inputqueue->pop(); + + // encode frame from input queue + fo = encode(fi); + + // and push result on output queue + outputqueue->push(fo); + + // delete the input frame + //delete fi; + } + // delete input queue + delete inputqueue; + sem_post(&done); + } +} + +Queue<Frame> *MovEncoder::getResultSequence() +{ + // wait for sempahore + sem_wait(&done); + + // fprintf(stderr, "POP!\n"); fflush(stderr); + + // return output queue + return outputqueue; +} + |