]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit 'f89ec87afaf0d1abb6d450253b0b348fd554533b'
authorJames Almer <jamrial@gmail.com>
Tue, 11 Sep 2018 14:48:38 +0000 (11:48 -0300)
committerJames Almer <jamrial@gmail.com>
Tue, 11 Sep 2018 16:08:50 +0000 (13:08 -0300)
* commit 'f89ec87afaf0d1abb6d450253b0b348fd554533b':
  frame: Simplify the video allocation

Merged-by: James Almer <jamrial@gmail.com>
Padding-Remixed-by: Michael Niedermayer <michael@niedermayer.cc>
1  2 
libavutil/frame.c

index deb9b6f334b3f6ff7c9373cd998d556aabf3c850,fa6245914e2dae7d43a8246807e9a6f7683ae626..6c2c28f18fc799ec2ce7a46b390ecf3a7128d140
@@@ -210,11 -89,7 +210,12 @@@ void av_frame_free(AVFrame **frame
  
  static int get_video_buffer(AVFrame *frame, int align)
  {
 -    int ret, i;
 +    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
-     int ret, i;
++    int ret, i, padded_height;
++    int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align);
 +
 +    if (!desc)
 +        return AVERROR(EINVAL);
  
      if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
          return ret;
              frame->linesize[i] = FFALIGN(frame->linesize[i], align);
      }
  
-     for (i = 0; i < 4 && frame->linesize[i]; i++) {
-         int h = FFALIGN(frame->height, 32);
-         if (i == 1 || i == 2)
-             h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
 -    if ((ret = av_image_fill_pointers(frame->data, frame->format, frame->height,
++    padded_height = FFALIGN(frame->height, 32);
++    if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
+                                       NULL, frame->linesize)) < 0)
+         return ret;
 -    frame->buf[0] = av_buffer_alloc(ret);
++    frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding);
+     if (!frame->buf[0])
+         goto fail;
  
-         frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1);
-         if (!frame->buf[i])
-             goto fail;
 -    if (av_image_fill_pointers(frame->data, frame->format, frame->height,
++    if (av_image_fill_pointers(frame->data, frame->format, padded_height,
+                                frame->buf[0]->data, frame->linesize) < 0)
+         goto fail;
  
-         frame->data[i] = frame->buf[i]->data;
-     }
-     if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & FF_PSEUDOPAL) {
-         av_buffer_unref(&frame->buf[1]);
-         frame->buf[1] = av_buffer_alloc(AVPALETTE_SIZE);
-         if (!frame->buf[1])
-             goto fail;
-         frame->data[1] = frame->buf[1]->data;
++    for (i = 1; i < 4; i++) {
++        if (frame->data[i])
++            frame->data[i] += i * plane_padding;
 +    }
 +
      frame->extended_data = frame->data;
  
      return 0;