mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-26 01:02:33 +00:00
avcodec/h2645_parse: replace three bool arguments in ff_h2645_packet_split with a single flags one
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
parent
8060644237
commit
a754ee0844
@ -193,7 +193,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
|
ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
|
||||||
ctx, 0, 0, ctx->par_in->codec_id, 1, 0);
|
ctx, 0, ctx->par_in->codec_id, H2645_FLAG_SMALL_PADDING);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -573,7 +573,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
err = ff_h2645_packet_split(&priv->read_packet,
|
err = ff_h2645_packet_split(&priv->read_packet,
|
||||||
frag->data + start, end - start,
|
frag->data + start, end - start,
|
||||||
ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
|
ctx->log_ctx, 2, AV_CODEC_ID_H264,
|
||||||
|
H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n");
|
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n");
|
||||||
return err;
|
return err;
|
||||||
@ -597,7 +598,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
err = ff_h2645_packet_split(&priv->read_packet,
|
err = ff_h2645_packet_split(&priv->read_packet,
|
||||||
frag->data + start, end - start,
|
frag->data + start, end - start,
|
||||||
ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
|
ctx->log_ctx, 2, AV_CODEC_ID_H264,
|
||||||
|
H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n");
|
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n");
|
||||||
return err;
|
return err;
|
||||||
@ -651,7 +653,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
err = ff_h2645_packet_split(&priv->read_packet,
|
err = ff_h2645_packet_split(&priv->read_packet,
|
||||||
frag->data + start, end - start,
|
frag->data + start, end - start,
|
||||||
ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1);
|
ctx->log_ctx, 2, AV_CODEC_ID_HEVC,
|
||||||
|
H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
|
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
|
||||||
"HVCC array %d (%d NAL units of type %d).\n",
|
"HVCC array %d (%d NAL units of type %d).\n",
|
||||||
@ -721,7 +724,8 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
|
|
||||||
err = ff_h2645_packet_split(&priv->read_packet,
|
err = ff_h2645_packet_split(&priv->read_packet,
|
||||||
frag->data + start, end - start,
|
frag->data + start, end - start,
|
||||||
ctx->log_ctx, 1, 2, AV_CODEC_ID_VVC, 1, 1);
|
ctx->log_ctx, 2, AV_CODEC_ID_VVC,
|
||||||
|
H2645_FLAG_IS_NALFF | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
|
av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
|
||||||
"VVCC array %d (%d NAL units of type %d).\n",
|
"VVCC array %d (%d NAL units of type %d).\n",
|
||||||
@ -733,13 +737,14 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
int flags = (H2645_FLAG_IS_NALFF * !!priv->mp4) | H2645_FLAG_SMALL_PADDING | H2645_FLAG_USE_REF;
|
||||||
// Annex B, or later MP4 with already-known parameters.
|
// Annex B, or later MP4 with already-known parameters.
|
||||||
|
|
||||||
err = ff_h2645_packet_split(&priv->read_packet,
|
err = ff_h2645_packet_split(&priv->read_packet,
|
||||||
frag->data, frag->data_size,
|
frag->data, frag->data_size,
|
||||||
ctx->log_ctx,
|
ctx->log_ctx,
|
||||||
priv->mp4, priv->nal_length_size,
|
priv->nal_length_size,
|
||||||
codec_id, 1, 1);
|
codec_id, flags);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -463,16 +463,16 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
||||||
void *logctx, int is_nalff, int nal_length_size,
|
void *logctx, int nal_length_size,
|
||||||
enum AVCodecID codec_id, int small_padding, int use_ref)
|
enum AVCodecID codec_id, int flags)
|
||||||
{
|
{
|
||||||
GetByteContext bc;
|
GetByteContext bc;
|
||||||
int consumed, ret = 0;
|
int consumed, ret = 0;
|
||||||
int next_avc = is_nalff ? 0 : length;
|
int next_avc = (flags & H2645_FLAG_IS_NALFF) ? 0 : length;
|
||||||
int64_t padding = small_padding ? 0 : MAX_MBPAIR_SIZE;
|
int64_t padding = (flags & H2645_FLAG_SMALL_PADDING) ? 0 : MAX_MBPAIR_SIZE;
|
||||||
|
|
||||||
bytestream2_init(&bc, buf, length);
|
bytestream2_init(&bc, buf, length);
|
||||||
alloc_rbsp_buffer(&pkt->rbsp, length + padding, use_ref);
|
alloc_rbsp_buffer(&pkt->rbsp, length + padding, !!(flags & H2645_FLAG_USE_REF));
|
||||||
|
|
||||||
if (!pkt->rbsp.rbsp_buffer)
|
if (!pkt->rbsp.rbsp_buffer)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -549,11 +549,12 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
|||||||
}
|
}
|
||||||
nal = &pkt->nals[pkt->nb_nals];
|
nal = &pkt->nals[pkt->nb_nals];
|
||||||
|
|
||||||
consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal, small_padding);
|
consumed = ff_h2645_extract_rbsp(bc.buffer, extract_length, &pkt->rbsp, nal,
|
||||||
|
!!(flags & H2645_FLAG_SMALL_PADDING));
|
||||||
if (consumed < 0)
|
if (consumed < 0)
|
||||||
return consumed;
|
return consumed;
|
||||||
|
|
||||||
if (is_nalff && (extract_length != consumed) && extract_length)
|
if ((flags & H2645_FLAG_IS_NALFF) && (extract_length != consumed) && extract_length)
|
||||||
av_log(logctx, AV_LOG_DEBUG,
|
av_log(logctx, AV_LOG_DEBUG,
|
||||||
"NALFF: Consumed only %d bytes instead of %d\n",
|
"NALFF: Consumed only %d bytes instead of %d\n",
|
||||||
consumed, extract_length);
|
consumed, extract_length);
|
||||||
|
@ -93,6 +93,12 @@ typedef struct H2645Packet {
|
|||||||
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp,
|
int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp,
|
||||||
H2645NAL *nal, int small_padding);
|
H2645NAL *nal, int small_padding);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
H2645_FLAG_IS_NALFF = (1 << 0),
|
||||||
|
H2645_FLAG_SMALL_PADDING = (1 << 1),
|
||||||
|
H2645_FLAG_USE_REF = (1 << 2),
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split an input packet into NAL units.
|
* Split an input packet into NAL units.
|
||||||
*
|
*
|
||||||
@ -103,13 +109,14 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length, H2645RBSP *rbsp,
|
|||||||
* packet's H2645RBSP.
|
* packet's H2645RBSP.
|
||||||
*
|
*
|
||||||
* If the packet's rbsp_buffer_ref is not NULL, the underlying AVBuffer must
|
* If the packet's rbsp_buffer_ref is not NULL, the underlying AVBuffer must
|
||||||
* own rbsp_buffer. If not and rbsp_buffer is not NULL, use_ref must be 0.
|
* own rbsp_buffer. If not and rbsp_buffer is not NULL, H2645_FLAG_USE_REF
|
||||||
* If use_ref is set, rbsp_buffer will be reference-counted and owned by
|
* must not be set in flags.
|
||||||
* the underlying AVBuffer of rbsp_buffer_ref.
|
* If H2645_FLAG_USE_REF is set in flags, rbsp_buffer will be reference-counted
|
||||||
|
* and owned by the underlying AVBuffer of rbsp_buffer_ref.
|
||||||
*/
|
*/
|
||||||
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
|
||||||
void *logctx, int is_nalff, int nal_length_size,
|
void *logctx, int nal_length_size,
|
||||||
enum AVCodecID codec_id, int small_padding, int use_ref);
|
enum AVCodecID codec_id, int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free all the allocated memory in the packet.
|
* Free all the allocated memory in the packet.
|
||||||
|
@ -368,9 +368,10 @@ static int decode_extradata_ps(const uint8_t *data, int size, H264ParamSets *ps,
|
|||||||
int is_avc, void *logctx)
|
int is_avc, void *logctx)
|
||||||
{
|
{
|
||||||
H2645Packet pkt = { 0 };
|
H2645Packet pkt = { 0 };
|
||||||
|
int flags = (H2645_FLAG_IS_NALFF * !!is_avc) | H2645_FLAG_SMALL_PADDING;
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&pkt, data, size, logctx, is_avc, 2, AV_CODEC_ID_H264, 1, 0);
|
ret = ff_h2645_packet_split(&pkt, data, size, logctx, 2, AV_CODEC_ID_H264, flags);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -612,8 +612,8 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
|
|||||||
h->is_avc = 1;
|
h->is_avc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc, h->nal_length_size,
|
ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->nal_length_size,
|
||||||
avctx->codec_id, 0, 0);
|
avctx->codec_id, !!h->is_avc * H2645_FLAG_IS_NALFF);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(avctx, AV_LOG_ERROR,
|
av_log(avctx, AV_LOG_ERROR,
|
||||||
"Error splitting the input into NAL units.\n");
|
"Error splitting the input into NAL units.\n");
|
||||||
|
@ -3294,6 +3294,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
|
|||||||
{
|
{
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
int eos_at_start = 1;
|
int eos_at_start = 1;
|
||||||
|
int flags = (H2645_FLAG_IS_NALFF * !!s->is_nalff) | H2645_FLAG_SMALL_PADDING;
|
||||||
|
|
||||||
s->cur_frame = s->collocated_ref = NULL;
|
s->cur_frame = s->collocated_ref = NULL;
|
||||||
s->last_eos = s->eos;
|
s->last_eos = s->eos;
|
||||||
@ -3302,8 +3303,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
|
|||||||
|
|
||||||
/* split the input packet into NAL units, so we know the upper bound on the
|
/* split the input packet into NAL units, so we know the upper bound on the
|
||||||
* number of slices in the frame */
|
* number of slices in the frame */
|
||||||
ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx, s->is_nalff,
|
ret = ff_h2645_packet_split(&s->pkt, buf, length, s->avctx,
|
||||||
s->nal_length_size, s->avctx->codec_id, 1, 0);
|
s->nal_length_size, s->avctx->codec_id, flags);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(s->avctx, AV_LOG_ERROR,
|
av_log(s->avctx, AV_LOG_ERROR,
|
||||||
"Error splitting the input into NAL units.\n");
|
"Error splitting the input into NAL units.\n");
|
||||||
|
@ -27,10 +27,11 @@ static int hevc_decode_nal_units(const uint8_t *buf, int buf_size, HEVCParamSets
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int flags = (H2645_FLAG_IS_NALFF * !!is_nalff) | H2645_FLAG_SMALL_PADDING;
|
||||||
H2645Packet pkt = { 0 };
|
H2645Packet pkt = { 0 };
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&pkt, buf, buf_size, logctx, is_nalff,
|
ret = ff_h2645_packet_split(&pkt, buf, buf_size, logctx,
|
||||||
nal_length_size, AV_CODEC_ID_HEVC, 1, 0);
|
nal_length_size, AV_CODEC_ID_HEVC, flags);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -182,6 +182,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
|||||||
HEVCParserContext *ctx = s->priv_data;
|
HEVCParserContext *ctx = s->priv_data;
|
||||||
HEVCParamSets *ps = &ctx->ps;
|
HEVCParamSets *ps = &ctx->ps;
|
||||||
HEVCSEI *sei = &ctx->sei;
|
HEVCSEI *sei = &ctx->sei;
|
||||||
|
int flags = (H2645_FLAG_IS_NALFF * !!ctx->is_avc) | H2645_FLAG_SMALL_PADDING;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
|
|
||||||
/* set some sane default values */
|
/* set some sane default values */
|
||||||
@ -191,8 +192,8 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf,
|
|||||||
|
|
||||||
ff_hevc_reset_sei(sei);
|
ff_hevc_reset_sei(sei);
|
||||||
|
|
||||||
ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx, ctx->is_avc,
|
ret = ff_h2645_packet_split(&ctx->pkt, buf, buf_size, avctx,
|
||||||
ctx->nal_length_size, AV_CODEC_ID_HEVC, 1, 0);
|
ctx->nal_length_size, AV_CODEC_ID_HEVC, flags);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user