diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-09-03 13:32:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-10-01 14:31:55 +0200 |
commit | 21ba0c5d4bf8fba15dddd97cd693bad2358b77fd (patch) | |
tree | 91be119f694044dfc1ff9fdc054459e925de9df0 /chromium/media/base | |
parent | 03c549e0392f92c02536d3f86d5e1d8dfa3435ac (diff) | |
download | qtwebengine-chromium-21ba0c5d4bf8fba15dddd97cd693bad2358b77fd.tar.gz |
BASELINE: Update Chromium to 92.0.4515.166
Change-Id: I42a050486714e9e54fc271f2a8939223a02ae364
Diffstat (limited to 'chromium/media/base')
111 files changed, 770 insertions, 520 deletions
diff --git a/chromium/media/base/BUILD.gn b/chromium/media/base/BUILD.gn index 54e6842abd4..eb2295b777f 100644 --- a/chromium/media/base/BUILD.gn +++ b/chromium/media/base/BUILD.gn @@ -374,6 +374,7 @@ source_set("base") { "//ui/display:display", "//ui/events:events", "//ui/events:events_base", + "//ui/events:keyboard_hook", "//url:url", ] @@ -394,6 +395,10 @@ source_set("base") { ] } + if (is_chromeos_ash) { + deps += [ "//ash/constants" ] + } + if (media_use_libvpx) { deps += [ "//third_party/libvpx" ] } diff --git a/chromium/media/base/DEPS b/chromium/media/base/DEPS new file mode 100644 index 00000000000..f51400454f2 --- /dev/null +++ b/chromium/media/base/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+ash/constants", +] diff --git a/chromium/media/base/android/media_codec_bridge.h b/chromium/media/base/android/media_codec_bridge.h index f9cb49f9cfe..4858127716e 100644 --- a/chromium/media/base/android/media_codec_bridge.h +++ b/chromium/media/base/android/media_codec_bridge.h @@ -14,11 +14,11 @@ #include "base/android/jni_android.h" #include "base/android/scoped_java_ref.h" #include "base/macros.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/encryption_pattern.h" #include "media/base/encryption_scheme.h" #include "media/base/media_export.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/size.h" namespace media { @@ -95,7 +95,7 @@ class MEDIA_EXPORT MediaCodecBridge { const std::string& iv, const std::vector<SubsampleEntry>& subsamples, EncryptionScheme encryption_scheme, - base::Optional<EncryptionPattern> encryption_pattern, + absl::optional<EncryptionPattern> encryption_pattern, base::TimeDelta presentation_time) = 0; // Submits an empty buffer with the END_OF_STREAM flag set. diff --git a/chromium/media/base/android/media_codec_bridge_impl.cc b/chromium/media/base/android/media_codec_bridge_impl.cc index 8bd73acadf1..68d6a8b0969 100644 --- a/chromium/media/base/android/media_codec_bridge_impl.cc +++ b/chromium/media/base/android/media_codec_bridge_impl.cc @@ -383,7 +383,7 @@ MediaCodecStatus MediaCodecBridgeImpl::QueueSecureInputBuffer( const std::string& iv, const std::vector<SubsampleEntry>& subsamples, EncryptionScheme encryption_scheme, - base::Optional<EncryptionPattern> encryption_pattern, + absl::optional<EncryptionPattern> encryption_pattern, base::TimeDelta presentation_time) { DVLOG(3) << __func__ << " " << index << ": " << data_size; if (data_size > diff --git a/chromium/media/base/android/media_codec_bridge_impl.h b/chromium/media/base/android/media_codec_bridge_impl.h index 1d4ce6da9d8..a1375a8ae10 100644 --- a/chromium/media/base/android/media_codec_bridge_impl.h +++ b/chromium/media/base/android/media_codec_bridge_impl.h @@ -54,7 +54,7 @@ class MEDIA_EXPORT VideoCodecConfig { // VP9 HDR metadata is only embedded in the container. HDR10 metadata is // embedded in the video stream. - base::Optional<gfx::HDRMetadata> hdr_metadata; + absl::optional<gfx::HDRMetadata> hdr_metadata; // Enables the async MediaCodec.Callback API. |on_buffers_available_cb| // will be called when input or output buffers are available. This will be @@ -122,7 +122,7 @@ class MEDIA_EXPORT MediaCodecBridgeImpl : public MediaCodecBridge { const std::string& iv, const std::vector<SubsampleEntry>& subsamples, EncryptionScheme encryption_scheme, - base::Optional<EncryptionPattern> encryption_pattern, + absl::optional<EncryptionPattern> encryption_pattern, base::TimeDelta presentation_time) override; void QueueEOS(int input_buffer_index) override; MediaCodecStatus DequeueInputBuffer(base::TimeDelta timeout, diff --git a/chromium/media/base/android/media_codec_loop.h b/chromium/media/base/android/media_codec_loop.h index 81651149a3c..a66c38cb265 100644 --- a/chromium/media/base/android/media_codec_loop.h +++ b/chromium/media/base/android/media_codec_loop.h @@ -124,7 +124,7 @@ class MEDIA_EXPORT MediaCodecLoop { bool is_eos = false; EncryptionScheme encryption_scheme = EncryptionScheme::kUnencrypted; - base::Optional<EncryptionPattern> encryption_pattern; + absl::optional<EncryptionPattern> encryption_pattern; }; // Handy enum for "no buffer". diff --git a/chromium/media/base/android/media_codec_loop_unittest.cc b/chromium/media/base/android/media_codec_loop_unittest.cc index b52a888f33e..f3ac9638026 100644 --- a/chromium/media/base/android/media_codec_loop_unittest.cc +++ b/chromium/media/base/android/media_codec_loop_unittest.cc @@ -92,8 +92,8 @@ class MediaCodecLoopTest : public testing::Test { std::unique_ptr<MediaCodecBridge> codec(new MockMediaCodecBridge()); // Since we're providing a codec, we do not expect an error. EXPECT_CALL(*client_, OnCodecLoopError()).Times(0); - codec_loop_.reset(new MediaCodecLoop(sdk_int, client_.get(), - std::move(codec), mock_task_runner_)); + codec_loop_ = std::make_unique<MediaCodecLoop>( + sdk_int, client_.get(), std::move(codec), mock_task_runner_); codec_loop_->SetTestTickClock(mock_task_runner_->GetMockTickClock()); Mock::VerifyAndClearExpectations(client_.get()); } @@ -199,9 +199,9 @@ TEST_F(MediaCodecLoopTest, TestConstructionWithNullCodec) { std::unique_ptr<MediaCodecBridge> codec; EXPECT_CALL(*client_, OnCodecLoopError()).Times(1); const int sdk_int = base::android::SDK_VERSION_LOLLIPOP; - codec_loop_.reset( - new MediaCodecLoop(sdk_int, client_.get(), std::move(codec), - scoped_refptr<base::SingleThreadTaskRunner>())); + codec_loop_ = std::make_unique<MediaCodecLoop>( + sdk_int, client_.get(), std::move(codec), + scoped_refptr<base::SingleThreadTaskRunner>()); // Do not WaitUntilIdle() here, since that assumes that we have a codec. ASSERT_FALSE(codec_loop_->GetCodec()); diff --git a/chromium/media/base/android/media_crypto_context_impl.h b/chromium/media/base/android/media_crypto_context_impl.h index 435c96d953a..27e9eda77d6 100644 --- a/chromium/media/base/android/media_crypto_context_impl.h +++ b/chromium/media/base/android/media_crypto_context_impl.h @@ -7,8 +7,6 @@ #include <jni.h> -#include <memory> - #include "base/android/scoped_java_ref.h" #include "base/macros.h" #include "media/base/android/media_crypto_context.h" diff --git a/chromium/media/base/android/media_drm_bridge.cc b/chromium/media/base/android/media_drm_bridge.cc index 182dc13ad28..69356037f75 100644 --- a/chromium/media/base/android/media_drm_bridge.cc +++ b/chromium/media/base/android/media_drm_bridge.cc @@ -265,22 +265,6 @@ std::string GetSecurityLevelString( return ""; } -bool AreMediaDrmApisAvailable() { - if (base::android::BuildInfo::GetInstance()->sdk_int() < - base::android::SDK_VERSION_KITKAT) - return false; - - int32_t os_major_version = 0; - int32_t os_minor_version = 0; - int32_t os_bugfix_version = 0; - base::SysInfo::OperatingSystemVersionNumbers( - &os_major_version, &os_minor_version, &os_bugfix_version); - if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) - return false; - - return true; -} - int GetFirstApiLevel() { JNIEnv* env = AttachCurrentThread(); int first_api_level = Java_MediaDrmBridge_getFirstApiLevel(env); @@ -293,7 +277,7 @@ int GetFirstApiLevel() { // APIs and MediaCodec APIs must be enabled and not blocked. // static bool MediaDrmBridge::IsAvailable() { - return AreMediaDrmApisAvailable() && MediaCodecUtil::IsMediaCodecAvailable(); + return MediaCodecUtil::IsMediaCodecAvailable(); } // static @@ -375,7 +359,6 @@ scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( const SessionKeysChangeCB& session_keys_change_cb, const SessionExpirationUpdateCB& session_expiration_update_cb) { // All paths requires the MediaDrmApis. - DCHECK(AreMediaDrmApisAvailable()); DCHECK(!scheme_uuid.empty()); // TODO(crbug.com/917527): Check that |origin_id| is specified on devices @@ -400,10 +383,6 @@ scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( CreateFetcherCB create_fetcher_cb) { DVLOG(1) << __func__; - // Sessions won't be used so decoding capability is not required. - if (!AreMediaDrmApisAvailable()) - return nullptr; - UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); if (scheme_uuid.empty()) return nullptr; diff --git a/chromium/media/base/android/media_drm_bridge_unittest.cc b/chromium/media/base/android/media_drm_bridge_unittest.cc index 40c31575c49..06260327382 100644 --- a/chromium/media/base/android/media_drm_bridge_unittest.cc +++ b/chromium/media/base/android/media_drm_bridge_unittest.cc @@ -127,16 +127,11 @@ TEST_F(MediaDrmBridgeTest, IsKeySystemSupported_Widevine) { EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoMp4)); - if (base::android::BuildInfo::GetInstance()->sdk_int() <= - base::android::SDK_VERSION_KITKAT) { - EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); - EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); - } else { - EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( + + EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( IsKeySystemSupportedWithType(kWidevineKeySystem, kAudioWebM)); - EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( + EXPECT_TRUE_IF_WIDEVINE_AVAILABLE( IsKeySystemSupportedWithType(kWidevineKeySystem, kVideoWebM)); - } EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "unknown")); EXPECT_FALSE(IsKeySystemSupportedWithType(kWidevineKeySystem, "video/avi")); diff --git a/chromium/media/base/android/mock_media_codec_bridge.h b/chromium/media/base/android/mock_media_codec_bridge.h index 85325f56cff..babe78a3064 100644 --- a/chromium/media/base/android/mock_media_codec_bridge.h +++ b/chromium/media/base/android/mock_media_codec_bridge.h @@ -44,7 +44,7 @@ class MockMediaCodecBridge : public MediaCodecBridge, const std::string& iv, const std::vector<SubsampleEntry>& subsamples, EncryptionScheme encryption_scheme, - base::Optional<EncryptionPattern> encryption_pattern, + absl::optional<EncryptionPattern> encryption_pattern, base::TimeDelta presentation_time)); MOCK_METHOD1(QueueEOS, void(int input_buffer_index)); MOCK_METHOD2(DequeueInputBuffer, diff --git a/chromium/media/base/android/mock_media_crypto_context.h b/chromium/media/base/android/mock_media_crypto_context.h index a113613545b..1cd64809cfd 100644 --- a/chromium/media/base/android/mock_media_crypto_context.h +++ b/chromium/media/base/android/mock_media_crypto_context.h @@ -5,8 +5,6 @@ #ifndef MEDIA_BASE_ANDROID_MOCK_MEDIA_CRYPTO_CONTEXT_H_ #define MEDIA_BASE_ANDROID_MOCK_MEDIA_CRYPTO_CONTEXT_H_ -#include <memory> - #include "base/macros.h" #include "media/base/android/media_crypto_context.h" #include "media/base/cdm_context.h" diff --git a/chromium/media/base/android/test_destruction_observable.h b/chromium/media/base/android/test_destruction_observable.h index 90dddfeec9e..d11b7ab9dda 100644 --- a/chromium/media/base/android/test_destruction_observable.h +++ b/chromium/media/base/android/test_destruction_observable.h @@ -7,7 +7,7 @@ #include "base/callback_helpers.h" #include "base/memory/weak_ptr.h" -#include "base/optional.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -55,7 +55,7 @@ class DestructionObserver { bool destructed_; // Whether to expect destruction. Unset if there is no expectation. - base::Optional<bool> expect_destruction_; + absl::optional<bool> expect_destruction_; base::WeakPtrFactory<DestructionObserver> weak_factory_{this}; DISALLOW_COPY_AND_ASSIGN(DestructionObserver); diff --git a/chromium/media/base/android_overlay_mojo_factory.h b/chromium/media/base/android_overlay_mojo_factory.h index a7c0d06ed20..4a94579f27b 100644 --- a/chromium/media/base/android_overlay_mojo_factory.h +++ b/chromium/media/base/android_overlay_mojo_factory.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_CB_H_ -#define MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_CB_H_ +#ifndef MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_H_ +#define MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_H_ #include "base/callback.h" #include "base/macros.h" @@ -20,4 +20,4 @@ using AndroidOverlayMojoFactoryCB = } // namespace media -#endif // MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_CB_H_ +#endif // MEDIA_BASE_ANDROID_OVERLAY_MOJO_FACTORY_H_ diff --git a/chromium/media/base/audio_buffer.cc b/chromium/media/base/audio_buffer.cc index 99cbfb6af4c..56761fbe610 100644 --- a/chromium/media/base/audio_buffer.cc +++ b/chromium/media/base/audio_buffer.cc @@ -6,6 +6,7 @@ #include <cmath> +#include "base/callback_helpers.h" #include "base/logging.h" #include "base/notreached.h" #include "media/base/audio_bus.h" @@ -187,6 +188,26 @@ scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom( } // static +scoped_refptr<AudioBuffer> AudioBuffer::CopyFrom( + int sample_rate, + const base::TimeDelta timestamp, + const AudioBus* audio_bus, + scoped_refptr<AudioBufferMemoryPool> pool) { + DCHECK(audio_bus->frames()); + + const int channel_count = audio_bus->channels(); + DCHECK(channel_count); + + std::vector<const uint8_t*> data(channel_count); + for (int ch = 0; ch < channel_count; ch++) + data[ch] = reinterpret_cast<const uint8_t*>(audio_bus->channel(ch)); + + return CopyFrom(kSampleFormatPlanarF32, GuessChannelLayout(channel_count), + channel_count, sample_rate, audio_bus->frames(), data.data(), + timestamp, std::move(pool)); +} + +// static scoped_refptr<AudioBuffer> AudioBuffer::CopyBitstreamFrom( SampleFormat sample_format, ChannelLayout channel_layout, @@ -255,6 +276,44 @@ scoped_refptr<AudioBuffer> AudioBuffer::CreateEOSBuffer() { nullptr, 0, kNoTimestamp, nullptr)); } +// static +std::unique_ptr<AudioBus> AudioBuffer::WrapOrCopyToAudioBus( + scoped_refptr<AudioBuffer> buffer) { + DCHECK(buffer); + + const int channels = buffer->channel_count(); + const int frames = buffer->frame_count(); + + DCHECK(channels); + DCHECK(frames); + + // |buffer| might already have the right memory layout. Prevent a data copy + // by wrapping it instead. + if (buffer->sample_format() == SampleFormat::kSampleFormatPlanarF32) { + auto audio_bus = AudioBus::CreateWrapper(channels); + + for (int ch = 0; ch < channels; ++ch) { + audio_bus->SetChannelData( + ch, reinterpret_cast<float*>(buffer->channel_data()[ch])); + } + + audio_bus->set_frames(frames); + + // Keep |buffer| alive as long as |audio_bus|. + audio_bus->SetWrappedDataDeleter( + base::BindOnce(base::DoNothing::Once<scoped_refptr<AudioBuffer>>(), + std::move(buffer))); + + return audio_bus; + } + + // |buffer|'s memory can't be wrapped directly. Convert and copy it instead. + auto audio_bus = AudioBus::Create(channels, frames); + buffer->ReadFrames(frames, 0, 0, audio_bus.get()); + + return audio_bus; +} + void AudioBuffer::AdjustSampleRate(int sample_rate) { DCHECK(!end_of_stream_); sample_rate_ = sample_rate; diff --git a/chromium/media/base/audio_buffer.h b/chromium/media/base/audio_buffer.h index 9a90ef1d88d..7042fab41b0 100644 --- a/chromium/media/base/audio_buffer.h +++ b/chromium/media/base/audio_buffer.h @@ -65,6 +65,15 @@ class MEDIA_EXPORT AudioBuffer const base::TimeDelta timestamp, scoped_refptr<AudioBufferMemoryPool> pool = nullptr); + // Create an AudioBuffer from a copy of the data in |audio_bus|. + // For optimal efficiency when many buffers are being created, a + // AudioBufferMemoryPool can be provided to avoid thrashing memory. + static scoped_refptr<AudioBuffer> CopyFrom( + int sample_rate, + const base::TimeDelta timestamp, + const AudioBus* audio_bus, + scoped_refptr<AudioBufferMemoryPool> pool = nullptr); + // Create an AudioBuffer for compressed bitstream. Its channel data is copied // from |data|, and the size is |data_size|. |data| must not be null and // |frame_count| must be >= 0. @@ -110,6 +119,13 @@ class MEDIA_EXPORT AudioBuffer int frame_count, const base::TimeDelta timestamp); + // Helper function that creates a new AudioBus which wraps |audio_buffer| and + // takes a reference on it, if the memory layout (e.g. |sample_format_|) is + // compatible with wrapping. Otherwise, this copies |audio_buffer| to a new + // AudioBus, using ReadFrames(). + static std::unique_ptr<AudioBus> WrapOrCopyToAudioBus( + scoped_refptr<AudioBuffer> audio_buffer); + // Create a AudioBuffer indicating we've reached end of stream. // Calling any method other than end_of_stream() on the resulting buffer // is disallowed. diff --git a/chromium/media/base/audio_buffer_converter.h b/chromium/media/base/audio_buffer_converter.h index 3a0320be67d..f59e8f23354 100644 --- a/chromium/media/base/audio_buffer_converter.h +++ b/chromium/media/base/audio_buffer_converter.h @@ -9,7 +9,6 @@ #include "base/containers/circular_deque.h" #include "base/memory/ref_counted.h" -#include "base/time/time.h" #include "media/base/audio_buffer.h" #include "media/base/audio_converter.h" #include "media/base/audio_parameters.h" diff --git a/chromium/media/base/audio_buffer_unittest.cc b/chromium/media/base/audio_buffer_unittest.cc index 3a30db21d2d..88ea630fc2a 100644 --- a/chromium/media/base/audio_buffer_unittest.cc +++ b/chromium/media/base/audio_buffer_unittest.cc @@ -174,6 +174,44 @@ TEST(AudioBufferTest, CopyFrom) { EXPECT_FALSE(original_buffer->end_of_stream()); } +TEST(AudioBufferTest, CopyFromAudioBus) { + const int kChannelCount = 2; + const int kFrameCount = kSampleRate / 100; + + // For convenience's sake, create an arbitrary |temp_buffer| and copy it to + // |audio_bus|, instead of generating data in |audio_bus| ourselves. + scoped_refptr<AudioBuffer> temp_buffer = MakeAudioBuffer<uint8_t>( + kSampleFormatU8, CHANNEL_LAYOUT_STEREO, kChannelCount, kSampleRate, 1, 1, + kFrameCount, base::TimeDelta()); + + auto audio_bus = media::AudioBus::Create(kChannelCount, kFrameCount); + temp_buffer->ReadFrames(kFrameCount, 0, 0, audio_bus.get()); + + const base::TimeDelta kTimestamp = base::TimeDelta::FromMilliseconds(123); + + auto audio_buffer_from_bus = + media::AudioBuffer::CopyFrom(kSampleRate, kTimestamp, audio_bus.get()); + + EXPECT_EQ(audio_buffer_from_bus->channel_count(), audio_bus->channels()); + EXPECT_EQ(audio_buffer_from_bus->channel_layout(), + GuessChannelLayout(kChannelCount)); + EXPECT_EQ(audio_buffer_from_bus->frame_count(), audio_bus->frames()); + EXPECT_EQ(audio_buffer_from_bus->timestamp(), kTimestamp); + EXPECT_EQ(audio_buffer_from_bus->sample_rate(), kSampleRate); + EXPECT_EQ(audio_buffer_from_bus->sample_format(), + SampleFormat::kSampleFormatPlanarF32); + EXPECT_FALSE(audio_buffer_from_bus->end_of_stream()); + + for (int ch = 0; ch < kChannelCount; ++ch) { + const float* bus_data = audio_bus->channel(ch); + const float* buffer_data = reinterpret_cast<const float*>( + audio_buffer_from_bus->channel_data()[ch]); + + for (int i = 0; i < kFrameCount; ++i) + EXPECT_EQ(buffer_data[i], bus_data[i]); + } +} + TEST(AudioBufferTest, CopyBitstreamFrom) { const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; const int kChannelCount = ChannelLayoutToChannelCount(kChannelLayout); @@ -456,6 +494,38 @@ TEST(AudioBufferTest, ReadF32Planar) { VerifyBus(bus.get(), frames, 1, 1, ValueType::kFloat); } +TEST(AudioBufferTest, WrapOrCopyToAudioBus) { + const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; + const int channels = ChannelLayoutToChannelCount(channel_layout); + const int frames = 100; + const base::TimeDelta start_time; + scoped_refptr<AudioBuffer> buffer = + MakeAudioBuffer<float>(kSampleFormatPlanarF32, channel_layout, channels, + kSampleRate, 1.0f, 1.0f, frames, start_time); + + // With kSampleFormatPlanarF32, the memory layout should allow |bus| to + // directly wrap |buffer|'s data. + std::unique_ptr<AudioBus> bus = AudioBuffer::WrapOrCopyToAudioBus(buffer); + for (int ch = 0; ch < channels; ++ch) { + EXPECT_EQ(bus->channel(ch), + reinterpret_cast<float*>(buffer->channel_data()[ch])); + } + + // |bus| should have its own reference on |buffer|, so clearing it here should + // not free the underlying data. + buffer.reset(); + VerifyBus(bus.get(), frames, 1, 1, ValueType::kFloat); + + // Interleaved samples cannot be wrapped, and samples will be copied out. + buffer = MakeAudioBuffer<float>(kSampleFormatF32, channel_layout, channels, + kSampleRate, 1.0f, 1.0f, frames, start_time); + + bus = AudioBuffer::WrapOrCopyToAudioBus(buffer); + buffer.reset(); + + VerifyBus(bus.get(), frames, 1, 1, ValueType::kFloat); +} + TEST(AudioBufferTest, EmptyBuffer) { const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0; const int channels = ChannelLayoutToChannelCount(channel_layout); diff --git a/chromium/media/base/audio_bus.cc b/chromium/media/base/audio_bus.cc index 76ee5c24218..3115558f367 100644 --- a/chromium/media/base/audio_bus.cc +++ b/chromium/media/base/audio_bus.cc @@ -64,8 +64,7 @@ void AudioBus::CheckOverflow(int start_frame, int frames, int total_frames) { } AudioBus::AudioBus(int channels, int frames) - : frames_(frames), - can_set_channel_data_(false) { + : frames_(frames), is_wrapper_(false) { ValidateConfig(channels, frames_); int aligned_frames = 0; @@ -78,8 +77,7 @@ AudioBus::AudioBus(int channels, int frames) } AudioBus::AudioBus(int channels, int frames, float* data) - : frames_(frames), - can_set_channel_data_(false) { + : frames_(frames), is_wrapper_(false) { // Since |data| may have come from an external source, ensure it's valid. CHECK(data); ValidateConfig(channels, frames_); @@ -91,9 +89,7 @@ AudioBus::AudioBus(int channels, int frames, float* data) } AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) - : channel_data_(channel_data), - frames_(frames), - can_set_channel_data_(false) { + : channel_data_(channel_data), frames_(frames), is_wrapper_(false) { ValidateConfig( base::checked_cast<int>(channel_data_.size()), frames_); @@ -103,15 +99,16 @@ AudioBus::AudioBus(int frames, const std::vector<float*>& channel_data) } AudioBus::AudioBus(int channels) - : channel_data_(channels), - frames_(0), - can_set_channel_data_(true) { + : channel_data_(channels), frames_(0), is_wrapper_(true) { CHECK_GT(channels, 0); for (size_t i = 0; i < channel_data_.size(); ++i) channel_data_[i] = NULL; } -AudioBus::~AudioBus() = default; +AudioBus::~AudioBus() { + if (wrapped_data_deleter_cb_) + std::move(wrapped_data_deleter_cb_).Run(); +} std::unique_ptr<AudioBus> AudioBus::Create(int channels, int frames) { return base::WrapUnique(new AudioBus(channels, frames)); @@ -171,7 +168,7 @@ std::unique_ptr<const AudioBus> AudioBus::WrapReadOnlyMemory( } void AudioBus::SetChannelData(int channel, float* data) { - CHECK(can_set_channel_data_); + CHECK(is_wrapper_); CHECK(data); CHECK_GE(channel, 0); CHECK_LT(static_cast<size_t>(channel), channel_data_.size()); @@ -180,11 +177,17 @@ void AudioBus::SetChannelData(int channel, float* data) { } void AudioBus::set_frames(int frames) { - CHECK(can_set_channel_data_); + CHECK(is_wrapper_); ValidateConfig(static_cast<int>(channel_data_.size()), frames); frames_ = frames; } +void AudioBus::SetWrappedDataDeleter(base::OnceClosure deleter) { + CHECK(is_wrapper_); + DCHECK(!wrapped_data_deleter_cb_); + wrapped_data_deleter_cb_ = std::move(deleter); +} + size_t AudioBus::GetBitstreamDataSize() const { DCHECK(is_bitstream_format_); return bitstream_data_size_; diff --git a/chromium/media/base/audio_bus.h b/chromium/media/base/audio_bus.h index 1c520279146..75792baa9b8 100644 --- a/chromium/media/base/audio_bus.h +++ b/chromium/media/base/audio_bus.h @@ -10,6 +10,7 @@ #include <memory> #include <vector> +#include "base/callback.h" #include "base/macros.h" #include "base/memory/aligned_memory.h" #include "media/base/audio_sample_types.h" @@ -76,6 +77,13 @@ class MEDIA_SHMEM_EXPORT AudioBus { void SetChannelData(int channel, float* data); void set_frames(int frames); + // Method optionally called after AudioBus::CreateWrapper(). + // Runs |deleter| when on |this|' destruction, freeing external data + // referenced by SetChannelData(). + // Note: It is illegal to call this method when using a factory method other + // than CreateWrapper(). + void SetWrappedDataDeleter(base::OnceClosure deleter); + // Methods for compressed bitstream formats. The data size may not be equal to // the capacity of the AudioBus. Also, the frame count may not be equal to the // capacity of the AudioBus. Thus, we need extra methods to access the real @@ -220,8 +228,13 @@ class MEDIA_SHMEM_EXPORT AudioBus { std::vector<float*> channel_data_; int frames_; - // Protect SetChannelData() and set_frames() for use by CreateWrapper(). - bool can_set_channel_data_; + // Protect SetChannelData(), set_frames() and SetWrappedDataDeleter() for use + // by CreateWrapper(). + bool is_wrapper_; + + // Run on destruction. Frees memory to the data set via SetChannelData(). + // Only used with CreateWrapper(). + base::OnceClosure wrapped_data_deleter_cb_; DISALLOW_COPY_AND_ASSIGN(AudioBus); }; diff --git a/chromium/media/base/audio_bus_unittest.cc b/chromium/media/base/audio_bus_unittest.cc index 38d5cbd09da..e2cac3c8e29 100644 --- a/chromium/media/base/audio_bus_unittest.cc +++ b/chromium/media/base/audio_bus_unittest.cc @@ -11,6 +11,7 @@ #include "base/memory/aligned_memory.h" #include "base/stl_util.h" #include "base/strings/stringprintf.h" +#include "base/test/bind.h" #include "base/time/time.h" #include "build/build_config.h" #include "media/base/audio_bus.h" @@ -157,8 +158,16 @@ TEST_F(AudioBusTest, CreateWrapper) { for (int i = 0; i < bus->channels(); ++i) bus->SetChannelData(i, data_[i]); + bool deleted = false; + bus->SetWrappedDataDeleter( + base::BindLambdaForTesting([&]() { deleted = true; })); + VerifyChannelAndFrameCount(bus.get()); VerifyReadWriteAndAlignment(bus.get()); + + EXPECT_FALSE(deleted); + bus.reset(); + EXPECT_TRUE(deleted); } // Verify an AudioBus created via wrapping a vector works as advertised. diff --git a/chromium/media/base/audio_capturer_source.h b/chromium/media/base/audio_capturer_source.h index ca91a598c22..7ec2136eb5f 100644 --- a/chromium/media/base/audio_capturer_source.h +++ b/chromium/media/base/audio_capturer_source.h @@ -23,6 +23,11 @@ class AudioProcessorControls; class AudioCapturerSource : public base::RefCountedThreadSafe<media::AudioCapturerSource> { public: + enum class ErrorCode { + kUnknown = 0, + kSystemPermissions = 1, + }; + class CaptureCallback { public: // Signals that audio recording has been started. Called asynchronously @@ -40,7 +45,7 @@ class AudioCapturerSource bool key_pressed) = 0; // Signals an error has occurred. - virtual void OnCaptureError(const std::string& message) = 0; + virtual void OnCaptureError(ErrorCode code, const std::string& message) = 0; // Signals the muted state has changed. May be called before // OnCaptureStarted. diff --git a/chromium/media/base/audio_converter.h b/chromium/media/base/audio_converter.h index 5e1b609fabf..45b667b1fe8 100644 --- a/chromium/media/base/audio_converter.h +++ b/chromium/media/base/audio_converter.h @@ -23,7 +23,6 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/time/time.h" #include "media/base/audio_parameters.h" #include "media/base/media_export.h" diff --git a/chromium/media/base/audio_decoder.h b/chromium/media/base/audio_decoder.h index 245ac2979a0..961d570e561 100644 --- a/chromium/media/base/audio_decoder.h +++ b/chromium/media/base/audio_decoder.h @@ -5,8 +5,6 @@ #ifndef MEDIA_BASE_AUDIO_DECODER_H_ #define MEDIA_BASE_AUDIO_DECODER_H_ -#include <string> - #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" diff --git a/chromium/media/base/audio_encoder.h b/chromium/media/base/audio_encoder.h index 2d3362bebca..d7979cca1e9 100644 --- a/chromium/media/base/audio_encoder.h +++ b/chromium/media/base/audio_encoder.h @@ -55,7 +55,7 @@ class MEDIA_EXPORT AudioEncoder { Options(const Options&); ~Options(); - base::Optional<int> bitrate; + absl::optional<int> bitrate; int channels; @@ -69,7 +69,7 @@ class MEDIA_EXPORT AudioEncoder { // invoked on the same sequence on which EncodeAudio() is called. using OutputCB = base::RepeatingCallback<void(EncodedAudioBuffer output, - base::Optional<CodecDescription>)>; + absl::optional<CodecDescription>)>; // Signature of the callback to report errors. using StatusCB = base::OnceCallback<void(Status error)>; diff --git a/chromium/media/base/audio_parameters.h b/chromium/media/base/audio_parameters.h index 9d571a3c6e2..fbebe23cf45 100644 --- a/chromium/media/base/audio_parameters.h +++ b/chromium/media/base/audio_parameters.h @@ -11,7 +11,6 @@ #include "base/compiler_specific.h" #include "base/numerics/checked_math.h" -#include "base/optional.h" #include "base/time/time.h" #include "build/build_config.h" #include "media/base/audio_bus.h" @@ -20,6 +19,7 @@ #include "media/base/channel_layout.h" #include "media/base/media_shmem_export.h" #include "media/base/sample_format.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -254,7 +254,7 @@ class MEDIA_SHMEM_EXPORT AudioParameters { } int frames_per_buffer() const { return frames_per_buffer_; } - base::Optional<HardwareCapabilities> hardware_capabilities() const { + absl::optional<HardwareCapabilities> hardware_capabilities() const { return hardware_capabilities_; } @@ -305,7 +305,7 @@ class MEDIA_SHMEM_EXPORT AudioParameters { // Audio hardware specific parameters, these are treated as read-only and // changing them has no effect. - base::Optional<HardwareCapabilities> hardware_capabilities_; + absl::optional<HardwareCapabilities> hardware_capabilities_; }; // Comparison is useful when AudioParameters is used with std structures. diff --git a/chromium/media/base/audio_processing.h b/chromium/media/base/audio_processing.h index 46428114847..52f32fbc6ef 100644 --- a/chromium/media/base/audio_processing.h +++ b/chromium/media/base/audio_processing.h @@ -8,7 +8,6 @@ #include <string> #include "base/files/file.h" -#include "base/time/time.h" #include "base/unguessable_token.h" #include "media/base/media_export.h" diff --git a/chromium/media/base/audio_renderer.h b/chromium/media/base/audio_renderer.h index 15701b34294..907d0fc7f82 100644 --- a/chromium/media/base/audio_renderer.h +++ b/chromium/media/base/audio_renderer.h @@ -7,11 +7,11 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/buffering_state.h" #include "media/base/media_export.h" #include "media/base/pipeline_status.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -63,7 +63,7 @@ class MEDIA_EXPORT AudioRenderer { // Set a hint indicating target latency. See comment in renderer.h. // |latency_hint| may be nullopt to indicate the hint has been cleared // (restore UA default). - virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0; + virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0; // Sets a flag indicating that the AudioRenderer should use or avoid pitch // preservation when playing back at speeds other than 1.0. diff --git a/chromium/media/base/audio_renderer_mixer_input.h b/chromium/media/base/audio_renderer_mixer_input.h index c56e1f209c8..724cba483d5 100644 --- a/chromium/media/base/audio_renderer_mixer_input.h +++ b/chromium/media/base/audio_renderer_mixer_input.h @@ -83,7 +83,7 @@ class MEDIA_EXPORT AudioRendererMixerInput double volume_ GUARDED_BY(volume_lock_) = 1.0; scoped_refptr<AudioRendererSink> sink_; - base::Optional<OutputDeviceInfo> device_info_; + absl::optional<OutputDeviceInfo> device_info_; // AudioConverter::InputCallback implementation. double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; diff --git a/chromium/media/base/cdm_context.cc b/chromium/media/base/cdm_context.cc index 9b30303dd4b..fc2901585bb 100644 --- a/chromium/media/base/cdm_context.cc +++ b/chromium/media/base/cdm_context.cc @@ -22,8 +22,8 @@ Decryptor* CdmContext::GetDecryptor() { return nullptr; } -base::Optional<base::UnguessableToken> CdmContext::GetCdmId() const { - return base::nullopt; +absl::optional<base::UnguessableToken> CdmContext::GetCdmId() const { + return absl::nullopt; } std::string CdmContext::CdmIdToString(const base::UnguessableToken* cdm_id) { diff --git a/chromium/media/base/cdm_context.h b/chromium/media/base/cdm_context.h index 9bb677217cc..f426dd3fd13 100644 --- a/chromium/media/base/cdm_context.h +++ b/chromium/media/base/cdm_context.h @@ -7,17 +7,13 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/optional.h" +#include "base/memory/scoped_refptr.h" #include "base/unguessable_token.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "media/base/media_export.h" #include "media/media_buildflags.h" - -#if defined(OS_WIN) -#include <wrl/client.h> -struct IMFCdmProxy; -#endif +#include "third_party/abseil-cpp/absl/types/optional.h" #if BUILDFLAG(IS_CHROMEOS_ASH) namespace chromeos { @@ -35,6 +31,10 @@ class MediaCryptoContext; class FuchsiaCdmContext; #endif +#if defined(OS_WIN) +class MediaFoundationCdmProxy; +#endif + // An interface representing the context that a media player needs from a // content decryption module (CDM) to decrypt (and decode) encrypted buffers. // Typically this will be passed to the media player (e.g. using SetCdm()). @@ -88,9 +88,9 @@ class MEDIA_EXPORT CdmContext { virtual Decryptor* GetDecryptor(); // Returns an ID that can be used to find a remote CDM, in which case this CDM - // serves as a proxy to the remote one. Returns base::nullopt when remote CDM + // serves as a proxy to the remote one. Returns absl::nullopt when remote CDM // is not supported (e.g. this CDM is a local CDM). - virtual base::Optional<base::UnguessableToken> GetCdmId() const; + virtual absl::optional<base::UnguessableToken> GetCdmId() const; static std::string CdmIdToString(const base::UnguessableToken* cdm_id); @@ -101,7 +101,7 @@ class MEDIA_EXPORT CdmContext { virtual bool RequiresMediaFoundationRenderer(); using GetMediaFoundationCdmProxyCB = - base::OnceCallback<void(Microsoft::WRL::ComPtr<IMFCdmProxy>)>; + base::OnceCallback<void(scoped_refptr<MediaFoundationCdmProxy>)>; // This allows a CdmContext to expose an IMFTrustedInput instance for use in // a Media Foundation rendering pipeline. This method is asynchronous because // the underlying MF-based CDM might not have a native session created yet. diff --git a/chromium/media/base/data_source.h b/chromium/media/base/data_source.h index 82dd76485fa..08c740c0fa0 100644 --- a/chromium/media/base/data_source.h +++ b/chromium/media/base/data_source.h @@ -9,7 +9,6 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/time/time.h" #include "media/base/media_export.h" namespace media { diff --git a/chromium/media/base/decoder_buffer.h b/chromium/media/base/decoder_buffer.h index ea64fa50d0b..9a305f3e77a 100644 --- a/chromium/media/base/decoder_buffer.h +++ b/chromium/media/base/decoder_buffer.h @@ -14,7 +14,6 @@ #include "base/check.h" #include "base/macros.h" -#include "base/memory/aligned_memory.h" #include "base/memory/read_only_shared_memory_region.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" diff --git a/chromium/media/base/decrypt_config.cc b/chromium/media/base/decrypt_config.cc index 5b7c02c8f5e..ff3ed63f7a4 100644 --- a/chromium/media/base/decrypt_config.cc +++ b/chromium/media/base/decrypt_config.cc @@ -19,7 +19,7 @@ std::unique_ptr<DecryptConfig> DecryptConfig::CreateCencConfig( const std::string& iv, const std::vector<SubsampleEntry>& subsamples) { return std::make_unique<DecryptConfig>(EncryptionScheme::kCenc, key_id, iv, - subsamples, base::nullopt); + subsamples, absl::nullopt); } // static @@ -27,7 +27,7 @@ std::unique_ptr<DecryptConfig> DecryptConfig::CreateCbcsConfig( const std::string& key_id, const std::string& iv, const std::vector<SubsampleEntry>& subsamples, - base::Optional<EncryptionPattern> encryption_pattern) { + absl::optional<EncryptionPattern> encryption_pattern) { return std::make_unique<DecryptConfig>(EncryptionScheme::kCbcs, key_id, iv, subsamples, std::move(encryption_pattern)); @@ -38,7 +38,7 @@ DecryptConfig::DecryptConfig( const std::string& key_id, const std::string& iv, const std::vector<SubsampleEntry>& subsamples, - base::Optional<EncryptionPattern> encryption_pattern) + absl::optional<EncryptionPattern> encryption_pattern) : encryption_scheme_(encryption_scheme), key_id_(key_id), iv_(iv), diff --git a/chromium/media/base/decrypt_config.h b/chromium/media/base/decrypt_config.h index 79905419bdd..a9c55064566 100644 --- a/chromium/media/base/decrypt_config.h +++ b/chromium/media/base/decrypt_config.h @@ -13,11 +13,11 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "media/base/encryption_pattern.h" #include "media/base/encryption_scheme.h" #include "media/base/media_export.h" #include "media/base/subsample_entry.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -47,20 +47,20 @@ class MEDIA_EXPORT DecryptConfig { const std::string& key_id, const std::string& iv, const std::vector<SubsampleEntry>& subsamples, - base::Optional<EncryptionPattern> encryption_pattern); + absl::optional<EncryptionPattern> encryption_pattern); DecryptConfig(EncryptionScheme encryption_scheme, const std::string& key_id, const std::string& iv, const std::vector<SubsampleEntry>& subsamples, - base::Optional<EncryptionPattern> encryption_pattern); + absl::optional<EncryptionPattern> encryption_pattern); ~DecryptConfig(); const std::string& key_id() const { return key_id_; } const std::string& iv() const { return iv_; } const std::vector<SubsampleEntry>& subsamples() const { return subsamples_; } EncryptionScheme encryption_scheme() const { return encryption_scheme_; } - const base::Optional<EncryptionPattern>& encryption_pattern() const { + const absl::optional<EncryptionPattern>& encryption_pattern() const { return encryption_pattern_; } @@ -95,7 +95,7 @@ class MEDIA_EXPORT DecryptConfig { const std::vector<SubsampleEntry> subsamples_; // Only specified if |encryption_mode_| requires a pattern. - base::Optional<EncryptionPattern> encryption_pattern_; + absl::optional<EncryptionPattern> encryption_pattern_; DISALLOW_ASSIGN(DecryptConfig); }; diff --git a/chromium/media/base/decrypt_config_unittest.cc b/chromium/media/base/decrypt_config_unittest.cc index e39d7a79461..014ee6a4d23 100644 --- a/chromium/media/base/decrypt_config_unittest.cc +++ b/chromium/media/base/decrypt_config_unittest.cc @@ -78,7 +78,7 @@ TEST(DecryptConfigTest, CbcsConstruction) { // Now without pattern. config = DecryptConfig::CreateCbcsConfig(kAlternateKeyId, kDefaultIV, - {{1, 2}}, base::nullopt); + {{1, 2}}, absl::nullopt); EXPECT_EQ(config->key_id(), kAlternateKeyId); EXPECT_EQ(config->iv(), kDefaultIV); EXPECT_EQ(config->subsamples().size(), 1u); @@ -173,7 +173,7 @@ TEST(DecryptConfigTest, CbcsMatches) { // Without pattern. auto config6 = DecryptConfig::CreateCbcsConfig(kDefaultKeyId, kDefaultIV, {}, - base::nullopt); + absl::nullopt); EXPECT_FALSE(config1->Matches(*config6)); EXPECT_FALSE(config5->Matches(*config6)); EXPECT_FALSE(config6->Matches(*config1)); @@ -192,7 +192,7 @@ TEST(DecryptConfigTest, Output) { // Simple 'cbcs' config. stream << *DecryptConfig::CreateCbcsConfig(kDefaultKeyId, kDefaultIV, {}, - base::nullopt); + absl::nullopt); // 'cbcs' config with subsamples and pattern. stream << *DecryptConfig::CreateCbcsConfig(kAlternateKeyId, kAlternateIV, diff --git a/chromium/media/base/demuxer.h b/chromium/media/base/demuxer.h index c9a4ebbd6b8..e048fca2d9c 100644 --- a/chromium/media/base/demuxer.h +++ b/chromium/media/base/demuxer.h @@ -11,7 +11,6 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/container_names.h" #include "media/base/data_source.h" @@ -22,6 +21,7 @@ #include "media/base/media_track.h" #include "media/base/pipeline_status.h" #include "media/base/ranges.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -149,7 +149,7 @@ class MEDIA_EXPORT Demuxer : public MediaResource { // Implementations where this is not meaningful will return an empty value. // Implementations that do provide values should always provide a value, // returning CONTAINER_UNKNOWN in cases where the container is not known. - virtual base::Optional<container_names::MediaContainerName> + virtual absl::optional<container_names::MediaContainerName> GetContainerForMetrics() const = 0; // The |track_ids| vector has either 1 track, or is empty, indicating that diff --git a/chromium/media/base/demuxer_memory_limit_cast_unittest.cc b/chromium/media/base/demuxer_memory_limit_cast_unittest.cc index 41b68a20aed..4dbe6d4308b 100644 --- a/chromium/media/base/demuxer_memory_limit_cast_unittest.cc +++ b/chromium/media/base/demuxer_memory_limit_cast_unittest.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/optional.h" #include "media/base/audio_decoder_config.h" #include "media/base/demuxer.h" #include "media/base/demuxer_memory_limit.h" #include "media/base/media_util.h" #include "media/base/video_decoder_config.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { diff --git a/chromium/media/base/demuxer_stream.h b/chromium/media/base/demuxer_stream.h index 30236894215..3b10523f7fb 100644 --- a/chromium/media/base/demuxer_stream.h +++ b/chromium/media/base/demuxer_stream.h @@ -7,7 +7,6 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" -#include "base/time/time.h" #include "media/base/media_export.h" #include "media/base/video_transformation.h" diff --git a/chromium/media/base/eme_constants.h b/chromium/media/base/eme_constants.h index 11e7c1ed3ff..6e47c0ed18a 100644 --- a/chromium/media/base/eme_constants.h +++ b/chromium/media/base/eme_constants.h @@ -187,19 +187,20 @@ enum class EmeConfigRule { IDENTIFIER_AND_PERSISTENCE_REQUIRED, // The configuration option prevents use of hardware-secure codecs. - // This rule only has meaning on platforms that distinguish hardware-secure - // codecs (i.e. Android, Windows and ChromeOS). HW_SECURE_CODECS_NOT_ALLOWED, // The configuration option is supported if hardware-secure codecs are used. - // This rule only has meaning on platforms that distinguish hardware-secure - // codecs (i.e. Android, Windows and ChromeOS). HW_SECURE_CODECS_REQUIRED, // The configuration option is supported on platforms where hardware-secure // codecs are used and an identifier is also required (i.e. ChromeOS). IDENTIFIER_AND_HW_SECURE_CODECS_REQUIRED, + // The configuration option is supported on platforms where hardware-secure + // codecs are used and both identifier and persistent state are required (i.e. + // Windows). + IDENTIFIER_PERSISTENCE_AND_HW_SECURE_CODECS_REQUIRED, + // The configuration option is supported without conditions. SUPPORTED, }; diff --git a/chromium/media/base/encryption_pattern.h b/chromium/media/base/encryption_pattern.h index 928c1dbadb9..89c3e28b115 100644 --- a/chromium/media/base/encryption_pattern.h +++ b/chromium/media/base/encryption_pattern.h @@ -20,7 +20,7 @@ namespace media { // encrypted, and the next nine are skipped. This pattern is applied // repeatedly until the end of the last 16-byte block in the subsample. // Any remaining bytes are left clear. -// TODO(jrummell): Use base::Optional<EncryptionPattern> everywhere. +// TODO(jrummell): Use absl::optional<EncryptionPattern> everywhere. class MEDIA_EXPORT EncryptionPattern { public: EncryptionPattern(); diff --git a/chromium/media/base/fake_audio_renderer_sink.h b/chromium/media/base/fake_audio_renderer_sink.h index 9918eabad63..63af4b5b987 100644 --- a/chromium/media/base/fake_audio_renderer_sink.h +++ b/chromium/media/base/fake_audio_renderer_sink.h @@ -7,8 +7,6 @@ #include <stdint.h> -#include <string> - #include "base/macros.h" #include "media/base/audio_parameters.h" #include "media/base/audio_renderer_sink.h" diff --git a/chromium/media/base/fake_text_track_stream.cc b/chromium/media/base/fake_text_track_stream.cc index 72a1655cfa8..5a9bd62f5ce 100644 --- a/chromium/media/base/fake_text_track_stream.cc +++ b/chromium/media/base/fake_text_track_stream.cc @@ -63,8 +63,8 @@ void FakeTextTrackStream::SatisfyPendingRead( const uint8_t* const sd_buf = &side_data[0]; const int sd_len = static_cast<int>(side_data.size()); - scoped_refptr<DecoderBuffer> buffer; - buffer = DecoderBuffer::CopyFrom(data_buf, data_len, sd_buf, sd_len); + scoped_refptr<DecoderBuffer> buffer = + DecoderBuffer::CopyFrom(data_buf, data_len, sd_buf, sd_len); buffer->set_timestamp(start); buffer->set_duration(duration); diff --git a/chromium/media/base/format_utils.cc b/chromium/media/base/format_utils.cc index be5a8b9c411..b9fc8143bd6 100644 --- a/chromium/media/base/format_utils.cc +++ b/chromium/media/base/format_utils.cc @@ -8,7 +8,7 @@ namespace media { -base::Optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat( +absl::optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat( gfx::BufferFormat format) { switch (format) { case gfx::BufferFormat::BGRX_8888: @@ -40,11 +40,11 @@ base::Optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat( default: DLOG(WARNING) << "Unsupported BufferFormat: " << gfx::BufferFormatToString(format); - return base::nullopt; + return absl::nullopt; } } -base::Optional<gfx::BufferFormat> VideoPixelFormatToGfxBufferFormat( +absl::optional<gfx::BufferFormat> VideoPixelFormatToGfxBufferFormat( VideoPixelFormat pixel_format) { switch (pixel_format) { case PIXEL_FORMAT_ARGB: @@ -70,7 +70,7 @@ base::Optional<gfx::BufferFormat> VideoPixelFormatToGfxBufferFormat( default: DLOG(WARNING) << "Unsupported VideoPixelFormat: " << pixel_format; - return base::nullopt; + return absl::nullopt; } } diff --git a/chromium/media/base/format_utils.h b/chromium/media/base/format_utils.h index de7980c7034..eed468b553f 100644 --- a/chromium/media/base/format_utils.h +++ b/chromium/media/base/format_utils.h @@ -5,17 +5,17 @@ #ifndef MEDIA_BASE_FORMAT_UTILS_H_ #define MEDIA_BASE_FORMAT_UTILS_H_ -#include "base/optional.h" #include "media/base/media_export.h" #include "media/base/video_types.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/buffer_types.h" namespace media { -MEDIA_EXPORT base::Optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat( +MEDIA_EXPORT absl::optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat( gfx::BufferFormat format); -MEDIA_EXPORT base::Optional<gfx::BufferFormat> +MEDIA_EXPORT absl::optional<gfx::BufferFormat> VideoPixelFormatToGfxBufferFormat(VideoPixelFormat pixel_format); } // namespace media diff --git a/chromium/media/base/frame_rate_estimator.cc b/chromium/media/base/frame_rate_estimator.cc index 96a39b90707..48cf9f9a56d 100644 --- a/chromium/media/base/frame_rate_estimator.cc +++ b/chromium/media/base/frame_rate_estimator.cc @@ -62,7 +62,7 @@ void FrameRateEstimator::AddSample(base::TimeDelta frame_duration) { most_recent_bucket_ = bucketed_fps_min; } -base::Optional<int> FrameRateEstimator::ComputeFPS() { +absl::optional<int> FrameRateEstimator::ComputeFPS() { return most_recent_bucket_; } diff --git a/chromium/media/base/frame_rate_estimator.h b/chromium/media/base/frame_rate_estimator.h index 3a00f7bcd5e..38262abe4fc 100644 --- a/chromium/media/base/frame_rate_estimator.h +++ b/chromium/media/base/frame_rate_estimator.h @@ -6,9 +6,9 @@ #define MEDIA_BASE_FRAME_RATE_ESTIMATOR_H_ #include "base/macros.h" -#include "base/optional.h" #include "media/base/media_export.h" #include "media/base/moving_average.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -25,7 +25,7 @@ class MEDIA_EXPORT FrameRateEstimator { // Return the current (bucketed) frame rate (not duration), or nullopt if one // isn't available with suitable certainty. - base::Optional<int> ComputeFPS(); + absl::optional<int> ComputeFPS(); // Reset everything. void Reset(); @@ -43,7 +43,7 @@ class MEDIA_EXPORT FrameRateEstimator { uint64_t required_samples_; // Most recently computed bucketed FPS (not duration), if any. - base::Optional<int> most_recent_bucket_; + absl::optional<int> most_recent_bucket_; }; } // namespace media diff --git a/chromium/media/base/ipc/media_param_traits.cc b/chromium/media/base/ipc/media_param_traits.cc index 271754aff43..884ac079019 100644 --- a/chromium/media/base/ipc/media_param_traits.cc +++ b/chromium/media/base/ipc/media_param_traits.cc @@ -41,7 +41,7 @@ bool ParamTraits<AudioParameters>::Read(const base::Pickle* m, int sample_rate, frames_per_buffer, channels, effects; std::vector<media::Point> mic_positions; AudioLatency::LatencyType latency_tag; - base::Optional<media::AudioParameters::HardwareCapabilities> + absl::optional<media::AudioParameters::HardwareCapabilities> hardware_capabilities; if (!ReadParam(m, iter, &format) || !ReadParam(m, iter, &channel_layout) || diff --git a/chromium/media/base/key_system_names.cc b/chromium/media/base/key_system_names.cc index 6fdf44cac9e..6a8bc0a9f42 100644 --- a/chromium/media/base/key_system_names.cc +++ b/chromium/media/base/key_system_names.cc @@ -13,15 +13,14 @@ bool IsClearKey(const std::string& key_system) { return key_system == kClearKey; } -bool IsChildKeySystemOf(const std::string& key_system, - const std::string& base) { +bool IsSubKeySystemOf(const std::string& key_system, const std::string& base) { std::string prefix = base + '.'; return key_system.substr(0, prefix.size()) == prefix; } bool IsExternalClearKey(const std::string& key_system) { return key_system == kExternalClearKey || - IsChildKeySystemOf(key_system, kExternalClearKey); + IsSubKeySystemOf(key_system, kExternalClearKey); } } // namespace media diff --git a/chromium/media/base/key_system_names.h b/chromium/media/base/key_system_names.h index 0ba1934a275..e7ed8840b1e 100644 --- a/chromium/media/base/key_system_names.h +++ b/chromium/media/base/key_system_names.h @@ -18,8 +18,8 @@ namespace media { MEDIA_EXPORT bool IsClearKey(const std::string& key_system); // Returns true if |key_system| is (reverse) sub-domain of |base|. -MEDIA_EXPORT bool IsChildKeySystemOf(const std::string& key_system, - const std::string& base); +MEDIA_EXPORT bool IsSubKeySystemOf(const std::string& key_system, + const std::string& base); // Returns true if |key_system| is External Clear Key, false otherwise. MEDIA_EXPORT bool IsExternalClearKey(const std::string& key_system); diff --git a/chromium/media/base/key_system_properties.h b/chromium/media/base/key_system_properties.h index 032f745fd42..0cd832ff69a 100644 --- a/chromium/media/base/key_system_properties.h +++ b/chromium/media/base/key_system_properties.h @@ -40,9 +40,17 @@ class MEDIA_EXPORT KeySystemProperties { virtual SupportedCodecs GetSupportedHwSecureCodecs() const; // Returns the configuration rule for supporting a robustness requirement. + // If `hw_secure_requirement` is true, then the key system already has a HW + // secure requirement, if false then it already has a requirement to disallow + // HW secure; if null then there is no HW secure requirement to apply. This + // does not imply that `requested_robustness` should be ignored, both rules + // must be applied. + // TODO(crbug.com/1204284): Refactor this and remove the + // `hw_secure_requirement` argument. virtual EmeConfigRule GetRobustnessConfigRule( EmeMediaType media_type, - const std::string& requested_robustness) const = 0; + const std::string& requested_robustness, + const bool* hw_secure_requirement) const = 0; // Returns the support this key system provides for persistent-license // sessions. diff --git a/chromium/media/base/key_systems.cc b/chromium/media/base/key_systems.cc index c05c68495e6..03c1007bcd2 100644 --- a/chromium/media/base/key_systems.cc +++ b/chromium/media/base/key_systems.cc @@ -162,7 +162,8 @@ class ClearKeyProperties : public KeySystemProperties { EmeConfigRule GetRobustnessConfigRule( EmeMediaType media_type, - const std::string& requested_robustness) const override { + const std::string& requested_robustness, + const bool* /*hw_secure_requirement*/) const override { return requested_robustness.empty() ? EmeConfigRule::SUPPORTED : EmeConfigRule::NOT_SUPPORTED; } @@ -219,7 +220,7 @@ static bool IsPotentiallySupportedKeySystem(const std::string& key_system) { // Chromecast defines behaviors for Cast clients within its reverse domain. const char kChromecastRoot[] = "com.chromecast"; - if (IsChildKeySystemOf(key_system, kChromecastRoot)) + if (IsSubKeySystemOf(key_system, kChromecastRoot)) return true; // Implementations that do not have a specification or appropriate glue code @@ -264,7 +265,8 @@ class KeySystemsImpl : public KeySystems { EmeConfigRule GetRobustnessConfigRule( const std::string& key_system, EmeMediaType media_type, - const std::string& requested_robustness) const override; + const std::string& requested_robustness, + const bool* hw_secure_requirement) const override; EmeSessionTypeSupport GetPersistentLicenseSessionSupport( const std::string& key_system) const override; @@ -711,7 +713,8 @@ EmeConfigRule KeySystemsImpl::GetContentTypeConfigRule( EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( const std::string& key_system, EmeMediaType media_type, - const std::string& requested_robustness) const { + const std::string& requested_robustness, + const bool* hw_secure_requirement) const { DCHECK(thread_checker_.CalledOnValidThread()); auto key_system_iter = key_system_properties_map_.find(key_system); @@ -719,8 +722,8 @@ EmeConfigRule KeySystemsImpl::GetRobustnessConfigRule( NOTREACHED(); return EmeConfigRule::NOT_SUPPORTED; } - return key_system_iter->second->GetRobustnessConfigRule(media_type, - requested_robustness); + return key_system_iter->second->GetRobustnessConfigRule( + media_type, requested_robustness, hw_secure_requirement); } EmeSessionTypeSupport KeySystemsImpl::GetPersistentLicenseSessionSupport( diff --git a/chromium/media/base/key_systems.h b/chromium/media/base/key_systems.h index 34fd6a46602..9d2e2b7fc26 100644 --- a/chromium/media/base/key_systems.h +++ b/chromium/media/base/key_systems.h @@ -56,10 +56,18 @@ class MEDIA_EXPORT KeySystems { const std::vector<std::string>& codecs) const = 0; // Returns the configuration rule for supporting a robustness requirement. + // If `hw_secure_requirement` is true, then the key system already has a HW + // secure requirement, if false then it already has a requirement to disallow + // HW secure; if null then there is no HW secure requirement to apply. This + // does not imply that `requested_robustness` should be ignored, both rules + // must be applied. + // TODO(crbug.com/1204284): Refactor this and remove the + // `hw_secure_requirement` argument. virtual EmeConfigRule GetRobustnessConfigRule( const std::string& key_system, EmeMediaType media_type, - const std::string& requested_robustness) const = 0; + const std::string& requested_robustness, + const bool* hw_secure_requirement) const = 0; // Returns the support |key_system| provides for persistent-license sessions. virtual EmeSessionTypeSupport GetPersistentLicenseSessionSupport( diff --git a/chromium/media/base/key_systems_unittest.cc b/chromium/media/base/key_systems_unittest.cc index e38e2b33c2b..4a21bb67c4b 100644 --- a/chromium/media/base/key_systems_unittest.cc +++ b/chromium/media/base/key_systems_unittest.cc @@ -76,7 +76,8 @@ class TestKeySystemPropertiesBase : public KeySystemProperties { EmeConfigRule GetRobustnessConfigRule( EmeMediaType media_type, - const std::string& requested_robustness) const override { + const std::string& requested_robustness, + const bool* /*hw_secure_requirement*/) const override { return requested_robustness.empty() ? EmeConfigRule::SUPPORTED : EmeConfigRule::NOT_SUPPORTED; } @@ -140,7 +141,8 @@ class ExternalKeySystemProperties : public TestKeySystemPropertiesBase { EmeConfigRule GetRobustnessConfigRule( EmeMediaType media_type, - const std::string& requested_robustness) const override { + const std::string& requested_robustness, + const bool* /*hw_secure_requirement*/) const override { if (requested_robustness == kRobustnessSupported) return EmeConfigRule::SUPPORTED; else if (requested_robustness == kRobustnessSecureCodecsRequired) @@ -206,7 +208,7 @@ bool IsSupportedKeySystem(const std::string& key_system) { EmeConfigRule GetRobustnessConfigRule(const std::string& requested_robustness) { return KeySystems::GetInstance()->GetRobustnessConfigRule( - kExternal, EmeMediaType::VIDEO, requested_robustness); + kExternal, EmeMediaType::VIDEO, requested_robustness, nullptr); } // Adds test container and codec masks. @@ -268,7 +270,7 @@ class TestMediaClient : public MediaClient { // test the key system update case. void DisableExternalKeySystemSupport(); - base::Optional<::media::AudioRendererAlgorithmParameters> + absl::optional<::media::AudioRendererAlgorithmParameters> GetAudioRendererAlgorithmParameters(AudioParameters audio_parameters) final; private: @@ -317,10 +319,10 @@ void TestMediaClient::DisableExternalKeySystemSupport() { supports_external_key_system_ = false; } -base::Optional<::media::AudioRendererAlgorithmParameters> +absl::optional<::media::AudioRendererAlgorithmParameters> TestMediaClient::GetAudioRendererAlgorithmParameters( AudioParameters audio_parameters) { - return base::nullopt; + return absl::nullopt; } } // namespace diff --git a/chromium/media/base/limits.h b/chromium/media/base/limits.h index edc8fc6a39e..5430e09c1cb 100644 --- a/chromium/media/base/limits.h +++ b/chromium/media/base/limits.h @@ -32,6 +32,9 @@ enum { // restriction. // - Most PC audio hardware is limited to 192 kHz, some specialized DAC // devices will use 768 kHz though. + // + // kMaxSampleRate should be updated with + // blink::audio_utilities::MaxAudioBufferSampleRate() kMaxSampleRate = 768000, kMinSampleRate = 3000, kMaxChannels = 32, diff --git a/chromium/media/base/localized_strings.h b/chromium/media/base/localized_strings.h index 9ee50b18bb7..48779b0af56 100644 --- a/chromium/media/base/localized_strings.h +++ b/chromium/media/base/localized_strings.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MEDIA_BASE_MEDIA_LOCALIZED_STRINGS_H_ -#define MEDIA_BASE_MEDIA_LOCALIZED_STRINGS_H_ +#ifndef MEDIA_BASE_LOCALIZED_STRINGS_H_ +#define MEDIA_BASE_LOCALIZED_STRINGS_H_ #include <string> @@ -46,4 +46,4 @@ std::u16string GetLocalizedStringUTF16(MessageId message_id); } // namespace media -#endif // MEDIA_BASE_MEDIA_LOCALIZED_STRINGS_H_ +#endif // MEDIA_BASE_LOCALIZED_STRINGS_H_ diff --git a/chromium/media/base/mac/videotoolbox_helpers.cc b/chromium/media/base/mac/videotoolbox_helpers.cc index 014cd2a05dd..25c7b864933 100644 --- a/chromium/media/base/mac/videotoolbox_helpers.cc +++ b/chromium/media/base/mac/videotoolbox_helpers.cc @@ -74,6 +74,10 @@ class RawAnnexBBuffer : public AnnexBBuffer { : annexb_buffer_(annexb_buffer), annexb_buffer_size_(annexb_buffer_size), annexb_buffer_offset_(0) {} + RawAnnexBBuffer() = delete; + RawAnnexBBuffer(const RawAnnexBBuffer&) = delete; + RawAnnexBBuffer& operator=(const RawAnnexBBuffer&) = delete; + bool Reserve(size_t size) override { reserved_size_ = size; return size <= annexb_buffer_size_; @@ -90,14 +94,16 @@ class RawAnnexBBuffer : public AnnexBBuffer { size_t annexb_buffer_size_; size_t annexb_buffer_offset_; size_t reserved_size_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(RawAnnexBBuffer); }; class StringAnnexBBuffer : public AnnexBBuffer { public: explicit StringAnnexBBuffer(std::string* str_annexb_buffer) : str_annexb_buffer_(str_annexb_buffer) {} + StringAnnexBBuffer() = delete; + StringAnnexBBuffer(const StringAnnexBBuffer&) = delete; + StringAnnexBBuffer& operator=(const StringAnnexBBuffer&) = delete; + bool Reserve(size_t size) override { str_annexb_buffer_->reserve(size); return true; @@ -109,7 +115,6 @@ class StringAnnexBBuffer : public AnnexBBuffer { private: std::string* str_annexb_buffer_; - DISALLOW_IMPLICIT_CONSTRUCTORS(StringAnnexBBuffer); }; template <typename NalSizeType> diff --git a/chromium/media/base/media_client.h b/chromium/media/base/media_client.h index 5c7d6c06c68..db1d3091990 100644 --- a/chromium/media/base/media_client.h +++ b/chromium/media/base/media_client.h @@ -9,7 +9,6 @@ #include <string> #include <vector> -#include "base/optional.h" #include "media/base/audio_codecs.h" #include "media/base/audio_parameters.h" #include "media/base/key_system_properties.h" @@ -17,6 +16,7 @@ #include "media/base/media_types.h" #include "media/base/video_codecs.h" #include "media/base/video_color_space.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/color_space.h" #include "url/gurl.h" @@ -61,7 +61,7 @@ class MEDIA_EXPORT MediaClient { virtual bool IsSupportedBitstreamAudioCodec(AudioCodec codec) = 0; // Optionally returns audio renderer algorithm parameters. - virtual base::Optional<::media::AudioRendererAlgorithmParameters> + virtual absl::optional<::media::AudioRendererAlgorithmParameters> GetAudioRendererAlgorithmParameters(AudioParameters audio_parameters) = 0; }; diff --git a/chromium/media/base/media_drm_storage.h b/chromium/media/base/media_drm_storage.h index ac17314bc3e..d691f232b60 100644 --- a/chromium/media/base/media_drm_storage.h +++ b/chromium/media/base/media_drm_storage.h @@ -14,9 +14,9 @@ #include "base/callback.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/optional.h" #include "media/base/media_drm_key_type.h" #include "media/base/media_export.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "url/origin.h" namespace base { @@ -32,7 +32,7 @@ class MEDIA_EXPORT MediaDrmStorage public: // When using per-origin provisioning, this is the ID for the origin. // If not specified, the device specific origin ID is to be used. - using MediaDrmOriginId = base::Optional<base::UnguessableToken>; + using MediaDrmOriginId = absl::optional<base::UnguessableToken>; struct MEDIA_EXPORT SessionData { SessionData(std::vector<uint8_t> key_set_id, diff --git a/chromium/media/base/media_log.h b/chromium/media/base/media_log.h index dc3ea25be66..46b52ae5587 100644 --- a/chromium/media/base/media_log.h +++ b/chromium/media/base/media_log.h @@ -214,8 +214,9 @@ class MEDIA_EXPORT LogHelper { // Provides a stringstream to collect a log entry to pass to the provided // MediaLog at the requested level. -#define MEDIA_LOG(level, media_log) \ - LogHelper((MediaLogMessageLevel::k##level), (media_log)).stream() +#define MEDIA_LOG(level, media_log) \ + media::LogHelper((media::MediaLogMessageLevel::k##level), (media_log)) \ + .stream() // Logs only while |count| < |max|, increments |count| for each log, and warns // in the log if |count| has just reached |max|. diff --git a/chromium/media/base/media_serializers.h b/chromium/media/base/media_serializers.h index 5dbff1ba7fb..a91f8bc2413 100644 --- a/chromium/media/base/media_serializers.h +++ b/chromium/media/base/media_serializers.h @@ -61,8 +61,8 @@ struct MediaSerializer<std::vector<VecType>> { // serialize optional types template <typename OptType> -struct MediaSerializer<base::Optional<OptType>> { - static base::Value Serialize(const base::Optional<OptType>& opt) { +struct MediaSerializer<absl::optional<OptType>> { + static base::Value Serialize(const absl::optional<OptType>& opt) { return opt ? MediaSerializer<OptType>::Serialize(opt.value()) : base::Value("unset"); // TODO(tmathmeyer) maybe empty string? } diff --git a/chromium/media/base/media_serializers_unittest.cc b/chromium/media/base/media_serializers_unittest.cc index e3f3a7bfc5c..466155569b8 100644 --- a/chromium/media/base/media_serializers_unittest.cc +++ b/chromium/media/base/media_serializers_unittest.cc @@ -41,7 +41,7 @@ TEST(MediaSerializersTest, BaseTypes) { } TEST(MediaSerializersTest, Optional) { - base::Optional<int> foo; + absl::optional<int> foo; ASSERT_EQ(ToString(MediaSerialize(foo)), "unset"); foo = 1; diff --git a/chromium/media/base/media_switches.cc b/chromium/media/base/media_switches.cc index 065ff8a0bd6..7c6ca90d52a 100644 --- a/chromium/media/base/media_switches.cc +++ b/chromium/media/base/media_switches.cc @@ -9,6 +9,14 @@ #include "build/chromeos_buildflags.h" #include "components/system_media_controls/linux/buildflags/buildflags.h" +#if defined(OS_LINUX) +#include "base/cpu.h" +#endif + +#if BUILDFLAG(IS_CHROMEOS_ASH) +#include "ash/constants/ash_features.h" +#endif + namespace switches { // Allow users to specify a custom buffer size for debugging purpose. @@ -91,8 +99,8 @@ const char kUseCras[] = "use-cras"; #endif // defined(USE_CRAS) // For automated testing of protected content, this switch allows specific -// domains (e.g. example.com) to skip asking the user for permission to share -// the protected media identifier. In this context, domain does not include the +// domains (e.g. example.com) to always allow the permission to share the +// protected media identifier. In this context, domain does not include the // port number. User's content settings will not be affected by enabling this // switch. // Reference: http://crbug.com/718608 @@ -178,7 +186,8 @@ const char kOverrideEnabledCdmInterfaceVersion[] = // Overrides hardware secure codecs support for testing. If specified, real // platform hardware secure codecs check will be skipped. Codecs are separated -// by comma. Valid codecs are "vp8", "vp9" and "avc1". For example: +// by comma. Valid video codecs are "vp8", "vp9" and "avc1", and the only valid +// audio codec is "vorbis". For example: // --override-hardware-secure-codecs-for-testing=vp8,vp9 // --override-hardware-secure-codecs-for-testing=avc1 // CENC encryption scheme is assumed to be supported for the specified codecs. @@ -331,7 +340,7 @@ const base::Feature kD3D11PrintCodecOnCrash{"D3D11PrintCodecOnCrash", // Enable The D3D11 Video decoder. const base::Feature kD3D11VideoDecoder{"D3D11VideoDecoder", - base::FEATURE_DISABLED_BY_DEFAULT}; + base::FEATURE_ENABLED_BY_DEFAULT}; // Tell D3D11VideoDecoder to ignore workarounds for zero copy. Requires that // kD3D11VideoDecoder is enabled. @@ -452,7 +461,7 @@ const base::Feature kSuspendMutedAudio{"SuspendMutedAudio", // Enables using the media history store to store media engagement metrics. const base::Feature kUseMediaHistoryStore{"UseMediaHistoryStore", - base::FEATURE_ENABLED_BY_DEFAULT}; + base::FEATURE_DISABLED_BY_DEFAULT}; // Use R16 texture for 9-16 bit channel instead of half-float conversion by CPU. const base::Feature kUseR16Texture{"use-r16-texture", @@ -517,17 +526,9 @@ const base::Feature kVideoBlitColorAccuracy{"video-blit-color-accuracy", const base::Feature kExternalClearKeyForTesting{ "ExternalClearKeyForTesting", base::FEATURE_DISABLED_BY_DEFAULT}; -// Enables the Live Caption feature. -const base::Feature kLiveCaption { - "LiveCaption", -#if defined(OS_CHROMEOS) - // TODO(crbug.com/1209058): Remove this special case after it's merged - // into M91. - base::FEATURE_DISABLED_BY_DEFAULT -#else - base::FEATURE_ENABLED_BY_DEFAULT -#endif -}; +// Enables the Live Caption feature on supported devices. +const base::Feature kLiveCaption{"LiveCaption", + base::FEATURE_ENABLED_BY_DEFAULT}; // Use the Speech On-Device API (SODA) to power the Live Caption feature instead // of the Cloud-based Open Speech API. @@ -631,11 +632,6 @@ const base::Feature kMediaDrmPreprovisioning{"MediaDrmPreprovisioning", const base::Feature kMediaDrmPreprovisioningAtStartup{ "MediaDrmPreprovisioningAtStartup", base::FEATURE_ENABLED_BY_DEFAULT}; -// Prevents using SurfaceLayer for videos. This is meant to be used by embedders -// that cannot support SurfaceLayer at the moment. -const base::Feature kDisableSurfaceLayerForVideo{ - "DisableSurfaceLayerForVideo", base::FEATURE_DISABLED_BY_DEFAULT}; - // Enable picture in picture web api for android. const base::Feature kPictureInPictureAPI{"PictureInPictureAPI", base::FEATURE_DISABLED_BY_DEFAULT}; @@ -859,6 +855,10 @@ const base::Feature kUseFakeDeviceForMediaStream{ const base::Feature kBresenhamCadence{"BresenhamCadence", base::FEATURE_DISABLED_BY_DEFAULT}; +// Display the playback speed button on the media controls. +const base::Feature kPlaybackSpeedButton{"PlaybackSpeedButton", + base::FEATURE_DISABLED_BY_DEFAULT}; + bool IsVideoCaptureAcceleratedJpegDecodingEnabled() { if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kDisableAcceleratedMjpegDecode)) { @@ -874,4 +874,35 @@ bool IsVideoCaptureAcceleratedJpegDecodingEnabled() { return false; } +bool IsLiveCaptionFeatureEnabled() { + if (!base::FeatureList::IsEnabled(media::kLiveCaption)) + return false; + +#if BUILDFLAG(IS_CHROMEOS_ASH) + // Some Chrome OS devices do not support on-device speech. + if (!base::FeatureList::IsEnabled(ash::features::kOnDeviceSpeechRecognition)) + return false; +#endif + +#if defined(OS_LINUX) + if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) { + // Check if the CPU has the required instruction set to run the Speech + // On-Device API (SODA) library. + static bool has_sse41 = base::CPU().has_sse41(); + if (!has_sse41) + return false; + } +#endif + +#if defined(OS_WIN) && defined(ARCH_CPU_ARM64) + if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) { + // The Speech On-Device API (SODA) component does not support Windows on + // arm64. + return false; + } +#endif + + return true; +} + } // namespace media diff --git a/chromium/media/base/media_switches.h b/chromium/media/base/media_switches.h index 57ae439f02b..69b9cfcc7b8 100644 --- a/chromium/media/base/media_switches.h +++ b/chromium/media/base/media_switches.h @@ -10,6 +10,7 @@ #include <string> #include "base/feature_list.h" +#include "base/metrics/field_trial_params.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" #include "media/base/media_export.h" @@ -162,6 +163,7 @@ MEDIA_EXPORT extern const base::Feature kMediaSessionWebRTC; MEDIA_EXPORT extern const base::Feature kMemoryPressureBasedSourceBufferGC; MEDIA_EXPORT extern const base::Feature kOverlayFullscreenVideo; MEDIA_EXPORT extern const base::Feature kPictureInPicture; +MEDIA_EXPORT extern const base::Feature kPlaybackSpeedButton; MEDIA_EXPORT extern const base::Feature kPreloadMediaEngagementData; MEDIA_EXPORT extern const base::Feature kPreloadMetadataLazyLoad; MEDIA_EXPORT extern const base::Feature kPreloadMetadataSuspend; @@ -205,7 +207,6 @@ MEDIA_EXPORT extern const base::Feature kMediaControlsExpandGesture; MEDIA_EXPORT extern const base::Feature kMediaDrmPersistentLicense; MEDIA_EXPORT extern const base::Feature kMediaDrmPreprovisioning; MEDIA_EXPORT extern const base::Feature kMediaDrmPreprovisioningAtStartup; -MEDIA_EXPORT extern const base::Feature kDisableSurfaceLayerForVideo; MEDIA_EXPORT extern const base::Feature kCanPlayHls; MEDIA_EXPORT extern const base::Feature kPictureInPictureAPI; MEDIA_EXPORT extern const base::Feature kHlsPlayer; @@ -246,6 +247,8 @@ MEDIA_EXPORT std::string GetEffectiveAutoplayPolicy( MEDIA_EXPORT bool IsVideoCaptureAcceleratedJpegDecodingEnabled(); +MEDIA_EXPORT bool IsLiveCaptionFeatureEnabled(); + enum class kCrosGlobalMediaControlsPinOptions { kPin, kNotPin, diff --git a/chromium/media/base/media_url_demuxer.cc b/chromium/media/base/media_url_demuxer.cc index cff132e69e2..734604a4a7f 100644 --- a/chromium/media/base/media_url_demuxer.cc +++ b/chromium/media/base/media_url_demuxer.cc @@ -83,9 +83,9 @@ int64_t MediaUrlDemuxer::GetMemoryUsage() const { return 0; } -base::Optional<container_names::MediaContainerName> +absl::optional<container_names::MediaContainerName> MediaUrlDemuxer::GetContainerForMetrics() const { - return base::nullopt; + return absl::nullopt; } void MediaUrlDemuxer::OnEnabledAudioTracksChanged( diff --git a/chromium/media/base/media_url_demuxer.h b/chromium/media/base/media_url_demuxer.h index 638cc9b14a7..4d497ebacec 100644 --- a/chromium/media/base/media_url_demuxer.h +++ b/chromium/media/base/media_url_demuxer.h @@ -58,7 +58,7 @@ class MEDIA_EXPORT MediaUrlDemuxer : public Demuxer { base::TimeDelta GetStartTime() const override; base::Time GetTimelineOffset() const override; int64_t GetMemoryUsage() const override; - base::Optional<container_names::MediaContainerName> GetContainerForMetrics() + absl::optional<container_names::MediaContainerName> GetContainerForMetrics() const override; void OnEnabledAudioTracksChanged(const std::vector<MediaTrack::Id>& track_ids, base::TimeDelta curr_time, diff --git a/chromium/media/base/memory_dump_provider_proxy.h b/chromium/media/base/memory_dump_provider_proxy.h index 0473c79403d..0bdda75b7c5 100644 --- a/chromium/media/base/memory_dump_provider_proxy.h +++ b/chromium/media/base/memory_dump_provider_proxy.h @@ -8,10 +8,6 @@ #include <stddef.h> #include <stdint.h> -#include <memory> -#include <string> -#include <utility> - #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/single_thread_task_runner.h" diff --git a/chromium/media/base/mock_filters.cc b/chromium/media/base/mock_filters.cc index 4bf36edf546..981c4363d84 100644 --- a/chromium/media/base/mock_filters.cc +++ b/chromium/media/base/mock_filters.cc @@ -169,12 +169,12 @@ MockCdmContext::MockCdmContext() = default; MockCdmContext::~MockCdmContext() = default; -base::Optional<base::UnguessableToken> MockCdmContext::GetCdmId() const { +absl::optional<base::UnguessableToken> MockCdmContext::GetCdmId() const { return cdm_id_; } void MockCdmContext::set_cdm_id(const base::UnguessableToken& cdm_id) { - cdm_id_ = base::make_optional(cdm_id); + cdm_id_ = absl::make_optional(cdm_id); } MockCdmPromise::MockCdmPromise(bool expect_success) { diff --git a/chromium/media/base/mock_filters.h b/chromium/media/base/mock_filters.h index 281afd56335..e70cb8c6d9f 100644 --- a/chromium/media/base/mock_filters.h +++ b/chromium/media/base/mock_filters.h @@ -69,7 +69,7 @@ class MockPipelineClient : public Pipeline::Client { MOCK_METHOD1(OnVideoConfigChange, void(const VideoDecoderConfig&)); MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); MOCK_METHOD1(OnVideoOpacityChange, void(bool)); - MOCK_METHOD1(OnVideoFrameRateChange, void(base::Optional<int>)); + MOCK_METHOD1(OnVideoFrameRateChange, void(absl::optional<int>)); MOCK_METHOD0(OnVideoAverageKeyframeDistanceUpdate, void()); MOCK_METHOD1(OnAudioDecoderChange, void(const AudioDecoderInfo&)); MOCK_METHOD1(OnVideoDecoderChange, void(const VideoDecoderInfo&)); @@ -103,7 +103,7 @@ class MockPipeline : public Pipeline { MOCK_METHOD2(OnEnabledAudioTracksChanged, void(const std::vector<MediaTrack::Id>&, base::OnceClosure)); MOCK_METHOD2(OnSelectedVideoTrackChanged, - void(base::Optional<MediaTrack::Id>, base::OnceClosure)); + void(absl::optional<MediaTrack::Id>, base::OnceClosure)); // TODO(sandersd): This should automatically return true between Start() and // Stop(). (Or better, remove it from the interface entirely.) @@ -116,7 +116,7 @@ class MockPipeline : public Pipeline { MOCK_METHOD1(SetPlaybackRate, void(double)); MOCK_CONST_METHOD0(GetVolume, float()); MOCK_METHOD1(SetVolume, void(float)); - MOCK_METHOD1(SetLatencyHint, void(base::Optional<base::TimeDelta>)); + MOCK_METHOD1(SetLatencyHint, void(absl::optional<base::TimeDelta>)); MOCK_METHOD1(SetPreservesPitch, void(bool)); MOCK_METHOD1(SetAutoplayInitiated, void(bool)); @@ -175,7 +175,7 @@ class MockDemuxer : public Demuxer { MOCK_CONST_METHOD0(GetTimelineOffset, base::Time()); MOCK_CONST_METHOD0(GetMemoryUsage, int64_t()); MOCK_CONST_METHOD0(GetContainerForMetrics, - base::Optional<container_names::MediaContainerName>()); + absl::optional<container_names::MediaContainerName>()); MOCK_METHOD3(OnEnabledAudioTracksChanged, void(const std::vector<MediaTrack::Id>&, base::TimeDelta, @@ -401,7 +401,7 @@ class MockRendererClient : public RendererClient { MOCK_METHOD1(OnVideoConfigChange, void(const VideoDecoderConfig&)); MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size&)); MOCK_METHOD1(OnVideoOpacityChange, void(bool)); - MOCK_METHOD1(OnVideoFrameRateChange, void(base::Optional<int>)); + MOCK_METHOD1(OnVideoFrameRateChange, void(absl::optional<int>)); MOCK_METHOD1(OnDurationChange, void(base::TimeDelta)); MOCK_METHOD1(OnRemotePlayStateChange, void(MediaStatus::State state)); MOCK_METHOD0(IsVideoStreamAvailable, bool()); @@ -431,7 +431,7 @@ class MockVideoRenderer : public VideoRenderer { MOCK_METHOD0(OnTimeProgressing, void()); MOCK_METHOD0(OnTimeStopped, void()); MOCK_METHOD1(SetLatencyHint, - void(base::Optional<base::TimeDelta> latency_hint)); + void(absl::optional<base::TimeDelta> latency_hint)); private: DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer); @@ -459,7 +459,7 @@ class MockAudioRenderer : public AudioRenderer { MOCK_METHOD0(StartPlaying, void()); MOCK_METHOD1(SetVolume, void(float volume)); MOCK_METHOD1(SetLatencyHint, - void(base::Optional<base::TimeDelta> latency_hint)); + void(absl::optional<base::TimeDelta> latency_hint)); MOCK_METHOD1(SetPreservesPitch, void(bool)); MOCK_METHOD1(SetAutoplayInitiated, void(bool)); @@ -482,7 +482,7 @@ class MockRenderer : public Renderer { void(MediaResource* media_resource, RendererClient* client, PipelineStatusCallback& init_cb)); - MOCK_METHOD1(SetLatencyHint, void(base::Optional<base::TimeDelta>)); + MOCK_METHOD1(SetLatencyHint, void(absl::optional<base::TimeDelta>)); MOCK_METHOD1(SetPreservesPitch, void(bool)); MOCK_METHOD1(SetAutoplayInitiated, void(bool)); void Flush(base::OnceClosure flush_cb) override { OnFlush(flush_cb); } @@ -638,12 +638,12 @@ class MockCdmContext : public CdmContext { bool(GetMediaFoundationCdmProxyCB get_mf_cdm_proxy_cb)); #endif - base::Optional<base::UnguessableToken> GetCdmId() const override; + absl::optional<base::UnguessableToken> GetCdmId() const override; void set_cdm_id(const base::UnguessableToken& cdm_id); private: - base::Optional<base::UnguessableToken> cdm_id_; + absl::optional<base::UnguessableToken> cdm_id_; DISALLOW_COPY_AND_ASSIGN(MockCdmContext); }; @@ -830,7 +830,7 @@ class MockMediaClient : public media::MediaClient { MOCK_METHOD1(IsSupportedVideoType, bool(const media::VideoType& type)); MOCK_METHOD1(IsSupportedBitstreamAudioCodec, bool(media::AudioCodec codec)); MOCK_METHOD1(GetAudioRendererAlgorithmParameters, - base::Optional<::media::AudioRendererAlgorithmParameters>( + absl::optional<::media::AudioRendererAlgorithmParameters>( media::AudioParameters audio_parameters)); private: diff --git a/chromium/media/base/offloading_audio_encoder_unittest.cc b/chromium/media/base/offloading_audio_encoder_unittest.cc index b1377ae44c8..a3bbe6482f4 100644 --- a/chromium/media/base/offloading_audio_encoder_unittest.cc +++ b/chromium/media/base/offloading_audio_encoder_unittest.cc @@ -55,7 +55,7 @@ TEST_F(OffloadingAudioEncoderTest, Initialize) { bool called_output = false; AudioEncoder::Options options; AudioEncoder::OutputCB output_cb = base::BindLambdaForTesting( - [&](EncodedAudioBuffer, base::Optional<AudioEncoder::CodecDescription>) { + [&](EncodedAudioBuffer, absl::optional<AudioEncoder::CodecDescription>) { EXPECT_TRUE(callback_runner_->RunsTasksInCurrentSequence()); called_output = true; }); diff --git a/chromium/media/base/offloading_video_encoder_unittest.cc b/chromium/media/base/offloading_video_encoder_unittest.cc index 8b2bc0a28b5..570c7dd98b6 100644 --- a/chromium/media/base/offloading_video_encoder_unittest.cc +++ b/chromium/media/base/offloading_video_encoder_unittest.cc @@ -57,7 +57,7 @@ TEST_F(OffloadingVideoEncoderTest, Initialize) { VideoEncoder::Options options; VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; VideoEncoder::OutputCB output_cb = base::BindLambdaForTesting( - [&](VideoEncoderOutput, base::Optional<VideoEncoder::CodecDescription>) { + [&](VideoEncoderOutput, absl::optional<VideoEncoder::CodecDescription>) { EXPECT_TRUE(callback_runner_->RunsTasksInCurrentSequence()); called_output = true; }); @@ -111,7 +111,7 @@ TEST_F(OffloadingVideoEncoderTest, ChangeOptions) { }); VideoEncoder::OutputCB output_cb = base::BindRepeating( - [](VideoEncoderOutput, base::Optional<VideoEncoder::CodecDescription>) { + [](VideoEncoderOutput, absl::optional<VideoEncoder::CodecDescription>) { }); EXPECT_CALL(*mock_video_encoder_, ChangeOptions(_, _, _)) diff --git a/chromium/media/base/overlay_info.h b/chromium/media/base/overlay_info.h index 603a2208f86..f0f1e6448ed 100644 --- a/chromium/media/base/overlay_info.h +++ b/chromium/media/base/overlay_info.h @@ -7,16 +7,16 @@ #include "base/callback.h" #include "base/macros.h" -#include "base/optional.h" #include "base/unguessable_token.h" #include "media/base/media_export.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { struct MEDIA_EXPORT OverlayInfo { // An unset routing token indicates "do not use any routing token". A null // routing token isn't serializable, else we'd probably use that instead. - using RoutingToken = base::Optional<base::UnguessableToken>; + using RoutingToken = absl::optional<base::UnguessableToken>; OverlayInfo(); OverlayInfo(const OverlayInfo&); diff --git a/chromium/media/base/pipeline.h b/chromium/media/base/pipeline.h index 3e1180fb019..ffa8ad8a029 100644 --- a/chromium/media/base/pipeline.h +++ b/chromium/media/base/pipeline.h @@ -8,7 +8,6 @@ #include <memory> #include "base/memory/ref_counted.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/audio_decoder_config.h" #include "media/base/buffering_state.h" @@ -22,6 +21,7 @@ #include "media/base/video_decoder_config.h" #include "media/base/video_transformation.h" #include "media/base/waiting.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/size.h" namespace media { @@ -85,7 +85,7 @@ class MEDIA_EXPORT Pipeline { // Executed whenever the video frame rate changes. |fps| will be unset if // the frame rate is unstable. The duration used for the frame rate is // based on wall clock time, not media time. - virtual void OnVideoFrameRateChange(base::Optional<int> fps) = 0; + virtual void OnVideoFrameRateChange(absl::optional<int> fps) = 0; }; virtual ~Pipeline() {} @@ -148,7 +148,7 @@ class MEDIA_EXPORT Pipeline { // |selected_track_id| is either empty, which means no video track is // selected, or contains the selected video track id. virtual void OnSelectedVideoTrackChanged( - base::Optional<MediaTrack::Id> selected_track_id, + absl::optional<MediaTrack::Id> selected_track_id, base::OnceClosure change_completed_cb) = 0; // Stops the pipeline. This is a blocking function. @@ -223,7 +223,7 @@ class MEDIA_EXPORT Pipeline { // post-decode buffering required to start playback or resume from // seek/underflow. A null option indicates the hint is unset and the pipeline // can choose its own default. - virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0; + virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0; // Sets whether pitch adjustment should be applied when the playback rate is // different than 1.0. diff --git a/chromium/media/base/pipeline_impl.cc b/chromium/media/base/pipeline_impl.cc index 9eeeb52b324..f29e529019c 100644 --- a/chromium/media/base/pipeline_impl.cc +++ b/chromium/media/base/pipeline_impl.cc @@ -71,7 +71,7 @@ class PipelineImpl::RendererWrapper final : public DemuxerHost, void Resume(std::unique_ptr<Renderer> default_renderer, base::TimeDelta time); void SetPlaybackRate(double playback_rate); void SetVolume(float volume); - void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint); + void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint); void SetPreservesPitch(bool preserves_pitch); void SetAutoplayInitiated(bool autoplay_initiated); base::TimeDelta GetMediaTime() const; @@ -88,7 +88,7 @@ class PipelineImpl::RendererWrapper final : public DemuxerHost, // |selected_track_id| is either empty, which means no video track is // selected, or contains the selected video track id. void OnSelectedVideoTrackChanged( - base::Optional<MediaTrack::Id> selected_track_id, + absl::optional<MediaTrack::Id> selected_track_id, base::OnceClosure change_completed_cb); private: @@ -150,7 +150,7 @@ class PipelineImpl::RendererWrapper final : public DemuxerHost, void OnVideoConfigChange(const VideoDecoderConfig& config) final; void OnVideoNaturalSizeChange(const gfx::Size& size) final; void OnVideoOpacityChange(bool opaque) final; - void OnVideoFrameRateChange(base::Optional<int> fps) final; + void OnVideoFrameRateChange(absl::optional<int> fps) final; // Common handlers for notifications from renderers and demuxer. void OnPipelineError(PipelineStatus error); @@ -194,7 +194,7 @@ class PipelineImpl::RendererWrapper final : public DemuxerHost, double playback_rate_; float volume_; - base::Optional<base::TimeDelta> latency_hint_; + absl::optional<base::TimeDelta> latency_hint_; CdmContext* cdm_context_; // By default, apply pitch adjustments. @@ -480,7 +480,7 @@ void PipelineImpl::RendererWrapper::SetVolume(float volume) { } void PipelineImpl::RendererWrapper::SetLatencyHint( - base::Optional<base::TimeDelta> latency_hint) { + absl::optional<base::TimeDelta> latency_hint) { DCHECK(media_task_runner_->BelongsToCurrentThread()); if (latency_hint_ == latency_hint) @@ -580,16 +580,16 @@ void PipelineImpl::RendererWrapper::CreateRendererInternal( DCHECK(cdm_context_ || !HasEncryptedStream()) << "CDM should be available now if has encrypted stream"; - base::Optional<RendererFactoryType> factory_type; + absl::optional<RendererType> renderer_type; #if defined(OS_WIN) if (cdm_context_ && cdm_context_->RequiresMediaFoundationRenderer()) - factory_type = RendererFactoryType::kMediaFoundation; + renderer_type = RendererType::kMediaFoundation; #endif // defined(OS_WIN) // TODO(xhwang): During Resume(), the |default_renderer_| might already match - // the |factory_type|, in which case we shouldn't need to create a new one. - if (!default_renderer_ || factory_type) { + // the |renderer_type|, in which case we shouldn't need to create a new one. + if (!default_renderer_ || renderer_type) { // Create the Renderer asynchronously on the main task runner. Use // BindToCurrentLoop to call OnRendererCreated() on the media task runner. auto renderer_created_cb = BindToCurrentLoop( @@ -598,7 +598,7 @@ void PipelineImpl::RendererWrapper::CreateRendererInternal( main_task_runner_->PostTask( FROM_HERE, base::BindOnce(&PipelineImpl::AsyncCreateRenderer, weak_pipeline_, - factory_type, std::move(renderer_created_cb))); + renderer_type, std::move(renderer_created_cb))); return; } @@ -701,7 +701,7 @@ void PipelineImpl::RendererWrapper::OnEnabledAudioTracksChanged( } void PipelineImpl::OnSelectedVideoTrackChanged( - base::Optional<MediaTrack::Id> selected_track_id, + absl::optional<MediaTrack::Id> selected_track_id, base::OnceClosure change_completed_cb) { DCHECK(thread_checker_.CalledOnValidThread()); media_task_runner_->PostTask( @@ -713,7 +713,7 @@ void PipelineImpl::OnSelectedVideoTrackChanged( } void PipelineImpl::RendererWrapper::OnSelectedVideoTrackChanged( - base::Optional<MediaTrack::Id> selected_track_id, + absl::optional<MediaTrack::Id> selected_track_id, base::OnceClosure change_completed_cb) { DCHECK(media_task_runner_->BelongsToCurrentThread()); @@ -856,7 +856,7 @@ void PipelineImpl::RendererWrapper::OnVideoOpacityChange(bool opaque) { } void PipelineImpl::RendererWrapper::OnVideoFrameRateChange( - base::Optional<int> fps) { + absl::optional<int> fps) { DCHECK(media_task_runner_->BelongsToCurrentThread()); main_task_runner_->PostTask( @@ -1229,7 +1229,7 @@ void PipelineImpl::Start(StartType start_type, // play. In this case, not creating a default renderer to reduce memory usage. std::unique_ptr<Renderer> default_renderer; if (start_type != StartType::kSuspendAfterMetadata) - default_renderer = create_renderer_cb_.Run(base::nullopt); + default_renderer = create_renderer_cb_.Run(absl::nullopt); media_task_runner_->PostTask( FROM_HERE, @@ -1317,7 +1317,7 @@ void PipelineImpl::Resume(base::TimeDelta time, last_media_time_ = base::TimeDelta(); // Always create a default renderer for Resume(). - auto default_renderer = create_renderer_cb_.Run(base::nullopt); + auto default_renderer = create_renderer_cb_.Run(absl::nullopt); media_task_runner_->PostTask( FROM_HERE, base::BindOnce(&RendererWrapper::Resume, @@ -1383,7 +1383,7 @@ void PipelineImpl::SetVolume(float volume) { } void PipelineImpl::SetLatencyHint( - base::Optional<base::TimeDelta> latency_hint) { + absl::optional<base::TimeDelta> latency_hint) { DVLOG(1) << __func__ << "(" << (latency_hint ? base::NumberToString(latency_hint->InMilliseconds()) + "ms" @@ -1507,12 +1507,12 @@ const char* PipelineImpl::GetStateString(State state) { #undef RETURN_STRING void PipelineImpl::AsyncCreateRenderer( - base::Optional<RendererFactoryType> factory_type, + absl::optional<RendererType> renderer_type, RendererCreatedCB renderer_created_cb) { DVLOG(2) << __func__; DCHECK(thread_checker_.CalledOnValidThread()); - std::move(renderer_created_cb).Run(create_renderer_cb_.Run(factory_type)); + std::move(renderer_created_cb).Run(create_renderer_cb_.Run(renderer_type)); } void PipelineImpl::OnError(PipelineStatus error) { @@ -1603,7 +1603,7 @@ void PipelineImpl::OnVideoOpacityChange(bool opaque) { client_->OnVideoOpacityChange(opaque); } -void PipelineImpl::OnVideoFrameRateChange(base::Optional<int> fps) { +void PipelineImpl::OnVideoFrameRateChange(absl::optional<int> fps) { DVLOG(2) << __func__; DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(IsRunning()); diff --git a/chromium/media/base/pipeline_impl.h b/chromium/media/base/pipeline_impl.h index beb88adb2b6..3edada0a981 100644 --- a/chromium/media/base/pipeline_impl.h +++ b/chromium/media/base/pipeline_impl.h @@ -10,12 +10,12 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" -#include "base/optional.h" #include "base/threading/thread_checker.h" #include "media/base/media_export.h" #include "media/base/pipeline.h" #include "media/base/renderer.h" #include "media/base/renderer_factory_selector.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace base { class SingleThreadTaskRunner; @@ -25,13 +25,13 @@ namespace media { class MediaLog; -// Callbacks used for Renderer creation. When the FactoryType is nullopt, the +// Callbacks used for Renderer creation. When the RendererType is nullopt, the // current base one will be created. using CreateRendererCB = base::RepeatingCallback<std::unique_ptr<Renderer>( - base::Optional<RendererFactoryType>)>; + absl::optional<RendererType>)>; using RendererCreatedCB = base::OnceCallback<void(std::unique_ptr<Renderer>)>; using AsyncCreateRendererCB = - base::RepeatingCallback<void(base::Optional<RendererFactoryType>, + base::RepeatingCallback<void(absl::optional<RendererType>, RendererCreatedCB)>; // Pipeline runs the media pipeline. Filters are created and called on the @@ -103,7 +103,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline { void SetPlaybackRate(double playback_rate) override; float GetVolume() const override; void SetVolume(float volume) override; - void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) override; + void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) override; void SetPreservesPitch(bool preserves_pitch) override; void SetAutoplayInitiated(bool autoplay_initiated) override; base::TimeDelta GetMediaTime() const override; @@ -121,7 +121,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline { // |selected_track_id| is either empty, which means no video track is // selected, or contains the selected video track id. void OnSelectedVideoTrackChanged( - base::Optional<MediaTrack::Id> selected_track_id, + absl::optional<MediaTrack::Id> selected_track_id, base::OnceClosure change_completed_cb) override; private: @@ -146,7 +146,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline { // Create a Renderer asynchronously. Must be called on the main task runner // and the callback will be called on the main task runner as well. - void AsyncCreateRenderer(base::Optional<RendererFactoryType> factory_type, + void AsyncCreateRenderer(absl::optional<RendererType> renderer_type, RendererCreatedCB renderer_created_cb); // Notifications from RendererWrapper. @@ -165,7 +165,7 @@ class MEDIA_EXPORT PipelineImpl : public Pipeline { void OnAudioDecoderChange(const AudioDecoderInfo& info); void OnVideoDecoderChange(const VideoDecoderInfo& info); void OnRemotePlayStateChange(MediaStatus::State state); - void OnVideoFrameRateChange(base::Optional<int> fps); + void OnVideoFrameRateChange(absl::optional<int> fps); // Task completion callbacks from RendererWrapper. void OnSeekDone(bool is_suspended); diff --git a/chromium/media/base/pipeline_impl_unittest.cc b/chromium/media/base/pipeline_impl_unittest.cc index 8ff37cf90bc..69a0bed8c75 100644 --- a/chromium/media/base/pipeline_impl_unittest.cc +++ b/chromium/media/base/pipeline_impl_unittest.cc @@ -295,7 +295,7 @@ class PipelineImplTest : public ::testing::Test { } std::unique_ptr<Renderer> CreateRenderer( - base::Optional<RendererFactoryType> /* factory_type */) { + absl::optional<RendererType> /* renderer_type */) { return std::move(scoped_renderer_); } diff --git a/chromium/media/base/pipeline_status.cc b/chromium/media/base/pipeline_status.cc index ab7dfbee853..32c24f13563 100644 --- a/chromium/media/base/pipeline_status.cc +++ b/chromium/media/base/pipeline_status.cc @@ -8,7 +8,7 @@ namespace media { -base::Optional<PipelineStatus> StatusCodeToPipelineStatus(StatusCode status) { +absl::optional<PipelineStatus> StatusCodeToPipelineStatus(StatusCode status) { switch (status) { case StatusCode::kOk: return PIPELINE_OK; @@ -48,7 +48,7 @@ base::Optional<PipelineStatus> StatusCodeToPipelineStatus(StatusCode status) { return DEMUXER_ERROR_DETECTED_HLS; default: NOTREACHED(); - return base::nullopt; + return absl::nullopt; } } diff --git a/chromium/media/base/pipeline_status.h b/chromium/media/base/pipeline_status.h index a9e448040de..cab7506d68d 100644 --- a/chromium/media/base/pipeline_status.h +++ b/chromium/media/base/pipeline_status.h @@ -10,12 +10,12 @@ #include <string> #include "base/callback.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/decoder.h" #include "media/base/media_export.h" #include "media/base/status.h" #include "media/base/timestamp_constants.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -62,7 +62,7 @@ enum PipelineStatus { PIPELINE_STATUS_MAX = DEMUXER_ERROR_DETECTED_HLS, }; -MEDIA_EXPORT base::Optional<PipelineStatus> StatusCodeToPipelineStatus( +MEDIA_EXPORT absl::optional<PipelineStatus> StatusCodeToPipelineStatus( StatusCode status); MEDIA_EXPORT StatusCode PipelineStatusToStatusCode(PipelineStatus status); diff --git a/chromium/media/base/renderer.h b/chromium/media/base/renderer.h index 9244948c287..09d775f0c99 100644 --- a/chromium/media/base/renderer.h +++ b/chromium/media/base/renderer.h @@ -8,12 +8,12 @@ #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/optional.h" #include "base/time/time.h" #include "media/base/buffering_state.h" #include "media/base/demuxer_stream.h" #include "media/base/media_export.h" #include "media/base/pipeline_status.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -49,7 +49,7 @@ class MEDIA_EXPORT Renderer { // of decoded data is buffered. A nullopt hint indicates the user is clearing // their preference and the renderer should restore its default buffering // thresholds. - virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0; + virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0; // Sets whether pitch adjustment should be applied when the playback rate is // different than 1.0. diff --git a/chromium/media/base/renderer_client.h b/chromium/media/base/renderer_client.h index f11f2132430..cb4c7131101 100644 --- a/chromium/media/base/renderer_client.h +++ b/chromium/media/base/renderer_client.h @@ -5,7 +5,6 @@ #ifndef MEDIA_BASE_RENDERER_CLIENT_H_ #define MEDIA_BASE_RENDERER_CLIENT_H_ -#include "base/time/time.h" #include "media/base/audio_decoder_config.h" #include "media/base/buffering_state.h" #include "media/base/media_status.h" @@ -58,7 +57,7 @@ class MEDIA_EXPORT RendererClient { // Called when the bucketed frames per second has changed. |fps| will be // unset if the frame rate is unstable. The duration used for the frame rate // is based on the wall clock time, not the media time. - virtual void OnVideoFrameRateChange(base::Optional<int> fps) = 0; + virtual void OnVideoFrameRateChange(absl::optional<int> fps) = 0; }; } // namespace media diff --git a/chromium/media/base/renderer_factory_selector.cc b/chromium/media/base/renderer_factory_selector.cc index 0e912d86a9b..c3d8fa5d371 100644 --- a/chromium/media/base/renderer_factory_selector.cc +++ b/chromium/media/base/renderer_factory_selector.cc @@ -13,30 +13,30 @@ RendererFactorySelector::RendererFactorySelector() = default; RendererFactorySelector::~RendererFactorySelector() = default; void RendererFactorySelector::AddBaseFactory( - RendererFactoryType type, + RendererType type, std::unique_ptr<RendererFactory> factory) { DVLOG(1) << __func__ << ": type=" << static_cast<int>(type); - DCHECK(!base_factory_type_) << "At most one base factory!"; + DCHECK(!base_renderer_type_) << "At most one base factory!"; AddFactory(type, std::move(factory)); - SetBaseFactoryType(type); + SetBaseRendererType(type); } void RendererFactorySelector::AddConditionalFactory( - RendererFactoryType type, + RendererType type, std::unique_ptr<RendererFactory> factory, ConditionalFactoryCB callback) { DCHECK(factory); DCHECK(callback); - DCHECK(!conditional_factory_types_.count(type)) + DCHECK(!conditional_factories_.count(type)) << "At most one conditional factory for a given type!"; - conditional_factory_types_.emplace(type, callback); + conditional_factories_.emplace(type, callback); AddFactory(type, std::move(factory)); } void RendererFactorySelector::AddFactory( - RendererFactoryType type, + RendererType type, std::unique_ptr<RendererFactory> factory) { DCHECK(factory); DCHECK(!factories_.count(type)); @@ -44,26 +44,26 @@ void RendererFactorySelector::AddFactory( factories_[type] = std::move(factory); } -void RendererFactorySelector::SetBaseFactoryType(RendererFactoryType type) { +void RendererFactorySelector::SetBaseRendererType(RendererType type) { DCHECK(factories_.count(type)); - base_factory_type_ = type; + base_renderer_type_ = type; } -RendererFactoryType RendererFactorySelector::GetCurrentFactoryType() { - for (const auto& entry : conditional_factory_types_) { +RendererType RendererFactorySelector::GetCurrentRendererType() { + for (const auto& entry : conditional_factories_) { if (entry.second.Run()) return entry.first; } - return base_factory_type_.value(); + return base_renderer_type_.value(); } RendererFactory* RendererFactorySelector::GetCurrentFactory() { - RendererFactoryType current_factory_type = GetCurrentFactoryType(); + RendererType current_renderer_type = GetCurrentRendererType(); DVLOG(1) << __func__ << " Selecting factory type: " - << static_cast<int>(current_factory_type); - auto* current_factory = factories_[current_factory_type].get(); + << static_cast<int>(current_renderer_type); + auto* current_factory = factories_[current_renderer_type].get(); DCHECK(current_factory); return current_factory; diff --git a/chromium/media/base/renderer_factory_selector.h b/chromium/media/base/renderer_factory_selector.h index c291fb35d20..a9599314b85 100644 --- a/chromium/media/base/renderer_factory_selector.h +++ b/chromium/media/base/renderer_factory_selector.h @@ -8,10 +8,10 @@ #include <map> #include "base/callback.h" -#include "base/optional.h" #include "build/build_config.h" #include "media/base/media_status.h" #include "media/base/renderer_factory.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -30,14 +30,14 @@ namespace media { // // Notes: // - One and at most one base factory must be set. -// - The base factory can be changed by calling SetBaseFactoryType(). +// - The base factory can be changed by calling SetBaseRendererType(). // - Multiple conditional factories are supported but there should be at most // one conditional factory for any factory type. If multiple conditions are // met, it's up to the implementation detail which factory will be returned. // These values are persisted to logs. Entries should not be renumbered and // numeric values should never be reused. -enum class RendererFactoryType { +enum class RendererType { kDefault = 0, // DefaultRendererFactory kMojo = 1, // MojoRendererFactory kMediaPlayer = 2, // MediaPlayerRendererClientFactory @@ -46,7 +46,7 @@ enum class RendererFactoryType { kCast = 5, // CastRendererClientFactory kMediaFoundation = 6, // MediaFoundationRendererClientFactory kFuchsia = 7, // FuchsiaRendererFactory - kRemoting = 8, // RemotingRendererFactory + kRemoting = 8, // RemotingRendererFactory for remoting::Receiver kMaxValue = kRemoting, }; @@ -58,27 +58,26 @@ class MEDIA_EXPORT RendererFactorySelector { ~RendererFactorySelector(); // See file level comments above. - void AddBaseFactory(RendererFactoryType type, + void AddBaseFactory(RendererType type, std::unique_ptr<RendererFactory> factory); - void AddConditionalFactory(RendererFactoryType type, + void AddConditionalFactory(RendererType type, std::unique_ptr<RendererFactory> factory, ConditionalFactoryCB callback); - void AddFactory(RendererFactoryType type, - std::unique_ptr<RendererFactory> factory); + void AddFactory(RendererType type, std::unique_ptr<RendererFactory> factory); // Sets the base factory to be returned, when there are no signals telling us // to select any specific factory. - // NOTE: |type| can be different than FactoryType::kDefault. kDefault is used + // NOTE: |type| can be different than RendererType::kDefault. kDefault is used // to identify the DefaultRendererFactory, not to indicate that a factory // should be used by default. - void SetBaseFactoryType(RendererFactoryType type); + void SetBaseRendererType(RendererType type); - // Returns the type of the factory that GetCurrentFactory() would return. - // NOTE: SetBaseFactoryType() must be called before calling this method. - RendererFactoryType GetCurrentFactoryType(); + // Returns the type of the Renderer for what GetCurrentFactory() would return. + // NOTE: SetBaseRendererType() must be called before calling this method. + RendererType GetCurrentRendererType(); // Updates |current_factory_| if necessary, and returns its value. - // NOTE: SetBaseFactoryType() must be called before calling this method. + // NOTE: SetBaseRendererType() must be called before calling this method. RendererFactory* GetCurrentFactory(); #if defined(OS_ANDROID) @@ -94,19 +93,18 @@ class MEDIA_EXPORT RendererFactorySelector { #endif private: - base::Optional<RendererFactoryType> base_factory_type_; + absl::optional<RendererType> base_renderer_type_; - // Use a map to avoid duplicate entires for the same FactoryType. - std::map<RendererFactoryType, ConditionalFactoryCB> - conditional_factory_types_; + // Use a map to avoid duplicate entries for the same RendererType. + std::map<RendererType, ConditionalFactoryCB> conditional_factories_; RequestRemotePlayStateChangeCB remote_play_state_change_cb_request_; - std::map<RendererFactoryType, std::unique_ptr<RendererFactory>> factories_; + std::map<RendererType, std::unique_ptr<RendererFactory>> factories_; DISALLOW_COPY_AND_ASSIGN(RendererFactorySelector); }; } // namespace media -#endif // MEDIA_BASE_RENDERER_FACTORY_H_ +#endif // MEDIA_BASE_RENDERER_FACTORY_SELECTOR_H_ diff --git a/chromium/media/base/renderer_factory_selector_unittest.cc b/chromium/media/base/renderer_factory_selector_unittest.cc index c4900ab51e8..468d49cf685 100644 --- a/chromium/media/base/renderer_factory_selector_unittest.cc +++ b/chromium/media/base/renderer_factory_selector_unittest.cc @@ -14,11 +14,9 @@ namespace media { class RendererFactorySelectorTest : public testing::Test { public: - using FactoryType = RendererFactoryType; - class FakeFactory : public RendererFactory { public: - explicit FakeFactory(FactoryType type) : type_(type) {} + explicit FakeFactory(RendererType type) : type_(type) {} std::unique_ptr<Renderer> CreateRenderer( const scoped_refptr<base::SingleThreadTaskRunner>& media_task_runner, @@ -30,23 +28,23 @@ class RendererFactorySelectorTest : public testing::Test { return nullptr; } - FactoryType factory_type() { return type_; } + RendererType factory_type() { return type_; } private: - FactoryType type_; + RendererType type_; }; RendererFactorySelectorTest() = default; - void AddBaseFactory(FactoryType type) { + void AddBaseFactory(RendererType type) { selector_.AddBaseFactory(type, std::make_unique<FakeFactory>(type)); } - void AddFactory(FactoryType type) { + void AddFactory(RendererType type) { selector_.AddFactory(type, std::make_unique<FakeFactory>(type)); } - void AddConditionalFactory(FactoryType type) { + void AddConditionalFactory(RendererType type) { condition_met_map_[type] = false; selector_.AddConditionalFactory( type, std::make_unique<FakeFactory>(type), @@ -54,75 +52,75 @@ class RendererFactorySelectorTest : public testing::Test { base::Unretained(this), type)); } - FactoryType GetCurrentlySelectedFactoryType() { + RendererType GetCurrentlySelectedRendererType() { return reinterpret_cast<FakeFactory*>(selector_.GetCurrentFactory()) ->factory_type(); } - bool IsConditionMet(FactoryType type) { + bool IsConditionMet(RendererType type) { DCHECK(condition_met_map_.count(type)); return condition_met_map_[type]; } protected: RendererFactorySelector selector_; - std::map<FactoryType, bool> condition_met_map_; + std::map<RendererType, bool> condition_met_map_; DISALLOW_COPY_AND_ASSIGN(RendererFactorySelectorTest); }; TEST_F(RendererFactorySelectorTest, SingleFactory) { - AddBaseFactory(FactoryType::kDefault); - EXPECT_EQ(FactoryType::kDefault, GetCurrentlySelectedFactoryType()); + AddBaseFactory(RendererType::kDefault); + EXPECT_EQ(RendererType::kDefault, GetCurrentlySelectedRendererType()); } TEST_F(RendererFactorySelectorTest, MultipleFactory) { - AddBaseFactory(FactoryType::kDefault); - AddFactory(FactoryType::kMojo); + AddBaseFactory(RendererType::kDefault); + AddFactory(RendererType::kMojo); - EXPECT_EQ(FactoryType::kDefault, GetCurrentlySelectedFactoryType()); + EXPECT_EQ(RendererType::kDefault, GetCurrentlySelectedRendererType()); - selector_.SetBaseFactoryType(FactoryType::kMojo); - EXPECT_EQ(FactoryType::kMojo, GetCurrentlySelectedFactoryType()); + selector_.SetBaseRendererType(RendererType::kMojo); + EXPECT_EQ(RendererType::kMojo, GetCurrentlySelectedRendererType()); } TEST_F(RendererFactorySelectorTest, ConditionalFactory) { - AddBaseFactory(FactoryType::kDefault); - AddFactory(FactoryType::kMojo); - AddConditionalFactory(FactoryType::kCourier); + AddBaseFactory(RendererType::kDefault); + AddFactory(RendererType::kMojo); + AddConditionalFactory(RendererType::kCourier); - EXPECT_EQ(FactoryType::kDefault, GetCurrentlySelectedFactoryType()); + EXPECT_EQ(RendererType::kDefault, GetCurrentlySelectedRendererType()); - condition_met_map_[FactoryType::kCourier] = true; - EXPECT_EQ(FactoryType::kCourier, GetCurrentlySelectedFactoryType()); + condition_met_map_[RendererType::kCourier] = true; + EXPECT_EQ(RendererType::kCourier, GetCurrentlySelectedRendererType()); - selector_.SetBaseFactoryType(FactoryType::kMojo); - EXPECT_EQ(FactoryType::kCourier, GetCurrentlySelectedFactoryType()); + selector_.SetBaseRendererType(RendererType::kMojo); + EXPECT_EQ(RendererType::kCourier, GetCurrentlySelectedRendererType()); - condition_met_map_[FactoryType::kCourier] = false; - EXPECT_EQ(FactoryType::kMojo, GetCurrentlySelectedFactoryType()); + condition_met_map_[RendererType::kCourier] = false; + EXPECT_EQ(RendererType::kMojo, GetCurrentlySelectedRendererType()); } TEST_F(RendererFactorySelectorTest, MultipleConditionalFactories) { - AddBaseFactory(FactoryType::kDefault); - AddConditionalFactory(FactoryType::kFlinging); - AddConditionalFactory(FactoryType::kCourier); + AddBaseFactory(RendererType::kDefault); + AddConditionalFactory(RendererType::kFlinging); + AddConditionalFactory(RendererType::kCourier); - EXPECT_EQ(FactoryType::kDefault, GetCurrentlySelectedFactoryType()); + EXPECT_EQ(RendererType::kDefault, GetCurrentlySelectedRendererType()); - condition_met_map_[FactoryType::kFlinging] = false; - condition_met_map_[FactoryType::kCourier] = true; - EXPECT_EQ(FactoryType::kCourier, GetCurrentlySelectedFactoryType()); + condition_met_map_[RendererType::kFlinging] = false; + condition_met_map_[RendererType::kCourier] = true; + EXPECT_EQ(RendererType::kCourier, GetCurrentlySelectedRendererType()); - condition_met_map_[FactoryType::kFlinging] = true; - condition_met_map_[FactoryType::kCourier] = false; - EXPECT_EQ(FactoryType::kFlinging, GetCurrentlySelectedFactoryType()); + condition_met_map_[RendererType::kFlinging] = true; + condition_met_map_[RendererType::kCourier] = false; + EXPECT_EQ(RendererType::kFlinging, GetCurrentlySelectedRendererType()); // It's up to the implementation detail to decide which one to use. - condition_met_map_[FactoryType::kFlinging] = true; - condition_met_map_[FactoryType::kCourier] = true; - EXPECT_TRUE(GetCurrentlySelectedFactoryType() == FactoryType::kFlinging || - GetCurrentlySelectedFactoryType() == FactoryType::kCourier); + condition_met_map_[RendererType::kFlinging] = true; + condition_met_map_[RendererType::kCourier] = true; + EXPECT_TRUE(GetCurrentlySelectedRendererType() == RendererType::kFlinging || + GetCurrentlySelectedRendererType() == RendererType::kCourier); } } // namespace media diff --git a/chromium/media/base/routing_token_callback.h b/chromium/media/base/routing_token_callback.h index 9663c17f3f0..cecff0f6219 100644 --- a/chromium/media/base/routing_token_callback.h +++ b/chromium/media/base/routing_token_callback.h @@ -22,4 +22,4 @@ using RequestRoutingTokenCallback = } // namespace media -#endif // MEDIA_BASE_ANDROID_ROUTING_TOKEN_CALLBACK_H_ +#endif // MEDIA_BASE_ROUTING_TOKEN_CALLBACK_H_ diff --git a/chromium/media/base/sample_rates.h b/chromium/media/base/sample_rates.h index edba90ed2a6..80aa2ff5ca9 100644 --- a/chromium/media/base/sample_rates.h +++ b/chromium/media/base/sample_rates.h @@ -27,7 +27,7 @@ enum AudioSampleRate { k384000Hz = 12, k768000Hz = 13, // Must always equal the largest value ever reported: - kAudioSampleRateMax = k384000Hz, + kAudioSampleRateMax = k768000Hz, }; // Helper method to convert integral values to their respective enum values, diff --git a/chromium/media/base/sinc_resampler.cc b/chromium/media/base/sinc_resampler.cc index 06c85f9349b..118667ff83d 100644 --- a/chromium/media/base/sinc_resampler.cc +++ b/chromium/media/base/sinc_resampler.cc @@ -78,6 +78,7 @@ #include <limits> #include "base/check_op.h" +#include "base/cpu.h" #include "base/numerics/math_constants.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" diff --git a/chromium/media/base/sinc_resampler_perftest.cc b/chromium/media/base/sinc_resampler_perftest.cc index 9570e792bd7..4ac8c8a2941 100644 --- a/chromium/media/base/sinc_resampler_perftest.cc +++ b/chromium/media/base/sinc_resampler_perftest.cc @@ -4,6 +4,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" +#include "base/cpu.h" #include "base/time/time.h" #include "build/build_config.h" #include "media/base/sinc_resampler.h" diff --git a/chromium/media/base/status.cc b/chromium/media/base/status.cc index 1e30c223c4b..8bfa2f999b2 100644 --- a/chromium/media/base/status.cc +++ b/chromium/media/base/status.cc @@ -5,6 +5,7 @@ #include "media/base/status.h" #include <memory> +#include "base/strings/string_piece.h" #include "media/base/media_serializers.h" namespace media { @@ -19,7 +20,7 @@ Status::Status(StatusCode code, DCHECK(message.empty()); return; } - data_ = std::make_unique<StatusInternal>(code, message.as_string()); + data_ = std::make_unique<StatusInternal>(code, std::string(message)); AddFrame(location); } diff --git a/chromium/media/base/status.h b/chromium/media/base/status.h index 8a7b4e0b9c7..d8e74805bb9 100644 --- a/chromium/media/base/status.h +++ b/chromium/media/base/status.h @@ -257,10 +257,10 @@ class StatusOr { private: // Optional error. - base::Optional<Status> error_; + absl::optional<Status> error_; // We wrap |T| in a container so that windows COM wrappers work. They - // override operator& and similar, and won't compile in a base::Optional. - base::Optional<std::tuple<T>> value_; + // override operator& and similar, and won't compile in a absl::optional. + absl::optional<std::tuple<T>> value_; }; } // namespace media diff --git a/chromium/media/base/status_codes.h b/chromium/media/base/status_codes.h index 45eee6460fa..70078b05dcb 100644 --- a/chromium/media/base/status_codes.h +++ b/chromium/media/base/status_codes.h @@ -94,6 +94,7 @@ enum class StatusCode : StatusCodeType { kGetQuantBufferFailed = 0x00000328, kReleaseQuantBufferFailed = 0x00000329, kBitstreamBufferSliceTooBig = 0x00000330, + kCreateSharedImageFailed = 0x00000331, // MojoDecoder Errors: 0x04 kMojoDecoderNoWrappedDecoder = 0x00000401, diff --git a/chromium/media/base/tuneable.h b/chromium/media/base/tuneable.h index e1efc37458d..913fd3533c2 100644 --- a/chromium/media/base/tuneable.h +++ b/chromium/media/base/tuneable.h @@ -6,7 +6,6 @@ #define MEDIA_BASE_TUNEABLE_H_ #include "base/macros.h" -#include "base/time/time.h" #include "base/unguessable_token.h" #include "media/base/media_export.h" diff --git a/chromium/media/base/user_input_monitor_win.cc b/chromium/media/base/user_input_monitor_win.cc index 6082070ace0..327b28bb711 100644 --- a/chromium/media/base/user_input_monitor_win.cc +++ b/chromium/media/base/user_input_monitor_win.cc @@ -13,7 +13,6 @@ #include "base/logging.h" #include "base/macros.h" #include "base/single_thread_task_runner.h" -#include "base/strings/stringprintf.h" #include "base/synchronization/lock.h" #include "base/task/current_thread.h" #include "base/win/message_window.h" diff --git a/chromium/media/base/video_color_space.h b/chromium/media/base/video_color_space.h index ee639452198..72a7d73fcb5 100644 --- a/chromium/media/base/video_color_space.h +++ b/chromium/media/base/video_color_space.h @@ -107,4 +107,4 @@ class MEDIA_EXPORT VideoColorSpace { } // namespace media -#endif +#endif // MEDIA_BASE_VIDEO_COLOR_SPACE_H_ diff --git a/chromium/media/base/video_decoder.h b/chromium/media/base/video_decoder.h index 8c6cb290dc2..77772ab6b82 100644 --- a/chromium/media/base/video_decoder.h +++ b/chromium/media/base/video_decoder.h @@ -5,9 +5,6 @@ #ifndef MEDIA_BASE_VIDEO_DECODER_H_ #define MEDIA_BASE_VIDEO_DECODER_H_ -#include <string> - -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "media/base/decode_status.h" #include "media/base/decoder.h" @@ -41,6 +38,8 @@ class MEDIA_EXPORT VideoDecoder : public Decoder { using DecodeCB = base::OnceCallback<void(Status)>; VideoDecoder(); + VideoDecoder(const VideoDecoder&) = delete; + VideoDecoder& operator=(const VideoDecoder&) = delete; ~VideoDecoder() override; // Initializes a VideoDecoder with the given |config|, executing the @@ -131,9 +130,6 @@ class MEDIA_EXPORT VideoDecoder : public Decoder { // this should return the underlying type, if it is known, otherwise return // its own type. virtual VideoDecoderType GetDecoderType() const = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(VideoDecoder); }; } // namespace media diff --git a/chromium/media/base/video_decoder_config.h b/chromium/media/base/video_decoder_config.h index 144f7d61a15..af04252500c 100644 --- a/chromium/media/base/video_decoder_config.h +++ b/chromium/media/base/video_decoder_config.h @@ -11,13 +11,13 @@ #include <vector> #include "base/macros.h" -#include "base/optional.h" #include "media/base/encryption_scheme.h" #include "media/base/media_export.h" #include "media/base/video_codecs.h" #include "media/base/video_color_space.h" #include "media/base/video_transformation.h" #include "media/base/video_types.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/hdr_metadata.h" @@ -155,7 +155,7 @@ class MEDIA_EXPORT VideoDecoderConfig { void set_hdr_metadata(const gfx::HDRMetadata& hdr_metadata) { hdr_metadata_ = hdr_metadata; } - const base::Optional<gfx::HDRMetadata>& hdr_metadata() const { + const absl::optional<gfx::HDRMetadata>& hdr_metadata() const { return hdr_metadata_; } @@ -194,7 +194,7 @@ class MEDIA_EXPORT VideoDecoderConfig { EncryptionScheme encryption_scheme_ = EncryptionScheme::kUnencrypted; VideoColorSpace color_space_info_; - base::Optional<gfx::HDRMetadata> hdr_metadata_; + absl::optional<gfx::HDRMetadata> hdr_metadata_; bool is_rtc_ = false; // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler diff --git a/chromium/media/base/video_encoder.h b/chromium/media/base/video_encoder.h index 4a5eb6bda79..2d80329c4f4 100644 --- a/chromium/media/base/video_encoder.h +++ b/chromium/media/base/video_encoder.h @@ -6,11 +6,10 @@ #define MEDIA_BASE_VIDEO_ENCODER_H_ #include "base/callback.h" -#include "base/macros.h" -#include "base/optional.h" #include "media/base/media_export.h" #include "media/base/status.h" #include "media/base/video_codecs.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/size.h" namespace media { @@ -44,12 +43,12 @@ class MEDIA_EXPORT VideoEncoder { Options(); Options(const Options&); ~Options(); - base::Optional<uint64_t> bitrate; - base::Optional<double> framerate; + absl::optional<uint64_t> bitrate; + absl::optional<double> framerate; gfx::Size frame_size; - base::Optional<int> keyframe_interval = 10000; + absl::optional<int> keyframe_interval = 10000; // Requested number of SVC temporal layers. int temporal_layers = 1; @@ -67,12 +66,14 @@ class MEDIA_EXPORT VideoEncoder { // becomes available. using OutputCB = base::RepeatingCallback<void(VideoEncoderOutput output, - base::Optional<CodecDescription>)>; + absl::optional<CodecDescription>)>; // Callback to report success and errors in encoder calls. using StatusCB = base::OnceCallback<void(Status error)>; VideoEncoder(); + VideoEncoder(const VideoEncoder&) = delete; + VideoEncoder& operator=(const VideoEncoder&) = delete; virtual ~VideoEncoder(); // Initializes a VideoEncoder with the given |options|, executing the @@ -117,9 +118,6 @@ class MEDIA_EXPORT VideoEncoder { // Requests all outputs for already encoded frames to be // produced via |output_cb| and calls |dene_cb| after that. virtual void Flush(StatusCB done_cb) = 0; - - protected: - DISALLOW_COPY_AND_ASSIGN(VideoEncoder); }; } // namespace media diff --git a/chromium/media/base/video_frame.cc b/chromium/media/base/video_frame.cc index 452b1782164..d895ebf38a4 100644 --- a/chromium/media/base/video_frame.cc +++ b/chromium/media/base/video_frame.cc @@ -14,7 +14,7 @@ #include "base/bits.h" #include "base/callback_helpers.h" #include "base/logging.h" -#include "base/memory/aligned_memory.h" +#include "base/process/memory.h" #include "base/stl_util.h" #include "base/strings/string_piece.h" #include "base/strings/stringprintf.h" @@ -210,7 +210,7 @@ static bool RequiresEvenSizeAllocation(VideoPixelFormat format) { } // Creates VideoFrameLayout for tightly packed frame. -static base::Optional<VideoFrameLayout> GetDefaultLayout( +static absl::optional<VideoFrameLayout> GetDefaultLayout( VideoPixelFormat format, const gfx::Size& coded_size) { std::vector<ColorPlaneLayout> planes; @@ -259,7 +259,7 @@ static base::Optional<VideoFrameLayout> GetDefaultLayout( // http://crbug.com/555909 . DLOG(ERROR) << "Unsupported pixel format" << VideoPixelFormatToString(format); - return base::nullopt; + return absl::nullopt; } return VideoFrameLayout::CreateWithPlanes(format, coded_size, planes); @@ -291,33 +291,8 @@ bool VideoFrame::IsValidConfig(VideoPixelFormat format, const gfx::Size& coded_size, const gfx::Rect& visible_rect, const gfx::Size& natural_size) { - // Check maximum limits for all formats. - int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); - int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); - static_assert(limits::kMaxCanvas < INT_MAX, ""); - if (coded_size_area > limits::kMaxCanvas || - coded_size.width() > limits::kMaxDimension || - coded_size.height() > limits::kMaxDimension || visible_rect.x() < 0 || - visible_rect.y() < 0 || visible_rect.right() > coded_size.width() || - visible_rect.bottom() > coded_size.height() || - natural_size_area > limits::kMaxCanvas || - natural_size.width() > limits::kMaxDimension || - natural_size.height() > limits::kMaxDimension) { - return false; - } - - // Make sure new formats are properly accounted for in the method. - static_assert(PIXEL_FORMAT_MAX == 33, - "Added pixel format, please review IsValidConfig()"); - - if (format == PIXEL_FORMAT_UNKNOWN) { - return coded_size.IsEmpty() && visible_rect.IsEmpty() && - natural_size.IsEmpty(); - } - - // Check that software-allocated buffer formats are not empty. - return !coded_size.IsEmpty() && !visible_rect.IsEmpty() && - !natural_size.IsEmpty(); + return IsValidConfigInternal(format, FrameControlType::kNone, coded_size, + visible_rect, natural_size); } // static @@ -336,9 +311,9 @@ scoped_refptr<VideoFrame> VideoFrame::CreateVideoHoleFrame( const gfx::Size& natural_size, base::TimeDelta timestamp) { auto layout = VideoFrameLayout::Create(PIXEL_FORMAT_UNKNOWN, natural_size); - scoped_refptr<VideoFrame> frame = - new VideoFrame(*layout, StorageType::STORAGE_OPAQUE, - gfx::Rect(natural_size), natural_size, timestamp); + scoped_refptr<VideoFrame> frame = new VideoFrame( + *layout, StorageType::STORAGE_OPAQUE, gfx::Rect(natural_size), + natural_size, timestamp, FrameControlType::kVideoHole); frame->metadata().overlay_plane_id = overlay_plane_id; return frame; } @@ -603,7 +578,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalGpuMemoryBuffer( const gpu::MailboxHolder (&mailbox_holders)[kMaxPlanes], ReleaseMailboxCB mailbox_holder_release_cb, base::TimeDelta timestamp) { - const base::Optional<VideoPixelFormat> format = + const absl::optional<VideoPixelFormat> format = GfxBufferFormatToVideoPixelFormat(gpu_memory_buffer->GetFormat()); if (!format) return nullptr; @@ -740,7 +715,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapUnacceleratedIOSurface( std::vector<int32_t> strides; for (size_t i = 0; i < num_planes; ++i) strides.push_back(IOSurfaceGetBytesPerRowOfPlane(io_surface, i)); - base::Optional<VideoFrameLayout> layout = + absl::optional<VideoFrameLayout> layout = media::VideoFrameLayout::CreateWithStrides(pixel_format, size, strides); if (!layout) { DLOG(ERROR) << "Invalid layout."; @@ -857,7 +832,7 @@ scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( } size_t new_plane_count = NumPlanes(format); - base::Optional<VideoFrameLayout> new_layout; + absl::optional<VideoFrameLayout> new_layout; if (format == frame->format()) { new_layout = frame->layout(); } else { @@ -913,8 +888,9 @@ scoped_refptr<VideoFrame> VideoFrame::CreateEOSFrame() { DLOG(ERROR) << "Invalid layout."; return nullptr; } - scoped_refptr<VideoFrame> frame = new VideoFrame( - *layout, STORAGE_UNKNOWN, gfx::Rect(), gfx::Size(), kNoTimestamp); + scoped_refptr<VideoFrame> frame = + new VideoFrame(*layout, STORAGE_UNKNOWN, gfx::Rect(), gfx::Size(), + kNoTimestamp, FrameControlType::kEos); frame->metadata().end_of_stream = true; return frame; } @@ -1322,7 +1298,8 @@ VideoFrame::VideoFrame(const VideoFrameLayout& layout, StorageType storage_type, const gfx::Rect& visible_rect, const gfx::Size& natural_size, - base::TimeDelta timestamp) + base::TimeDelta timestamp, + FrameControlType frame_control_type) : layout_(layout), storage_type_(storage_type), visible_rect_(Intersection(visible_rect, gfx::Rect(layout.coded_size()))), @@ -1332,8 +1309,8 @@ VideoFrame::VideoFrame(const VideoFrameLayout& layout, #endif timestamp_(timestamp), unique_id_(g_unique_id_generator.GetNext()) { - DCHECK(IsValidConfig(format(), storage_type, coded_size(), visible_rect_, - natural_size_)); + DCHECK(IsValidConfigInternal(format(), frame_control_type, coded_size(), + visible_rect_, natural_size_)); DCHECK(visible_rect_ == visible_rect) << "visible_rect " << visible_rect.ToString() << " exceeds coded_size " << coded_size().ToString(); @@ -1383,6 +1360,46 @@ gfx::Size VideoFrame::DetermineAlignedSize(VideoPixelFormat format, } // static +bool VideoFrame::IsValidConfigInternal(VideoPixelFormat format, + FrameControlType frame_control_type, + const gfx::Size& coded_size, + const gfx::Rect& visible_rect, + const gfx::Size& natural_size) { + // Check maximum limits for all formats. + int coded_size_area = coded_size.GetCheckedArea().ValueOrDefault(INT_MAX); + int natural_size_area = natural_size.GetCheckedArea().ValueOrDefault(INT_MAX); + static_assert(limits::kMaxCanvas < INT_MAX, ""); + if (coded_size_area > limits::kMaxCanvas || + coded_size.width() > limits::kMaxDimension || + coded_size.height() > limits::kMaxDimension || visible_rect.x() < 0 || + visible_rect.y() < 0 || visible_rect.right() > coded_size.width() || + visible_rect.bottom() > coded_size.height() || + natural_size_area > limits::kMaxCanvas || + natural_size.width() > limits::kMaxDimension || + natural_size.height() > limits::kMaxDimension) { + return false; + } + + // Make sure new formats are properly accounted for in the method. + static_assert(PIXEL_FORMAT_MAX == 33, + "Added pixel format, please review AreSizesValid()"); + switch (frame_control_type) { + case FrameControlType::kNone: + // Check that software-allocated buffer formats are not empty. + return !coded_size.IsEmpty() && !visible_rect.IsEmpty() && + !natural_size.IsEmpty(); + case FrameControlType::kEos: + DCHECK_EQ(format, PIXEL_FORMAT_UNKNOWN); + return coded_size.IsEmpty() && visible_rect.IsEmpty() && + natural_size.IsEmpty(); + case FrameControlType::kVideoHole: + DCHECK_EQ(format, PIXEL_FORMAT_UNKNOWN); + return !coded_size.IsEmpty() && !visible_rect.IsEmpty() && + !natural_size.IsEmpty(); + } +} + +// static scoped_refptr<VideoFrame> VideoFrame::CreateFrameInternal( VideoPixelFormat format, const gfx::Size& coded_size, @@ -1390,9 +1407,10 @@ scoped_refptr<VideoFrame> VideoFrame::CreateFrameInternal( const gfx::Size& natural_size, base::TimeDelta timestamp, bool zero_initialize_memory) { - // Since we're creating a new frame (and allocating memory for it ourselves), - // we can pad the requested |coded_size| if necessary if the request does not - // line up on sample boundaries. See discussion at http://crrev.com/1240833003 + // Since we're creating a new frame (and allocating memory for it + // ourselves), we can pad the requested |coded_size| if necessary if the + // request does not line up on sample boundaries. See discussion at + // http://crrev.com/1240833003 const gfx::Size new_coded_size = DetermineAlignedSize(format, coded_size); auto layout = VideoFrameLayout::CreateWithStrides( format, new_coded_size, ComputeStrides(format, new_coded_size)); @@ -1422,8 +1440,7 @@ scoped_refptr<VideoFrame> VideoFrame::CreateFrameWithLayout( scoped_refptr<VideoFrame> frame(new VideoFrame( std::move(layout), storage, visible_rect, natural_size, timestamp)); - frame->AllocateMemory(zero_initialize_memory); - return frame; + return frame->AllocateMemory(zero_initialize_memory) ? frame : nullptr; } // static @@ -1438,27 +1455,43 @@ gfx::Size VideoFrame::CommonAlignment(VideoPixelFormat format) { return gfx::Size(max_sample_width, max_sample_height); } -void VideoFrame::AllocateMemory(bool zero_initialize_memory) { +bool VideoFrame::AllocateMemory(bool zero_initialize_memory) { DCHECK_EQ(storage_type_, STORAGE_OWNED_MEMORY); static_assert(0 == kYPlane, "y plane data must be index 0"); std::vector<size_t> plane_size = CalculatePlaneSize(); - const size_t total_buffer_size = + const size_t buffer_size = std::accumulate(plane_size.begin(), plane_size.end(), 0u); + const size_t allocation_size = + buffer_size + (layout_.buffer_addr_align() - 1); - uint8_t* data = reinterpret_cast<uint8_t*>( - base::AlignedAlloc(total_buffer_size, layout_.buffer_addr_align())); + uint8_t* data = nullptr; if (zero_initialize_memory) { - memset(data, 0, total_buffer_size); + if (!base::UncheckedCalloc(1, allocation_size, + reinterpret_cast<void**>(&data)) || + !data) { + return false; + } + } else { + if (!base::UncheckedMalloc(allocation_size, + reinterpret_cast<void**>(&data)) || + !data) { + return false; + } } - AddDestructionObserver(base::BindOnce(&base::AlignedFree, data)); + private_data_.reset(data); + + data = base::bits::Align(data, layout_.buffer_addr_align()); + DCHECK_LE(data + buffer_size, private_data_.get() + allocation_size); - // Note that if layout.buffer_sizes is specified, color planes' layout is the - // same as buffers'. See CalculatePlaneSize() for detail. + // Note that if layout.buffer_sizes is specified, color planes' layout is + // the same as buffers'. See CalculatePlaneSize() for detail. for (size_t plane = 0, offset = 0; plane < NumPlanes(format()); ++plane) { data_[plane] = data + offset; offset += plane_size[plane]; } + + return true; } bool VideoFrame::IsValidSharedMemoryFrame() const { diff --git a/chromium/media/base/video_frame.h b/chromium/media/base/video_frame.h index cf10ff045c1..373d0268b67 100644 --- a/chromium/media/base/video_frame.h +++ b/chromium/media/base/video_frame.h @@ -16,11 +16,9 @@ #include "base/callback.h" #include "base/check_op.h" #include "base/hash/md5.h" -#include "base/macros.h" -#include "base/memory/aligned_memory.h" +#include "base/memory/free_deleter.h" #include "base/memory/ref_counted.h" #include "base/memory/unsafe_shared_memory_region.h" -#include "base/optional.h" #include "base/synchronization/lock.h" #include "base/thread_annotations.h" #include "base/unguessable_token.h" @@ -30,6 +28,7 @@ #include "media/base/video_frame_layout.h" #include "media/base/video_frame_metadata.h" #include "media/base/video_types.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/color_space.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -104,16 +103,21 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // the GPU Command Buffer and wait for it. class SyncTokenClient { public: - SyncTokenClient() {} + SyncTokenClient() = default; + SyncTokenClient(const SyncTokenClient&) = delete; + SyncTokenClient& operator=(const SyncTokenClient&) = delete; + virtual void GenerateSyncToken(gpu::SyncToken* sync_token) = 0; virtual void WaitSyncToken(const gpu::SyncToken& sync_token) = 0; protected: - virtual ~SyncTokenClient() {} - - DISALLOW_COPY_AND_ASSIGN(SyncTokenClient); + virtual ~SyncTokenClient() = default; }; + VideoFrame() = delete; + VideoFrame(const VideoFrame&) = delete; + VideoFrame& operator=(const VideoFrame&) = delete; + // Returns true if frame configuration is valid. static bool IsValidConfig(VideoPixelFormat format, StorageType storage_type, @@ -448,11 +452,11 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { color_space_ = color_space; } - const base::Optional<gfx::HDRMetadata>& hdr_metadata() const { + const absl::optional<gfx::HDRMetadata>& hdr_metadata() const { return hdr_metadata_; } - void set_hdr_metadata(const base::Optional<gfx::HDRMetadata>& hdr_metadata) { + void set_hdr_metadata(const absl::optional<gfx::HDRMetadata>& hdr_metadata) { hdr_metadata_ = hdr_metadata; } @@ -499,7 +503,7 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { return data_[plane]; } - const base::Optional<gpu::VulkanYCbCrInfo>& ycbcr_info() const { + const absl::optional<gpu::VulkanYCbCrInfo>& ycbcr_info() const { return wrapped_frame_ ? wrapped_frame_->ycbcr_info() : ycbcr_info_; } @@ -597,13 +601,19 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { size_t BitDepth() const; // Provide the sampler conversion information for the frame. - void set_ycbcr_info(const base::Optional<gpu::VulkanYCbCrInfo>& ycbcr_info) { + void set_ycbcr_info(const absl::optional<gpu::VulkanYCbCrInfo>& ycbcr_info) { ycbcr_info_ = ycbcr_info; } protected: friend class base::RefCountedThreadSafe<VideoFrame>; + enum class FrameControlType { + kNone, + kEos, + kVideoHole, + }; + // Clients must use the static factory/wrapping methods to create a new frame. // Derived classes should create their own factory/wrapping methods, and use // this constructor to do basic initialization. @@ -611,8 +621,8 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { StorageType storage_type, const gfx::Rect& visible_rect, const gfx::Size& natural_size, - base::TimeDelta timestamp); - + base::TimeDelta timestamp, + FrameControlType frame_control_type = FrameControlType::kNone); virtual ~VideoFrame(); // Creates a summary of the configuration settings provided as parameters. @@ -629,6 +639,15 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { } private: + // The constructor of VideoFrame should use IsValidConfigInternal() + // instead of the public IsValidConfig() to check the config, because we can + // create special video frames that won't pass the check by IsValidConfig(). + static bool IsValidConfigInternal(VideoPixelFormat format, + FrameControlType frame_control_type, + const gfx::Size& coded_size, + const gfx::Rect& visible_rect, + const gfx::Size& natural_size); + static scoped_refptr<VideoFrame> CreateFrameInternal( VideoPixelFormat format, const gfx::Size& coded_size, @@ -641,7 +660,9 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { // alignment for each individual plane. static gfx::Size CommonAlignment(VideoPixelFormat format); - void AllocateMemory(bool zero_initialize_memory); + // Tries to allocate the requisite amount of memory for this frame. Returns + // false if this would cause an out of memory error. + WARN_UNUSED_RESULT bool AllocateMemory(bool zero_initialize_memory); // Calculates plane size. // It first considers buffer size layout_ object provides. If layout's @@ -729,12 +750,13 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { const int unique_id_; gfx::ColorSpace color_space_; - base::Optional<gfx::HDRMetadata> hdr_metadata_; + absl::optional<gfx::HDRMetadata> hdr_metadata_; // Sampler conversion information which is used in vulkan context for android. - base::Optional<gpu::VulkanYCbCrInfo> ycbcr_info_; + absl::optional<gpu::VulkanYCbCrInfo> ycbcr_info_; - DISALLOW_IMPLICIT_CONSTRUCTORS(VideoFrame); + // Allocation which makes up |data_| planes for self-allocated frames. + std::unique_ptr<uint8_t, base::FreeDeleter> private_data_; }; } // namespace media diff --git a/chromium/media/base/video_frame_layout.cc b/chromium/media/base/video_frame_layout.cc index dcf0dd23cc5..3eef408656d 100644 --- a/chromium/media/base/video_frame_layout.cc +++ b/chromium/media/base/video_frame_layout.cc @@ -87,7 +87,7 @@ size_t VideoFrameLayout::NumPlanes(VideoPixelFormat format) { } // static -base::Optional<VideoFrameLayout> VideoFrameLayout::Create( +absl::optional<VideoFrameLayout> VideoFrameLayout::Create( VideoPixelFormat format, const gfx::Size& coded_size) { return CreateWithStrides(format, coded_size, @@ -95,7 +95,7 @@ base::Optional<VideoFrameLayout> VideoFrameLayout::Create( } // static -base::Optional<VideoFrameLayout> VideoFrameLayout::CreateWithStrides( +absl::optional<VideoFrameLayout> VideoFrameLayout::CreateWithStrides( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<int32_t> strides, @@ -106,32 +106,32 @@ base::Optional<VideoFrameLayout> VideoFrameLayout::CreateWithStrides( } // static -base::Optional<VideoFrameLayout> VideoFrameLayout::CreateWithPlanes( +absl::optional<VideoFrameLayout> VideoFrameLayout::CreateWithPlanes( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<ColorPlaneLayout> planes, size_t buffer_addr_align, uint64_t modifier) { // NOTE: Even if format is UNKNOWN, it is valid if coded_sizes is not Empty(). - // TODO(crbug.com/896135): Return base::nullopt, + // TODO(crbug.com/896135): Return absl::nullopt, // if (format != PIXEL_FORMAT_UNKNOWN || !coded_sizes.IsEmpty()) - // TODO(crbug.com/896135): Return base::nullopt, + // TODO(crbug.com/896135): Return absl::nullopt, // if (planes.size() != NumPlanes(format)) return VideoFrameLayout(format, coded_size, std::move(planes), false /*is_multi_planar */, buffer_addr_align, modifier); } -base::Optional<VideoFrameLayout> VideoFrameLayout::CreateMultiPlanar( +absl::optional<VideoFrameLayout> VideoFrameLayout::CreateMultiPlanar( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<ColorPlaneLayout> planes, size_t buffer_addr_align, uint64_t modifier) { // NOTE: Even if format is UNKNOWN, it is valid if coded_sizes is not Empty(). - // TODO(crbug.com/896135): Return base::nullopt, + // TODO(crbug.com/896135): Return absl::nullopt, // if (format != PIXEL_FORMAT_UNKNOWN || !coded_sizes.IsEmpty()) - // TODO(crbug.com/896135): Return base::nullopt, + // TODO(crbug.com/896135): Return absl::nullopt, // if (planes.size() != NumPlanes(format)) return VideoFrameLayout(format, coded_size, std::move(planes), true /*is_multi_planar */, buffer_addr_align, diff --git a/chromium/media/base/video_frame_layout.h b/chromium/media/base/video_frame_layout.h index 9d1f7c17437..73b106e0d4a 100644 --- a/chromium/media/base/video_frame_layout.h +++ b/chromium/media/base/video_frame_layout.h @@ -13,10 +13,10 @@ #include <utility> #include <vector> -#include "base/optional.h" #include "media/base/color_plane_layout.h" #include "media/base/media_export.h" #include "media/base/video_types.h" +#include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/native_pixmap_handle.h" @@ -47,19 +47,19 @@ class MEDIA_EXPORT VideoFrameLayout { // |modifier| is the additional information of |format|. It will become some // value else than gfx::NativePixmapHandle::kNoModifier when the underlying // buffer format is different from a standard |format| due to tiling. - // The returned base::Optional will be base::nullopt if the configured values + // The returned absl::optional will be absl::nullopt if the configured values // are invalid. // Create a layout suitable for |format| at |coded_size|. The stride, offsets // and size of all planes are set to 0, since that information cannot reliably // be infered from the arguments. - static base::Optional<VideoFrameLayout> Create(VideoPixelFormat format, + static absl::optional<VideoFrameLayout> Create(VideoPixelFormat format, const gfx::Size& coded_size); // Create a layout suitable for |format| at |coded_size|, with the |strides| // for each plane specified. The offsets and size of all planes are set to 0. // The size of |strides| must be equal to NumPlanes(|format|). - static base::Optional<VideoFrameLayout> CreateWithStrides( + static absl::optional<VideoFrameLayout> CreateWithStrides( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<int32_t> strides, @@ -69,7 +69,7 @@ class MEDIA_EXPORT VideoFrameLayout { // Create a layout suitable for |format| at |coded_size|, with the |planes| // fully provided. // The size of |planes| must be equal to NumPlanes(|format|). - static base::Optional<VideoFrameLayout> CreateWithPlanes( + static absl::optional<VideoFrameLayout> CreateWithPlanes( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<ColorPlaneLayout> planes, @@ -79,7 +79,7 @@ class MEDIA_EXPORT VideoFrameLayout { // This constructor should be called for situations where the frames using // this format are backed by multiple physical buffers, instead of having each // plane at different offsets of the same buffer. Currently only used by V4L2. - static base::Optional<VideoFrameLayout> CreateMultiPlanar( + static absl::optional<VideoFrameLayout> CreateMultiPlanar( VideoPixelFormat format, const gfx::Size& coded_size, std::vector<ColorPlaneLayout> planes, diff --git a/chromium/media/base/video_frame_metadata.h b/chromium/media/base/video_frame_metadata.h index 3456e0703bd..844fde80b4d 100644 --- a/chromium/media/base/video_frame_metadata.h +++ b/chromium/media/base/video_frame_metadata.h @@ -5,9 +5,6 @@ #ifndef MEDIA_BASE_VIDEO_FRAME_METADATA_H_ #define MEDIA_BASE_VIDEO_FRAME_METADATA_H_ -#include <memory> -#include <string> - #include "base/compiler_specific.h" #include "base/macros.h" #include "base/time/time.h" @@ -55,8 +52,8 @@ struct MEDIA_EXPORT VideoFrameMetadata { // Video capture begin/end timestamps. Consumers can use these values for // dynamic optimizations, logging stats, etc. - base::Optional<base::TimeTicks> capture_begin_time; - base::Optional<base::TimeTicks> capture_end_time; + absl::optional<base::TimeTicks> capture_begin_time; + absl::optional<base::TimeTicks> capture_end_time; // A counter that is increased by the producer of video frames each time // it pushes out a new frame. By looking for gaps in this counter, clients @@ -64,7 +61,7 @@ struct MEDIA_EXPORT VideoFrameMetadata { // the producer between two consecutively received frames. Note that the // counter may start at arbitrary values, so the absolute value of it has no // meaning. - base::Optional<int> capture_counter; + absl::optional<int> capture_counter; // The rectangular region of the frame that has changed since the frame // with the directly preceding CAPTURE_COUNTER. If that frame was not @@ -73,11 +70,11 @@ struct MEDIA_EXPORT VideoFrameMetadata { // The rectangle is relative to the full frame data, i.e. [0, 0, // coded_size().width(), coded_size().height()]. It does not have to be // fully contained within visible_rect(). - base::Optional<gfx::Rect> capture_update_rect; + absl::optional<gfx::Rect> capture_update_rect; // If not null, it indicates how video frame mailbox should be copied to a // new mailbox. - base::Optional<CopyMode> copy_mode; + absl::optional<CopyMode> copy_mode; // Indicates if the current frame is the End of its current Stream. bool end_of_stream = false; @@ -88,12 +85,12 @@ struct MEDIA_EXPORT VideoFrameMetadata { // vary unpredictably for every frame. Consumers can use this to optimize // playback scheduling, make encoding quality decisions, and/or compute // frame-level resource utilization stats. - base::Optional<base::TimeDelta> frame_duration; + absl::optional<base::TimeDelta> frame_duration; // Represents either the fixed frame rate, or the maximum frame rate to // expect from a variable-rate source. This value generally remains the // same for all frames in the same session. - base::Optional<double> frame_rate; + absl::optional<double> frame_rate; // This is a boolean that signals that the video capture engine detects // interactive content. One possible optimization that this signal can help @@ -107,7 +104,7 @@ struct MEDIA_EXPORT VideoFrameMetadata { // a high-resolution timestamp, and so it should not be used as a // presentation time; but, instead, it should be used for buffering playback // and for A/V synchronization purposes. - base::Optional<base::TimeTicks> reference_time; + absl::optional<base::TimeTicks> reference_time; // Sources of VideoFrames use this marker to indicate that an instance of // VideoFrameExternalResources produced from the associated video frame @@ -115,7 +112,7 @@ struct MEDIA_EXPORT VideoFrameMetadata { bool read_lock_fences_enabled = false; // Indicates that the frame has a rotation and/or flip. - base::Optional<VideoTransformation> transformation; + absl::optional<VideoTransformation> transformation; // Android only: if set, then this frame is not suitable for overlay, even // if ALLOW_OVERLAY is set. However, it allows us to process the overlay @@ -140,7 +137,7 @@ struct MEDIA_EXPORT VideoFrameMetadata { // An UnguessableToken that identifies VideoOverlayFactory that created // this VideoFrame. It's used by Cast to help with video hole punch. - base::Optional<base::UnguessableToken> overlay_plane_id; + absl::optional<base::UnguessableToken> overlay_plane_id; // Whether this frame was decoded in a power efficient way. bool power_efficient = false; @@ -149,46 +146,46 @@ struct MEDIA_EXPORT VideoFrameMetadata { // remote debugging. // TODO(crbug.com/832220): Use a customized dictionary value instead of // using these keys directly. - base::Optional<double> device_scale_factor; - base::Optional<double> page_scale_factor; - base::Optional<double> root_scroll_offset_x; - base::Optional<double> root_scroll_offset_y; - base::Optional<double> top_controls_visible_height; + absl::optional<double> device_scale_factor; + absl::optional<double> page_scale_factor; + absl::optional<double> root_scroll_offset_x; + absl::optional<double> root_scroll_offset_y; + absl::optional<double> top_controls_visible_height; // If present, this field represents the local time at which the VideoFrame // was decoded from whichever format it was encoded in. Sometimes only // DECODE_END_TIME will be present. - base::Optional<base::TimeTicks> decode_begin_time; - base::Optional<base::TimeTicks> decode_end_time; + absl::optional<base::TimeTicks> decode_begin_time; + absl::optional<base::TimeTicks> decode_end_time; // If present, this field represents the elapsed time from the submission of // the encoded packet with the same PTS as this frame to the decoder until // the decoded frame was ready for presentation. - base::Optional<base::TimeDelta> processing_time; + absl::optional<base::TimeDelta> processing_time; // The RTP timestamp associated with this video frame. Stored as a double // since base::DictionaryValue doesn't have a uint32_t type. // // https://w3c.github.io/webrtc-pc/#dom-rtcrtpcontributingsource-rtptimestamp - base::Optional<double> rtp_timestamp; + absl::optional<double> rtp_timestamp; // For video frames coming from a remote source, this is the time the // encoded frame was received by the platform, i.e., the time at // which the last packet belonging to this frame was received over the // network. - base::Optional<base::TimeTicks> receive_time; + absl::optional<base::TimeTicks> receive_time; // If present, this field represents the duration this frame is ideally // expected to spend on the screen during playback. Unlike FRAME_DURATION // this field takes into account current playback rate. - base::Optional<base::TimeDelta> wallclock_frame_duration; + absl::optional<base::TimeDelta> wallclock_frame_duration; // WebRTC streams only: if present, this field represents the maximum // composition delay that is allowed for this frame. This is respected // in a best effort manner. // This is an experimental feature, see crbug.com/1138888 for more // information. - base::Optional<int> maximum_composition_delay_in_frames; + absl::optional<int> maximum_composition_delay_in_frames; }; } // namespace media diff --git a/chromium/media/base/video_frame_pool.cc b/chromium/media/base/video_frame_pool.cc index 4541324af7b..b5db2c3fbab 100644 --- a/chromium/media/base/video_frame_pool.cc +++ b/chromium/media/base/video_frame_pool.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/containers/circular_deque.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "base/thread_annotations.h" @@ -19,6 +18,8 @@ class VideoFramePool::PoolImpl : public base::RefCountedThreadSafe<VideoFramePool::PoolImpl> { public: PoolImpl(); + PoolImpl(const PoolImpl&) = delete; + PoolImpl& operator=(const PoolImpl&) = delete; // See VideoFramePool::CreateFrame() for usage. Attempts to keep |frames_| in // LRU order by always pulling from the back of |frames_|. @@ -65,8 +66,6 @@ class VideoFramePool::PoolImpl // |tick_clock_| is always a DefaultTickClock outside of testing. const base::TickClock* tick_clock_; - - DISALLOW_COPY_AND_ASSIGN(PoolImpl); }; VideoFramePool::PoolImpl::PoolImpl() diff --git a/chromium/media/base/video_frame_pool.h b/chromium/media/base/video_frame_pool.h index e6532b4bf41..88cac326086 100644 --- a/chromium/media/base/video_frame_pool.h +++ b/chromium/media/base/video_frame_pool.h @@ -7,7 +7,6 @@ #include <stddef.h> -#include "base/macros.h" #include "media/base/media_export.h" #include "media/base/video_frame.h" @@ -28,6 +27,8 @@ namespace media { class MEDIA_EXPORT VideoFramePool { public: VideoFramePool(); + VideoFramePool(const VideoFramePool&) = delete; + VideoFramePool& operator=(const VideoFramePool&) = delete; ~VideoFramePool(); // Returns a frame from the pool that matches the specified @@ -53,8 +54,6 @@ class MEDIA_EXPORT VideoFramePool { private: class PoolImpl; scoped_refptr<PoolImpl> pool_; - - DISALLOW_COPY_AND_ASSIGN(VideoFramePool); }; } // namespace media diff --git a/chromium/media/base/video_frame_unittest.cc b/chromium/media/base/video_frame_unittest.cc index 50836987e0d..a16ecbcd3cf 100644 --- a/chromium/media/base/video_frame_unittest.cc +++ b/chromium/media/base/video_frame_unittest.cc @@ -291,6 +291,11 @@ TEST(VideoFrame, CreateFrame) { // Test an empty frame. frame = VideoFrame::CreateEOSFrame(); EXPECT_TRUE(frame->metadata().end_of_stream); + + // Test an video hole frame. + frame = VideoFrame::CreateVideoHoleFrame(base::UnguessableToken::Create(), + size, kTimestamp); + ASSERT_TRUE(frame); } TEST(VideoFrame, CreateZeroInitializedFrame) { diff --git a/chromium/media/base/video_renderer.h b/chromium/media/base/video_renderer.h index bfbc676c856..6e5611886f2 100644 --- a/chromium/media/base/video_renderer.h +++ b/chromium/media/base/video_renderer.h @@ -6,11 +6,10 @@ #define MEDIA_BASE_VIDEO_RENDERER_H_ #include "base/callback_forward.h" -#include "base/macros.h" -#include "base/optional.h" #include "media/base/media_export.h" #include "media/base/pipeline_status.h" #include "media/base/time_source.h" +#include "third_party/abseil-cpp/absl/types/optional.h" namespace media { @@ -21,6 +20,8 @@ class RendererClient; class MEDIA_EXPORT VideoRenderer { public: VideoRenderer(); + VideoRenderer(const VideoRenderer&) = delete; + VideoRenderer& operator=(const VideoRenderer&) = delete; // Stops all operations and fires all pending callbacks. virtual ~VideoRenderer(); @@ -68,10 +69,7 @@ class MEDIA_EXPORT VideoRenderer { // media::Renderer::SetLatencyHint(). // |latency_hint| may be nullopt to indicate the hint has been cleared // (restore UA default). - virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(VideoRenderer); + virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0; }; } // namespace media diff --git a/chromium/media/base/video_thumbnail_decoder.h b/chromium/media/base/video_thumbnail_decoder.h index 409ec23ab6a..af70aaf20dd 100644 --- a/chromium/media/base/video_thumbnail_decoder.h +++ b/chromium/media/base/video_thumbnail_decoder.h @@ -9,7 +9,6 @@ #include <vector> #include "base/callback.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "media/base/media_export.h" @@ -32,6 +31,8 @@ class MEDIA_EXPORT VideoThumbnailDecoder { VideoThumbnailDecoder(std::unique_ptr<VideoDecoder> decoder, const VideoDecoderConfig& config, std::vector<uint8_t> encoded_data); + VideoThumbnailDecoder(const VideoThumbnailDecoder&) = delete; + VideoThumbnailDecoder& operator=(const VideoThumbnailDecoder&) = delete; ~VideoThumbnailDecoder(); // Starts to decode the video frame. @@ -56,8 +57,6 @@ class MEDIA_EXPORT VideoThumbnailDecoder { VideoFrameCallback video_frame_callback_; base::WeakPtrFactory<VideoThumbnailDecoder> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(VideoThumbnailDecoder); }; } // namespace media diff --git a/chromium/media/base/video_thumbnail_decoder_unittest.cc b/chromium/media/base/video_thumbnail_decoder_unittest.cc index 10aa6e34f6b..f070c07cce9 100644 --- a/chromium/media/base/video_thumbnail_decoder_unittest.cc +++ b/chromium/media/base/video_thumbnail_decoder_unittest.cc @@ -28,8 +28,11 @@ namespace { class VideoThumbnailDecoderTest : public testing::Test { public: - VideoThumbnailDecoderTest() {} - ~VideoThumbnailDecoderTest() override {} + VideoThumbnailDecoderTest() = default; + VideoThumbnailDecoderTest(const VideoThumbnailDecoderTest&) = delete; + VideoThumbnailDecoderTest& operator=(const VideoThumbnailDecoderTest&) = + delete; + ~VideoThumbnailDecoderTest() override = default; protected: void SetUp() override { @@ -76,8 +79,6 @@ class VideoThumbnailDecoderTest : public testing::Test { // The video frame returned from the thumbnail decoder. scoped_refptr<VideoFrame> frame_; - - DISALLOW_COPY_AND_ASSIGN(VideoThumbnailDecoderTest); }; // Verifies a video frame can be delivered when decoder successfully created diff --git a/chromium/media/base/video_util_unittest.cc b/chromium/media/base/video_util_unittest.cc index c6ae0616ddc..abaa9e25696 100644 --- a/chromium/media/base/video_util_unittest.cc +++ b/chromium/media/base/video_util_unittest.cc @@ -9,7 +9,6 @@ #include <cmath> #include <memory> -#include "base/macros.h" #include "media/base/video_frame.h" #include "testing/gtest/include/gtest/gtest.h" @@ -151,7 +150,8 @@ class VideoUtilTest : public testing::Test { u_stride_(0), v_stride_(0) { } - + VideoUtilTest(const VideoUtilTest&) = delete; + VideoUtilTest& operator=(const VideoUtilTest&) = delete; ~VideoUtilTest() override = default; void CreateSourceFrame(int width, int height, @@ -187,8 +187,6 @@ class VideoUtilTest : public testing::Test { int v_stride_; scoped_refptr<VideoFrame> destination_frame_; - - DISALLOW_COPY_AND_ASSIGN(VideoUtilTest); }; TEST_F(VideoUtilTest, GetPixelAspectRatio) { @@ -408,15 +406,14 @@ class VideoUtilRotationTest VideoUtilRotationTest() { dest_.reset(new uint8_t[GetParam().width * GetParam().height]); } - - virtual ~VideoUtilRotationTest() = default; + VideoUtilRotationTest(const VideoUtilRotationTest&) = delete; + VideoUtilRotationTest& operator=(const VideoUtilRotationTest&) = delete; + ~VideoUtilRotationTest() override = default; uint8_t* dest_plane() { return dest_.get(); } private: std::unique_ptr<uint8_t[]> dest_; - - DISALLOW_COPY_AND_ASSIGN(VideoUtilRotationTest); }; TEST_P(VideoUtilRotationTest, Rotate) { diff --git a/chromium/media/base/win/BUILD.gn b/chromium/media/base/win/BUILD.gn index b78090ac9c1..97dfcd06aa6 100644 --- a/chromium/media/base/win/BUILD.gn +++ b/chromium/media/base/win/BUILD.gn @@ -54,7 +54,7 @@ source_set("hresult_status_helper") { } source_set("mf_cdm_proxy") { - sources = [ "mf_cdm_proxy.h" ] + sources = [ "media_foundation_cdm_proxy.h" ] deps = [ "//base" ] } diff --git a/chromium/media/base/win/dxgi_device_manager.h b/chromium/media/base/win/dxgi_device_manager.h index d489b3160c2..98e830154f2 100644 --- a/chromium/media/base/win/dxgi_device_manager.h +++ b/chromium/media/base/win/dxgi_device_manager.h @@ -33,7 +33,7 @@ class MF_INITIALIZER_EXPORT DXGIDeviceScopedHandle { }; class MF_INITIALIZER_EXPORT DXGIDeviceManager - : public base::RefCounted<DXGIDeviceManager> { + : public base::RefCountedThreadSafe<DXGIDeviceManager> { public: DXGIDeviceManager(const DXGIDeviceManager&) = delete; DXGIDeviceManager& operator=(const DXGIDeviceManager&) = delete; @@ -61,7 +61,7 @@ class MF_INITIALIZER_EXPORT DXGIDeviceManager Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> GetMFDXGIDeviceManager(); protected: - friend class base::RefCounted<DXGIDeviceManager>; + friend class base::RefCountedThreadSafe<DXGIDeviceManager>; DXGIDeviceManager( Microsoft::WRL::ComPtr<IMFDXGIDeviceManager> mf_dxgi_device_manager, UINT d3d_device_reset_token); diff --git a/chromium/media/base/win/mf_cdm_proxy.h b/chromium/media/base/win/media_foundation_cdm_proxy.h index fcbeff51a85..e7e7c51d9d2 100644 --- a/chromium/media/base/win/mf_cdm_proxy.h +++ b/chromium/media/base/win/media_foundation_cdm_proxy.h @@ -2,27 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MEDIA_BASE_WIN_MF_CDM_PROXY_H_ -#define MEDIA_BASE_WIN_MF_CDM_PROXY_H_ +#ifndef MEDIA_BASE_WIN_MEDIA_FOUNDATION_CDM_PROXY_H_ +#define MEDIA_BASE_WIN_MEDIA_FOUNDATION_CDM_PROXY_H_ +#include <mfobjects.h> #include <stdint.h> #include <unknwn.h> +#include <windef.h> -// Interface for clients to get information from MediaFoundationCdm to -// implements COM interfaces. -// COM interface is used because we are working with Media Foundation which uses -// COM extensively for object lifetime management. -MIDL_INTERFACE("565ab5c2-9923-44e0-997a-f93ccba5dcbf") -IMFCdmProxy : public IUnknown { +#include "base/memory/ref_counted.h" + +namespace media { + +// Interface for the media pipeline to get information from MediaFoundationCdm. +// TODO(xhwang): Investigate whether this class needs to be ref-counted. +class MediaFoundationCdmProxy + : public base::RefCountedThreadSafe<MediaFoundationCdmProxy> { public: // Used by MediaFoundationProtectionManager to get // ABI::Windows::Media::Protection::IMediaProtectionPMPServer to implement - // ABI::Windows::Media::Protection::IMediaProtectionManager::get_Properties as - // in + // ABI::Windows::Media::Protection::IMediaProtectionManager::get_Properties // https://docs.microsoft.com/en-us/uwp/api/windows.media.protection.mediaprotectionmanager - virtual HRESULT STDMETHODCALLTYPE GetPMPServer( - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out_opt LPVOID * object_result) = 0; + virtual HRESULT GetPMPServer(REFIID riid, LPVOID* object_result) = 0; // Used by MediaFoundationSourceWrapper to implement // IMFTrustedInput::GetInputTrustAuthority as in @@ -30,30 +31,35 @@ IMFCdmProxy : public IUnknown { // // |content_init_data| is optional initialization data as in // https://www.w3.org/TR/encrypted-media/#initialization-data - virtual HRESULT STDMETHODCALLTYPE GetInputTrustAuthority( - _In_ uint32_t stream_id, _In_ uint32_t stream_count, - _In_reads_bytes_opt_(content_init_data_size) - const uint8_t* content_init_data, - _In_ uint32_t content_init_data_size, _In_ REFIID riid, - _COM_Outptr_ IUnknown** object_out) = 0; + virtual HRESULT GetInputTrustAuthority(uint32_t stream_id, + uint32_t stream_count, + const uint8_t* content_init_data, + uint32_t content_init_data_size, + REFIID riid, + IUnknown** object_out) = 0; // When the media Renderer is suspended, `MediaFoundationSourceWrapper` // provides its last set of key IDs using `SetLastKeyId()` when it is // destructed. Then during resume, the new `MediaFoundationSourceWrapper` // calls `RefreshTrustedInput()` to let the CDM use the key IDs information to // perform some optimization. - virtual HRESULT STDMETHODCALLTYPE SetLastKeyId(_In_ uint32_t stream_id, - _In_ REFGUID key_id) = 0; - virtual HRESULT STDMETHODCALLTYPE RefreshTrustedInput() = 0; + virtual HRESULT SetLastKeyId(uint32_t stream_id, REFGUID key_id) = 0; + virtual HRESULT RefreshTrustedInput() = 0; // Used by MediaFoundationProtectionManager to implement // IMFContentProtectionManager::BeginEnableContent as in // https://msdn.microsoft.com/en-us/windows/ms694217(v=vs.71) // - // |result| is used to obtain the result of an asynchronous operation as in + // `result` is used to obtain the result of an asynchronous operation as in // https://docs.microsoft.com/en-us/windows/win32/api/mfobjects/nn-mfobjects-imfasyncresult - virtual HRESULT STDMETHODCALLTYPE ProcessContentEnabler( - _In_ IUnknown * request, _In_ IMFAsyncResult * result) = 0; + virtual HRESULT ProcessContentEnabler(IUnknown* request, + IMFAsyncResult* result) = 0; + + protected: + friend base::RefCountedThreadSafe<MediaFoundationCdmProxy>; + virtual ~MediaFoundationCdmProxy() = default; }; -#endif // MEDIA_BASE_WIN_MF_CDM_PROXY_H_ +} // namespace media + +#endif // MEDIA_BASE_WIN_MEDIA_FOUNDATION_CDM_PROXY_H_ |