[Redbutton-devel] SF.net SVN: redbutton: [87] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-06-08 02:43:32
|
Revision: 87 Author: skilvington Date: 2006-06-07 09:09:27 -0700 (Wed, 07 Jun 2006) ViewCVS: http://svn.sourceforge.net/redbutton/?rev=87&view=rev Log Message: ----------- avoid unnecessary memcpy when decoding audio Modified Paths: -------------- redbutton-browser/trunk/MHEGStreamPlayer.c redbutton-browser/trunk/MHEGStreamPlayer.h Modified: redbutton-browser/trunk/MHEGStreamPlayer.c =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.c 2006-06-02 15:38:18 UTC (rev 86) +++ redbutton-browser/trunk/MHEGStreamPlayer.c 2006-06-07 16:09:27 UTC (rev 87) @@ -54,7 +54,27 @@ return; } +LIST_TYPE(AudioFrame) * +new_AudioFrameListItem(void) +{ + LIST_TYPE(AudioFrame) *af = safe_malloc(sizeof(LIST_TYPE(AudioFrame))); + + af->item.pts = AV_NOPTS_VALUE; + + af->item.size = 0; + + return af; +} + void +free_AudioFrameListItem(LIST_TYPE(AudioFrame) *af) +{ + safe_free(af); + + return; +} + +void MHEGStreamPlayer_init(MHEGStreamPlayer *p) { bzero(p, sizeof(MHEGStreamPlayer)); @@ -72,6 +92,9 @@ p->videoq_len = 0; p->videoq = NULL; + pthread_mutex_init(&p->audioq_lock, NULL); + p->audioq = NULL; + return; } @@ -81,6 +104,7 @@ MHEGStreamPlayer_stop(p); pthread_mutex_destroy(&p->videoq_lock); + pthread_mutex_destroy(&p->audioq_lock); return; } @@ -215,8 +239,8 @@ AVFrame *frame; LIST_TYPE(VideoFrame) *video_frame; int got_picture; - uint16_t audio_data[AVCODEC_MAX_AUDIO_FRAME_SIZE]; - int audio_size; + LIST_TYPE(AudioFrame) *audio_frame; + AudioFrame *af; int used; unsigned char *data; int size; @@ -264,27 +288,35 @@ /* see what stream we got a packet for */ if(pkt.stream_index == p->audio_pid && pkt.pts != AV_NOPTS_VALUE) { +#if 0 //printf("decode: got audio packet\n"); pts = pkt.pts; data = pkt.data; size = pkt.size; while(size > 0) { - used = avcodec_decode_audio(audio_codec_ctx, audio_data, &audio_size, data, size); -//printf("decode audio: pts=%f used=%d (size=%d) audio_size=%d\n", pts / audio_time_base, used, size, audio_size); + audio_frame = new_AudioFrameListItem(); + af = &audio_frame->item; + used = avcodec_decode_audio(audio_codec_ctx, af->data, &af->size, data, size); +//printf("decode audio: pts=%f used=%d (size=%d) audio_size=%d\n", pts / audio_time_base, used, size, af->size); data += used; size -= used; - if(audio_size > 0) + if(af->size > 0) { - pts += (audio_size * 1000.0) / ((audio_codec_ctx->channels * 2) * audio_codec_ctx->sample_rate); -// audio_frame = new_AudioFrameListItem(pts / audio_time_base, audio_data, audio_size); -// pthread_mutex_lock(&opts->audioq_lock); -// LIST_APPEND(&opts->audioq, audio_frame); -// pthread_mutex_unlock(&opts->audioq_lock); + pts += (af->size * 1000.0) / ((audio_codec_ctx->channels * 2) * audio_codec_ctx->sample_rate); + af->pts = pts / audio_time_base; + pthread_mutex_lock(&p->audioq_lock); + LIST_APPEND(&p->audioq, audio_frame); + pthread_mutex_unlock(&p->audioq_lock); } + else + { + free_AudioFrameListItem(audio_frame); + } } /* don't want one thread hogging the CPU time */ pthread_yield(); +#endif } else if(pkt.stream_index == p->video_pid && pkt.dts != AV_NOPTS_VALUE) { Modified: redbutton-browser/trunk/MHEGStreamPlayer.h =================================================================== --- redbutton-browser/trunk/MHEGStreamPlayer.h 2006-06-02 15:38:18 UTC (rev 86) +++ redbutton-browser/trunk/MHEGStreamPlayer.h 2006-06-07 16:09:27 UTC (rev 87) @@ -32,6 +32,19 @@ LIST_TYPE(VideoFrame) *new_VideoFrameListItem(double, enum PixelFormat, unsigned int, unsigned int, AVFrame *); void free_VideoFrameListItem(LIST_TYPE(VideoFrame) *); +/* list of decoded audio samples to play */ +typedef struct +{ + double pts; /* presentation time stamp */ + unsigned int size; /* size of data in bytes (not uint16_t's) */ + uint16_t data[AVCODEC_MAX_AUDIO_FRAME_SIZE]; +} AudioFrame; + +DEFINE_LIST_OF(AudioFrame); + +LIST_TYPE(AudioFrame) *new_AudioFrameListItem(void); +void free_AudioFrameListItem(LIST_TYPE(AudioFrame) *); + /* player state */ typedef struct { @@ -53,6 +66,8 @@ pthread_mutex_t videoq_lock; /* list of decoded video frames */ unsigned int videoq_len; /* number of frames on the videoq */ LIST_OF(VideoFrame) *videoq; /* head of list is next to be displayed */ + pthread_mutex_t audioq_lock; /* list of decoded audio samples */ + LIST_OF(AudioFrame) *audioq; /* head of list is next to be played */ } MHEGStreamPlayer; void MHEGStreamPlayer_init(MHEGStreamPlayer *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |