Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 6/9] avcodec/evc_parse: pass a GetBitContext to the slice header parsing function
Date: Tue, 20 Jun 2023 11:40:39 -0300
Message-ID: <20230620144042.9629-6-jamrial@gmail.com> (raw)
In-Reply-To: <20230620144042.9629-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_frame_merge_bsf.c |  6 +++-
 libavcodec/evc_parse.c           | 52 ++++++++++++++------------------
 libavcodec/evc_parse.h           |  4 +--
 libavcodec/evc_parser.c          |  6 +++-
 4 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index bd30a09b15..3904170ebd 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -145,7 +145,11 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
     case EVC_NOIDR_NUT: {
         EVCParserSliceHeader sh;
 
-        err = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, nalu, nalu_size);
+        err = init_get_bits8(&gb, nalu, nalu_size);
+        if (err < 0)
+            return err;
+
+        err = ff_evc_parse_slice_header(&gb, &sh, &ctx->ps, nalu_type);
         if (err < 0) {
             av_log(bsf, AV_LOG_ERROR, "Slice header parsing error\n");
             goto end;
diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 0c35e40b47..dee48e947b 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -44,21 +44,15 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx)
 }
 
 // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
-int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
-                              enum EVCNALUnitType nalu_type, const uint8_t *bs, int bs_size)
+int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
+                              const EVCParamSets *ps, enum EVCNALUnitType nalu_type)
 {
-    GetBitContext gb;
     const EVCParserPPS *pps;
     const EVCParserSPS *sps;
-
     int num_tiles_in_slice = 0;
     int slice_pic_parameter_set_id;
-    int ret;
-
-    if ((ret = init_get_bits8(&gb, bs, bs_size)) < 0)
-        return ret;
 
-    slice_pic_parameter_set_id = get_ue_golomb(&gb);
+    slice_pic_parameter_set_id = get_ue_golomb(gb);
 
     if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
         return AVERROR_INVALIDDATA;
@@ -75,47 +69,47 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
     sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;
 
     if (!pps->single_tile_in_pic_flag) {
-        sh->single_tile_in_slice_flag = get_bits1(&gb);
-        sh->first_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1);
+        sh->single_tile_in_slice_flag = get_bits1(gb);
+        sh->first_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1);
     } else
         sh->single_tile_in_slice_flag = 1;
 
     if (!sh->single_tile_in_slice_flag) {
         if (pps->arbitrary_slice_present_flag)
-            sh->arbitrary_slice_flag = get_bits1(&gb);
+            sh->arbitrary_slice_flag = get_bits1(gb);
 
         if (!sh->arbitrary_slice_flag)
-            sh->last_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1);
+            sh->last_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1);
         else {
-            sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb(&gb);
+            sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb(gb);
             num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2;
             for (int i = 0; i < num_tiles_in_slice - 1; ++i)
-                sh->delta_tile_id_minus1[i] = get_ue_golomb(&gb);
+                sh->delta_tile_id_minus1[i] = get_ue_golomb(gb);
         }
     }
 
-    sh->slice_type = get_ue_golomb(&gb);
+    sh->slice_type = get_ue_golomb(gb);
 
     if (nalu_type == EVC_IDR_NUT)
-        sh->no_output_of_prior_pics_flag = get_bits1(&gb);
+        sh->no_output_of_prior_pics_flag = get_bits1(gb);
 
     if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P)))
-        sh->mmvd_group_enable_flag = get_bits1(&gb);
+        sh->mmvd_group_enable_flag = get_bits1(gb);
     else
         sh->mmvd_group_enable_flag = 0;
 
     if (sps->sps_alf_flag) {
         int ChromaArrayType = sps->chroma_format_idc;
 
-        sh->slice_alf_enabled_flag = get_bits1(&gb);
+        sh->slice_alf_enabled_flag = get_bits1(gb);
 
         if (sh->slice_alf_enabled_flag) {
-            sh->slice_alf_luma_aps_id = get_bits(&gb, 5);
-            sh->slice_alf_map_flag = get_bits1(&gb);
-            sh->slice_alf_chroma_idc = get_bits(&gb, 2);
+            sh->slice_alf_luma_aps_id = get_bits(gb, 5);
+            sh->slice_alf_map_flag = get_bits1(gb);
+            sh->slice_alf_chroma_idc = get_bits(gb, 2);
 
             if ((ChromaArrayType == 1 || ChromaArrayType == 2) && sh->slice_alf_chroma_idc > 0)
-                sh->slice_alf_chroma_aps_id =  get_bits(&gb, 5);
+                sh->slice_alf_chroma_aps_id =  get_bits(gb, 5);
         }
         if (ChromaArrayType == 3) {
             int sliceChromaAlfEnabledFlag = 0;
@@ -136,23 +130,23 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
             }
 
             if (!sh->slice_alf_enabled_flag)
-                sh->slice_alf_chroma_idc = get_bits(&gb, 2);
+                sh->slice_alf_chroma_idc = get_bits(gb, 2);
 
             if (sliceChromaAlfEnabledFlag) {
-                sh->slice_alf_chroma_aps_id = get_bits(&gb, 5);
-                sh->slice_alf_chroma_map_flag = get_bits1(&gb);
+                sh->slice_alf_chroma_aps_id = get_bits(gb, 5);
+                sh->slice_alf_chroma_map_flag = get_bits1(gb);
             }
 
             if (sliceChroma2AlfEnabledFlag) {
-                sh->slice_alf_chroma2_aps_id = get_bits(&gb, 5);
-                sh->slice_alf_chroma2_map_flag = get_bits1(&gb);
+                sh->slice_alf_chroma2_aps_id = get_bits(gb, 5);
+                sh->slice_alf_chroma2_map_flag = get_bits1(gb);
             }
         }
     }
 
     if (nalu_type != EVC_IDR_NUT) {
         if (sps->sps_pocs_flag)
-            sh->slice_pic_order_cnt_lsb = get_bits(&gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
+            sh->slice_pic_order_cnt_lsb = get_bits(gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
     }
 
     // @note
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index a1fbbc643d..322f52c928 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -117,8 +117,8 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si
 // nuh_temporal_id specifies a temporal identifier for the NAL unit
 int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
-int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
-                              enum EVCNALUnitType nalu_type, const uint8_t *buf, int buf_size);
+int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
+                              const EVCParamSets *ps, enum EVCNALUnitType nalu_type);
 
 // POC (picture order count of the current picture) derivation
 // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index 8dd6b5fda7..ae399ef8cc 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -116,7 +116,11 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
         EVCParserSliceHeader sh;
         int bit_depth;
 
-        ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
+        ret = init_get_bits8(&gb, buf, buf_size);
+        if (ret < 0)
+            return ret;
+
+        ret = ff_evc_parse_slice_header(&gb, &sh, &ctx->ps, nalu_type);
         if (ret < 0) {
             av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n");
             return ret;
-- 
2.41.0

_______________________________________________
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".

  parent reply	other threads:[~2023-06-20 14:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 2/9] avformat/evcdec: remove unnecessary av_packet_unref() calls James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 3/9] avformat/evcdec: flush the bsf on EOF James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 4/9] avformat/evcdec: use an unsigned type for nalu_size James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 5/9] avcodec/evc_ps: pass a GetBitContext to the SPS and PPS parsing functions James Almer
2023-06-20 14:40 ` James Almer [this message]
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/evc_frame_merge: use a GetBitContext to parse entire NALUs James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: " James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 9/9] avformat/evc: move NALU length and type parsing functions to a header James Almer
2023-06-21 16:31 ` [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230620144042.9629-6-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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