1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

vp9_metadata_bsf: Use common cbs bsf implementation

This commit is contained in:
Mark Thompson 2021-01-01 21:35:21 +00:00
parent f35b268327
commit e46aa5a894

View File

@ -21,15 +21,12 @@
#include "libavutil/opt.h"
#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_bsf.h"
#include "cbs_vp9.h"
typedef struct VP9MetadataContext {
const AVClass *class;
CodedBitstreamContext *cbc;
CodedBitstreamFragment fragment;
CBSBSFContext common;
int color_space;
int color_range;
@ -38,21 +35,11 @@ typedef struct VP9MetadataContext {
} VP9MetadataContext;
static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
static int vp9_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt,
CodedBitstreamFragment *frag)
{
VP9MetadataContext *ctx = bsf->priv_data;
CodedBitstreamFragment *frag = &ctx->fragment;
int err, i;
err = ff_bsf_get_packet_ref(bsf, pkt);
if (err < 0)
return err;
err = ff_cbs_read_packet(ctx->cbc, frag, pkt);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n");
goto fail;
}
int i;
for (i = 0; i < frag->nb_units; i++) {
VP9RawFrame *frame = frag->units[i].content;
@ -90,35 +77,19 @@ static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
}
}
err = ff_cbs_write_packet(ctx->cbc, pkt, frag);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n");
goto fail;
}
err = 0;
fail:
ff_cbs_fragment_reset(frag);
if (err < 0)
av_packet_unref(pkt);
return err;
return 0;
}
static const CBSBSFType vp9_metadata_type = {
.codec_id = AV_CODEC_ID_VP9,
.fragment_name = "superframe",
.unit_name = "frame",
.update_fragment = &vp9_metadata_update_fragment,
};
static int vp9_metadata_init(AVBSFContext *bsf)
{
VP9MetadataContext *ctx = bsf->priv_data;
return ff_cbs_init(&ctx->cbc, AV_CODEC_ID_VP9, bsf);
}
static void vp9_metadata_close(AVBSFContext *bsf)
{
VP9MetadataContext *ctx = bsf->priv_data;
ff_cbs_fragment_free(&ctx->fragment);
ff_cbs_close(&ctx->cbc);
return ff_cbs_bsf_generic_init(bsf, &vp9_metadata_type);
}
#define OFFSET(x) offsetof(VP9MetadataContext, x)
@ -169,7 +140,7 @@ const AVBitStreamFilter ff_vp9_metadata_bsf = {
.priv_data_size = sizeof(VP9MetadataContext),
.priv_class = &vp9_metadata_class,
.init = &vp9_metadata_init,
.close = &vp9_metadata_close,
.filter = &vp9_metadata_filter,
.close = &ff_cbs_bsf_generic_close,
.filter = &ff_cbs_bsf_generic_filter,
.codec_ids = vp9_metadata_codec_ids,
};