[FFmpeg-devel,v1,1/3] avcodec/bitpacked: move ff_get_buffer

Submitted by Patrick Keroulas on April 10, 2018, 9:21 p.m.

Details

Message ID 1523395297-13466-1-git-send-email-patrick.keroulas@savoirfairelinux.com
State New
Headers show

Commit Message

Patrick Keroulas April 10, 2018, 9:21 p.m.
From: Damien Riegel <damien.riegel@savoirfairelinux.com>

ff_get_buffer is used to allocate a buffer to hold frame's content. This
function was called in the function in charge of decoding an AVPacket
containing raw video with the yuv422 pixel format and a depth of 10-bit.

RFC4175 supports both progressive and interlaced mode. But the
interlaced mode doesn't consist of interlaced frames, only of fields.
FFmpeg cannot handle fields on their own, so the codec has to recreate
interlaced frames based on two consecutive fields.

As the function `bitpacked_decode_yuv422p10` will need to be called
twice to do that, it cannot be in charge of the buffer allocation, so
move it into its caller.

Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
---
 libavcodec/bitpacked.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

Rostislav Pehlivanov April 11, 2018, 12:45 p.m.
On 10 April 2018 at 22:21, Patrick Keroulas <
patrick.keroulas@savoirfairelinux.com> wrote:

> From: Damien Riegel <damien.riegel@savoirfairelinux.com>
>
> ff_get_buffer is used to allocate a buffer to hold frame's content. This
> function was called in the function in charge of decoding an AVPacket
> containing raw video with the yuv422 pixel format and a depth of 10-bit.
>
> RFC4175 supports both progressive and interlaced mode. But the
> interlaced mode doesn't consist of interlaced frames, only of fields.
> FFmpeg cannot handle fields on their own, so the codec has to recreate
> interlaced frames based on two consecutive fields.
>
> As the function `bitpacked_decode_yuv422p10` will need to be called
> twice to do that, it cannot be in charge of the buffer allocation, so
> move it into its caller.
>
> Signed-off-by: Damien Riegel <damien.riegel@savoirfairelinux.com>
> ---
>  libavcodec/bitpacked.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c
> index f0b417d..85d4bdd 100644
> --- a/libavcodec/bitpacked.c
> +++ b/libavcodec/bitpacked.c
> @@ -64,9 +64,6 @@ static int bitpacked_decode_yuv422p10(AVCodecContext
> *avctx, AVFrame *frame,
>      uint16_t *y, *u, *v;
>      int ret, i, j;
>
> -    ret = ff_get_buffer(avctx, frame, 0);
> -    if (ret < 0)
> -        return ret;
>
>      if (frame_size > packet_size)
>          return AVERROR_INVALIDDATA;
> @@ -128,6 +125,12 @@ static int bitpacked_decode(AVCodecContext *avctx,
> void *data, int *got_frame,
>      frame->pict_type = AV_PICTURE_TYPE_I;
>      frame->key_frame = 1;
>
> +    if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10) {
> +        res = ff_get_buffer(avctx, frame, 0);
> +        if (res < 0)
> +            return res;
> +    }
> +
>      res = bc->decode(avctx, frame, avpkt);
>      if (res)
>          return res;
> --
> 2.7.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

LGTM, will apply once your interlaced patch is okay.

Patch hide | download patch | download mbox

diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c
index f0b417d..85d4bdd 100644
--- a/libavcodec/bitpacked.c
+++ b/libavcodec/bitpacked.c
@@ -64,9 +64,6 @@  static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
     uint16_t *y, *u, *v;
     int ret, i, j;
 
-    ret = ff_get_buffer(avctx, frame, 0);
-    if (ret < 0)
-        return ret;
 
     if (frame_size > packet_size)
         return AVERROR_INVALIDDATA;
@@ -128,6 +125,12 @@  static int bitpacked_decode(AVCodecContext *avctx, void *data, int *got_frame,
     frame->pict_type = AV_PICTURE_TYPE_I;
     frame->key_frame = 1;
 
+    if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10) {
+        res = ff_get_buffer(avctx, frame, 0);
+        if (res < 0)
+            return res;
+    }
+
     res = bc->decode(avctx, frame, avpkt);
     if (res)
         return res;