mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-11 06:58:18 +00:00
avcodec/evc_parse: use a local EVCParserSliceHeader when parsing slices
There's no need to store EVC_MAX_PPS_COUNT amount of slice headers in EVCParserContext. Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
57879b23bc
commit
44f26315c8
@ -419,40 +419,33 @@ EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
|
// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
|
||||||
EVCParserSliceHeader *ff_evc_parse_slice_header(EVCParserContext *ctx, const uint8_t *bs, int bs_size)
|
static int evc_parse_slice_header(EVCParserContext *ctx, EVCParserSliceHeader *sh, const uint8_t *bs, int bs_size)
|
||||||
{
|
{
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
EVCParserSliceHeader *sh;
|
|
||||||
EVCParserPPS *pps;
|
EVCParserPPS *pps;
|
||||||
EVCParserSPS *sps;
|
EVCParserSPS *sps;
|
||||||
|
|
||||||
int num_tiles_in_slice = 0;
|
int num_tiles_in_slice = 0;
|
||||||
int slice_pic_parameter_set_id;
|
int slice_pic_parameter_set_id;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (init_get_bits8(&gb, bs, bs_size) < 0)
|
if ((ret = init_get_bits8(&gb, bs, bs_size)) < 0)
|
||||||
return NULL;
|
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)
|
if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
|
||||||
return NULL;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
if(!ctx->slice_header[slice_pic_parameter_set_id]) {
|
|
||||||
if((ctx->slice_header[slice_pic_parameter_set_id] = av_malloc(sizeof(EVCParserSliceHeader))) == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sh = ctx->slice_header[slice_pic_parameter_set_id];
|
|
||||||
memset(sh, 0, sizeof(*sh));
|
|
||||||
|
|
||||||
pps = ctx->pps[slice_pic_parameter_set_id];
|
pps = ctx->pps[slice_pic_parameter_set_id];
|
||||||
if(!pps)
|
if(!pps)
|
||||||
return NULL;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
sps = ctx->sps[slice_pic_parameter_set_id];
|
sps = ctx->sps[slice_pic_parameter_set_id];
|
||||||
if(!sps)
|
if(!sps)
|
||||||
return NULL;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
|
memset(sh, 0, sizeof(*sh));
|
||||||
sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;
|
sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;
|
||||||
|
|
||||||
if (!pps->single_tile_in_pic_flag) {
|
if (!pps->single_tile_in_pic_flag) {
|
||||||
@ -540,7 +533,7 @@ EVCParserSliceHeader *ff_evc_parse_slice_header(EVCParserContext *ctx, const uin
|
|||||||
// If necessary, add the missing fields to the EVCParserSliceHeader structure
|
// If necessary, add the missing fields to the EVCParserSliceHeader structure
|
||||||
// and then extend parser implementation
|
// and then extend parser implementation
|
||||||
|
|
||||||
return sh;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
|
int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx)
|
||||||
@ -660,17 +653,17 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
|
|||||||
break;
|
break;
|
||||||
case EVC_IDR_NUT: // Coded slice of a IDR or non-IDR picture
|
case EVC_IDR_NUT: // Coded slice of a IDR or non-IDR picture
|
||||||
case EVC_NOIDR_NUT: {
|
case EVC_NOIDR_NUT: {
|
||||||
EVCParserSliceHeader *sh;
|
EVCParserSliceHeader sh;
|
||||||
EVCParserSPS *sps;
|
EVCParserSPS *sps;
|
||||||
int slice_pic_parameter_set_id;
|
int ret;
|
||||||
|
|
||||||
sh = ff_evc_parse_slice_header(ctx, data, nalu_size);
|
ret = evc_parse_slice_header(ctx, &sh, data, nalu_size);
|
||||||
if (!sh) {
|
if (ret < 0) {
|
||||||
av_log(logctx, AV_LOG_ERROR, "Slice header parsing error\n");
|
av_log(logctx, AV_LOG_ERROR, "Slice header parsing error\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sh->slice_type) {
|
switch (sh.slice_type) {
|
||||||
case EVC_SLICE_TYPE_B: {
|
case EVC_SLICE_TYPE_B: {
|
||||||
ctx->pict_type = AV_PICTURE_TYPE_B;
|
ctx->pict_type = AV_PICTURE_TYPE_B;
|
||||||
break;
|
break;
|
||||||
@ -692,8 +685,7 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
|
|||||||
|
|
||||||
// POC (picture order count of the current picture) derivation
|
// 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
|
// @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
|
||||||
slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id;
|
sps = ctx->sps[sh.slice_pic_parameter_set_id];
|
||||||
sps = ctx->sps[slice_pic_parameter_set_id];
|
|
||||||
|
|
||||||
if (sps && sps->sps_pocs_flag) {
|
if (sps && sps->sps_pocs_flag) {
|
||||||
|
|
||||||
@ -709,20 +701,20 @@ int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_siz
|
|||||||
int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb;
|
int prevPicOrderCntMsb = ctx->poc.PicOrderCntVal - prevPicOrderCntLsb;
|
||||||
|
|
||||||
|
|
||||||
if ((sh->slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
|
if ((sh.slice_pic_order_cnt_lsb < prevPicOrderCntLsb) &&
|
||||||
((prevPicOrderCntLsb - sh->slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
|
((prevPicOrderCntLsb - sh.slice_pic_order_cnt_lsb) >= (MaxPicOrderCntLsb / 2)))
|
||||||
|
|
||||||
PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
|
PicOrderCntMsb = prevPicOrderCntMsb + MaxPicOrderCntLsb;
|
||||||
|
|
||||||
else if ((sh->slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
|
else if ((sh.slice_pic_order_cnt_lsb > prevPicOrderCntLsb) &&
|
||||||
((sh->slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
|
((sh.slice_pic_order_cnt_lsb - prevPicOrderCntLsb) > (MaxPicOrderCntLsb / 2)))
|
||||||
|
|
||||||
PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
|
PicOrderCntMsb = prevPicOrderCntMsb - MaxPicOrderCntLsb;
|
||||||
|
|
||||||
else
|
else
|
||||||
PicOrderCntMsb = prevPicOrderCntMsb;
|
PicOrderCntMsb = prevPicOrderCntMsb;
|
||||||
}
|
}
|
||||||
ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh->slice_pic_order_cnt_lsb;
|
ctx->poc.PicOrderCntVal = PicOrderCntMsb + sh.slice_pic_order_cnt_lsb;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (nalu_type == EVC_IDR_NUT) {
|
if (nalu_type == EVC_IDR_NUT) {
|
||||||
|
@ -261,7 +261,6 @@ typedef struct EVCParserContext {
|
|||||||
//ParseContext pc;
|
//ParseContext pc;
|
||||||
EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
|
EVCParserSPS *sps[EVC_MAX_SPS_COUNT];
|
||||||
EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
|
EVCParserPPS *pps[EVC_MAX_PPS_COUNT];
|
||||||
EVCParserSliceHeader *slice_header[EVC_MAX_PPS_COUNT];
|
|
||||||
|
|
||||||
EVCParserPoc poc;
|
EVCParserPoc poc;
|
||||||
|
|
||||||
@ -349,9 +348,6 @@ EVCParserSPS *ff_evc_parse_sps(EVCParserContext *ctx, const uint8_t *bs, int bs_
|
|||||||
// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
|
// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
|
||||||
EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
|
EVCParserPPS *ff_evc_parse_pps(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
|
||||||
|
|
||||||
// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
|
|
||||||
EVCParserSliceHeader *ff_evc_parse_slice_header(EVCParserContext *ctx, const uint8_t *bs, int bs_size);
|
|
||||||
|
|
||||||
int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
|
int ff_evc_parse_nal_unit(EVCParserContext *ctx, const uint8_t *buf, int buf_size, void *logctx);
|
||||||
|
|
||||||
#endif /* AVCODEC_EVC_PARSE_H */
|
#endif /* AVCODEC_EVC_PARSE_H */
|
||||||
|
@ -209,10 +209,8 @@ static void evc_parser_close(AVCodecParserContext *s)
|
|||||||
|
|
||||||
for(int i = 0; i < EVC_MAX_PPS_COUNT; i++) {
|
for(int i = 0; i < EVC_MAX_PPS_COUNT; i++) {
|
||||||
EVCParserPPS *pps = ctx->pps[i];
|
EVCParserPPS *pps = ctx->pps[i];
|
||||||
EVCParserSliceHeader *sh = ctx->slice_header[i];
|
|
||||||
|
|
||||||
av_freep(&pps);
|
av_freep(&pps);
|
||||||
av_freep(&sh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user