Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/vvc_parser: Don't store state unnecessarily
@ 2023-06-29 21:53 Andreas Rheinhardt
  2023-06-29 21:58 ` James Almer
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2023-06-29 21:53 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

VVCParserContext.au_info is only used once (and in a read-only manner);
but this happens immediately after au_info has been completely
overwritten. Therefore one can just the src structure used to overwrite
au_info directly and remove au_info.

This also means that the whole referencing and unreferncing of au_info
(which duplicates AVBufferRefs CodedBitstreamH266Context and is
therefore of dubious gain) can be removed, as can the AVBufferRef*
contained in PuInfo; this also removes a certain uglyness: Sometimes
these AVBufferRef* were ownership pointers and sometimes not.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/vvc_parser.c | 63 +----------------------------------------
 1 file changed, 1 insertion(+), 62 deletions(-)

diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
index efea833565..69696eef57 100644
--- a/libavcodec/vvc_parser.c
+++ b/libavcodec/vvc_parser.c
@@ -29,11 +29,6 @@
 #define IS_H266_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= VVC_GDR_NUT))
 
 typedef struct PuInfo {
-    AVBufferRef *sps_ref;
-    AVBufferRef *pps_ref;
-    AVBufferRef *slice_ref;
-    AVBufferRef *ph_ref;
-
     const H266RawPPS *pps;
     const H266RawSPS *sps;
     const H266RawPH *ph;
@@ -53,7 +48,6 @@ typedef struct VVCParserContext {
 
     CodedBitstreamFragment picture_unit;
 
-    PuInfo   au_info;
     AVPacket au;
     AVPacket last_au;
 
@@ -150,41 +144,6 @@ static int get_pict_type(const CodedBitstreamFragment *pu)
     return has_p ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
 }
 
-static void pu_info_unref(PuInfo *info)
-{
-    av_buffer_unref(&info->slice_ref);
-    av_buffer_unref(&info->ph_ref);
-    av_buffer_unref(&info->pps_ref);
-    av_buffer_unref(&info->sps_ref);
-    info->slice = NULL;
-    info->ph = NULL;
-    info->pps = NULL;
-    info->sps = NULL;
-    info->pic_type = AV_PICTURE_TYPE_NONE;
-}
-
-static int pu_info_ref(PuInfo *dest, const PuInfo *src)
-{
-    pu_info_unref(dest);
-    dest->sps_ref = av_buffer_ref(src->sps_ref);
-    dest->pps_ref = av_buffer_ref(src->pps_ref);
-    if (src->ph_ref)
-        dest->ph_ref = av_buffer_ref(src->ph_ref);
-    dest->slice_ref = av_buffer_ref(src->slice_ref);
-    if (!dest->sps_ref || !dest->pps_ref || (src->ph_ref && !dest->ph_ref)
-        || !dest->slice_ref) {
-        pu_info_unref(dest);
-        return AVERROR(ENOMEM);
-    }
-
-    dest->sps = src->sps;
-    dest->pps = src->pps;
-    dest->ph = src->ph;
-    dest->slice = src->slice;
-    dest->pic_type = src->pic_type;
-    return 0;
-}
-
 static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
                            const PuInfo *pu)
 {
@@ -241,20 +200,6 @@ static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
     }
 }
 
-static int set_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
-                   const PuInfo *next_pu)
-{
-    VVCParserContext *ctx = s->priv_data;
-
-    int ret = pu_info_ref(&ctx->au_info, next_pu);
-    if (ret < 0)
-        return ret;
-
-    set_parser_ctx(s, avctx, &ctx->au_info);
-
-    return 0;
-}
-
 //8.3.1 Decoding process for picture order count.
 //VTM did not follow the spec, and it's much simpler than spec.
 //We follow the VTM.
@@ -338,10 +283,8 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
             continue;
         if ( nal->nal_unit_type == VVC_PH_NUT ) {
             info->ph = pu->units[i].content;
-            info->ph_ref = pu->units[i].content_ref;
         } else if (IS_H266_SLICE(nal->nal_unit_type)) {
             info->slice = pu->units[i].content;
-            info->slice_ref = pu->units[i].content_ref;
             if (info->slice->header.sh_picture_header_in_slice_header_flag)
                 info->ph = &info->slice->header.sh_picture_header;
             if (!info->ph) {
@@ -365,7 +308,6 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
         ret = AVERROR_INVALIDDATA;
         goto error;
     }
-    info->pps_ref = h266->pps_ref[info->ph->ph_pic_parameter_set_id];
     info->sps = h266->sps[info->pps->pps_seq_parameter_set_id];
     if (!info->sps) {
         av_log(logctx, AV_LOG_ERROR, "SPS id %d is not avaliable.\n",
@@ -373,7 +315,6 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
         ret = AVERROR_INVALIDDATA;
         goto error;
     }
-    info->sps_ref = h266->sps_ref[info->pps->pps_seq_parameter_set_id];
     info->pic_type = get_pict_type(pu);
     return 0;
   error:
@@ -430,8 +371,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
         goto end;
     }
     if (is_au_start(ctx, &info, avctx)) {
-        if ((ret = set_ctx(s, avctx, &info)) < 0)
-            goto end;
+        set_parser_ctx(s, avctx, &info);
         av_packet_move_ref(&ctx->last_au, &ctx->au);
     } else {
         ret = 1; //not a completed au
@@ -560,7 +500,6 @@ static void vvc_parser_close(AVCodecParserContext *s)
 {
     VVCParserContext *ctx = s->priv_data;
 
-    pu_info_unref(&ctx->au_info);
     av_packet_unref(&ctx->au);
     av_packet_unref(&ctx->last_au);
     ff_cbs_fragment_free(&ctx->picture_unit);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] avcodec/vvc_parser: Don't store state unnecessarily
  2023-06-29 21:53 [FFmpeg-devel] [PATCH] avcodec/vvc_parser: Don't store state unnecessarily Andreas Rheinhardt
@ 2023-06-29 21:58 ` James Almer
  0 siblings, 0 replies; 2+ messages in thread
From: James Almer @ 2023-06-29 21:58 UTC (permalink / raw)
  To: ffmpeg-devel

On 6/29/2023 6:53 PM, Andreas Rheinhardt wrote:
> VVCParserContext.au_info is only used once (and in a read-only manner);
> but this happens immediately after au_info has been completely
> overwritten. Therefore one can just the src structure used to overwrite
> au_info directly and remove au_info.
> 
> This also means that the whole referencing and unreferncing of au_info
> (which duplicates AVBufferRefs CodedBitstreamH266Context and is
> therefore of dubious gain) can be removed, as can the AVBufferRef*
> contained in PuInfo; this also removes a certain uglyness: Sometimes
> these AVBufferRef* were ownership pointers and sometimes not.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavcodec/vvc_parser.c | 63 +----------------------------------------
>   1 file changed, 1 insertion(+), 62 deletions(-)
> 
> diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
> index efea833565..69696eef57 100644
> --- a/libavcodec/vvc_parser.c
> +++ b/libavcodec/vvc_parser.c
> @@ -29,11 +29,6 @@
>   #define IS_H266_SLICE(nut) (nut <= VVC_RASL_NUT || (nut >= VVC_IDR_W_RADL && nut <= VVC_GDR_NUT))
>   
>   typedef struct PuInfo {
> -    AVBufferRef *sps_ref;
> -    AVBufferRef *pps_ref;
> -    AVBufferRef *slice_ref;
> -    AVBufferRef *ph_ref;
> -
>       const H266RawPPS *pps;
>       const H266RawSPS *sps;
>       const H266RawPH *ph;
> @@ -53,7 +48,6 @@ typedef struct VVCParserContext {
>   
>       CodedBitstreamFragment picture_unit;
>   
> -    PuInfo   au_info;
>       AVPacket au;
>       AVPacket last_au;
>   
> @@ -150,41 +144,6 @@ static int get_pict_type(const CodedBitstreamFragment *pu)
>       return has_p ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
>   }
>   
> -static void pu_info_unref(PuInfo *info)
> -{
> -    av_buffer_unref(&info->slice_ref);
> -    av_buffer_unref(&info->ph_ref);
> -    av_buffer_unref(&info->pps_ref);
> -    av_buffer_unref(&info->sps_ref);
> -    info->slice = NULL;
> -    info->ph = NULL;
> -    info->pps = NULL;
> -    info->sps = NULL;
> -    info->pic_type = AV_PICTURE_TYPE_NONE;
> -}
> -
> -static int pu_info_ref(PuInfo *dest, const PuInfo *src)
> -{
> -    pu_info_unref(dest);
> -    dest->sps_ref = av_buffer_ref(src->sps_ref);
> -    dest->pps_ref = av_buffer_ref(src->pps_ref);
> -    if (src->ph_ref)
> -        dest->ph_ref = av_buffer_ref(src->ph_ref);
> -    dest->slice_ref = av_buffer_ref(src->slice_ref);
> -    if (!dest->sps_ref || !dest->pps_ref || (src->ph_ref && !dest->ph_ref)
> -        || !dest->slice_ref) {
> -        pu_info_unref(dest);
> -        return AVERROR(ENOMEM);
> -    }
> -
> -    dest->sps = src->sps;
> -    dest->pps = src->pps;
> -    dest->ph = src->ph;
> -    dest->slice = src->slice;
> -    dest->pic_type = src->pic_type;
> -    return 0;
> -}
> -
>   static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
>                              const PuInfo *pu)
>   {
> @@ -241,20 +200,6 @@ static void set_parser_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
>       }
>   }
>   
> -static int set_ctx(AVCodecParserContext *s, AVCodecContext *avctx,
> -                   const PuInfo *next_pu)
> -{
> -    VVCParserContext *ctx = s->priv_data;
> -
> -    int ret = pu_info_ref(&ctx->au_info, next_pu);
> -    if (ret < 0)
> -        return ret;
> -
> -    set_parser_ctx(s, avctx, &ctx->au_info);
> -
> -    return 0;
> -}
> -
>   //8.3.1 Decoding process for picture order count.
>   //VTM did not follow the spec, and it's much simpler than spec.
>   //We follow the VTM.
> @@ -338,10 +283,8 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
>               continue;
>           if ( nal->nal_unit_type == VVC_PH_NUT ) {
>               info->ph = pu->units[i].content;
> -            info->ph_ref = pu->units[i].content_ref;
>           } else if (IS_H266_SLICE(nal->nal_unit_type)) {
>               info->slice = pu->units[i].content;
> -            info->slice_ref = pu->units[i].content_ref;
>               if (info->slice->header.sh_picture_header_in_slice_header_flag)
>                   info->ph = &info->slice->header.sh_picture_header;
>               if (!info->ph) {
> @@ -365,7 +308,6 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
>           ret = AVERROR_INVALIDDATA;
>           goto error;
>       }
> -    info->pps_ref = h266->pps_ref[info->ph->ph_pic_parameter_set_id];
>       info->sps = h266->sps[info->pps->pps_seq_parameter_set_id];
>       if (!info->sps) {
>           av_log(logctx, AV_LOG_ERROR, "SPS id %d is not avaliable.\n",
> @@ -373,7 +315,6 @@ static int get_pu_info(PuInfo *info, const CodedBitstreamH266Context *h266,
>           ret = AVERROR_INVALIDDATA;
>           goto error;
>       }
> -    info->sps_ref = h266->sps_ref[info->pps->pps_seq_parameter_set_id];
>       info->pic_type = get_pict_type(pu);
>       return 0;
>     error:
> @@ -430,8 +371,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
>           goto end;
>       }
>       if (is_au_start(ctx, &info, avctx)) {
> -        if ((ret = set_ctx(s, avctx, &info)) < 0)
> -            goto end;
> +        set_parser_ctx(s, avctx, &info);
>           av_packet_move_ref(&ctx->last_au, &ctx->au);
>       } else {
>           ret = 1; //not a completed au
> @@ -560,7 +500,6 @@ static void vvc_parser_close(AVCodecParserContext *s)
>   {
>       VVCParserContext *ctx = s->priv_data;
>   
> -    pu_info_unref(&ctx->au_info);
>       av_packet_unref(&ctx->au);
>       av_packet_unref(&ctx->last_au);
>       ff_cbs_fragment_free(&ctx->picture_unit);

Should be ok.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-29 21:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29 21:53 [FFmpeg-devel] [PATCH] avcodec/vvc_parser: Don't store state unnecessarily Andreas Rheinhardt
2023-06-29 21:58 ` James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git