diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2012-08-02 13:11:16 +0200 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2012-08-03 16:28:12 +0200 |
commit | b99381e8b5355bdf26a9f03064a7a7e4fe1415e8 (patch) | |
tree | e59d52f27ab4eefa9113cd67a939d841f8f05d64 | |
parent | 39a8275fdf4f607023b483a58b255600d5f7a9e7 (diff) | |
download | ffmpeg-b99381e8b5355bdf26a9f03064a7a7e4fe1415e8.tar.gz |
lavc/utils: generalize ff_init_buffer_info() and use it when seems feasible
Extend ff_init_buffer_info() to init audio frames as well as video
frames.
Avoid code duplication.
-rw-r--r-- | libavcodec/utils.c | 53 |
1 files changed, 17 insertions, 36 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 2f4cb5dbc8..4e729a4d84 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -301,10 +301,21 @@ void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic) pic->pkt_duration = 0; } pic->reordered_opaque= s->reordered_opaque; - pic->sample_aspect_ratio = s->sample_aspect_ratio; - pic->width = s->width; - pic->height = s->height; - pic->format = s->pix_fmt; + + switch (s->codec->type) { + case AVMEDIA_TYPE_VIDEO: + pic->width = s->width; + pic->height = s->height; + pic->format = s->pix_fmt; + pic->sample_aspect_ratio = s->sample_aspect_ratio; + break; + case AVMEDIA_TYPE_AUDIO: + pic->sample_rate = s->sample_rate; + pic->format = s->sample_fmt; + pic->channel_layout = s->channel_layout; + pic->channels = s->channels; + break; + } } int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, @@ -411,23 +422,7 @@ static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) } frame->type = FF_BUFFER_TYPE_INTERNAL; - - if (avctx->pkt) { - frame->pkt_pts = avctx->pkt->pts; - frame->pkt_pos = avctx->pkt->pos; - frame->pkt_duration = avctx->pkt->duration; - } else { - frame->pkt_pts = AV_NOPTS_VALUE; - frame->pkt_pos = -1; - frame->pkt_duration = 0; - } - - frame->reordered_opaque = avctx->reordered_opaque; - - frame->sample_rate = avctx->sample_rate; - frame->format = avctx->sample_fmt; - frame->channel_layout = avctx->channel_layout; - frame->channels = avctx->channels; + ff_init_buffer_info(avctx, frame); if (avctx->debug & FF_DEBUG_BUFFERS) av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, " @@ -553,22 +548,8 @@ static int video_get_buffer(AVCodecContext *s, AVFrame *pic) pic->width = buf->width; pic->height = buf->height; pic->format = buf->pix_fmt; - pic->sample_aspect_ratio = s->sample_aspect_ratio; - if (s->pkt) { - pic->pkt_pts = s->pkt->pts; - pic->pkt_pos = s->pkt->pos; - pic->pkt_duration = s->pkt->duration; - } else { - pic->pkt_pts = AV_NOPTS_VALUE; - pic->pkt_pos = -1; - pic->pkt_duration = 0; - } - pic->reordered_opaque= s->reordered_opaque; - pic->sample_aspect_ratio = s->sample_aspect_ratio; - pic->width = s->width; - pic->height = s->height; - pic->format = s->pix_fmt; + ff_init_buffer_info(s, pic); if(s->debug&FF_DEBUG_BUFFERS) av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d " |