* [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback
@ 2023-06-20 14:40 James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 2/9] avformat/evcdec: remove unnecessary av_packet_unref() calls James Almer
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/evcdec.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 890babd3cb..9c4969e78f 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -30,6 +30,7 @@
#include "rawdec.h"
#include "avformat.h"
+#include "avio_internal.h"
#include "internal.h"
@@ -192,8 +193,12 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
}
while(!au_end_found) {
-
uint8_t buf[EVC_NALU_LENGTH_PREFIX_SIZE];
+
+ ret = ffio_ensure_seekback(s->pb, EVC_NALU_LENGTH_PREFIX_SIZE);
+ if (ret < 0)
+ return ret;
+
ret = avio_read(s->pb, (unsigned char *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
if (ret < 0) {
av_packet_unref(pkt);
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 2/9] avformat/evcdec: remove unnecessary av_packet_unref() calls
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 ` James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 3/9] avformat/evcdec: flush the bsf on EOF James Almer
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
And return proper error codes.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/evcdec.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 9c4969e78f..68f3a91e53 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -186,11 +186,8 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
EVCDemuxContext *const c = s->priv_data;
- int eof = avio_feof (s->pb);
- if(eof) {
- av_packet_unref(pkt);
+ if (avio_feof(s->pb))
return AVERROR_EOF;
- }
while(!au_end_found) {
uint8_t buf[EVC_NALU_LENGTH_PREFIX_SIZE];
@@ -200,16 +197,12 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
ret = avio_read(s->pb, (unsigned char *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
- if (ret < 0) {
- av_packet_unref(pkt);
+ if (ret < 0)
return ret;
- }
nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
- if(nalu_size <= 0) {
- av_packet_unref(pkt);
- return -1;
- }
+ if (nalu_size <= 0)
+ return AVERROR_INVALIDDATA;
avio_seek(s->pb, -EVC_NALU_LENGTH_PREFIX_SIZE, SEEK_CUR);
@@ -217,7 +210,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0)
return ret;
if (ret != (nalu_size + EVC_NALU_LENGTH_PREFIX_SIZE))
- return AVERROR(EIO);
+ return AVERROR_INVALIDDATA;
ret = av_bsf_send_packet(c->bsf, pkt);
if (ret < 0) {
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 3/9] avformat/evcdec: flush the bsf on EOF
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 ` James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 4/9] avformat/evcdec: use an unsigned type for nalu_size James Almer
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/evcdec.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 68f3a91e53..842258d229 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -183,15 +183,14 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
int ret;
int32_t nalu_size;
int au_end_found = 0;
-
EVCDemuxContext *const c = s->priv_data;
- if (avio_feof(s->pb))
- return AVERROR_EOF;
-
while(!au_end_found) {
uint8_t buf[EVC_NALU_LENGTH_PREFIX_SIZE];
+ if (avio_feof(s->pb))
+ goto end;
+
ret = ffio_ensure_seekback(s->pb, EVC_NALU_LENGTH_PREFIX_SIZE);
if (ret < 0)
return ret;
@@ -212,6 +211,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret != (nalu_size + EVC_NALU_LENGTH_PREFIX_SIZE))
return AVERROR_INVALIDDATA;
+end:
ret = av_bsf_send_packet(c->bsf, pkt);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Failed to send packet to "
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 4/9] avformat/evcdec: use an unsigned type for nalu_size
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 ` 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
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
But ensure the value returned by evc_read_nal_unit_length() fits in an int.
Should prevent integer overflows later in the code.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/evcdec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index 842258d229..ef743028ae 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -181,7 +181,7 @@ fail:
static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret;
- int32_t nalu_size;
+ uint32_t nalu_size;
int au_end_found = 0;
EVCDemuxContext *const c = s->priv_data;
@@ -200,7 +200,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
- if (nalu_size <= 0)
+ if (!nalu_size || nalu_size > INT_MAX)
return AVERROR_INVALIDDATA;
avio_seek(s->pb, -EVC_NALU_LENGTH_PREFIX_SIZE, SEEK_CUR);
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 5/9] avcodec/evc_ps: pass a GetBitContext to the SPS and PPS parsing functions
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (2 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
This is in preparation for the following patch.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/evc_frame_merge_bsf.c | 11 +-
libavcodec/evc_parser.c | 11 +-
libavcodec/evc_ps.c | 186 +++++++++++++++----------------
libavcodec/evc_ps.h | 5 +-
4 files changed, 109 insertions(+), 104 deletions(-)
diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 8e7ce9a2ab..bd30a09b15 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -75,6 +75,7 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
EVCFMergeContext *ctx = bsf->priv_data;
AVPacket *in = ctx->in;
uint8_t *buffer, *nalu = NULL;
+ GetBitContext gb;
enum EVCNALUnitType nalu_type;
int tid, nalu_size = 0;
int au_end_found = 0;
@@ -121,14 +122,20 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
switch (nalu_type) {
case EVC_SPS_NUT:
- err = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
+ err = init_get_bits8(&gb, nalu, nalu_size);
+ if (err < 0)
+ return err;
+ err = ff_evc_parse_sps(&gb, &ctx->ps);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
goto end;
}
break;
case EVC_PPS_NUT:
- err = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
+ err = init_get_bits8(&gb, nalu, nalu_size);
+ if (err < 0)
+ return err;
+ err = ff_evc_parse_pps(&gb, &ctx->ps);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
goto end;
diff --git a/libavcodec/evc_parser.c b/libavcodec/evc_parser.c
index 5c8fcc5970..8dd6b5fda7 100644
--- a/libavcodec/evc_parser.c
+++ b/libavcodec/evc_parser.c
@@ -62,6 +62,7 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
EVCParserContext *ctx = s->priv_data;
+ GetBitContext gb;
int nalu_type, tid;
int ret;
@@ -89,14 +90,20 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
switch (nalu_type) {
case EVC_SPS_NUT:
- ret = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
+ 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");
return ret;
}
break;
case EVC_PPS_NUT:
- ret = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
+ 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");
return ret;
diff --git a/libavcodec/evc_ps.c b/libavcodec/evc_ps.c
index ed39af104e..156f76554a 100644
--- a/libavcodec/evc_ps.c
+++ b/libavcodec/evc_ps.c
@@ -132,18 +132,13 @@ static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
}
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps)
{
- GetBitContext gb;
EVCParserSPS *sps;
int sps_seq_parameter_set_id;
int ret;
- ret = init_get_bits8(&gb, bs, bs_size);
- if (ret < 0)
- return ret;
-
- sps_seq_parameter_set_id = get_ue_golomb(&gb);
+ sps_seq_parameter_set_id = get_ue_golomb(gb);
if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
return AVERROR_INVALIDDATA;
@@ -158,74 +153,74 @@ int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
// the Baseline profile is indicated by profile_idc eqal to 0
// the Main profile is indicated by profile_idc eqal to 1
- sps->profile_idc = get_bits(&gb, 8);
+ sps->profile_idc = get_bits(gb, 8);
- sps->level_idc = get_bits(&gb, 8);
+ sps->level_idc = get_bits(gb, 8);
- skip_bits_long(&gb, 32); /* skip toolset_idc_h */
- skip_bits_long(&gb, 32); /* skip toolset_idc_l */
+ skip_bits_long(gb, 32); /* skip toolset_idc_h */
+ skip_bits_long(gb, 32); /* skip toolset_idc_l */
// 0 - monochrome
// 1 - 4:2:0
// 2 - 4:2:2
// 3 - 4:4:4
- sps->chroma_format_idc = get_ue_golomb(&gb);
+ sps->chroma_format_idc = get_ue_golomb(gb);
- sps->pic_width_in_luma_samples = get_ue_golomb(&gb);
- sps->pic_height_in_luma_samples = get_ue_golomb(&gb);
+ sps->pic_width_in_luma_samples = get_ue_golomb(gb);
+ sps->pic_height_in_luma_samples = get_ue_golomb(gb);
- sps->bit_depth_luma_minus8 = get_ue_golomb(&gb);
- sps->bit_depth_chroma_minus8 = get_ue_golomb(&gb);
+ sps->bit_depth_luma_minus8 = get_ue_golomb(gb);
+ sps->bit_depth_chroma_minus8 = get_ue_golomb(gb);
- sps->sps_btt_flag = get_bits1(&gb);
+ sps->sps_btt_flag = get_bits1(gb);
if (sps->sps_btt_flag) {
- sps->log2_ctu_size_minus5 = get_ue_golomb(&gb);
- sps->log2_min_cb_size_minus2 = get_ue_golomb(&gb);
- sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(&gb);
- sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(&gb);
- sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(&gb);
+ sps->log2_ctu_size_minus5 = get_ue_golomb(gb);
+ sps->log2_min_cb_size_minus2 = get_ue_golomb(gb);
+ sps->log2_diff_ctu_max_14_cb_size = get_ue_golomb(gb);
+ sps->log2_diff_ctu_max_tt_cb_size = get_ue_golomb(gb);
+ sps->log2_diff_min_cb_min_tt_cb_size_minus2 = get_ue_golomb(gb);
}
- sps->sps_suco_flag = get_bits1(&gb);
+ sps->sps_suco_flag = get_bits1(gb);
if (sps->sps_suco_flag) {
- sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(&gb);
- sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(&gb);
+ sps->log2_diff_ctu_size_max_suco_cb_size = get_ue_golomb(gb);
+ sps->log2_diff_max_suco_min_suco_cb_size = get_ue_golomb(gb);
}
- sps->sps_admvp_flag = get_bits1(&gb);
+ sps->sps_admvp_flag = get_bits1(gb);
if (sps->sps_admvp_flag) {
- sps->sps_affine_flag = get_bits1(&gb);
- sps->sps_amvr_flag = get_bits1(&gb);
- sps->sps_dmvr_flag = get_bits1(&gb);
- sps->sps_mmvd_flag = get_bits1(&gb);
- sps->sps_hmvp_flag = get_bits1(&gb);
+ sps->sps_affine_flag = get_bits1(gb);
+ sps->sps_amvr_flag = get_bits1(gb);
+ sps->sps_dmvr_flag = get_bits1(gb);
+ sps->sps_mmvd_flag = get_bits1(gb);
+ sps->sps_hmvp_flag = get_bits1(gb);
}
- sps->sps_eipd_flag = get_bits1(&gb);
+ sps->sps_eipd_flag = get_bits1(gb);
if (sps->sps_eipd_flag) {
- sps->sps_ibc_flag = get_bits1(&gb);
+ sps->sps_ibc_flag = get_bits1(gb);
if (sps->sps_ibc_flag)
- sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(&gb);
+ sps->log2_max_ibc_cand_size_minus2 = get_ue_golomb(gb);
}
- sps->sps_cm_init_flag = get_bits1(&gb);
+ sps->sps_cm_init_flag = get_bits1(gb);
if (sps->sps_cm_init_flag)
- sps->sps_adcc_flag = get_bits1(&gb);
+ sps->sps_adcc_flag = get_bits1(gb);
- sps->sps_iqt_flag = get_bits1(&gb);
+ sps->sps_iqt_flag = get_bits1(gb);
if (sps->sps_iqt_flag)
- sps->sps_ats_flag = get_bits1(&gb);
+ sps->sps_ats_flag = get_bits1(gb);
- sps->sps_addb_flag = get_bits1(&gb);
- sps->sps_alf_flag = get_bits1(&gb);
- sps->sps_htdf_flag = get_bits1(&gb);
- sps->sps_rpl_flag = get_bits1(&gb);
- sps->sps_pocs_flag = get_bits1(&gb);
- sps->sps_dquant_flag = get_bits1(&gb);
- sps->sps_dra_flag = get_bits1(&gb);
+ sps->sps_addb_flag = get_bits1(gb);
+ sps->sps_alf_flag = get_bits1(gb);
+ sps->sps_htdf_flag = get_bits1(gb);
+ sps->sps_rpl_flag = get_bits1(gb);
+ sps->sps_pocs_flag = get_bits1(gb);
+ sps->sps_dquant_flag = get_bits1(gb);
+ sps->sps_dra_flag = get_bits1(gb);
if (sps->sps_pocs_flag) {
- sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(&gb);
+ sps->log2_max_pic_order_cnt_lsb_minus4 = get_ue_golomb(gb);
if (sps->log2_max_pic_order_cnt_lsb_minus4 > 12U) {
ret = AVERROR_INVALIDDATA;
goto fail;
@@ -233,65 +228,65 @@ int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
}
if (!sps->sps_pocs_flag || !sps->sps_rpl_flag) {
- sps->log2_sub_gop_length = get_ue_golomb(&gb);
+ sps->log2_sub_gop_length = get_ue_golomb(gb);
if (sps->log2_sub_gop_length > 5U) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
if (sps->log2_sub_gop_length == 0)
- sps->log2_ref_pic_gap_length = get_ue_golomb(&gb);
+ sps->log2_ref_pic_gap_length = get_ue_golomb(gb);
}
if (!sps->sps_rpl_flag)
- sps->max_num_tid0_ref_pics = get_ue_golomb(&gb);
+ sps->max_num_tid0_ref_pics = get_ue_golomb(gb);
else {
- sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(&gb);
- sps->long_term_ref_pic_flag = get_bits1(&gb);
- sps->rpl1_same_as_rpl0_flag = get_bits1(&gb);
- sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(&gb);
+ sps->sps_max_dec_pic_buffering_minus1 = get_ue_golomb(gb);
+ sps->long_term_ref_pic_flag = get_bits1(gb);
+ sps->rpl1_same_as_rpl0_flag = get_bits1(gb);
+ sps->num_ref_pic_list_in_sps[0] = get_ue_golomb(gb);
for (int i = 0; i < sps->num_ref_pic_list_in_sps[0]; ++i)
- ref_pic_list_struct(&gb, &sps->rpls[0][i]);
+ ref_pic_list_struct(gb, &sps->rpls[0][i]);
if (!sps->rpl1_same_as_rpl0_flag) {
- sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(&gb);
+ sps->num_ref_pic_list_in_sps[1] = get_ue_golomb(gb);
for (int i = 0; i < sps->num_ref_pic_list_in_sps[1]; ++i)
- ref_pic_list_struct(&gb, &sps->rpls[1][i]);
+ ref_pic_list_struct(gb, &sps->rpls[1][i]);
}
}
- sps->picture_cropping_flag = get_bits1(&gb);
+ sps->picture_cropping_flag = get_bits1(gb);
if (sps->picture_cropping_flag) {
- sps->picture_crop_left_offset = get_ue_golomb(&gb);
- sps->picture_crop_right_offset = get_ue_golomb(&gb);
- sps->picture_crop_top_offset = get_ue_golomb(&gb);
- sps->picture_crop_bottom_offset = get_ue_golomb(&gb);
+ sps->picture_crop_left_offset = get_ue_golomb(gb);
+ sps->picture_crop_right_offset = get_ue_golomb(gb);
+ sps->picture_crop_top_offset = get_ue_golomb(gb);
+ sps->picture_crop_bottom_offset = get_ue_golomb(gb);
}
if (sps->chroma_format_idc != 0) {
- sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits1(&gb);
+ sps->chroma_qp_table_struct.chroma_qp_table_present_flag = get_bits1(gb);
if (sps->chroma_qp_table_struct.chroma_qp_table_present_flag) {
- sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits1(&gb);
- sps->chroma_qp_table_struct.global_offset_flag = get_bits1(&gb);
+ sps->chroma_qp_table_struct.same_qp_table_for_chroma = get_bits1(gb);
+ sps->chroma_qp_table_struct.global_offset_flag = get_bits1(gb);
for (int i = 0; i < (sps->chroma_qp_table_struct.same_qp_table_for_chroma ? 1 : 2); i++) {
- sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(&gb);
+ sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] = get_ue_golomb(gb);
if (sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i] >= EVC_MAX_QP_TABLE_SIZE) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
for (int j = 0; j <= sps->chroma_qp_table_struct.num_points_in_qp_table_minus1[i]; j++) {
- sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(&gb, 6);
- sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(&gb);
+ sps->chroma_qp_table_struct.delta_qp_in_val_minus1[i][j] = get_bits(gb, 6);
+ sps->chroma_qp_table_struct.delta_qp_out_val[i][j] = get_se_golomb(gb);
}
}
}
}
- sps->vui_parameters_present_flag = get_bits1(&gb);
+ sps->vui_parameters_present_flag = get_bits1(gb);
if (sps->vui_parameters_present_flag)
- vui_parameters(&gb, &(sps->vui_parameters));
+ vui_parameters(gb, &(sps->vui_parameters));
// @note
// If necessary, add the missing fields to the EVCParserSPS structure
@@ -313,18 +308,13 @@ fail:
// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
//
-int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
+int ff_evc_parse_pps(GetBitContext *gb, EVCParamSets *ps)
{
- GetBitContext gb;
EVCParserPPS *pps;
int pps_pic_parameter_set_id;
int ret;
- ret = init_get_bits8(&gb, bs, bs_size);
- if (ret < 0)
- return ret;
-
- pps_pic_parameter_set_id = get_ue_golomb(&gb);
+ pps_pic_parameter_set_id = get_ue_golomb(gb);
if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
return AVERROR_INVALIDDATA;
@@ -336,65 +326,65 @@ int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
- pps->pps_seq_parameter_set_id = get_ue_golomb(&gb);
+ pps->pps_seq_parameter_set_id = get_ue_golomb(gb);
if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
- pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
- pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(&gb);
- pps->additional_lt_poc_lsb_len = get_ue_golomb(&gb);
- pps->rpl1_idx_present_flag = get_bits1(&gb);
- pps->single_tile_in_pic_flag = get_bits1(&gb);
+ pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(gb);
+ pps->num_ref_idx_default_active_minus1[1] = get_ue_golomb(gb);
+ pps->additional_lt_poc_lsb_len = get_ue_golomb(gb);
+ pps->rpl1_idx_present_flag = get_bits1(gb);
+ pps->single_tile_in_pic_flag = get_bits1(gb);
if (!pps->single_tile_in_pic_flag) {
- pps->num_tile_columns_minus1 = get_ue_golomb(&gb);
- pps->num_tile_rows_minus1 = get_ue_golomb(&gb);
+ pps->num_tile_columns_minus1 = get_ue_golomb(gb);
+ pps->num_tile_rows_minus1 = get_ue_golomb(gb);
if (pps->num_tile_columns_minus1 >= EVC_MAX_TILE_COLUMNS ||
pps->num_tile_rows_minus1 >= EVC_MAX_TILE_ROWS) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
- pps->uniform_tile_spacing_flag = get_bits1(&gb);
+ pps->uniform_tile_spacing_flag = get_bits1(gb);
if (!pps->uniform_tile_spacing_flag) {
for (int i = 0; i < pps->num_tile_columns_minus1; i++)
- pps->tile_column_width_minus1[i] = get_ue_golomb(&gb);
+ pps->tile_column_width_minus1[i] = get_ue_golomb(gb);
for (int i = 0; i < pps->num_tile_rows_minus1; i++)
- pps->tile_row_height_minus1[i] = get_ue_golomb(&gb);
+ pps->tile_row_height_minus1[i] = get_ue_golomb(gb);
}
- pps->loop_filter_across_tiles_enabled_flag = get_bits1(&gb);
- pps->tile_offset_len_minus1 = get_ue_golomb(&gb);
+ pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb);
+ pps->tile_offset_len_minus1 = get_ue_golomb(gb);
}
- pps->tile_id_len_minus1 = get_ue_golomb(&gb);
+ pps->tile_id_len_minus1 = get_ue_golomb(gb);
if (pps->tile_id_len_minus1 > 15U) {
ret = AVERROR_INVALIDDATA;
goto fail;
}
- pps->explicit_tile_id_flag = get_bits1(&gb);
+ pps->explicit_tile_id_flag = get_bits1(gb);
if (pps->explicit_tile_id_flag) {
for (int i = 0; i <= pps->num_tile_rows_minus1; i++) {
for (int j = 0; j <= pps->num_tile_columns_minus1; j++)
- pps->tile_id_val[i][j] = get_bits(&gb, pps->tile_id_len_minus1 + 1);
+ pps->tile_id_val[i][j] = get_bits(gb, pps->tile_id_len_minus1 + 1);
}
}
pps->pic_dra_enabled_flag = 0;
- pps->pic_dra_enabled_flag = get_bits1(&gb);
+ pps->pic_dra_enabled_flag = get_bits1(gb);
if (pps->pic_dra_enabled_flag)
- pps->pic_dra_aps_id = get_bits(&gb, 5);
+ pps->pic_dra_aps_id = get_bits(gb, 5);
- pps->arbitrary_slice_present_flag = get_bits1(&gb);
- pps->constrained_intra_pred_flag = get_bits1(&gb);
- pps->cu_qp_delta_enabled_flag = get_bits1(&gb);
+ pps->arbitrary_slice_present_flag = get_bits1(gb);
+ pps->constrained_intra_pred_flag = get_bits1(gb);
+ pps->cu_qp_delta_enabled_flag = get_bits1(gb);
if (pps->cu_qp_delta_enabled_flag)
- pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(&gb);
+ pps->log2_cu_qp_delta_area_minus6 = get_ue_golomb(gb);
av_freep(&ps->pps[pps_pic_parameter_set_id]);
ps->pps[pps_pic_parameter_set_id] = pps;
diff --git a/libavcodec/evc_ps.h b/libavcodec/evc_ps.h
index c7ed2af37b..5aaa30de20 100644
--- a/libavcodec/evc_ps.h
+++ b/libavcodec/evc_ps.h
@@ -27,6 +27,7 @@
#include <stdint.h>
#include "evc.h"
+#include "get_bits.h"
#define EVC_MAX_QP_TABLE_SIZE 58
#define NUM_CPB 32
@@ -218,10 +219,10 @@ typedef struct EVCParamSets {
} EVCParamSets;
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
-int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+int ff_evc_parse_sps(GetBitContext *gb, EVCParamSets *ps);
// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
-int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
+int ff_evc_parse_pps(GetBitContext *gb, EVCParamSets *ps);
void ff_evc_ps_free(EVCParamSets *ps);
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 6/9] avcodec/evc_parse: pass a GetBitContext to the slice header parsing function
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (3 preceding siblings ...)
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
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 7/9] avcodec/evc_frame_merge: use a GetBitContext to parse entire NALUs James Almer
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 7/9] avcodec/evc_frame_merge: use a GetBitContext to parse entire NALUs
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (4 preceding siblings ...)
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 ` James Almer
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: " James Almer
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavcodec/evc_frame_merge_bsf.c | 48 +++++++++++---------------------
1 file changed, 17 insertions(+), 31 deletions(-)
diff --git a/libavcodec/evc_frame_merge_bsf.c b/libavcodec/evc_frame_merge_bsf.c
index 3904170ebd..a9b44f4d10 100644
--- a/libavcodec/evc_frame_merge_bsf.c
+++ b/libavcodec/evc_frame_merge_bsf.c
@@ -74,57 +74,50 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
{
EVCFMergeContext *ctx = bsf->priv_data;
AVPacket *in = ctx->in;
- uint8_t *buffer, *nalu = NULL;
+ uint8_t *buffer;
GetBitContext gb;
enum EVCNALUnitType nalu_type;
- int tid, nalu_size = 0;
- int au_end_found = 0;
+ uint32_t nalu_size;
+ int tid, au_end_found = 0;
int err;
err = ff_bsf_get_packet_ref(bsf, in);
if (err < 0)
return err;
- nalu_size = evc_read_nal_unit_length(in->data, EVC_NALU_LENGTH_PREFIX_SIZE, bsf);
- if (nalu_size <= 0) {
- err = AVERROR_INVALIDDATA;
- goto end;
- }
-
- nalu = in->data + EVC_NALU_LENGTH_PREFIX_SIZE;
- nalu_size = in->size - EVC_NALU_LENGTH_PREFIX_SIZE;
-
// NAL unit parsing needed to determine if end of AU was found
- if (nalu_size <= 0) {
+ nalu_size = evc_read_nal_unit_length(in->data, EVC_NALU_LENGTH_PREFIX_SIZE, bsf);
+ if (!nalu_size || nalu_size > INT_MAX) {
av_log(bsf, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", nalu_size);
err = AVERROR_INVALIDDATA;
goto end;
}
+ err = init_get_bits8(&gb, in->data + EVC_NALU_LENGTH_PREFIX_SIZE, nalu_size);
+ if (err < 0)
+ return err;
+
// @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(nalu, nalu_size, bsf);
- if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
- av_log(bsf, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
+ if (get_bits1(&gb)) {// forbidden_zero_bit
+ av_log(bsf, AV_LOG_ERROR, "Invalid NAL unit header\n");
err = AVERROR_INVALIDDATA;
goto end;
}
- tid = ff_evc_get_temporal_id(nalu, nalu_size, bsf);
- if (tid < 0) {
- av_log(bsf, 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(bsf, AV_LOG_ERROR, "Invalid NAL unit type: (%d)\n", nalu_type);
err = AVERROR_INVALIDDATA;
goto end;
}
- nalu += EVC_NALU_HEADER_SIZE;
- nalu_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:
- err = init_get_bits8(&gb, nalu, nalu_size);
- if (err < 0)
- return err;
err = ff_evc_parse_sps(&gb, &ctx->ps);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
@@ -132,9 +125,6 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
}
break;
case EVC_PPS_NUT:
- err = init_get_bits8(&gb, nalu, nalu_size);
- if (err < 0)
- return err;
err = ff_evc_parse_pps(&gb, &ctx->ps);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
@@ -145,10 +135,6 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
case EVC_NOIDR_NUT: {
EVCParserSliceHeader sh;
- 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");
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: use a GetBitContext to parse entire NALUs
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (5 preceding siblings ...)
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
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
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 9/9] avformat/evc: move NALU length and type parsing functions to a header
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (6 preceding siblings ...)
2023-06-20 14:40 ` [FFmpeg-devel] [PATCH 8/9] avcodec/evc_parser: " James Almer
@ 2023-06-20 14:40 ` James Almer
2023-06-21 16:31 ` [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-20 14:40 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/evc.c | 5 ++---
libavformat/evc.h | 30 ++++++++++++++++++++++++++++++
libavformat/evcdec.c | 44 ++++----------------------------------------
3 files changed, 36 insertions(+), 43 deletions(-)
diff --git a/libavformat/evc.c b/libavformat/evc.c
index 421ff84cb7..f6e53aa6cf 100644
--- a/libavformat/evc.c
+++ b/libavformat/evc.c
@@ -23,7 +23,6 @@
#include "libavcodec/get_bits.h"
#include "libavcodec/golomb.h"
#include "libavcodec/evc.h"
-#include "libavcodec/evc_parse.h"
#include "avformat.h"
#include "avio.h"
#include "evc.h"
@@ -361,7 +360,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
evcc_init(&evcc);
while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
- nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE, pb);
+ nalu_size = evc_read_nal_unit_length(data, EVC_NALU_LENGTH_PREFIX_SIZE);
if (nalu_size == 0) break;
data += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -369,7 +368,7 @@ int ff_isom_write_evcc(AVIOContext *pb, const uint8_t *data,
if (bytes_to_read < nalu_size) break;
- nalu_type = evc_get_nalu_type(data, bytes_to_read, pb);
+ nalu_type = evc_get_nalu_type(data, bytes_to_read);
if (nalu_type < EVC_NOIDR_NUT || nalu_type > EVC_UNSPEC_NUT62) {
ret = AVERROR_INVALIDDATA;
goto end;
diff --git a/libavformat/evc.h b/libavformat/evc.h
index db56275fd8..46b27f7df7 100644
--- a/libavformat/evc.h
+++ b/libavformat/evc.h
@@ -24,9 +24,39 @@
#include <stdint.h>
#include "libavutil/rational.h"
+#include "libavcodec/evc.h"
#include "avio.h"
+static inline int evc_get_nalu_type(const uint8_t *bits, int bits_size)
+{
+ 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) // Cannot get bitstream information. Malformed bitstream.
+ 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)
+{
+ uint32_t nalu_len = 0;
+
+ if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) {
+ unsigned char *p = (unsigned char *)bits;
+
+ for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
+ nalu_len = (nalu_len << 8) | p[i];
+ }
+
+ return nalu_len;
+}
/**
* Writes EVC sample metadata to the provided AVIOContext.
diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
index ef743028ae..73aab6c52f 100644
--- a/libavformat/evcdec.c
+++ b/libavformat/evcdec.c
@@ -31,6 +31,7 @@
#include "rawdec.h"
#include "avformat.h"
#include "avio_internal.h"
+#include "evc.h"
#include "internal.h"
@@ -59,43 +60,6 @@ static const AVClass evc_demuxer_class = {
.version = LIBAVUTIL_VERSION_INT,
};
-static int get_nalu_type(const uint8_t *bits, int bits_size)
-{
- 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) // Cannot get bitstream information. Malformed bitstream.
- return -1;
-
- // nal_unit_type
- unit_type_plus1 = (p[0] >> 1) & 0x3F;
- }
-
- return unit_type_plus1 - 1;
-}
-
-static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size)
-{
- uint32_t nalu_len = 0;
-
- if (bits_size >= EVC_NALU_LENGTH_PREFIX_SIZE) {
-
- int t = 0;
- unsigned char *p = (unsigned char *)bits;
-
- for (int i = 0; i < EVC_NALU_LENGTH_PREFIX_SIZE; i++)
- t = (t << 8) | p[i];
-
- nalu_len = t;
- if (nalu_len == 0) // Invalid bitstream size
- return 0;
- }
-
- return nalu_len;
-}
-
static int annexb_probe(const AVProbeData *p)
{
int nalu_type;
@@ -106,7 +70,7 @@ static int annexb_probe(const AVProbeData *p)
while (bytes_to_read > EVC_NALU_LENGTH_PREFIX_SIZE) {
- nalu_size = read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
+ nalu_size = evc_read_nal_unit_length(bits, EVC_NALU_LENGTH_PREFIX_SIZE);
if (nalu_size == 0) break;
bits += EVC_NALU_LENGTH_PREFIX_SIZE;
@@ -114,7 +78,7 @@ static int annexb_probe(const AVProbeData *p)
if(bytes_to_read < nalu_size) break;
- nalu_type = get_nalu_type(bits, bytes_to_read);
+ nalu_type = evc_get_nalu_type(bits, bytes_to_read);
if (nalu_type == EVC_SPS_NUT)
got_sps++;
@@ -199,7 +163,7 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0)
return ret;
- nalu_size = read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
+ nalu_size = evc_read_nal_unit_length((const uint8_t *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
if (!nalu_size || nalu_size > INT_MAX)
return AVERROR_INVALIDDATA;
--
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".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback
2023-06-20 14:40 [FFmpeg-devel] [PATCH 1/9] avformat/evcdec: ensure there are enough bytes to seekback James Almer
` (7 preceding siblings ...)
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 ` James Almer
8 siblings, 0 replies; 10+ messages in thread
From: James Almer @ 2023-06-21 16:31 UTC (permalink / raw)
To: ffmpeg-devel
On 6/20/2023 11:40 AM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/evcdec.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c
> index 890babd3cb..9c4969e78f 100644
> --- a/libavformat/evcdec.c
> +++ b/libavformat/evcdec.c
> @@ -30,6 +30,7 @@
>
> #include "rawdec.h"
> #include "avformat.h"
> +#include "avio_internal.h"
> #include "internal.h"
>
>
> @@ -192,8 +193,12 @@ static int evc_read_packet(AVFormatContext *s, AVPacket *pkt)
> }
>
> while(!au_end_found) {
> -
> uint8_t buf[EVC_NALU_LENGTH_PREFIX_SIZE];
> +
> + ret = ffio_ensure_seekback(s->pb, EVC_NALU_LENGTH_PREFIX_SIZE);
> + if (ret < 0)
> + return ret;
> +
> ret = avio_read(s->pb, (unsigned char *)&buf, EVC_NALU_LENGTH_PREFIX_SIZE);
> if (ret < 0) {
> av_packet_unref(pkt);
Will apply set.
_______________________________________________
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] 10+ messages in thread
end of thread, other threads:[~2023-06-21 16:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [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
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