From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: use a GetBitContext to parse entire NALUs
Date: Tue, 20 Jun 2023 11:40:41 -0300
Message-ID: <20230620144042.9629-8-jamrial@gmail.com> (raw)
In-Reply-To: <20230620144042.9629-1-jamrial@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/evc_parse.c | 22 ----------------------
libavcodec/evc_parse.h | 22 ----------------------
libavcodec/evc_parser.c | 30 ++++++++++++------------------
3 files changed, 12 insertions(+), 62 deletions(-)
diff --git a/libavcodec/evc_parse.c b/libavcodec/evc_parse.c
index dee48e947b..eff4b7bc38 100644
--- a/libavcodec/evc_parse.c
+++ b/libavcodec/evc_parse.c
@@ -21,28 +21,6 @@
#include "evc.h"
#include "evc_parse.h"
-// 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 temporal_id = 0;
- uint16_t t = 0;
-
- if (bits_size < EVC_NALU_HEADER_SIZE) {
- av_log(logctx, AV_LOG_ERROR, "Can't read NAL unit header\n");
- return 0;
- }
-
- // forbidden_zero_bit
- if ((bits[0] & 0x80) != 0)
- return -1;
-
- t = AV_RB16(bits);
-
- temporal_id = (t >> 6) & 0x0007;
-
- return temporal_id;
-}
-
// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
const EVCParamSets *ps, enum EVCNALUnitType nalu_type)
diff --git a/libavcodec/evc_parse.h b/libavcodec/evc_parse.h
index 322f52c928..0f142976f5 100644
--- a/libavcodec/evc_parse.h
+++ b/libavcodec/evc_parse.h
@@ -81,25 +81,6 @@ typedef struct EVCParserPoc {
int DocOffset; // the decoding order count of the previous picture
} EVCParserPoc;
-static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size, void *logctx)
-{
- int unit_type_plus1 = 0;
-
- if (bits_size >= EVC_NALU_HEADER_SIZE) {
- unsigned char *p = (unsigned char *)bits;
- // forbidden_zero_bit
- if ((p[0] & 0x80) != 0) {
- av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit header\n");
- return -1;
- }
-
- // nal_unit_type
- unit_type_plus1 = (p[0] >> 1) & 0x3F;
- }
-
- return unit_type_plus1 - 1;
-}
-
static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_size, void *logctx)
{
uint32_t nalu_len = 0;
@@ -114,9 +95,6 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si
return nalu_len;
}
-// 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(GetBitContext *gb, EVCParserSliceHeader *sh,
const EVCParamSets *ps, enum EVCNALUnitType nalu_type);
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index ae399ef8cc..76790d8111 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -71,28 +71,29 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
+ ret = init_get_bits8(&gb, buf, buf_size);
+ if (ret < 0)
+ return ret;
+
// @see ISO_IEC_23094-1_2020, 7.4.2.2 NAL unit header semantic (Table 4 - NAL unit type codes and NAL unit type classes)
// @see enum EVCNALUnitType in evc.h
- nalu_type = evc_get_nalu_type(buf, buf_size, avctx);
- if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
- av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
+ if (get_bits1(&gb)) {// forbidden_zero_bit
+ av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit header\n");
return AVERROR_INVALIDDATA;
}
- tid = ff_evc_get_temporal_id(buf, buf_size, avctx);
- if (tid < 0) {
- av_log(avctx, AV_LOG_ERROR, "Invalid temporial id: (%d)\n", tid);
+ nalu_type = get_bits(&gb, 6) - 1;
+ if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
return AVERROR_INVALIDDATA;
}
- buf += EVC_NALU_HEADER_SIZE;
- buf_size -= EVC_NALU_HEADER_SIZE;
+ tid = get_bits(&gb, 3);
+ skip_bits(&gb, 5); // nuh_reserved_zero_5bits
+ skip_bits1(&gb); // nuh_extension_flag
switch (nalu_type) {
case EVC_SPS_NUT:
- ret = init_get_bits8(&gb, buf, buf_size);
- if (ret < 0)
- return ret;
ret = ff_evc_parse_sps(&gb, &ctx->ps);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
@@ -100,9 +101,6 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
}
break;
case EVC_PPS_NUT:
- ret = init_get_bits8(&gb, buf, buf_size);
- if (ret < 0)
- return ret;
ret = ff_evc_parse_pps(&gb, &ctx->ps);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n");
@@ -116,10 +114,6 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
EVCParserSliceHeader sh;
int bit_depth;
- 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");
--
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".
next prev 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 ` [FFmpeg-devel] [PATCH 6/9] avcodec/evc_parse: pass a GetBitContext to the slice header parsing function James Almer
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 ` James Almer [this message]
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-8-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