return 0;
}
-static int bsfs_init(AVCodecContext *avctx)
+int ff_decode_bsfs_init(AVCodecContext *avctx)
{
AVCodecInternal *avci = avctx->internal;
DecodeFilterContext *s = &avci->filter;
if (avctx->internal->draining)
return AVERROR_EOF;
- ret = bsfs_init(avctx);
- if (ret < 0)
- return ret;
-
av_packet_unref(avci->buffer_pkt);
if (avpkt && (avpkt->data || avpkt->side_data_elems)) {
ret = av_packet_ref(avci->buffer_pkt, avpkt);
if (!avcodec_is_open(avctx) || !av_codec_is_decoder(avctx->codec))
return AVERROR(EINVAL);
- ret = bsfs_init(avctx);
- if (ret < 0)
- return ret;
-
if (avci->buffer_frame->buf[0]) {
av_frame_move_ref(frame, avci->buffer_frame);
} else {
return 0;
}
+static void bsfs_flush(AVCodecContext *avctx)
+{
+ DecodeFilterContext *s = &avctx->internal->filter;
+
+ for (int i = 0; i < s->nb_bsfs; i++)
+ av_bsf_flush(s->bsfs[i]);
+}
+
void avcodec_flush_buffers(AVCodecContext *avctx)
{
avctx->internal->draining = 0;
else if (avctx->codec->flush)
avctx->codec->flush(avctx);
- ff_decode_bsfs_uninit(avctx);
+ bsfs_flush(avctx);
if (!avctx->refcounted_frames)
av_frame_unref(avctx->internal->to_free);
avctx->time_base.den = avctx->sample_rate;
}
+ if (av_codec_is_decoder(avctx->codec)) {
+ ret = ff_decode_bsfs_init(avctx);
+ if (ret < 0)
+ goto free_and_end;
+ }
+
if (HAVE_THREADS) {
ret = ff_thread_init(avctx);
if (ret < 0) {
av_packet_free(&avctx->internal->last_pkt_props);
av_packet_free(&avctx->internal->ds.in_pkt);
+ ff_decode_bsfs_uninit(avctx);
av_freep(&avctx->internal->pool);
}