From 80b52138689e75f6ee6e55fa3be877500780bb17 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 25 Mar 2005 14:42:13 +0000 Subject: enabled audio. --- src/decoder.cc | 101 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/src/decoder.cc b/src/decoder.cc index 2171b1a..4d1f0ac 100644 --- a/src/decoder.cc +++ b/src/decoder.cc @@ -105,59 +105,60 @@ void Decoder::decode() /* NOTE: we only decode video, we only need the data from stream_index 0 */ /* (stream 0: video, stream 1: audio) */ - while(pkt.stream_index == 0 && len > 0) { - int ret; - int got_picture; - // buf_t *buf = buf_alloc(); - FFFrame *fff = new FFFrame(); - DVFrame *dvf = new DVFrame(); - dvf->type = DVF_VIDEO; - - memcpy(dvf->frame, ptr, len); - - // fprintf(stderr, "DVBufferSize: [%d]bytes\n", len); - ret = avcodec_decode_video(&fc->streams[0]->codec, - fff->frame, &got_picture, ptr, len); - - if(ret < 0) { - fprintf(stderr, "Error while decoding stream\n"); - exit(1); + while(len > 0) { + if(pkt.stream_index == 0) { + int ret; + int got_picture; + // buf_t *buf = buf_alloc(); + FFFrame *fff = new FFFrame(); + DVFrame *dvf = new DVFrame(); + dvf->type = DVF_VIDEO; + + memcpy(dvf->frame, ptr, len); + + // fprintf(stderr, "DVBufferSize: [%d]bytes\n", len); + ret = avcodec_decode_video(&fc->streams[0]->codec, + fff->frame, &got_picture, ptr, len); + + if(ret < 0) { + fprintf(stderr, "Error while decoding stream\n"); + exit(1); + } + + len -= ret; + ptr += ret; + + pthread_mutex_lock(mutex); + encode_queue->push(dvf); + player_queue->push(fff); + pthread_mutex_unlock(mutex); + + sem_post(encode_sem); + + user_event.type = SDL_USEREVENT; + user_event.user.code = 0; + user_event.user.data1 = NULL; + user_event.user.data2 = NULL; + SDL_PushEvent(&user_event); } - len -= ret; - ptr += ret; - - pthread_mutex_lock(mutex); - encode_queue->push(dvf); - player_queue->push(fff); - pthread_mutex_unlock(mutex); - - sem_post(encode_sem); - - user_event.type = SDL_USEREVENT; - user_event.user.code = 0; - user_event.user.data1 = NULL; - user_event.user.data2 = NULL; - SDL_PushEvent(&user_event); - } - - /* // For later use, when audio must be implemented - while(pkt.stream_index == 1 && len > 0) { - DVFrame *dvf = new DVFrame(); - dvf->type = DVF_AUDIO; - - memcpy(dvf->frame, ptr, sizeof(dvf->frame)); - - ptr += sizeof(dvf->frame); - len -= sizeof(dvf->frame); - - pthread_mutex_lock(mutex); - encode_queue->push(dvf); - pthread_mutex_unlock(mutex); - - sem_post(encode_sem); + // For later use, when audio must be implemented + if(pkt.stream_index == 1) { + DVFrame *dvf = new DVFrame(); + dvf->type = DVF_AUDIO; + + memcpy(dvf->frame, ptr, sizeof(dvf->frame)); + + ptr += sizeof(dvf->frame); + len -= sizeof(dvf->frame); + + pthread_mutex_lock(mutex); + encode_queue->push(dvf); + pthread_mutex_unlock(mutex); + + sem_post(encode_sem); + } } - */ av_free_packet(&pkt); } -- cgit v1.2.3