X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvp9_metadata_bsf.c;h=d904a0088dd78cd5095fc6d32d77bb738ac30548;hb=1ec87f50f42a16f9228444dc08aa8264879f61e1;hp=b79f08af6c37c10e8b5b11e23384a29b12d4c674;hpb=5ab44ff20cdc0e05adecbd0cd352d25fcb930094;p=ffmpeg diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c index b79f08af6c3..d904a0088dd 100644 --- a/libavcodec/vp9_metadata_bsf.c +++ b/libavcodec/vp9_metadata_bsf.c @@ -22,92 +22,74 @@ #include "bsf.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; - int color_range_rgb_warned; + int color_warnings; } VP9MetadataContext; -static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out) +static int vp9_metadata_update_fragment(AVBSFContext *bsf, AVPacket *pkt, + CodedBitstreamFragment *frag) { VP9MetadataContext *ctx = bsf->priv_data; - AVPacket *in = NULL; - CodedBitstreamFragment *frag = &ctx->fragment; - int err, i; - - err = ff_bsf_get_packet(bsf, &in); - if (err < 0) - return err; - - err = ff_cbs_read_packet(ctx->cbc, frag, in); - 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; VP9RawFrameHeader *header = &frame->header; + int profile = (header->profile_high_bit << 1) + header->profile_low_bit; + + if (header->frame_type == VP9_KEY_FRAME || + header->intra_only && profile > 0) { + if (ctx->color_space >= 0) { + if (!(profile & 1) && ctx->color_space == VP9_CS_RGB) { + if (!(ctx->color_warnings & 2)) { + av_log(bsf, AV_LOG_WARNING, "Warning: RGB " + "incompatible with profiles 0 and 2.\n"); + ctx->color_warnings |= 2; + } + } else + header->color_space = ctx->color_space; + } - if (ctx->color_space >= 0) { - header->color_space = ctx->color_space; - } - if (ctx->color_range >= 0) { - if (ctx->color_range == 0 && - header->color_space == VP9_CS_RGB && - !ctx->color_range_rgb_warned) { - av_log(bsf, AV_LOG_WARNING, "Warning: color_range cannot " - "be set to limited in RGB streams.\n"); - ctx->color_range_rgb_warned = 1; - } else { + if (ctx->color_range >= 0) header->color_range = ctx->color_range; + if (header->color_space == VP9_CS_RGB) { + if (!(ctx->color_warnings & 1) && !header->color_range) { + av_log(bsf, AV_LOG_WARNING, "Warning: Color space RGB " + "implicitly sets color range to PC range.\n"); + ctx->color_warnings |= 1; + } + header->color_range = 1; } + } else if (!(ctx->color_warnings & 4) && header->intra_only && !profile && + ctx->color_space >= 0 && ctx->color_space != VP9_CS_BT_601) { + av_log(bsf, AV_LOG_WARNING, "Warning: Intra-only frames in " + "profile 0 are automatically BT.601.\n"); + ctx->color_warnings |= 4; } } - err = ff_cbs_write_packet(ctx->cbc, out, frag); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); - goto fail; - } - - err = av_packet_copy_props(out, in); - if (err < 0) - goto fail; - - err = 0; -fail: - ff_cbs_fragment_reset(ctx->cbc, frag); - - if (err < 0) - av_packet_unref(out); - av_packet_free(&in); - - return err; + return 0; } -static int vp9_metadata_init(AVBSFContext *bsf) -{ - VP9MetadataContext *ctx = bsf->priv_data; - - return ff_cbs_init(&ctx->cbc, AV_CODEC_ID_VP9, bsf); -} +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 void vp9_metadata_close(AVBSFContext *bsf) +static int vp9_metadata_init(AVBSFContext *bsf) { - VP9MetadataContext *ctx = bsf->priv_data; - - ff_cbs_fragment_free(ctx->cbc, &ctx->fragment); - ff_cbs_close(&ctx->cbc); + return ff_cbs_bsf_generic_init(bsf, &vp9_metadata_type); } #define OFFSET(x) offsetof(VP9MetadataContext, x) @@ -158,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, };