diff mbox series

[FFmpeg-devel,1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support

Message ID 20230319141514.28134-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/snowenc: AV_CODEC_CAP_ENCODER_RECON_FRAME support | expand

Commit Message

Michael Niedermayer March 19, 2023, 2:15 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/snowenc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

James Almer March 19, 2023, 3:34 p.m. UTC | #1
On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   libavcodec/snowenc.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
> index 658684c575..a03e4292ee 100644
> --- a/libavcodec/snowenc.c
> +++ b/libavcodec/snowenc.c
> @@ -26,6 +26,7 @@
>   #include "avcodec.h"
>   #include "codec_internal.h"
>   #include "encode.h"
> +#include "internal.h" //For AVCodecInternal.recon_frame
>   #include "me_cmp.h"
>   #include "packet_internal.h"
>   #include "snow_dwt.h"
> @@ -1576,6 +1577,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
>   {
>       SnowContext *s = avctx->priv_data;
>       RangeCoder * const c= &s->c;
> +    AVCodecInternal *avci = avctx->internal;
>       AVFrame *pic;
>       const int width= s->avctx->width;
>       const int height= s->avctx->height;
> @@ -1877,6 +1879,10 @@ redo_frame:
>                                      s->encoding_error,
>                                      (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
>                                      s->current_picture->pict_type);
> +    if (avci->recon_frame) {

The proper check is (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME). 
avci->recon_frame could start being allocated unconditionally in the 
future for whatever reason.

> +        av_frame_unref(avci->recon_frame);
> +        av_frame_ref(avci->recon_frame, s->current_picture);
> +    }
>   
>       pkt->size = ff_rac_terminate(c, 0);
>       if (s->current_picture->key_frame)
> @@ -1934,7 +1940,9 @@ const FFCodec ff_snow_encoder = {
>       CODEC_LONG_NAME("Snow"),
>       .p.type         = AVMEDIA_TYPE_VIDEO,
>       .p.id           = AV_CODEC_ID_SNOW,
> -    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> +    .p.capabilities = AV_CODEC_CAP_DR1 |
> +                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
> +                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
>       .priv_data_size = sizeof(SnowContext),
>       .init           = encode_init,
>       FF_CODEC_ENCODE_CB(encode_frame),
Michael Niedermayer March 19, 2023, 7:27 p.m. UTC | #2
On Sun, Mar 19, 2023 at 12:34:50PM -0300, James Almer wrote:
> On 3/19/2023 11:15 AM, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >   libavcodec/snowenc.c | 10 +++++++++-
> >   1 file changed, 9 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
> > index 658684c575..a03e4292ee 100644
> > --- a/libavcodec/snowenc.c
> > +++ b/libavcodec/snowenc.c
> > @@ -26,6 +26,7 @@
> >   #include "avcodec.h"
> >   #include "codec_internal.h"
> >   #include "encode.h"
> > +#include "internal.h" //For AVCodecInternal.recon_frame
> >   #include "me_cmp.h"
> >   #include "packet_internal.h"
> >   #include "snow_dwt.h"
> > @@ -1576,6 +1577,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
> >   {
> >       SnowContext *s = avctx->priv_data;
> >       RangeCoder * const c= &s->c;
> > +    AVCodecInternal *avci = avctx->internal;
> >       AVFrame *pic;
> >       const int width= s->avctx->width;
> >       const int height= s->avctx->height;
> > @@ -1877,6 +1879,10 @@ redo_frame:
> >                                      s->encoding_error,
> >                                      (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
> >                                      s->current_picture->pict_type);
> > +    if (avci->recon_frame) {
> 
> The proper check is (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME).
> avci->recon_frame could start being allocated unconditionally in the future
> for whatever reason.

The docomentation says:
    /**
     * When the AV_CODEC_FLAG_RECON_FRAME flag is used. the encoder should store
     * here the reconstructed frame corresponding to the last returned packet.
     *
     * Not allocated in other cases.
     */
    AVFrame *recon_frame;
    
If thats not meant to be assumed to be true, the documentation should state
this differently

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 658684c575..a03e4292ee 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -26,6 +26,7 @@ 
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "encode.h"
+#include "internal.h" //For AVCodecInternal.recon_frame
 #include "me_cmp.h"
 #include "packet_internal.h"
 #include "snow_dwt.h"
@@ -1576,6 +1577,7 @@  static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 {
     SnowContext *s = avctx->priv_data;
     RangeCoder * const c= &s->c;
+    AVCodecInternal *avci = avctx->internal;
     AVFrame *pic;
     const int width= s->avctx->width;
     const int height= s->avctx->height;
@@ -1877,6 +1879,10 @@  redo_frame:
                                    s->encoding_error,
                                    (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
                                    s->current_picture->pict_type);
+    if (avci->recon_frame) {
+        av_frame_unref(avci->recon_frame);
+        av_frame_ref(avci->recon_frame, s->current_picture);
+    }
 
     pkt->size = ff_rac_terminate(c, 0);
     if (s->current_picture->key_frame)
@@ -1934,7 +1940,9 @@  const FFCodec ff_snow_encoder = {
     CODEC_LONG_NAME("Snow"),
     .p.type         = AVMEDIA_TYPE_VIDEO,
     .p.id           = AV_CODEC_ID_SNOW,
-    .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+    .p.capabilities = AV_CODEC_CAP_DR1 |
+                      AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
+                      AV_CODEC_CAP_ENCODER_RECON_FRAME,
     .priv_data_size = sizeof(SnowContext),
     .init           = encode_init,
     FF_CODEC_ENCODE_CB(encode_frame),