diff mbox series

[FFmpeg-devel] avcodec/encode: ensure encoders don't return empty packets

Message ID 20210413191646.2165-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/encode: ensure encoders don't return empty packets
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer April 13, 2021, 7:16 p.m. UTC
The current checks ensured that if they contained data, it was refcounted, but
then wrongly assumed that side data was present if there was no data, instead
of checking for it.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/encode.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 9a4140f91a..aac32cd0f4 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -259,11 +259,6 @@  end:
         av_frame_unref(frame);
     }
 
-    if (got_packet)
-        // Encoders must always return ref-counted buffers.
-        // Side-data only packets have no data and can be not ref-counted.
-        av_assert0(!avpkt->data || avpkt->buf);
-
     return ret;
 }
 
@@ -301,14 +296,15 @@  static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt
         ret = avctx->codec->receive_packet(avctx, avpkt);
         if (ret < 0)
             av_packet_unref(avpkt);
-        else
-            // Encoders must always return ref-counted buffers.
-            // Side-data only packets have no data and can be not ref-counted.
-            av_assert0(!avpkt->data || avpkt->buf);
     } else
         ret = encode_simple_receive_packet(avctx, avpkt);
 
-    if (ret == AVERROR_EOF)
+    if (!ret) {
+        // Encoders must always return ref-counted buffers.
+        av_assert0(!avpkt->data || avpkt->buf);
+        // Side-data only packets have no data and can be not ref-counted.
+        av_assert0(avpkt->data || avpkt->side_data);
+    } else if (ret == AVERROR_EOF)
         avci->draining_done = 1;
 
     return ret;