Commit ed1f08bf authored by James Almer's avatar James Almer

avcodec/bsf: make sure the AVBSFInternal stored packet is reference counted

Some bitstream filters may buffer said packet in their own contexts
for latter use. The documentation for av_bsf_send_packet() doesn't
forbid feeding it non-reference counted packets, which depending on
the way said packets were internally buffered by the bsf it may
result in the data described in them becoming invalid or unavailable
at any time.
This was the case with vp9_superframe after commit e1bc3f43, which
was then promptly fixed in 37f4a093 and 7a02b364. It is still the
case even today with vp9_reorder_raw.

With this change the bitstream filters will not have to worry how to
store or consume the packets fed to them.
Reviewed-by: 's avatarwm4 <nfxjfg@googlemail.com>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent 231a7330
......@@ -188,7 +188,15 @@ int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
ctx->internal->buffer_pkt->side_data_elems)
return AVERROR(EAGAIN);
av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
if (pkt->buf) {
av_packet_move_ref(ctx->internal->buffer_pkt, pkt);
} else {
int ret = av_packet_ref(ctx->internal->buffer_pkt, pkt);
if (ret < 0)
return ret;
av_packet_unref(pkt);
}
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment