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 06/10] avcodec/evc_parse: split off deriving PoC
Date: Sat, 17 Jun 2023 19:00:11 -0300
Message-ID: <20230617220015.12669-3-jamrial@gmail.com> (raw)
In-Reply-To: <20230617151848.1378-1-jamrial@gmail.com>

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/evc_parse.c | 142 +++++++++++++++++++++--------------------
 libavcodec/evc_parse.h |   5 ++
 2 files changed, 79 insertions(+), 68 deletions(-)

diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index 1fe58c8050..262ef5aa39 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -187,6 +187,77 @@ static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *s
     return 0;
 }
 
+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
+                      EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid)
+{
+    const EVCParserPPS *pps = ps->pps[sh->slice_pic_parameter_set_id];
+    const EVCParserSPS *sps;
+
+    if (!pps)
+        return AVERROR_INVALIDDATA;
+
+    sps = ps->sps[pps->pps_seq_parameter_set_id];
+    if (!sps)
+        return AVERROR_INVALIDDATA;
+
+    if (sps->sps_pocs_flag) {
+        int PicOrderCntMsb = 0;
+        poc->prevPicOrderCntVal = poc->PicOrderCntVal;
+
+        if (nalu_type == EVC_IDR_NUT)
+            PicOrderCntMsb = 0;
+        else {
+            int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
+            int prevPicOrderCntLsb = poc->PicOrderCntVal & (MaxPicOrderCntLsb - 1);
+            int prevPicOrderCntMsb = poc->PicOrderCntVal - prevPicOrderCntLsb;
+
+            if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
+                ((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
+                PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
+            else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
+                     ((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
+                PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
+            else
+                PicOrderCntMsb = prevPicOrderCntMsb;
+        }
+        poc->PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb;
+    } else {
+        if (nalu_type == EVC_IDR_NUT) {
+            poc->PicOrderCntVal = 0;
+            poc->DocOffset = -1;
+        } else {
+            int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
+            if (tid == 0) {
+                poc->PicOrderCntVal = poc->prevPicOrderCntVal + SubGopLength;
+                poc->DocOffset = 0;
+                poc->prevPicOrderCntVal = poc->PicOrderCntVal;
+            } else {
+                int ExpectedTemporalId;
+                int PocOffset;
+                int prevDocOffset = poc->DocOffset;
+
+                poc->DocOffset = (prevDocOffset + 1) % SubGopLength;
+                if (poc->DocOffset == 0) {
+                    poc->prevPicOrderCntVal += SubGopLength;
+                    ExpectedTemporalId = 0;
+                } else
+                    ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
+                while (tid != ExpectedTemporalId) {
+                    poc->DocOffset = (poc->DocOffset + 1) % SubGopLength;
+                    if (poc->DocOffset == 0)
+                        ExpectedTemporalId = 0;
+                    else
+                        ExpectedTemporalId = 1 + (int)log2(poc->DocOffset);
+                }
+                PocOffset = (int)(SubGopLength * ((2.0 * poc->DocOffset + 1) / (int)pow(2.0, tid) - 2));
+                poc->PicOrderCntVal = poc->prevPicOrderCntVal + PocOffset;
+            }
+        }
+    }
+
+    return 0;
+}
+
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
 {
     int nalu_type, nalu_size;
@@ -299,8 +370,6 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
     case EVC_IDR_NUT:   // Coded slice of a IDR or non-IDR picture
     case EVC_NOIDR_NUT: {
         EVCParserSliceHeader sh;
-        const EVCParserSPS *sps;
-        const EVCParserPPS *pps;
         int ret;
 
         ret = evc_parse_slice_header(ctx, &sh, data, nalu_size);
@@ -331,72 +400,9 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
 
         // 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
-        pps = ctx->ps.pps[sh.slice_pic_parameter_set_id];
-        sps = ctx->ps.sps[pps->pps_seq_parameter_set_id];
-        av_assert0(sps && pps);
-
-        if (sps->sps_pocs_flag) {
-
-            int PicOrderCntMsb = 0;
-            ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
-
-            if (nalu_type == EVC_IDR_NUT)
-                PicOrderCntMsb = 0;
-            else {
-                int MaxPicOrderCntLsb = 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
-
-                int prevPicOrderCntLsb = ctx->poc.PicOrderCntVal & (MaxPicOrderCntLsb - 1);
-                int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb;
-
-
-                if ((sh.slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
-                    ((prevPicOrderCntLsb - sh.slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
-
-                    PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
-
-                else if ((sh.slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
-                         ((sh.slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
-
-                    PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
-
-                else
-                    PicOrderCntMsb = prevPicOrderCntMsb;
-            }
-            ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh.slice_pic_order_cnt_lsb;
-
-        } else {
-            if (nalu_type == EVC_IDR_NUT) {
-                ctx->poc.PicOrderCntVal = 0;
-                ctx->poc.DocOffset = -1;
-            } else {
-                int SubGopLength = (int)pow(2.0, sps->log2_sub_gop_length);
-                if (tid == 0) {
-                    ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + SubGopLength;
-                    ctx->poc.DocOffset = 0;
-                    ctx->poc.prevPicOrderCntVal = ctx->poc.PicOrderCntVal;
-                } else {
-                    int ExpectedTemporalId;
-                    int PocOffset;
-                    int prevDocOffset = ctx->poc.DocOffset;
-
-                    ctx->poc.DocOffset = (prevDocOffset + 1) % SubGopLength;
-                    if (ctx->poc.DocOffset == 0) {
-                        ctx->poc.prevPicOrderCntVal += SubGopLength;
-                        ExpectedTemporalId = 0;
-                    } else
-                        ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
-                    while (tid != ExpectedTemporalId) {
-                        ctx->poc.DocOffset = (ctx->poc.DocOffset + 1) % SubGopLength;
-                        if (ctx->poc.DocOffset == 0)
-                            ExpectedTemporalId = 0;
-                        else
-                            ExpectedTemporalId = 1 + (int)log2(ctx->poc.DocOffset);
-                    }
-                    PocOffset = (int)(SubGopLength * ((2.0 * ctx->poc.DocOffset + 1) / (int)pow(2.0, tid) - 2));
-                    ctx->poc.PicOrderCntVal = ctx->poc.prevPicOrderCntVal + PocOffset;
-                }
-            }
-        }
+        ret = ff_evc_derive_poc(&ctx->ps, &sh, &ctx->poc, nalu_type, tid);
+        if (ret < 0)
+            return ret;
 
         ctx->output_picture_number = ctx->poc.PicOrderCntVal;
         ctx->key_frame = (nalu_type == EVC_IDR_NUT) ? 1 : 0;
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index 2748f8dfbf..97825efcd5 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -159,4 +159,9 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
 
 int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
 
+// 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
+int ff_evc_derive_poc(const EVCParamSets *ps, const EVCParserSliceHeader *sh,
+                      EVCParserPoc *poc, enum EVCNALUnitType nalu_type, int tid);
+
 #endif /* AVCODEC_EVC_PARSE_H */
-- 
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-17 22:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-17 15:18 [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() James Almer
2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 2/3] avcodec/evc_frame_merge_bsf: use av_new_packet() James Almer
2023-06-17 15:18 ` [FFmpeg-devel] [PATCH 3/3] fate/lavf-container: add a test to remux raw evc into mp4 James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 04/10] avcodec/evc_parse: split off Parameter Set parsing into its own file James Almer
2023-06-20  7:37   ` Dawid Kozinski/Multimedia (PLT) /SRPOL/Staff Engineer/Samsung Electronics
2023-06-20 11:37     ` James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 05/10] avcodec/evc_parser: stop exporting delay and gop_size James Almer
2023-06-17 22:00 ` James Almer [this message]
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 07/10] avcodec/evc_parser: make ff_evc_parse_nal_unit() local to the parser James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 08/10] avcodec/evc_parser: remove write only variable James Almer
2023-06-18 12:04   ` Paul B Mahol
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 09/10] avcodec/evc_frame_merge_bsf: make ff_evc_parse_nal_unit() local to the filter James Almer
2023-06-17 22:00 ` [FFmpeg-devel] [PATCH 10/10] avcodec/evc_parse: remove ff_evc_parse_nal_unit() James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 11/17] avformat/evc: don't use an AVIOContext as log context James Almer
2023-06-19 21:11   ` [FFmpeg-devel] [PATCH 11/17 v2] " James Almer
2023-06-20 14:38   ` [FFmpeg-devel] [PATCH 11/17] " James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 12/17] avformat/evcdec: deduplicate nalu length and type parsing functions James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 13/17] avformat/evcdec: simplify probe function James Almer
2023-06-19 20:29   ` Michael Niedermayer
2023-06-19 20:42     ` James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 14/17] avformat/evcdec: simplify au_end_found check James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 15/17] avformat/evcdec: don't set AVCodecParameters.framerate James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 16/17] avcodec/evc_ps: make ff_evc_parse_{sps, pps} return an error code James Almer
2023-06-18 23:43 ` [FFmpeg-devel] [PATCH 17/17] avcodec/evc_ps: Check log2_sub_gop_length James Almer
2023-06-19 18:28 ` [FFmpeg-devel] [PATCH 1/3] avcodec/evc_frame_merge: use av_fast_realloc() 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=20230617220015.12669-3-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