diff options
Diffstat (limited to '')
-rw-r--r-- | media/ffvpx/libavcodec/libdav1d.c | 141 |
1 files changed, 69 insertions, 72 deletions
diff --git a/media/ffvpx/libavcodec/libdav1d.c b/media/ffvpx/libavcodec/libdav1d.c index 11cdbca274..f022a4ad05 100644 --- a/media/ffvpx/libavcodec/libdav1d.c +++ b/media/ffvpx/libavcodec/libdav1d.c @@ -35,7 +35,9 @@ #include "bytestream.h" #include "codec_internal.h" #include "decode.h" +#include "dovi_rpu.h" #include "internal.h" +#include "itut35.h" #define FF_DAV1D_VERSION_AT_LEAST(x,y) \ (DAV1D_API_VERSION_MAJOR > (x) || DAV1D_API_VERSION_MAJOR == (x) && DAV1D_API_VERSION_MINOR >= (y)) @@ -44,6 +46,7 @@ typedef struct Libdav1dContext { AVClass *class; Dav1dContext *c; AVBufferPool *pool; + DOVIContext dovi; int pool_size; Dav1dData data; @@ -213,9 +216,10 @@ static av_cold int libdav1d_init(AVCodecContext *c) #else int threads = (c->thread_count ? c->thread_count : av_cpu_count()) * 3 / 2; #endif + const AVPacketSideData *sd; int res; - av_log(c, AV_LOG_INFO, "libdav1d %s\n", dav1d_version()); + av_log(c, AV_LOG_VERBOSE, "libdav1d %s\n", dav1d_version()); dav1d_default_settings(&s); s.logger.cookie = c; @@ -285,6 +289,11 @@ static av_cold int libdav1d_init(AVCodecContext *c) c->delay = res > 1 ? res : 0; #endif + dav1d->dovi.logctx = c; + dav1d->dovi.dv_profile = 10; // default for AV1 + sd = ff_get_coded_side_data(c, AV_PKT_DATA_DOVI_CONF); + if (sd && sd->size > 0) + ff_dovi_update_cfg(&dav1d->dovi, (AVDOVIDecoderConfigurationRecord *) sd->data); return 0; } @@ -296,13 +305,6 @@ static void libdav1d_flush(AVCodecContext *c) dav1d_flush(dav1d->c); } -typedef struct OpaqueData { - void *pkt_orig_opaque; -#if FF_API_REORDERED_OPAQUE - int64_t reordered_opaque; -#endif -} OpaqueData; - static void libdav1d_data_free(const uint8_t *data, void *opaque) { AVBufferRef *buf = opaque; @@ -312,7 +314,6 @@ static void libdav1d_data_free(const uint8_t *data, void *opaque) { static void libdav1d_user_data_free(const uint8_t *data, void *opaque) { AVPacket *pkt = opaque; av_assert0(data == opaque); - av_free(pkt->opaque); av_packet_free(&pkt); } @@ -335,8 +336,6 @@ static int libdav1d_receive_frame_internal(AVCodecContext *c, Dav1dPicture *p) } if (pkt->size) { - OpaqueData *od = NULL; - res = dav1d_data_wrap(data, pkt->data, pkt->size, libdav1d_data_free, pkt->buf); if (res < 0) { @@ -346,30 +345,9 @@ static int libdav1d_receive_frame_internal(AVCodecContext *c, Dav1dPicture *p) pkt->buf = NULL; -FF_DISABLE_DEPRECATION_WARNINGS - if ( -#if FF_API_REORDERED_OPAQUE - c->reordered_opaque != AV_NOPTS_VALUE || -#endif - (pkt->opaque && (c->flags & AV_CODEC_FLAG_COPY_OPAQUE))) { - od = av_mallocz(sizeof(*od)); - if (!od) { - av_packet_free(&pkt); - dav1d_data_unref(data); - return AVERROR(ENOMEM); - } - od->pkt_orig_opaque = pkt->opaque; -#if FF_API_REORDERED_OPAQUE - od->reordered_opaque = c->reordered_opaque; -#endif -FF_ENABLE_DEPRECATION_WARNINGS - } - pkt->opaque = od; - res = dav1d_data_wrap_user_data(data, (const uint8_t *)pkt, libdav1d_user_data_free, pkt); if (res < 0) { - av_free(pkt->opaque); av_packet_free(&pkt); dav1d_data_unref(data); return res; @@ -408,7 +386,6 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) Libdav1dContext *dav1d = c->priv_data; Dav1dPicture pic = { 0 }, *p = &pic; AVPacket *pkt; - OpaqueData *od = NULL; #if FF_DAV1D_VERSION_AT_LEAST(5,1) enum Dav1dEventFlags event_flags = 0; #endif @@ -463,24 +440,9 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame) ff_set_sar(c, frame->sample_aspect_ratio); pkt = (AVPacket *)p->m.user_data.data; - od = pkt->opaque; -#if FF_API_REORDERED_OPAQUE -FF_DISABLE_DEPRECATION_WARNINGS - if (od && od->reordered_opaque != AV_NOPTS_VALUE) - frame->reordered_opaque = od->reordered_opaque; - else - frame->reordered_opaque = AV_NOPTS_VALUE; -FF_ENABLE_DEPRECATION_WARNINGS -#endif - - // restore the original user opaque value for - // ff_decode_frame_props_from_pkt() - pkt->opaque = od ? od->pkt_orig_opaque : NULL; - av_freep(&od); // match timestamps and packet size res = ff_decode_frame_props_from_pkt(c, frame, pkt); - pkt->opaque = NULL; if (res < 0) goto fail; @@ -507,33 +469,38 @@ FF_ENABLE_DEPRECATION_WARNINGS } if (p->mastering_display) { - AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame); - if (!mastering) { - res = AVERROR(ENOMEM); + AVMasteringDisplayMetadata *mastering; + + res = ff_decode_mastering_display_new(c, frame, &mastering); + if (res < 0) goto fail; - } - for (int i = 0; i < 3; i++) { - mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16); - mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16); - } - mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16); - mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16); + if (mastering) { + for (int i = 0; i < 3; i++) { + mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16); + mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16); + } + mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16); + mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16); - mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8); - mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14); + mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8); + mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14); - mastering->has_primaries = 1; - mastering->has_luminance = 1; + mastering->has_primaries = 1; + mastering->has_luminance = 1; + } } if (p->content_light) { - AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame); - if (!light) { - res = AVERROR(ENOMEM); + AVContentLightMetadata *light; + + res = ff_decode_content_light_new(c, frame, &light); + if (res < 0) goto fail; + + if (light) { + light->MaxCLL = p->content_light->max_content_light_level; + light->MaxFALL = p->content_light->max_frame_average_light_level; } - light->MaxCLL = p->content_light->max_content_light_level; - light->MaxFALL = p->content_light->max_frame_average_light_level; } if (p->itut_t35) { #if FF_DAV1D_VERSION_AT_LEAST(6,9) @@ -549,7 +516,7 @@ FF_ENABLE_DEPRECATION_WARNINGS provider_code = bytestream2_get_be16(&gb); switch (provider_code) { - case 0x31: { // atsc_provider_code + case ITU_T_T35_PROVIDER_CODE_ATSC: { uint32_t user_identifier = bytestream2_get_be32(&gb); switch (user_identifier) { case MKBETAG('G', 'A', '9', '4'): { // closed captions @@ -561,8 +528,9 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!res) break; - if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, buf)) - av_buffer_unref(&buf); + res = ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, &buf, NULL); + if (res < 0) + goto fail; c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS; break; @@ -572,12 +540,12 @@ FF_ENABLE_DEPRECATION_WARNINGS } break; } - case 0x3C: { // smpte_provider_code + case ITU_T_T35_PROVIDER_CODE_SMTPE: { AVDynamicHDRPlus *hdrplus; int provider_oriented_code = bytestream2_get_be16(&gb); int application_identifier = bytestream2_get_byte(&gb); - if (itut_t35->country_code != 0xB5 || + if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || provider_oriented_code != 1 || application_identifier != 4) break; @@ -593,6 +561,24 @@ FF_ENABLE_DEPRECATION_WARNINGS goto fail; break; } + case ITU_T_T35_PROVIDER_CODE_DOLBY: { + int provider_oriented_code = bytestream2_get_be32(&gb); + if (itut_t35->country_code != ITU_T_T35_COUNTRY_CODE_US || + provider_oriented_code != 0x800) + break; + + res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer, + c->err_recognition); + if (res < 0) { + av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n"); + break; // ignore + } + + res = ff_dovi_attach_side_data(&dav1d->dovi, frame); + if (res < 0) + goto fail; + break; + } default: // ignore unsupported provider codes break; } @@ -603,6 +589,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if (p->frame_hdr->film_grain.present && (!dav1d->apply_grain || (c->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN))) { AVFilmGrainParams *fgp = av_film_grain_params_create_side_data(frame); + const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(frame->format); + av_assert0(pixdesc); if (!fgp) { res = AVERROR(ENOMEM); goto fail; @@ -610,6 +598,14 @@ FF_ENABLE_DEPRECATION_WARNINGS fgp->type = AV_FILM_GRAIN_PARAMS_AV1; fgp->seed = p->frame_hdr->film_grain.data.seed; + fgp->width = frame->width; + fgp->height = frame->height; + fgp->color_range = frame->color_range; + fgp->color_primaries = frame->color_primaries; + fgp->color_trc = frame->color_trc; + fgp->color_space = frame->colorspace; + fgp->subsampling_x = pixdesc->log2_chroma_w; + fgp->subsampling_y = pixdesc->log2_chroma_h; fgp->codec.aom.num_y_points = p->frame_hdr->film_grain.data.num_y_points; fgp->codec.aom.chroma_scaling_from_luma = p->frame_hdr->film_grain.data.chroma_scaling_from_luma; fgp->codec.aom.scaling_shift = p->frame_hdr->film_grain.data.scaling_shift; @@ -652,6 +648,7 @@ static av_cold int libdav1d_close(AVCodecContext *c) Libdav1dContext *dav1d = c->priv_data; av_buffer_pool_uninit(&dav1d->pool); + ff_dovi_ctx_unref(&dav1d->dovi); dav1d_data_unref(&dav1d->data); dav1d_close(&dav1d->c); |