Message ID | 20191109230817.3110-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | 73ee53f317418a5719f6169e6171b40f90d18321 |
Headers | show |
On 11/9/2019 8:08 PM, James Almer wrote: > Encoders must return reference counted packets. > > This was checked only for encoders using the encode2 AVCodec API, while > blindly accepting whatever encoders using the receive_packet AVCodec API > were returning. > > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavcodec/encode.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/encode.c b/libavcodec/encode.c > index d81b32b983..9ed2cf0f59 100644 > --- a/libavcodec/encode.c > +++ b/libavcodec/encode.c > @@ -428,9 +428,15 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * > return AVERROR(EINVAL); > > if (avctx->codec->receive_packet) { > + int ret; > if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) > return AVERROR_EOF; > - return avctx->codec->receive_packet(avctx, avpkt); > + ret = avctx->codec->receive_packet(avctx, avpkt); > + if (!ret) > + // 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; > } > > // Emulation via old API. Will apply soon.
diff --git a/libavcodec/encode.c b/libavcodec/encode.c index d81b32b983..9ed2cf0f59 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -428,9 +428,15 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * return AVERROR(EINVAL); if (avctx->codec->receive_packet) { + int ret; if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) return AVERROR_EOF; - return avctx->codec->receive_packet(avctx, avpkt); + ret = avctx->codec->receive_packet(avctx, avpkt); + if (!ret) + // 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; } // Emulation via old API.
Encoders must return reference counted packets. This was checked only for encoders using the encode2 AVCodec API, while blindly accepting whatever encoders using the receive_packet AVCodec API were returning. Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/encode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)