Commit 26513529 authored by Mark Thompson's avatar Mark Thompson

cbs: Allocate the context inside the init function

... instead of making callers allocate it themselves.  This is more
consistent with other APIs in libav.
parent cc1c94da
...@@ -39,9 +39,10 @@ static const CodedBitstreamType *cbs_type_table[] = { ...@@ -39,9 +39,10 @@ static const CodedBitstreamType *cbs_type_table[] = {
#endif #endif
}; };
int ff_cbs_init(CodedBitstreamContext *ctx, int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
enum AVCodecID codec_id, void *log_ctx) enum AVCodecID codec_id, void *log_ctx)
{ {
CodedBitstreamContext *ctx;
const CodedBitstreamType *type; const CodedBitstreamType *type;
int i; int i;
...@@ -55,27 +56,40 @@ int ff_cbs_init(CodedBitstreamContext *ctx, ...@@ -55,27 +56,40 @@ int ff_cbs_init(CodedBitstreamContext *ctx,
if (!type) if (!type)
return AVERROR(EINVAL); return AVERROR(EINVAL);
ctx = av_mallocz(sizeof(*ctx));
if (!ctx)
return AVERROR(ENOMEM);
ctx->log_ctx = log_ctx; ctx->log_ctx = log_ctx;
ctx->codec = type; ctx->codec = type;
ctx->priv_data = av_mallocz(ctx->codec->priv_data_size); ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
if (!ctx->priv_data) if (!ctx->priv_data) {
av_freep(&ctx);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
}
ctx->decompose_unit_types = NULL; ctx->decompose_unit_types = NULL;
ctx->trace_enable = 0; ctx->trace_enable = 0;
ctx->trace_level = AV_LOG_TRACE; ctx->trace_level = AV_LOG_TRACE;
*ctx_ptr = ctx;
return 0; return 0;
} }
void ff_cbs_close(CodedBitstreamContext *ctx) void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
{ {
CodedBitstreamContext *ctx = *ctx_ptr;
if (!ctx)
return;
if (ctx->codec && ctx->codec->close) if (ctx->codec && ctx->codec->close)
ctx->codec->close(ctx); ctx->codec->close(ctx);
av_freep(&ctx->priv_data); av_freep(&ctx->priv_data);
av_freep(ctx_ptr);
} }
static void cbs_unit_uninit(CodedBitstreamContext *ctx, static void cbs_unit_uninit(CodedBitstreamContext *ctx,
......
...@@ -169,15 +169,15 @@ typedef struct CodedBitstreamContext { ...@@ -169,15 +169,15 @@ typedef struct CodedBitstreamContext {
/** /**
* Initialise a new context for the given codec. * Create and initialise a new context for the given codec.
*/ */
int ff_cbs_init(CodedBitstreamContext *ctx, int ff_cbs_init(CodedBitstreamContext **ctx,
enum AVCodecID codec_id, void *log_ctx); enum AVCodecID codec_id, void *log_ctx);
/** /**
* Close a context and free all internal state. * Close a context and free all internal state.
*/ */
void ff_cbs_close(CodedBitstreamContext *ctx); void ff_cbs_close(CodedBitstreamContext **ctx);
/** /**
......
...@@ -35,7 +35,7 @@ enum { ...@@ -35,7 +35,7 @@ enum {
typedef struct H264MetadataContext { typedef struct H264MetadataContext {
const AVClass *class; const AVClass *class;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment access_unit; CodedBitstreamFragment access_unit;
H264RawAUD aud_nal; H264RawAUD aud_nal;
...@@ -214,7 +214,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -214,7 +214,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
if (err < 0) if (err < 0)
goto fail; goto fail;
err = ff_cbs_read_packet(&ctx->cbc, au, in); err = ff_cbs_read_packet(ctx->cbc, au, in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail; goto fail;
...@@ -229,7 +229,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -229,7 +229,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
// If an AUD is present, it must be the first NAL unit. // If an AUD is present, it must be the first NAL unit.
if (au->units[0].type == H264_NAL_AUD) { if (au->units[0].type == H264_NAL_AUD) {
if (ctx->aud == REMOVE) if (ctx->aud == REMOVE)
ff_cbs_delete_unit(&ctx->cbc, au, 0); ff_cbs_delete_unit(ctx->cbc, au, 0);
} else { } else {
if (ctx->aud == INSERT) { if (ctx->aud == INSERT) {
static const int primary_pic_type_table[] = { static const int primary_pic_type_table[] = {
...@@ -269,7 +269,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -269,7 +269,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
aud->nal_unit_header.nal_unit_type = H264_NAL_AUD; aud->nal_unit_header.nal_unit_type = H264_NAL_AUD;
aud->primary_pic_type = j; aud->primary_pic_type = j;
err = ff_cbs_insert_unit_content(&ctx->cbc, au, err = ff_cbs_insert_unit_content(ctx->cbc, au,
0, H264_NAL_AUD, aud); 0, H264_NAL_AUD, aud);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
...@@ -314,7 +314,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -314,7 +314,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
sei->nal_unit_header.nal_unit_type = H264_NAL_SEI; sei->nal_unit_header.nal_unit_type = H264_NAL_SEI;
err = ff_cbs_insert_unit_content(&ctx->cbc, au, err = ff_cbs_insert_unit_content(ctx->cbc, au,
sei_pos, H264_NAL_SEI, sei); sei_pos, H264_NAL_SEI, sei);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to insert SEI.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to insert SEI.\n");
...@@ -375,7 +375,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -375,7 +375,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
++sei->payload_count; ++sei->payload_count;
} }
err = ff_cbs_write_packet(&ctx->cbc, out, au); err = ff_cbs_write_packet(ctx->cbc, out, au);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail; goto fail;
...@@ -387,7 +387,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -387,7 +387,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, au); ff_cbs_fragment_uninit(ctx->cbc, au);
av_freep(&sei_udu_string); av_freep(&sei_udu_string);
av_packet_free(&in); av_packet_free(&in);
...@@ -406,7 +406,7 @@ static int h264_metadata_init(AVBSFContext *bsf) ...@@ -406,7 +406,7 @@ static int h264_metadata_init(AVBSFContext *bsf)
return err; return err;
if (bsf->par_in->extradata) { if (bsf->par_in->extradata) {
err = ff_cbs_read_extradata(&ctx->cbc, au, bsf->par_in); err = ff_cbs_read_extradata(ctx->cbc, au, bsf->par_in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
goto fail; goto fail;
...@@ -420,7 +420,7 @@ static int h264_metadata_init(AVBSFContext *bsf) ...@@ -420,7 +420,7 @@ static int h264_metadata_init(AVBSFContext *bsf)
} }
} }
err = ff_cbs_write_extradata(&ctx->cbc, bsf->par_out, au); err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, au);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
goto fail; goto fail;
...@@ -429,7 +429,7 @@ static int h264_metadata_init(AVBSFContext *bsf) ...@@ -429,7 +429,7 @@ static int h264_metadata_init(AVBSFContext *bsf)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, au); ff_cbs_fragment_uninit(ctx->cbc, au);
return err; return err;
} }
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
typedef struct H264RedundantPPSContext { typedef struct H264RedundantPPSContext {
CodedBitstreamContext input; CodedBitstreamContext *input;
CodedBitstreamContext output; CodedBitstreamContext *output;
CodedBitstreamFragment access_unit; CodedBitstreamFragment access_unit;
...@@ -77,7 +77,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -77,7 +77,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
if (err < 0) if (err < 0)
return err; return err;
err = ff_cbs_read_packet(&ctx->input, au, in); err = ff_cbs_read_packet(ctx->input, au, in);
if (err < 0) if (err < 0)
return err; return err;
...@@ -92,7 +92,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -92,7 +92,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
if (!au_has_sps) { if (!au_has_sps) {
av_log(ctx, AV_LOG_VERBOSE, "Deleting redundant PPS " av_log(ctx, AV_LOG_VERBOSE, "Deleting redundant PPS "
"at %"PRId64".\n", in->pts); "at %"PRId64".\n", in->pts);
ff_cbs_delete_unit(&ctx->input, au, i); ff_cbs_delete_unit(ctx->input, au, i);
} }
} }
if (nal->type == H264_NAL_SLICE || if (nal->type == H264_NAL_SLICE ||
...@@ -102,11 +102,11 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -102,11 +102,11 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
} }
} }
err = ff_cbs_write_packet(&ctx->output, out, au); err = ff_cbs_write_packet(ctx->output, out, au);
if (err < 0) if (err < 0)
return err; return err;
ff_cbs_fragment_uninit(&ctx->output, au); ff_cbs_fragment_uninit(ctx->output, au);
err = av_packet_copy_props(out, in); err = av_packet_copy_props(out, in);
if (err < 0) if (err < 0)
...@@ -134,7 +134,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) ...@@ -134,7 +134,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf)
ctx->global_pic_init_qp = 26; ctx->global_pic_init_qp = 26;
if (bsf->par_in->extradata) { if (bsf->par_in->extradata) {
err = ff_cbs_read_extradata(&ctx->input, au, bsf->par_in); err = ff_cbs_read_extradata(ctx->input, au, bsf->par_in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
return err; return err;
...@@ -145,13 +145,13 @@ static int h264_redundant_pps_init(AVBSFContext *bsf) ...@@ -145,13 +145,13 @@ static int h264_redundant_pps_init(AVBSFContext *bsf)
h264_redundant_pps_fixup_pps(ctx, au->units[i].content); h264_redundant_pps_fixup_pps(ctx, au->units[i].content);
} }
err = ff_cbs_write_extradata(&ctx->output, bsf->par_out, au); err = ff_cbs_write_extradata(ctx->output, bsf->par_out, au);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
return err; return err;
} }
ff_cbs_fragment_uninit(&ctx->output, au); ff_cbs_fragment_uninit(ctx->output, au);
} }
return 0; return 0;
......
...@@ -33,7 +33,7 @@ enum { ...@@ -33,7 +33,7 @@ enum {
typedef struct H265MetadataContext { typedef struct H265MetadataContext {
const AVClass *class; const AVClass *class;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment access_unit; CodedBitstreamFragment access_unit;
H265RawAUD aud_nal; H265RawAUD aud_nal;
...@@ -241,7 +241,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -241,7 +241,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
if (err < 0) if (err < 0)
goto fail; goto fail;
err = ff_cbs_read_packet(&ctx->cbc, au, in); err = ff_cbs_read_packet(ctx->cbc, au, in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail; goto fail;
...@@ -256,7 +256,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -256,7 +256,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
// If an AUD is present, it must be the first NAL unit. // If an AUD is present, it must be the first NAL unit.
if (au->units[0].type == HEVC_NAL_AUD) { if (au->units[0].type == HEVC_NAL_AUD) {
if (ctx->aud == REMOVE) if (ctx->aud == REMOVE)
ff_cbs_delete_unit(&ctx->cbc, au, 0); ff_cbs_delete_unit(ctx->cbc, au, 0);
} else { } else {
if (ctx->aud == INSERT) { if (ctx->aud == INSERT) {
H265RawAUD *aud = &ctx->aud_nal; H265RawAUD *aud = &ctx->aud_nal;
...@@ -288,7 +288,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -288,7 +288,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
}; };
aud->pic_type = pic_type; aud->pic_type = pic_type;
err = ff_cbs_insert_unit_content(&ctx->cbc, au, err = ff_cbs_insert_unit_content(ctx->cbc, au,
0, HEVC_NAL_AUD, aud); 0, HEVC_NAL_AUD, aud);
if (err) { if (err) {
av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to insert AUD.\n");
...@@ -310,7 +310,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -310,7 +310,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
} }
} }
err = ff_cbs_write_packet(&ctx->cbc, out, au); err = ff_cbs_write_packet(ctx->cbc, out, au);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail; goto fail;
...@@ -322,7 +322,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -322,7 +322,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, au); ff_cbs_fragment_uninit(ctx->cbc, au);
av_packet_free(&in); av_packet_free(&in);
...@@ -340,7 +340,7 @@ static int h265_metadata_init(AVBSFContext *bsf) ...@@ -340,7 +340,7 @@ static int h265_metadata_init(AVBSFContext *bsf)
return err; return err;
if (bsf->par_in->extradata) { if (bsf->par_in->extradata) {
err = ff_cbs_read_extradata(&ctx->cbc, au, bsf->par_in); err = ff_cbs_read_extradata(ctx->cbc, au, bsf->par_in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
goto fail; goto fail;
...@@ -359,7 +359,7 @@ static int h265_metadata_init(AVBSFContext *bsf) ...@@ -359,7 +359,7 @@ static int h265_metadata_init(AVBSFContext *bsf)
} }
} }
err = ff_cbs_write_extradata(&ctx->cbc, bsf->par_out, au); err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, au);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
goto fail; goto fail;
...@@ -368,7 +368,7 @@ static int h265_metadata_init(AVBSFContext *bsf) ...@@ -368,7 +368,7 @@ static int h265_metadata_init(AVBSFContext *bsf)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, au); ff_cbs_fragment_uninit(ctx->cbc, au);
return err; return err;
} }
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
typedef struct MPEG2MetadataContext { typedef struct MPEG2MetadataContext {
const AVClass *class; const AVClass *class;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment fragment; CodedBitstreamFragment fragment;
MPEG2RawExtensionData sequence_display_extension; MPEG2RawExtensionData sequence_display_extension;
...@@ -165,7 +165,7 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, ...@@ -165,7 +165,7 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf,
if (add_sde) { if (add_sde) {
int err; int err;
err = ff_cbs_insert_unit_content(&ctx->cbc, frag, se_pos + 1, err = ff_cbs_insert_unit_content(ctx->cbc, frag, se_pos + 1,
MPEG2_START_EXTENSION, MPEG2_START_EXTENSION,
&ctx->sequence_display_extension); &ctx->sequence_display_extension);
if (err < 0) { if (err < 0) {
...@@ -189,7 +189,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -189,7 +189,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out)
if (err < 0) if (err < 0)
goto fail; goto fail;
err = ff_cbs_read_packet(&ctx->cbc, frag, in); err = ff_cbs_read_packet(ctx->cbc, frag, in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail; goto fail;
...@@ -201,7 +201,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -201,7 +201,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out)
goto fail; goto fail;
} }
err = ff_cbs_write_packet(&ctx->cbc, out, frag); err = ff_cbs_write_packet(ctx->cbc, out, frag);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail; goto fail;
...@@ -215,7 +215,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out) ...@@ -215,7 +215,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, frag); ff_cbs_fragment_uninit(ctx->cbc, frag);
av_packet_free(&in); av_packet_free(&in);
...@@ -233,7 +233,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf) ...@@ -233,7 +233,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf)
return err; return err;
if (bsf->par_in->extradata) { if (bsf->par_in->extradata) {
err = ff_cbs_read_extradata(&ctx->cbc, frag, bsf->par_in); err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
goto fail; goto fail;
...@@ -245,7 +245,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf) ...@@ -245,7 +245,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf)
goto fail; goto fail;
} }
err = ff_cbs_write_extradata(&ctx->cbc, bsf->par_out, frag); err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
goto fail; goto fail;
...@@ -254,7 +254,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf) ...@@ -254,7 +254,7 @@ static int mpeg2_metadata_init(AVBSFContext *bsf)
err = 0; err = 0;
fail: fail:
ff_cbs_fragment_uninit(&ctx->cbc, frag); ff_cbs_fragment_uninit(ctx->cbc, frag);
return err; return err;
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
typedef struct TraceHeadersContext { typedef struct TraceHeadersContext {
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
} TraceHeadersContext; } TraceHeadersContext;
...@@ -40,21 +40,21 @@ static int trace_headers_init(AVBSFContext *bsf) ...@@ -40,21 +40,21 @@ static int trace_headers_init(AVBSFContext *bsf)
if (err < 0) if (err < 0)
return err; return err;
ctx->cbc.trace_enable = 1; ctx->cbc->trace_enable = 1;
ctx->cbc.trace_level = AV_LOG_INFO; ctx->cbc->trace_level = AV_LOG_INFO;
if (bsf->par_in->extradata) { if (bsf->par_in->extradata) {
CodedBitstreamFragment ps; CodedBitstreamFragment ps;
av_log(bsf, AV_LOG_INFO, "Extradata\n"); av_log(bsf, AV_LOG_INFO, "Extradata\n");
err = ff_cbs_read_extradata(&ctx->cbc, &ps, bsf->par_in); err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in);
if (err < 0) { if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
return err; return err;
} }
ff_cbs_fragment_uninit(&ctx->cbc, &ps); ff_cbs_fragment_uninit(ctx->cbc, &ps);
} }
return 0; return 0;
...@@ -97,11 +97,11 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *out) ...@@ -97,11 +97,11 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *out)
av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", in->size, tmp); av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", in->size, tmp);
err = ff_cbs_read_packet(&ctx->cbc, &au, in); err = ff_cbs_read_packet(ctx->cbc, &au, in);
if (err < 0) if (err < 0)
return err; return err;
ff_cbs_fragment_uninit(&ctx->cbc, &au); ff_cbs_fragment_uninit(ctx->cbc, &au);
av_packet_move_ref(out, in); av_packet_move_ref(out, in);
av_packet_free(&in); av_packet_free(&in);
......
...@@ -78,7 +78,7 @@ typedef struct VAAPIEncodeH264Context { ...@@ -78,7 +78,7 @@ typedef struct VAAPIEncodeH264Context {
int cpb_delay; int cpb_delay;
int dpb_delay; int dpb_delay;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment current_access_unit; CodedBitstreamFragment current_access_unit;
int aud_needed; int aud_needed;
int sei_needed; int sei_needed;
...@@ -104,7 +104,7 @@ static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx, ...@@ -104,7 +104,7 @@ static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx,
VAAPIEncodeH264Context *priv = ctx->priv_data; VAAPIEncodeH264Context *priv = ctx->priv_data;
int err; int err;
err = ff_cbs_write_fragment_data(&priv->cbc, au); err = ff_cbs_write_fragment_data(priv->cbc, au);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n"); av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
return err; return err;
...@@ -132,7 +132,7 @@ static int vaapi_encode_h264_add_nal(AVCodecContext *avctx, ...@@ -132,7 +132,7 @@ static int vaapi_encode_h264_add_nal(AVCodecContext *avctx,
H264RawNALUnitHeader *header = nal_unit; H264RawNALUnitHeader *header = nal_unit;
int err; int err;
err = ff_cbs_insert_unit_content(&priv->cbc, au, -1, err = ff_cbs_insert_unit_content(priv->cbc, au, -1,
header->nal_unit_type, nal_unit); header->nal_unit_type, nal_unit);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: " av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
...@@ -168,7 +168,7 @@ static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, ...@@ -168,7 +168,7 @@ static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au); err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
return err; return err;
} }
...@@ -195,7 +195,7 @@ static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, ...@@ -195,7 +195,7 @@ static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au); err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
return err; return err;
} }
...@@ -255,7 +255,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, ...@@ -255,7 +255,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
if (err < 0) if (err < 0)
goto fail; goto fail;
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
*type = VAEncPackedHeaderRawData; *type = VAEncPackedHeaderRawData;
return 0; return 0;
...@@ -277,7 +277,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, ...@@ -277,7 +277,7 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
} }
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
return err; return err;
} }
......
...@@ -55,7 +55,7 @@ typedef struct VAAPIEncodeH265Context { ...@@ -55,7 +55,7 @@ typedef struct VAAPIEncodeH265Context {
int slice_type; int slice_type;
int pic_type; int pic_type;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment current_access_unit; CodedBitstreamFragment current_access_unit;
int aud_needed; int aud_needed;
} VAAPIEncodeH265Context; } VAAPIEncodeH265Context;
...@@ -76,7 +76,7 @@ static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx, ...@@ -76,7 +76,7 @@ static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx,
VAAPIEncodeH265Context *priv = ctx->priv_data; VAAPIEncodeH265Context *priv = ctx->priv_data;
int err; int err;
err = ff_cbs_write_fragment_data(&priv->cbc, au); err = ff_cbs_write_fragment_data(priv->cbc, au);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n"); av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
return err; return err;
...@@ -104,7 +104,7 @@ static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, ...@@ -104,7 +104,7 @@ static int vaapi_encode_h265_add_nal(AVCodecContext *avctx,
H265RawNALUnitHeader *header = nal_unit; H265RawNALUnitHeader *header = nal_unit;
int err; int err;
err = ff_cbs_insert_unit_content(&priv->cbc, au, -1, err = ff_cbs_insert_unit_content(priv->cbc, au, -1,
header->nal_unit_type, nal_unit); header->nal_unit_type, nal_unit);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: " av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
...@@ -144,7 +144,7 @@ static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx, ...@@ -144,7 +144,7 @@ static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au); err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
return err; return err;
} }
...@@ -171,7 +171,7 @@ static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx, ...@@ -171,7 +171,7 @@ static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au); err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, au); ff_cbs_fragment_uninit(priv->cbc, au);
return err; return err;
} }
......
...@@ -52,7 +52,7 @@ typedef struct VAAPIEncodeMPEG2Context { ...@@ -52,7 +52,7 @@ typedef struct VAAPIEncodeMPEG2Context {
unsigned int f_code_horizontal; unsigned int f_code_horizontal;
unsigned int f_code_vertical; unsigned int f_code_vertical;
CodedBitstreamContext cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment current_fragment; CodedBitstreamFragment current_fragment;
} VAAPIEncodeMPEG2Context; } VAAPIEncodeMPEG2Context;
...@@ -65,7 +65,7 @@ static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, ...@@ -65,7 +65,7 @@ static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx,
VAAPIEncodeMPEG2Context *priv = ctx->priv_data; VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
int err; int err;
err = ff_cbs_write_fragment_data(&priv->cbc, frag); err = ff_cbs_write_fragment_data(priv->cbc, frag);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n"); av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
return err; return err;
...@@ -92,7 +92,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, ...@@ -92,7 +92,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx,
VAAPIEncodeMPEG2Context *priv = ctx->priv_data; VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
int err; int err;
err = ff_cbs_insert_unit_content(&priv->cbc, frag, -1, type, header); err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header);
if (err < 0) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to add header: " av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
"type = %d.\n", type); "type = %d.\n", type);
...@@ -132,7 +132,7 @@ static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, ...@@ -132,7 +132,7 @@ static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx,
err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, frag); ff_cbs_fragment_uninit(priv->cbc, frag);
return 0; return 0;
} }
...@@ -157,7 +157,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, ...@@ -157,7 +157,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx,
err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
fail: fail:
ff_cbs_fragment_uninit(&priv->cbc, frag); ff_cbs_fragment_uninit(priv->cbc, frag);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment