mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-01-21 14:53:10 +00:00
avcodec/hevc_parser: move slice header parsing to its own function
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com> Reviewed-by: Aaron Levinson <alevinsn@aracnet.com> Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
1c088632e9
commit
bf1e3be5a3
@ -92,77 +92,15 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf,
|
|||||||
return END_NOT_FOUND;
|
return END_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal,
|
||||||
* Parse NAL units of found picture and decode some basic information.
|
AVCodecContext *avctx)
|
||||||
*
|
|
||||||
* @param s parser context.
|
|
||||||
* @param avctx codec context.
|
|
||||||
* @param buf buffer with field/frame data.
|
|
||||||
* @param buf_size size of the buffer.
|
|
||||||
*/
|
|
||||||
static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
|
||||||
int buf_size, AVCodecContext *avctx)
|
|
||||||
{
|
{
|
||||||
HEVCParserContext *ctx = s->priv_data;
|
HEVCParserContext *ctx = s->priv_data;
|
||||||
SliceHeader *sh = &ctx->sh;
|
|
||||||
HEVCParamSets *ps = &ctx->ps;
|
HEVCParamSets *ps = &ctx->ps;
|
||||||
HEVCSEIContext *sei = &ctx->sei;
|
HEVCSEIContext *sei = &ctx->sei;
|
||||||
int is_global = buf == avctx->extradata;
|
SliceHeader *sh = &ctx->sh;
|
||||||
int i, ret;
|
|
||||||
|
|
||||||
/* set some sane default values */
|
|
||||||
s->pict_type = AV_PICTURE_TYPE_I;
|
|
||||||
s->key_frame = 0;
|
|
||||||
s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
|
|
||||||
|
|
||||||
ff_hevc_reset_sei(sei);
|
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0,
|
|
||||||
AV_CODEC_ID_HEVC, 1);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
for (i = 0; i < ctx->pkt.nb_nals; i++) {
|
|
||||||
H2645NAL *nal = &ctx->pkt.nals[i];
|
|
||||||
GetBitContext *gb = &nal->gb;
|
GetBitContext *gb = &nal->gb;
|
||||||
int num = 0, den = 0;
|
int i, num = 0, den = 0;
|
||||||
|
|
||||||
|
|
||||||
switch (nal->type) {
|
|
||||||
case HEVC_NAL_VPS:
|
|
||||||
ff_hevc_decode_nal_vps(gb, avctx, ps);
|
|
||||||
break;
|
|
||||||
case HEVC_NAL_SPS:
|
|
||||||
ff_hevc_decode_nal_sps(gb, avctx, ps, 1);
|
|
||||||
break;
|
|
||||||
case HEVC_NAL_PPS:
|
|
||||||
ff_hevc_decode_nal_pps(gb, avctx, ps);
|
|
||||||
break;
|
|
||||||
case HEVC_NAL_SEI_PREFIX:
|
|
||||||
case HEVC_NAL_SEI_SUFFIX:
|
|
||||||
ff_hevc_decode_nal_sei(gb, avctx, sei, ps, nal->type);
|
|
||||||
break;
|
|
||||||
case HEVC_NAL_TRAIL_N:
|
|
||||||
case HEVC_NAL_TRAIL_R:
|
|
||||||
case HEVC_NAL_TSA_N:
|
|
||||||
case HEVC_NAL_TSA_R:
|
|
||||||
case HEVC_NAL_STSA_N:
|
|
||||||
case HEVC_NAL_STSA_R:
|
|
||||||
case HEVC_NAL_RADL_N:
|
|
||||||
case HEVC_NAL_RADL_R:
|
|
||||||
case HEVC_NAL_RASL_N:
|
|
||||||
case HEVC_NAL_RASL_R:
|
|
||||||
case HEVC_NAL_BLA_W_LP:
|
|
||||||
case HEVC_NAL_BLA_W_RADL:
|
|
||||||
case HEVC_NAL_BLA_N_LP:
|
|
||||||
case HEVC_NAL_IDR_W_RADL:
|
|
||||||
case HEVC_NAL_IDR_N_LP:
|
|
||||||
case HEVC_NAL_CRA_NUT:
|
|
||||||
|
|
||||||
if (is_global) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type);
|
|
||||||
return AVERROR_INVALIDDATA;
|
|
||||||
}
|
|
||||||
|
|
||||||
sh->first_slice_in_pic_flag = get_bits1(gb);
|
sh->first_slice_in_pic_flag = get_bits1(gb);
|
||||||
s->picture_structure = sei->picture_timing.picture_struct;
|
s->picture_structure = sei->picture_timing.picture_struct;
|
||||||
@ -229,7 +167,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
|||||||
sh->dependent_slice_segment_flag = 0;
|
sh->dependent_slice_segment_flag = 0;
|
||||||
|
|
||||||
if (sh->dependent_slice_segment_flag)
|
if (sh->dependent_slice_segment_flag)
|
||||||
break;
|
return 0; /* break; */
|
||||||
|
|
||||||
for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++)
|
for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++)
|
||||||
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
|
skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
|
||||||
@ -267,7 +205,82 @@ static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
|||||||
nal->type != HEVC_NAL_RASL_R)
|
nal->type != HEVC_NAL_RASL_R)
|
||||||
ctx->pocTid0 = ctx->poc;
|
ctx->pocTid0 = ctx->poc;
|
||||||
|
|
||||||
return 0; /* no need to evaluate the rest */
|
return 1; /* no need to evaluate the rest */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse NAL units of found picture and decode some basic information.
|
||||||
|
*
|
||||||
|
* @param s parser context.
|
||||||
|
* @param avctx codec context.
|
||||||
|
* @param buf buffer with field/frame data.
|
||||||
|
* @param buf_size size of the buffer.
|
||||||
|
*/
|
||||||
|
static inline int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
||||||
|
int buf_size, AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
HEVCParserContext *ctx = s->priv_data;
|
||||||
|
HEVCParamSets *ps = &ctx->ps;
|
||||||
|
HEVCSEIContext *sei = &ctx->sei;
|
||||||
|
int is_global = buf == avctx->extradata;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
|
/* set some sane default values */
|
||||||
|
s->pict_type = AV_PICTURE_TYPE_I;
|
||||||
|
s->key_frame = 0;
|
||||||
|
s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
|
||||||
|
|
||||||
|
ff_hevc_reset_sei(sei);
|
||||||
|
|
||||||
|
ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, 0, 0,
|
||||||
|
AV_CODEC_ID_HEVC, 1);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
for (i = 0; i < ctx->pkt.nb_nals; i++) {
|
||||||
|
H2645NAL *nal = &ctx->pkt.nals[i];
|
||||||
|
GetBitContext *gb = &nal->gb;
|
||||||
|
|
||||||
|
switch (nal->type) {
|
||||||
|
case HEVC_NAL_VPS:
|
||||||
|
ff_hevc_decode_nal_vps(gb, avctx, ps);
|
||||||
|
break;
|
||||||
|
case HEVC_NAL_SPS:
|
||||||
|
ff_hevc_decode_nal_sps(gb, avctx, ps, 1);
|
||||||
|
break;
|
||||||
|
case HEVC_NAL_PPS:
|
||||||
|
ff_hevc_decode_nal_pps(gb, avctx, ps);
|
||||||
|
break;
|
||||||
|
case HEVC_NAL_SEI_PREFIX:
|
||||||
|
case HEVC_NAL_SEI_SUFFIX:
|
||||||
|
ff_hevc_decode_nal_sei(gb, avctx, sei, ps, nal->type);
|
||||||
|
break;
|
||||||
|
case HEVC_NAL_TRAIL_N:
|
||||||
|
case HEVC_NAL_TRAIL_R:
|
||||||
|
case HEVC_NAL_TSA_N:
|
||||||
|
case HEVC_NAL_TSA_R:
|
||||||
|
case HEVC_NAL_STSA_N:
|
||||||
|
case HEVC_NAL_STSA_R:
|
||||||
|
case HEVC_NAL_RADL_N:
|
||||||
|
case HEVC_NAL_RADL_R:
|
||||||
|
case HEVC_NAL_RASL_N:
|
||||||
|
case HEVC_NAL_RASL_R:
|
||||||
|
case HEVC_NAL_BLA_W_LP:
|
||||||
|
case HEVC_NAL_BLA_W_RADL:
|
||||||
|
case HEVC_NAL_BLA_N_LP:
|
||||||
|
case HEVC_NAL_IDR_W_RADL:
|
||||||
|
case HEVC_NAL_IDR_N_LP:
|
||||||
|
case HEVC_NAL_CRA_NUT:
|
||||||
|
|
||||||
|
if (is_global) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "Invalid NAL unit: %d\n", nal->type);
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = hevc_parse_slice_header(s, nal, avctx);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* didn't find a picture! */
|
/* didn't find a picture! */
|
||||||
|
Loading…
Reference in New Issue
Block a user