Message ID | 20220323155720.20017-2-anton@khirnov.net |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,1/8] lavc/avcodec: simplify codec id/type validity checking | expand |
Context | Check | Description |
---|---|---|
yinshiyou/make_loongarch64 | success | Make finished |
yinshiyou/make_fate_loongarch64 | success | Make fate finished |
andriy/make_x86 | success | Make finished |
andriy/make_fate_x86 | success | Make fate finished |
On 3/23/2022 12:57 PM, Anton Khirnov wrote: > And only when needed, i.e. for encoders using the simple API. > --- > libavcodec/avcodec.c | 4 +--- > libavcodec/encode.c | 7 +++++++ > 2 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c > index dbaa9f78a2..c7daa385e7 100644 > --- a/libavcodec/avcodec.c > +++ b/libavcodec/avcodec.c > @@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code > > avci->buffer_frame = av_frame_alloc(); > avci->buffer_pkt = av_packet_alloc(); > - avci->es.in_frame = av_frame_alloc(); > avci->in_pkt = av_packet_alloc(); > avci->last_pkt_props = av_packet_alloc(); > avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), > AV_FIFO_FLAG_AUTO_GROW); > if (!avci->buffer_frame || !avci->buffer_pkt || > - !avci->es.in_frame || !avci->in_pkt || > - !avci->last_pkt_props || !avci->pkt_props) { > + !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { > ret = AVERROR(ENOMEM); > goto free_and_end; > } > diff --git a/libavcodec/encode.c b/libavcodec/encode.c > index 70bd8da81f..837ffaa40d 100644 > --- a/libavcodec/encode.c > +++ b/libavcodec/encode.c > @@ -412,6 +412,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * > > int ff_encode_preinit(AVCodecContext *avctx) > { > + AVCodecInternal *avci = avctx->internal; > int i; > > if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { > @@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS > if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) > avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; > > + if (ffcodec(avctx->codec)->encode2) { > + avci->es.in_frame = av_frame_alloc(); Could use the chance to remove the EncodeSimpleContext struct and just have in_frame in AVCodecInternal. DecodeSimpleContext was removed the same way some time ago when it became a struct for a single field. > + if (!avci->es.in_frame) > + return AVERROR(ENOMEM); > + } > + > return 0; > }
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index dbaa9f78a2..c7daa385e7 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_alloc(); - avci->es.in_frame = av_frame_alloc(); avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), AV_FIFO_FLAG_AUTO_GROW); if (!avci->buffer_frame || !avci->buffer_pkt || - !avci->es.in_frame || !avci->in_pkt || - !avci->last_pkt_props || !avci->pkt_props) { + !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 70bd8da81f..837ffaa40d 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -412,6 +412,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * int ff_encode_preinit(AVCodecContext *avctx) { + AVCodecInternal *avci = avctx->internal; int i; if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { @@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; + if (ffcodec(avctx->codec)->encode2) { + avci->es.in_frame = av_frame_alloc(); + if (!avci->es.in_frame) + return AVERROR(ENOMEM); + } + return 0; }