avcodec/evc_ps: make ff_evc_parse_{sps,pps} return an error code
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
5cb9ef9300
commit
921596e677
@ -120,24 +120,20 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out)
|
|||||||
nalu_size -= EVC_NALU_HEADER_SIZE;
|
nalu_size -= EVC_NALU_HEADER_SIZE;
|
||||||
|
|
||||||
switch (nalu_type) {
|
switch (nalu_type) {
|
||||||
case EVC_SPS_NUT: {
|
case EVC_SPS_NUT:
|
||||||
EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
|
err = ff_evc_parse_sps(&ctx->ps, nalu, nalu_size);
|
||||||
if (!sps) {
|
if (err < 0) {
|
||||||
av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
|
av_log(bsf, AV_LOG_ERROR, "SPS parsing error\n");
|
||||||
err = AVERROR_INVALIDDATA;
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case EVC_PPS_NUT:
|
||||||
case EVC_PPS_NUT: {
|
err = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
|
||||||
EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, nalu, nalu_size);
|
if (err < 0) {
|
||||||
if (!pps) {
|
|
||||||
av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
|
av_log(bsf, AV_LOG_ERROR, "PPS parsing error\n");
|
||||||
err = AVERROR_INVALIDDATA;
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
@ -63,6 +63,7 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
|
|||||||
{
|
{
|
||||||
EVCParserContext *ctx = s->priv_data;
|
EVCParserContext *ctx = s->priv_data;
|
||||||
int nalu_type, tid;
|
int nalu_type, tid;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (buf_size <= 0) {
|
if (buf_size <= 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", buf_size);
|
av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit size: (%d)\n", buf_size);
|
||||||
@ -87,29 +88,26 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx,
|
|||||||
buf_size -= EVC_NALU_HEADER_SIZE;
|
buf_size -= EVC_NALU_HEADER_SIZE;
|
||||||
|
|
||||||
switch (nalu_type) {
|
switch (nalu_type) {
|
||||||
case EVC_SPS_NUT: {
|
case EVC_SPS_NUT:
|
||||||
EVCParserSPS *sps = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
|
ret = ff_evc_parse_sps(&ctx->ps, buf, buf_size);
|
||||||
if (!sps) {
|
if (ret < 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
|
av_log(avctx, AV_LOG_ERROR, "SPS parsing error\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return ret;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case EVC_PPS_NUT:
|
||||||
case EVC_PPS_NUT: {
|
ret = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
|
||||||
EVCParserPPS *pps = ff_evc_parse_pps(&ctx->ps, buf, buf_size);
|
if (ret < 0) {
|
||||||
if (!pps) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n");
|
av_log(avctx, AV_LOG_ERROR, "PPS parsing error\n");
|
||||||
return AVERROR_INVALIDDATA;
|
return ret;
|
||||||
}
|
}
|
||||||
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: {
|
||||||
const EVCParserPPS *pps;
|
const EVCParserPPS *pps;
|
||||||
const EVCParserSPS *sps;
|
const EVCParserSPS *sps;
|
||||||
EVCParserSliceHeader sh;
|
EVCParserSliceHeader sh;
|
||||||
int bit_depth;
|
int bit_depth;
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
|
ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -132,26 +132,26 @@ static int vui_parameters(GetBitContext *gb, VUIParameters *vui)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
|
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
|
||||||
EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
||||||
{
|
{
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
EVCParserSPS *sps;
|
EVCParserSPS *sps;
|
||||||
int sps_seq_parameter_set_id;
|
int sps_seq_parameter_set_id;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (init_get_bits8(&gb, bs, bs_size) < 0)
|
ret = init_get_bits8(&gb, bs, bs_size);
|
||||||
return NULL;
|
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)
|
if (sps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT)
|
||||||
return NULL;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
if(!ps->sps[sps_seq_parameter_set_id]) {
|
sps = av_malloc(sizeof(*sps));
|
||||||
if((ps->sps[sps_seq_parameter_set_id] = av_malloc(sizeof(EVCParserSPS))) == NULL)
|
if (!sps)
|
||||||
return NULL;
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
sps = ps->sps[sps_seq_parameter_set_id];
|
|
||||||
memset(sps, 0, sizeof(*sps));
|
memset(sps, 0, sizeof(*sps));
|
||||||
|
|
||||||
sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
|
sps->sps_seq_parameter_set_id = sps_seq_parameter_set_id;
|
||||||
@ -284,7 +284,10 @@ EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
|||||||
// If necessary, add the missing fields to the EVCParserSPS structure
|
// If necessary, add the missing fields to the EVCParserSPS structure
|
||||||
// and then extend parser implementation
|
// and then extend parser implementation
|
||||||
|
|
||||||
return sps;
|
av_freep(&ps->sps[sps_seq_parameter_set_id]);
|
||||||
|
ps->sps[sps_seq_parameter_set_id] = sps;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
|
// @see ISO_IEC_23094-1 (7.3.2.2 SPS RBSP syntax)
|
||||||
@ -294,34 +297,33 @@ EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
|||||||
// If it will be needed, parse_sps function could be extended to handle VUI parameters parsing
|
// 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
|
// to initialize fields of the AVCodecContex i.e. color_primaries, color_trc,color_range
|
||||||
//
|
//
|
||||||
EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
||||||
{
|
{
|
||||||
GetBitContext gb;
|
GetBitContext gb;
|
||||||
EVCParserPPS *pps;
|
EVCParserPPS *pps;
|
||||||
|
|
||||||
int pps_pic_parameter_set_id;
|
int pps_pic_parameter_set_id;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (init_get_bits8(&gb, bs, bs_size) < 0)
|
ret = init_get_bits8(&gb, bs, bs_size);
|
||||||
return NULL;
|
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)
|
if (pps_pic_parameter_set_id > EVC_MAX_PPS_COUNT)
|
||||||
return NULL;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
if(!ps->pps[pps_pic_parameter_set_id]) {
|
pps = av_malloc(sizeof(*pps));
|
||||||
if ((ps->pps[pps_pic_parameter_set_id] = av_malloc(sizeof(EVCParserPPS))) == NULL)
|
if (!pps)
|
||||||
return NULL;
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
pps = ps->pps[pps_pic_parameter_set_id];
|
|
||||||
memset(pps, 0, sizeof(*pps));
|
memset(pps, 0, sizeof(*pps));
|
||||||
|
|
||||||
pps->pps_pic_parameter_set_id = pps_pic_parameter_set_id;
|
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) {
|
if (pps->pps_seq_parameter_set_id >= EVC_MAX_SPS_COUNT) {
|
||||||
av_freep(&ps->pps[pps_pic_parameter_set_id]);
|
ret = AVERROR_INVALIDDATA;
|
||||||
return NULL;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
|
pps->num_ref_idx_default_active_minus1[0] = get_ue_golomb(&gb);
|
||||||
@ -369,7 +371,13 @@ EVCParserPPS *ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size)
|
|||||||
if (pps->cu_qp_delta_enabled_flag)
|
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);
|
||||||
|
|
||||||
return pps;
|
av_freep(&ps->pps[pps_pic_parameter_set_id]);
|
||||||
|
ps->pps[pps_pic_parameter_set_id] = pps;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
fail:
|
||||||
|
av_free(pps);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ff_evc_ps_free(EVCParamSets *ps) {
|
void ff_evc_ps_free(EVCParamSets *ps) {
|
||||||
|
@ -218,10 +218,10 @@ typedef struct EVCParamSets {
|
|||||||
} EVCParamSets;
|
} EVCParamSets;
|
||||||
|
|
||||||
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
|
// @see ISO_IEC_23094-1 (7.3.2.1 SPS RBSP syntax)
|
||||||
EVCParserSPS *ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
|
int ff_evc_parse_sps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
|
||||||
|
|
||||||
// @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(EVCParamSets *ps, const uint8_t *bs, int bs_size);
|
int ff_evc_parse_pps(EVCParamSets *ps, const uint8_t *bs, int bs_size);
|
||||||
|
|
||||||
void ff_evc_ps_free(EVCParamSets *ps);
|
void ff_evc_ps_free(EVCParamSets *ps);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user