summaryrefslogtreecommitdiff
path: root/chromium/media/ffmpeg/ffmpeg_common.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/ffmpeg/ffmpeg_common.cc')
-rw-r--r--chromium/media/ffmpeg/ffmpeg_common.cc34
1 files changed, 22 insertions, 12 deletions
diff --git a/chromium/media/ffmpeg/ffmpeg_common.cc b/chromium/media/ffmpeg/ffmpeg_common.cc
index 9500983595f..899d7521d3a 100644
--- a/chromium/media/ffmpeg/ffmpeg_common.cc
+++ b/chromium/media/ffmpeg/ffmpeg_common.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,6 +37,14 @@ EncryptionScheme GetEncryptionScheme(const AVStream* stream) {
return key ? EncryptionScheme::kCenc : EncryptionScheme::kUnencrypted;
}
+VideoDecoderConfig::AlphaMode GetAlphaMode(const AVStream* stream) {
+ AVDictionaryEntry* alpha_mode =
+ av_dict_get(stream->metadata, "alpha_mode", nullptr, 0);
+ return alpha_mode && !strcmp(alpha_mode->value, "1")
+ ? VideoDecoderConfig::AlphaMode::kHasAlpha
+ : VideoDecoderConfig::AlphaMode::kIsOpaque;
+}
+
} // namespace
// Why AV_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are
@@ -498,6 +506,7 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
// for now, but may not always be true forever. Fix this in the future.
gfx::Rect visible_rect(codec_context->width, codec_context->height);
gfx::Size coded_size = visible_rect.size();
+ gfx::HDRMetadata hdr_metadata;
// In some cases a container may have a DAR but no PAR, but FFmpeg translates
// everything to PAR. It is possible to get the render width and height, but I
@@ -534,6 +543,9 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
codec_context->color_range == AVCOL_RANGE_JPEG
? gfx::ColorSpace::RangeID::FULL
: gfx::ColorSpace::RangeID::LIMITED);
+
+ VideoDecoderConfig::AlphaMode alpha_mode = GetAlphaMode(stream);
+
switch (codec) {
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
case VideoCodec::kH264: {
@@ -572,6 +584,8 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
// the container
color_space = hevc_config.GetColorSpace();
}
+ hdr_metadata = hevc_config.GetHDRMetadata();
+ alpha_mode = hevc_config.GetAlphaMode();
#endif // BUILDFLAG(ENABLE_HEVC_PARSER_AND_HW_DECODER)
}
}
@@ -652,9 +666,6 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
profile = ProfileIDToVideoCodecProfile(codec_context->profile);
}
- auto* alpha_mode = av_dict_get(stream->metadata, "alpha_mode", nullptr, 0);
- const bool has_alpha = alpha_mode && !strcmp(alpha_mode->value, "1");
-
void* display_matrix =
av_stream_get_side_data(stream, AV_PKT_DATA_DISPLAYMATRIX, nullptr);
@@ -707,12 +718,9 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
codec_context->extradata + codec_context->extradata_size);
}
// TODO(tmathmeyer) ffmpeg can't provide us with an actual video rotation yet.
- config->Initialize(codec, profile,
- has_alpha ? VideoDecoderConfig::AlphaMode::kHasAlpha
- : VideoDecoderConfig::AlphaMode::kIsOpaque,
- color_space, video_transformation, coded_size,
- visible_rect, natural_size, extra_data,
- GetEncryptionScheme(stream));
+ config->Initialize(codec, profile, alpha_mode, color_space,
+ video_transformation, coded_size, visible_rect,
+ natural_size, extra_data, GetEncryptionScheme(stream));
// Set the aspect ratio explicitly since our version hasn't been rounded.
config->set_aspect_ratio(aspect_ratio);
@@ -722,7 +730,6 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
if (side_data.type != AV_PKT_DATA_MASTERING_DISPLAY_METADATA)
continue;
- gfx::HDRMetadata hdr_metadata{};
AVMasteringDisplayMetadata* metadata =
reinterpret_cast<AVMasteringDisplayMetadata*>(side_data.data);
if (metadata->has_primaries) {
@@ -744,10 +751,13 @@ bool AVStreamToVideoDecoderConfig(const AVStream* stream,
hdr_metadata.color_volume_metadata.luminance_min =
av_q2d(metadata->min_luminance);
}
- config->set_hdr_metadata(hdr_metadata);
}
}
+ if (hdr_metadata.IsValid()) {
+ config->set_hdr_metadata(hdr_metadata);
+ }
+
return true;
}