[004/250] lavc: set frame properties in ff_get_buffer().

Message ID 1354401337-7312-5-git-send-email-anton@khirnov.net
State Committed
Commit ff953fecffd3b9a616a046723fb9d4690be032a6
Headers show

Commit Message

Anton Khirnov Dec. 1, 2012, 10:31 p.m.
There is no point in duplicating this code in every get_buffer()
implementation.
---
 cmdutils.c         |    5 -----
 libavcodec/utils.c |   38 ++++++++++++++++++--------------------
 2 files changed, 18 insertions(+), 25 deletions(-)

Comments

Luca Barbato Dec. 2, 2012, 7:11 p.m. | #1
On 12/01/2012 11:31 PM, Anton Khirnov wrote:
> There is no point in duplicating this code in every get_buffer()
> implementation.
> ---
>  cmdutils.c         |    5 -----
>  libavcodec/utils.c |   38 ++++++++++++++++++--------------------
>  2 files changed, 18 insertions(+), 25 deletions(-)
> 

I doubt it would need to be overridden, patch ok.

Patch

diff --git a/cmdutils.c b/cmdutils.c
index 6746be1..42029d5 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1367,11 +1367,6 @@  int codec_get_buffer(AVCodecContext *s, AVFrame *frame)
     frame->opaque        = buf;
     frame->type          = FF_BUFFER_TYPE_USER;
     frame->extended_data = frame->data;
-    frame->pkt_pts       = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE;
-    frame->width         = buf->w;
-    frame->height        = buf->h;
-    frame->format        = buf->pix_fmt;
-    frame->sample_aspect_ratio = s->sample_aspect_ratio;
 
     for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) {
         frame->base[i]     = buf->base[i];  // XXX h264.c uses base though it shouldn't
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4909fc4..6226b28 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -366,16 +366,6 @@  static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame)
 
     frame->type = FF_BUFFER_TYPE_INTERNAL;
 
-    if (avctx->pkt)
-        frame->pkt_pts = avctx->pkt->pts;
-    else
-        frame->pkt_pts = AV_NOPTS_VALUE;
-    frame->reordered_opaque = avctx->reordered_opaque;
-
-    frame->sample_rate    = avctx->sample_rate;
-    frame->format         = avctx->sample_fmt;
-    frame->channel_layout = avctx->channel_layout;
-
     if (avctx->debug & FF_DEBUG_BUFFERS)
         av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, "
                                     "internal audio buffer used\n", frame);
@@ -496,16 +486,6 @@  static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
     }
     pic->extended_data = pic->data;
     avci->buffer_count++;
-    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;
-    else
-        pic->pkt_pts = AV_NOPTS_VALUE;
-    pic->reordered_opaque = s->reordered_opaque;
 
     if (s->debug & FF_DEBUG_BUFFERS)
         av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
@@ -528,6 +508,24 @@  int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame)
 
 int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
 {
+    switch (avctx->codec_type) {
+    case AVMEDIA_TYPE_VIDEO:
+        frame->width               = avctx->width;
+        frame->height              = avctx->height;
+        frame->format              = avctx->pix_fmt;
+        frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
+        break;
+    case AVMEDIA_TYPE_AUDIO:
+        frame->sample_rate    = avctx->sample_rate;
+        frame->format         = avctx->sample_fmt;
+        frame->channel_layout = avctx->channel_layout;
+        break;
+    default: return AVERROR(EINVAL);
+    }
+
+    frame->pkt_pts = avctx->pkt ? avctx->pkt->pts : AV_NOPTS_VALUE;
+    frame->reordered_opaque = avctx->reordered_opaque;
+
     return avctx->get_buffer(avctx, frame);
 }