Commit 238b6116 authored by Sandeep Vijayasekar's avatar Sandeep Vijayasekar Committed by Commit Bot

Plumb color_space and hdr_metadata to media_codec_bridge_impl

For taking the VP9 HDR metadata from the video container and passes it to MediaCodec
Reference for packing HDR metadata in MediaFormat:
https://github.com/google/ExoPlayer/pull/2729/commits/e93ce41a285fe6b0493faa91523b010469591be7

Bug: internal b/68950223
Test: none
Change-Id: Id2b83c98a0844832f3bdfae7e3bd1dfa9c3728dc
Reviewed-on: https://chromium-review.googlesource.com/755952Reviewed-by: default avatarFredrik Hubinette <hubbe@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarSergey Volk <servolk@chromium.org>
Commit-Queue: Sandeep Vijayasekar <sandv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521100}
parent 0368c787
...@@ -240,6 +240,8 @@ std::unique_ptr<MediaCodecBridge> MediaCodecBridgeImpl::CreateVideoDecoder( ...@@ -240,6 +240,8 @@ std::unique_ptr<MediaCodecBridge> MediaCodecBridgeImpl::CreateVideoDecoder(
const JavaRef<jobject>& media_crypto, const JavaRef<jobject>& media_crypto,
const std::vector<uint8_t>& csd0, const std::vector<uint8_t>& csd0,
const std::vector<uint8_t>& csd1, const std::vector<uint8_t>& csd1,
const VideoColorSpace& color_space,
const base::Optional<HDRMetadata>& hdr_metadata,
bool allow_adaptive_playback) { bool allow_adaptive_playback) {
if (!MediaCodecUtil::IsMediaCodecAvailable()) if (!MediaCodecUtil::IsMediaCodecAvailable())
return nullptr; return nullptr;
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
namespace media { namespace media {
class VideoColorSpace;
struct HDRMetadata;
// A bridge to a Java MediaCodec. // A bridge to a Java MediaCodec.
class MEDIA_EXPORT MediaCodecBridgeImpl : public MediaCodecBridge { class MEDIA_EXPORT MediaCodecBridgeImpl : public MediaCodecBridge {
public: public:
...@@ -38,6 +41,8 @@ class MEDIA_EXPORT MediaCodecBridgeImpl : public MediaCodecBridge { ...@@ -38,6 +41,8 @@ class MEDIA_EXPORT MediaCodecBridgeImpl : public MediaCodecBridge {
// Codec specific data. See MediaCodec docs. // Codec specific data. See MediaCodec docs.
const std::vector<uint8_t>& csd0, const std::vector<uint8_t>& csd0,
const std::vector<uint8_t>& csd1, const std::vector<uint8_t>& csd1,
const VideoColorSpace& color_space,
const base::Optional<HDRMetadata>& hdr_metadata,
// Should adaptive playback be allowed if supported. // Should adaptive playback be allowed if supported.
bool allow_adaptive_playback = true); bool allow_adaptive_playback = true);
......
...@@ -293,7 +293,8 @@ TEST(MediaCodecBridgeTest, CreateH264Decoder) { ...@@ -293,7 +293,8 @@ TEST(MediaCodecBridgeTest, CreateH264Decoder) {
MediaCodecBridgeImpl::CreateVideoDecoder( MediaCodecBridgeImpl::CreateVideoDecoder(
kCodecH264, CodecType::kAny, gfx::Size(640, 480), nullptr, nullptr, kCodecH264, CodecType::kAny, gfx::Size(640, 480), nullptr, nullptr,
std::vector<uint8_t>(), std::vector<uint8_t>()); std::vector<uint8_t>(), std::vector<uint8_t>(), VideoColorSpace(),
HDRMetadata());
} }
TEST(MediaCodecBridgeTest, DoNormal) { TEST(MediaCodecBridgeTest, DoNormal) {
...@@ -402,7 +403,8 @@ TEST(MediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) { ...@@ -402,7 +403,8 @@ TEST(MediaCodecBridgeTest, PresentationTimestampsDoNotDecrease) {
std::unique_ptr<MediaCodecBridge> media_codec( std::unique_ptr<MediaCodecBridge> media_codec(
MediaCodecBridgeImpl::CreateVideoDecoder( MediaCodecBridgeImpl::CreateVideoDecoder(
kCodecVP8, CodecType::kAny, gfx::Size(320, 240), nullptr, nullptr, kCodecVP8, CodecType::kAny, gfx::Size(320, 240), nullptr, nullptr,
std::vector<uint8_t>(), std::vector<uint8_t>())); std::vector<uint8_t>(), std::vector<uint8_t>(), VideoColorSpace(),
HDRMetadata()));
ASSERT_THAT(media_codec, NotNull()); ASSERT_THAT(media_codec, NotNull());
scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240"); scoped_refptr<DecoderBuffer> buffer = ReadTestDataFile("vp8-I-frame-320x240");
DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(), DecodeMediaFrame(media_codec.get(), buffer->data(), buffer->data_size(),
...@@ -429,10 +431,10 @@ TEST(MediaCodecBridgeTest, CreateUnsupportedCodec) { ...@@ -429,10 +431,10 @@ TEST(MediaCodecBridgeTest, CreateUnsupportedCodec) {
EXPECT_THAT(MediaCodecBridgeImpl::CreateAudioDecoder( EXPECT_THAT(MediaCodecBridgeImpl::CreateAudioDecoder(
NewAudioConfig(kUnknownAudioCodec), nullptr), NewAudioConfig(kUnknownAudioCodec), nullptr),
IsNull()); IsNull());
EXPECT_THAT( EXPECT_THAT(MediaCodecBridgeImpl::CreateVideoDecoder(
MediaCodecBridgeImpl::CreateVideoDecoder( kUnknownVideoCodec, CodecType::kAny, gfx::Size(320, 240),
kUnknownVideoCodec, CodecType::kAny, gfx::Size(320, 240), nullptr, nullptr, nullptr, std::vector<uint8_t>(),
nullptr, std::vector<uint8_t>(), std::vector<uint8_t>()), std::vector<uint8_t>(), VideoColorSpace(), HDRMetadata()),
IsNull()); IsNull());
} }
......
...@@ -54,6 +54,8 @@ std::unique_ptr<MediaCodecBridge> MockMediaCodecBridge::CreateVideoDecoder( ...@@ -54,6 +54,8 @@ std::unique_ptr<MediaCodecBridge> MockMediaCodecBridge::CreateVideoDecoder(
const base::android::JavaRef<jobject>& media_crypto, const base::android::JavaRef<jobject>& media_crypto,
const std::vector<uint8_t>& csd0, const std::vector<uint8_t>& csd0,
const std::vector<uint8_t>& csd1, const std::vector<uint8_t>& csd1,
const VideoColorSpace& color_space,
const base::Optional<HDRMetadata>& hdr_metadata,
bool allow_adaptive_playback) { bool allow_adaptive_playback) {
return base::MakeUnique<MockMediaCodecBridge>(); return base::MakeUnique<MockMediaCodecBridge>();
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/android/scoped_java_ref.h" #include "base/android/scoped_java_ref.h"
#include "media/base/android/media_codec_bridge.h" #include "media/base/android/media_codec_bridge.h"
#include "media/base/android/test_destruction_observable.h" #include "media/base/android/test_destruction_observable.h"
#include "media/base/hdr_metadata.h"
#include "media/base/video_codecs.h" #include "media/base/video_codecs.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -85,6 +86,8 @@ class MockMediaCodecBridge : public MediaCodecBridge, ...@@ -85,6 +86,8 @@ class MockMediaCodecBridge : public MediaCodecBridge,
const base::android::JavaRef<jobject>& media_crypto, const base::android::JavaRef<jobject>& media_crypto,
const std::vector<uint8_t>& csd0, const std::vector<uint8_t>& csd0,
const std::vector<uint8_t>& csd1, const std::vector<uint8_t>& csd1,
const VideoColorSpace& color_space,
const base::Optional<HDRMetadata>& hdr_metadata,
bool allow_adaptive_playback); bool allow_adaptive_playback);
private: private:
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "media/base/demuxer_stream.h" #include "media/base/demuxer_stream.h"
#include "media/base/eme_constants.h" #include "media/base/eme_constants.h"
#include "media/base/encryption_scheme.h" #include "media/base/encryption_scheme.h"
#include "media/base/hdr_metadata.h"
#include "media/base/media_log_event.h" #include "media/base/media_log_event.h"
#include "media/base/output_device_info.h" #include "media/base/output_device_info.h"
#include "media/base/overlay_info.h" #include "media/base/overlay_info.h"
...@@ -159,6 +160,21 @@ IPC_STRUCT_TRAITS_BEGIN(media::VideoColorSpace) ...@@ -159,6 +160,21 @@ IPC_STRUCT_TRAITS_BEGIN(media::VideoColorSpace)
IPC_STRUCT_TRAITS_MEMBER(range) IPC_STRUCT_TRAITS_MEMBER(range)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::MasteringMetadata)
IPC_STRUCT_TRAITS_MEMBER(primary_r)
IPC_STRUCT_TRAITS_MEMBER(primary_g)
IPC_STRUCT_TRAITS_MEMBER(primary_b)
IPC_STRUCT_TRAITS_MEMBER(white_point)
IPC_STRUCT_TRAITS_MEMBER(luminance_max)
IPC_STRUCT_TRAITS_MEMBER(luminance_min)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::HDRMetadata)
IPC_STRUCT_TRAITS_MEMBER(mastering_metadata)
IPC_STRUCT_TRAITS_MEMBER(max_content_light_level)
IPC_STRUCT_TRAITS_MEMBER(max_frame_average_light_level)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::OverlayInfo) IPC_STRUCT_TRAITS_BEGIN(media::OverlayInfo)
IPC_STRUCT_TRAITS_MEMBER(surface_id) IPC_STRUCT_TRAITS_MEMBER(surface_id)
IPC_STRUCT_TRAITS_MEMBER(routing_token) IPC_STRUCT_TRAITS_MEMBER(routing_token)
......
...@@ -334,6 +334,7 @@ void GpuVideoDecoder::CompleteInitialization(const OverlayInfo& overlay_info) { ...@@ -334,6 +334,7 @@ void GpuVideoDecoder::CompleteInitialization(const OverlayInfo& overlay_info) {
vda_config.initial_expected_coded_size = config_.coded_size(); vda_config.initial_expected_coded_size = config_.coded_size();
vda_config.container_color_space = config_.color_space_info(); vda_config.container_color_space = config_.color_space_info();
vda_config.target_color_space = target_color_space_; vda_config.target_color_space = target_color_space_;
vda_config.hdr_metadata = config_.hdr_metadata();
#if defined(OS_ANDROID) && BUILDFLAG(USE_PROPRIETARY_CODECS) #if defined(OS_ANDROID) && BUILDFLAG(USE_PROPRIETARY_CODECS)
// We pass the SPS and PPS on Android because it lets us initialize // We pass the SPS and PPS on Android because it lets us initialize
......
...@@ -321,6 +321,9 @@ bool AndroidVideoDecodeAccelerator::Initialize(const Config& config, ...@@ -321,6 +321,9 @@ bool AndroidVideoDecodeAccelerator::Initialize(const Config& config,
codec_config_->csd1 = config.pps; codec_config_->csd1 = config.pps;
} }
codec_config_->container_color_space = config.container_color_space;
codec_config_->hdr_metadata = config.hdr_metadata;
// Only use MediaCodec for VP8/9 if it's likely backed by hardware // Only use MediaCodec for VP8/9 if it's likely backed by hardware
// or if the stream is encrypted. // or if the stream is encrypted.
if (IsMediaCodecSoftwareDecodingForbidden() && if (IsMediaCodecSoftwareDecodingForbidden() &&
......
...@@ -62,7 +62,8 @@ std::unique_ptr<MediaCodecBridge> CreateMediaCodecInternal( ...@@ -62,7 +62,8 @@ std::unique_ptr<MediaCodecBridge> CreateMediaCodecInternal(
codec_config->codec, codec_type, codec_config->codec, codec_type,
codec_config->initial_expected_coded_size, codec_config->initial_expected_coded_size,
codec_config->surface_bundle->GetJavaSurface(), media_crypto, codec_config->surface_bundle->GetJavaSurface(), media_crypto,
codec_config->csd0, codec_config->csd1, true)); codec_config->csd0, codec_config->csd1,
codec_config->container_color_space, codec_config->hdr_metadata, true));
return codec; return codec;
} }
......
...@@ -73,6 +73,11 @@ class MEDIA_GPU_EXPORT CodecConfig ...@@ -73,6 +73,11 @@ class MEDIA_GPU_EXPORT CodecConfig
std::vector<uint8_t> csd0; std::vector<uint8_t> csd0;
std::vector<uint8_t> csd1; std::vector<uint8_t> csd1;
// VP9 HDR metadata is only embedded in the container
// HDR10 meta data is embedded in the video stream
VideoColorSpace container_color_space;
base::Optional<HDRMetadata> hdr_metadata;
protected: protected:
friend class base::RefCountedThreadSafe<CodecConfig>; friend class base::RefCountedThreadSafe<CodecConfig>;
virtual ~CodecConfig(); virtual ~CodecConfig();
...@@ -127,6 +132,8 @@ class MEDIA_GPU_EXPORT AVDACodecAllocator { ...@@ -127,6 +132,8 @@ class MEDIA_GPU_EXPORT AVDACodecAllocator {
const base::android::JavaRef<jobject>& media_crypto, const base::android::JavaRef<jobject>& media_crypto,
const std::vector<uint8_t>& csd0, const std::vector<uint8_t>& csd0,
const std::vector<uint8_t>& csd1, const std::vector<uint8_t>& csd1,
const VideoColorSpace& color_space,
const base::Optional<HDRMetadata>& hdr_metadata,
bool allow_adaptive_playback)>; bool allow_adaptive_playback)>;
// Make sure the construction threads are started for |client|. If the // Make sure the construction threads are started for |client|. If the
......
...@@ -29,6 +29,7 @@ IPC_STRUCT_TRAITS_BEGIN(media::VideoDecodeAccelerator::Config) ...@@ -29,6 +29,7 @@ IPC_STRUCT_TRAITS_BEGIN(media::VideoDecodeAccelerator::Config)
IPC_STRUCT_TRAITS_MEMBER(pps) IPC_STRUCT_TRAITS_MEMBER(pps)
IPC_STRUCT_TRAITS_MEMBER(container_color_space) IPC_STRUCT_TRAITS_MEMBER(container_color_space)
IPC_STRUCT_TRAITS_MEMBER(target_color_space) IPC_STRUCT_TRAITS_MEMBER(target_color_space)
IPC_STRUCT_TRAITS_MEMBER(hdr_metadata)
IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(media::CreateVideoEncoderParams) IPC_STRUCT_TRAITS_BEGIN(media::CreateVideoEncoderParams)
......
...@@ -178,6 +178,9 @@ class MEDIA_EXPORT VideoDecodeAccelerator { ...@@ -178,6 +178,9 @@ class MEDIA_EXPORT VideoDecodeAccelerator {
// Used as a hint to the decoder. Outputting VideoFrames in this color space // Used as a hint to the decoder. Outputting VideoFrames in this color space
// may avoid extra conversion steps. // may avoid extra conversion steps.
gfx::ColorSpace target_color_space; gfx::ColorSpace target_color_space;
// HDR metadata specified by the container.
base::Optional<HDRMetadata> hdr_metadata;
}; };
// Interface for collaborating with picture interface to provide memory for // Interface for collaborating with picture interface to provide memory for
......
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