diff options
Diffstat (limited to 'chromium/media/blink')
19 files changed, 153 insertions, 251 deletions
diff --git a/chromium/media/blink/BUILD.gn b/chromium/media/blink/BUILD.gn index a4e8c8f3a0c..fa0a3546689 100644 --- a/chromium/media/blink/BUILD.gn +++ b/chromium/media/blink/BUILD.gn @@ -99,6 +99,8 @@ component("blink") { "webmediaplayer_impl.cc", "webmediaplayer_impl.h", ] + + deps += [ "//media/remoting:remoting_constants" ] } } diff --git a/chromium/media/blink/cdm_session_adapter.cc b/chromium/media/blink/cdm_session_adapter.cc index e1673156290..a2fa29db1f1 100644 --- a/chromium/media/blink/cdm_session_adapter.cc +++ b/chromium/media/blink/cdm_session_adapter.cc @@ -20,7 +20,6 @@ #include "media/base/key_systems.h" #include "media/blink/webcontentdecryptionmodulesession_impl.h" #include "media/cdm/cdm_context_ref_impl.h" -#include "url/origin.h" namespace media { @@ -37,7 +36,6 @@ CdmSessionAdapter::~CdmSessionAdapter() = default; void CdmSessionAdapter::CreateCdm(CdmFactory* cdm_factory, const std::string& key_system, - const url::Origin& security_origin, const CdmConfig& cdm_config, WebCdmCreatedCB web_cdm_created_cb) { TRACE_EVENT_ASYNC_BEGIN0("media", "CdmSessionAdapter::CreateCdm", @@ -54,7 +52,7 @@ void CdmSessionAdapter::CreateCdm(CdmFactory* cdm_factory, web_cdm_created_cb_ = std::move(web_cdm_created_cb); cdm_factory->Create( - key_system, security_origin, cdm_config, + key_system, cdm_config, base::Bind(&CdmSessionAdapter::OnSessionMessage, weak_this), base::Bind(&CdmSessionAdapter::OnSessionClosed, weak_this), base::Bind(&CdmSessionAdapter::OnSessionKeysChange, weak_this), @@ -76,8 +74,10 @@ void CdmSessionAdapter::GetStatusForPolicy( } std::unique_ptr<WebContentDecryptionModuleSessionImpl> -CdmSessionAdapter::CreateSession() { - return std::make_unique<WebContentDecryptionModuleSessionImpl>(this); +CdmSessionAdapter::CreateSession( + blink::WebEncryptedMediaSessionType session_type) { + return std::make_unique<WebContentDecryptionModuleSessionImpl>(this, + session_type); } bool CdmSessionAdapter::RegisterSession( diff --git a/chromium/media/blink/cdm_session_adapter.h b/chromium/media/blink/cdm_session_adapter.h index d609af8319b..33255048f94 100644 --- a/chromium/media/blink/cdm_session_adapter.h +++ b/chromium/media/blink/cdm_session_adapter.h @@ -21,10 +21,6 @@ #include "media/blink/webcontentdecryptionmodule_impl.h" #include "third_party/blink/public/platform/web_content_decryption_module_session.h" -namespace url { -class Origin; -} - namespace media { struct CdmConfig; @@ -44,7 +40,6 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // via |result|. void CreateCdm(CdmFactory* cdm_factory, const std::string& key_system, - const url::Origin& security_origin, const CdmConfig& cdm_config, WebCdmCreatedCB web_cdm_created_cb); @@ -60,7 +55,8 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // Creates a new session and adds it to the internal map. RemoveSession() // must be called when destroying it, if RegisterSession() was called. - std::unique_ptr<WebContentDecryptionModuleSessionImpl> CreateSession(); + std::unique_ptr<WebContentDecryptionModuleSessionImpl> CreateSession( + blink::WebEncryptedMediaSessionType session_type); // Adds a session to the internal map. Called once the session is successfully // initialized. Returns true if the session was registered, false if there is diff --git a/chromium/media/blink/interval_map.h b/chromium/media/blink/interval_map.h index aa530034a00..1dd67a1ad1f 100644 --- a/chromium/media/blink/interval_map.h +++ b/chromium/media/blink/interval_map.h @@ -9,7 +9,7 @@ #include <limits> #include <map> -#include "base/logging.h" +#include "base/check.h" namespace media { diff --git a/chromium/media/blink/multibuffer.cc b/chromium/media/blink/multibuffer.cc index cb9f3eecd71..84bbc6b085d 100644 --- a/chromium/media/blink/multibuffer.cc +++ b/chromium/media/blink/multibuffer.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/location.h" +#include "base/logging.h" namespace media { diff --git a/chromium/media/blink/multibuffer_unittest.cc b/chromium/media/blink/multibuffer_unittest.cc index cc52013c46a..8e3c095d34d 100644 --- a/chromium/media/blink/multibuffer_unittest.cc +++ b/chromium/media/blink/multibuffer_unittest.cc @@ -12,6 +12,7 @@ #include "base/bind_helpers.h" #include "base/callback_helpers.h" #include "base/containers/circular_deque.h" +#include "base/logging.h" #include "base/test/simple_test_tick_clock.h" #include "media/base/fake_single_thread_task_runner.h" #include "media/base/test_random.h" diff --git a/chromium/media/blink/url_index.cc b/chromium/media/blink/url_index.cc index d68055f0638..9fc8b1f51e8 100644 --- a/chromium/media/blink/url_index.cc +++ b/chromium/media/blink/url_index.cc @@ -218,6 +218,7 @@ UrlIndex::UrlIndex(ResourceFetchContext* fetch_context, int block_shift) lru_(new MultiBuffer::GlobalLRU(base::ThreadTaskRunnerHandle::Get())), block_shift_(block_shift), memory_pressure_listener_( + FROM_HERE, base::Bind(&UrlIndex::OnMemoryPressure, base::Unretained(this))) {} UrlIndex::~UrlIndex() { diff --git a/chromium/media/blink/video_frame_compositor.h b/chromium/media/blink/video_frame_compositor.h index fc8456053bd..e79ab4b53e1 100644 --- a/chromium/media/blink/video_frame_compositor.h +++ b/chromium/media/blink/video_frame_compositor.h @@ -131,8 +131,8 @@ class MEDIA_BLINK_EXPORT VideoFrameCompositor : public VideoRendererSink, virtual void SetOnFramePresentedCallback(OnNewFramePresentedCB present_cb); // Gets the metadata for the last frame that was presented to the compositor. - // Used to populate the VideoFrameMetadata of video.requestAnimationFrame() - // callbacks. See https://wicg.github.io/video-raf/. + // Used to populate the VideoFrameMetadata of video.requestVideoFrameCallback + // callbacks. See https://wicg.github.io/video-rvfc/. // Can be called on any thread. virtual std::unique_ptr<blink::WebMediaPlayer::VideoFramePresentationMetadata> GetLastPresentedFrameMetadata(); @@ -255,8 +255,8 @@ class MEDIA_BLINK_EXPORT VideoFrameCompositor : public VideoRendererSink, base::Lock current_frame_lock_; scoped_refptr<VideoFrame> current_frame_; - // Used to fulfill video.requestAnimationFrame() calls. - // See https://wicg.github.io/video-raf/. + // Used to fulfill video.requestVideoFrameCallback() calls. + // See https://wicg.github.io/video-rvfc/. base::TimeTicks last_presentation_time_ GUARDED_BY(current_frame_lock_); base::TimeTicks last_expected_display_time_ GUARDED_BY(current_frame_lock_); uint32_t presentation_counter_ GUARDED_BY(current_frame_lock_) = 0u; diff --git a/chromium/media/blink/webcontentdecryptionmodule_impl.cc b/chromium/media/blink/webcontentdecryptionmodule_impl.cc index 9e4ade56fd7..b267d9d7d0c 100644 --- a/chromium/media/blink/webcontentdecryptionmodule_impl.cc +++ b/chromium/media/blink/webcontentdecryptionmodule_impl.cc @@ -107,7 +107,7 @@ void WebContentDecryptionModuleImpl::Create( // |web_cdm_created_cb|), it will keep a reference to |adapter|. Otherwise, // |adapter| will be destructed. scoped_refptr<CdmSessionAdapter> adapter(new CdmSessionAdapter()); - adapter->CreateCdm(cdm_factory, key_system_ascii, security_origin, cdm_config, + adapter->CreateCdm(cdm_factory, key_system_ascii, cdm_config, std::move(web_cdm_created_cb)); } @@ -119,8 +119,9 @@ WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() = default; std::unique_ptr<blink::WebContentDecryptionModuleSession> -WebContentDecryptionModuleImpl::CreateSession() { - return adapter_->CreateSession(); +WebContentDecryptionModuleImpl::CreateSession( + blink::WebEncryptedMediaSessionType session_type) { + return adapter_->CreateSession(session_type); } void WebContentDecryptionModuleImpl::SetServerCertificate( diff --git a/chromium/media/blink/webcontentdecryptionmodule_impl.h b/chromium/media/blink/webcontentdecryptionmodule_impl.h index 36c2a1dbd1f..fddf586b88e 100644 --- a/chromium/media/blink/webcontentdecryptionmodule_impl.h +++ b/chromium/media/blink/webcontentdecryptionmodule_impl.h @@ -46,8 +46,8 @@ class MEDIA_BLINK_EXPORT WebContentDecryptionModuleImpl ~WebContentDecryptionModuleImpl() override; // blink::WebContentDecryptionModule implementation. - std::unique_ptr<blink::WebContentDecryptionModuleSession> CreateSession() - override; + std::unique_ptr<blink::WebContentDecryptionModuleSession> CreateSession( + blink::WebEncryptedMediaSessionType session_type) override; void SetServerCertificate( const uint8_t* server_certificate, size_t server_certificate_length, diff --git a/chromium/media/blink/webcontentdecryptionmodulesession_impl.cc b/chromium/media/blink/webcontentdecryptionmodulesession_impl.cc index 464b8fa30a6..e7b274b9827 100644 --- a/chromium/media/blink/webcontentdecryptionmodulesession_impl.cc +++ b/chromium/media/blink/webcontentdecryptionmodulesession_impl.cc @@ -226,11 +226,12 @@ class IgnoreResponsePromise : public SimpleCdmPromise { } // namespace WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( - const scoped_refptr<CdmSessionAdapter>& adapter) + const scoped_refptr<CdmSessionAdapter>& adapter, + blink::WebEncryptedMediaSessionType session_type) : adapter_(adapter), + session_type_(convertSessionType(session_type)), has_close_been_called_(false), - is_closed_(false), - is_persistent_session_(false) {} + is_closed_(false) {} WebContentDecryptionModuleSessionImpl:: ~WebContentDecryptionModuleSessionImpl() { @@ -269,7 +270,6 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession( EmeInitDataType eme_init_data_type, const unsigned char* init_data, size_t init_data_length, - blink::WebEncryptedMediaSessionType session_type, blink::WebContentDecryptionModuleResult result) { DCHECK(init_data); DCHECK(session_id_.empty()); @@ -334,10 +334,8 @@ void WebContentDecryptionModuleSessionImpl::InitializeNewSession( // 10.8 Let cdm be the CDM instance represented by this object's cdm // instance value. // 10.9 Use the cdm to execute the following steps: - CdmSessionType cdm_session_type = convertSessionType(session_type); - is_persistent_session_ = cdm_session_type != CdmSessionType::kTemporary; adapter_->InitializeNewSession( - eme_init_data_type, sanitized_init_data, cdm_session_type, + eme_init_data_type, sanitized_init_data, session_type_, std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( result, adapter_->GetKeySystemUMAPrefix(), kGenerateRequestUMAName, base::BindOnce( @@ -352,6 +350,8 @@ void WebContentDecryptionModuleSessionImpl::Load( DCHECK(!session_id.IsEmpty()); DCHECK(session_id_.empty()); DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(session_type_ == CdmSessionType::kPersistentLicense || + session_type_ == CdmSessionType::kPersistentUsageRecord); // From https://w3c.github.io/encrypted-media/#load. // 8.1 Let sanitized session ID be a validated and/or sanitized version of @@ -368,12 +368,8 @@ void WebContentDecryptionModuleSessionImpl::Load( return; } - // TODO(jrummell): Now that there are 2 types of persistent sessions, the - // session type should be passed from blink. Type should also be passed in the - // constructor (and removed from initializeNewSession()). - is_persistent_session_ = true; adapter_->LoadSession( - CdmSessionType::kPersistentLicense, sanitized_session_id, + session_type_, sanitized_session_id, std::unique_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( result, adapter_->GetKeySystemUMAPrefix(), kLoadSessionUMAName, base::BindOnce( diff --git a/chromium/media/blink/webcontentdecryptionmodulesession_impl.h b/chromium/media/blink/webcontentdecryptionmodulesession_impl.h index 652c3d69754..b6c4572e96f 100644 --- a/chromium/media/blink/webcontentdecryptionmodulesession_impl.h +++ b/chromium/media/blink/webcontentdecryptionmodulesession_impl.h @@ -29,7 +29,8 @@ class WebContentDecryptionModuleSessionImpl : public blink::WebContentDecryptionModuleSession { public: WebContentDecryptionModuleSessionImpl( - const scoped_refptr<CdmSessionAdapter>& adapter); + const scoped_refptr<CdmSessionAdapter>& adapter, + blink::WebEncryptedMediaSessionType session_type); ~WebContentDecryptionModuleSessionImpl() override; // blink::WebContentDecryptionModuleSession implementation. @@ -40,7 +41,6 @@ class WebContentDecryptionModuleSessionImpl EmeInitDataType init_data_type, const unsigned char* initData, size_t initDataLength, - blink::WebEncryptedMediaSessionType session_type, blink::WebContentDecryptionModuleResult result) override; void Load(const blink::WebString& session_id, blink::WebContentDecryptionModuleResult result) override; @@ -66,6 +66,10 @@ class WebContentDecryptionModuleSessionImpl scoped_refptr<CdmSessionAdapter> adapter_; + // Keep track of the session type to be passed into InitializeNewSession() and + // LoadSession(). + const CdmSessionType session_type_; + // Non-owned pointer. Client* client_; @@ -84,9 +88,6 @@ class WebContentDecryptionModuleSessionImpl bool has_close_been_called_; bool is_closed_; - // Keep track of whether this is a persistent session or not. - bool is_persistent_session_; - base::ThreadChecker thread_checker_; // Since promises will live until they are fired, use a weak reference when // creating a promise in case this class disappears before the promise diff --git a/chromium/media/blink/webinbandtexttrack_impl.cc b/chromium/media/blink/webinbandtexttrack_impl.cc index df182a7b906..18fa8de1bef 100644 --- a/chromium/media/blink/webinbandtexttrack_impl.cc +++ b/chromium/media/blink/webinbandtexttrack_impl.cc @@ -8,17 +8,15 @@ namespace media { -WebInbandTextTrackImpl::WebInbandTextTrackImpl( - Kind kind, - const blink::WebString& label, - const blink::WebString& language, - const blink::WebString& id) - : client_(NULL), +WebInbandTextTrackImpl::WebInbandTextTrackImpl(Kind kind, + const blink::WebString& label, + const blink::WebString& language, + const blink::WebString& id) + : client_(nullptr), kind_(kind), label_(label), language_(language), - id_(id) { -} + id_(id) {} WebInbandTextTrackImpl::~WebInbandTextTrackImpl() { DCHECK(!client_); diff --git a/chromium/media/blink/webmediaplayer_impl.cc b/chromium/media/blink/webmediaplayer_impl.cc index 254902da241..8c769e69efa 100644 --- a/chromium/media/blink/webmediaplayer_impl.cc +++ b/chromium/media/blink/webmediaplayer_impl.cc @@ -56,6 +56,7 @@ #include "media/filters/memory_data_source.h" #include "media/learning/mojo/public/cpp/mojo_learning_task_controller.h" #include "media/media_buildflags.h" +#include "media/remoting/remoting_constants.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "net/base/data_url.h" #include "third_party/blink/public/platform/web_encrypted_media_types.h" @@ -280,6 +281,30 @@ void CreateAllocation(base::trace_event::ProcessMemoryDump* pmd, pmd->AddSuballocation(dump->guid(), std_allocator); } +// Determine whether we should update MediaPosition in |delegate_|. +bool MediaPositionNeedsUpdate( + const media_session::MediaPosition& old_position, + const media_session::MediaPosition& new_position) { + if (old_position.playback_rate() != new_position.playback_rate()) + return true; + + if (old_position.duration() != new_position.duration()) + return true; + + // MediaPosition is potentially changed upon each OnTimeUpdate() call. In + // practice most of these calls happen periodically during normal playback, + // with unchanged rate and duration. If we want to avoid updating + // MediaPosition unnecessarily, we need to compare the current time + // calculated from the old and new MediaPositions with some tolerance. That's + // because we don't know the exact time when GetMediaTime() calculated the + // media position. We choose an arbitrary tolerance that is high enough to + // eliminate a lot of MediaPosition updates and low enough not to make a + // perceptible difference. + const auto drift = + (old_position.GetPosition() - new_position.GetPosition()).magnitude(); + return drift > base::TimeDelta::FromMilliseconds(100); +} + } // namespace class BufferedDataSourceHostImpl; @@ -331,7 +356,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( params->IsBackgroundVideoPlaybackEnabled()), is_background_video_track_optimization_supported_( params->IsBackgroundVideoTrackOptimizationSupported()), - is_remoting_renderer_enabled_(params->IsRemotingRendererEnabled()), simple_watch_timer_( base::BindRepeating(&WebMediaPlayerImpl::OnSimpleWatchTimerTick, base::Unretained(this)), @@ -737,6 +761,12 @@ void WebMediaPlayerImpl::DoLoad(LoadType load_type, // used, the pipeline can start immediately. StartPipeline(); } else { + // If |loaded_url_| is remoting media, starting the pipeline. + if (loaded_url_.SchemeIs(remoting::kRemotingScheme)) { + StartPipeline(); + return; + } + // Short circuit the more complex loading path for data:// URLs. Sending // them through the network based loading path just wastes memory and causes // worse performance since reads become asynchronous. @@ -819,9 +849,6 @@ void WebMediaPlayerImpl::Play() { MaybeUpdateBufferSizesForPlayback(); UpdatePlayState(); - // Paused changed so we should update media position state. - UpdateMediaPositionState(); - // Notify the learning task, if needed. will_play_helper_.CompleteObservationIfNeeded(learning::TargetValue(true)); } @@ -865,9 +892,6 @@ void WebMediaPlayerImpl::Pause() { simple_watch_timer_.Stop(); media_log_->AddEvent<MediaLogEvent::kPause>(); - // Paused changed so we should update media position state. - UpdateMediaPositionState(); - UpdatePlayState(); } @@ -932,9 +956,6 @@ void WebMediaPlayerImpl::DoSeek(base::TimeDelta time, bool time_updated) { // This needs to be called after Seek() so that if a resume is triggered, it // is to the correct time. UpdatePlayState(); - - // The seek time has changed so we should update the media position state. - UpdateMediaPositionState(); } void WebMediaPlayerImpl::SetRate(double rate) { @@ -953,10 +974,6 @@ void WebMediaPlayerImpl::SetRate(double rate) { pipeline_controller_->SetPlaybackRate(rate); MaybeUpdateBufferSizesForPlayback(); - - // The playback rate has changed so we should rebuild the media position - // state. - UpdateMediaPositionState(); } void WebMediaPlayerImpl::SetVolume(double volume) { @@ -984,6 +1001,11 @@ void WebMediaPlayerImpl::SetLatencyHint(double seconds) { pipeline_controller_->SetLatencyHint(latency_hint); } +void WebMediaPlayerImpl::SetPreservesPitch(bool preserves_pitch) { + DCHECK(main_task_runner_->BelongsToCurrentThread()); + pipeline_controller_->SetPreservesPitch(preserves_pitch); +} + void WebMediaPlayerImpl::OnRequestPictureInPicture() { if (!surface_layer_for_video_enabled_) ActivateSurfaceLayerForVideo(); @@ -1430,10 +1452,9 @@ void WebMediaPlayerImpl::ComputeFrameUploadMetadata( out_metadata->frame_id = frame->unique_id(); out_metadata->visible_rect = frame->visible_rect(); out_metadata->timestamp = frame->timestamp(); - base::TimeDelta frame_duration; - if (frame->metadata()->GetTimeDelta(media::VideoFrameMetadata::FRAME_DURATION, - &frame_duration)) { - out_metadata->expected_timestamp = frame->timestamp() + frame_duration; + if (frame->metadata()->frame_duration.has_value()) { + out_metadata->expected_timestamp = + frame->timestamp() + *frame->metadata()->frame_duration; }; bool skip_possible = already_uploaded_id != -1; bool same_frame_id = frame->unique_id() == already_uploaded_id; @@ -1648,9 +1669,6 @@ void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { } attempting_suspended_start_ = false; - - // The current time has changed so we should update the media position state. - UpdateMediaPositionState(); } void WebMediaPlayerImpl::OnPipelineSuspended() { @@ -2187,6 +2205,7 @@ void WebMediaPlayerImpl::OnBufferingStateChangeInternal( !seeking_) { underflow_timer_ = std::make_unique<base::ElapsedTimer>(); watch_time_reporter_->OnUnderflow(); + delegate_->DidBufferUnderflow(delegate_id_); if (playback_events_recorder_) playback_events_recorder_->OnBuffering(); @@ -2227,9 +2246,6 @@ void WebMediaPlayerImpl::OnDurationChange() { client_->DurationChanged(); if (watch_time_reporter_) watch_time_reporter_->OnDurationChanged(GetPipelineMediaDuration()); - - // The duration has changed so we should update the media position state. - UpdateMediaPositionState(); } void WebMediaPlayerImpl::OnAddTextTrack(const TextTrackConfig& config, @@ -2820,8 +2836,9 @@ void WebMediaPlayerImpl::StartPipeline() { if (base::FeatureList::IsEnabled(kMemoryPressureBasedSourceBufferGC)) { // base::Unretained is safe because |this| owns memory_pressure_listener_. memory_pressure_listener_ = - std::make_unique<base::MemoryPressureListener>(base::Bind( - &WebMediaPlayerImpl::OnMemoryPressure, base::Unretained(this))); + std::make_unique<base::MemoryPressureListener>( + FROM_HERE, base::Bind(&WebMediaPlayerImpl::OnMemoryPressure, + base::Unretained(this))); } } @@ -2870,10 +2887,6 @@ void WebMediaPlayerImpl::SetReadyState(WebMediaPlayer::ReadyState state) { // Always notify to ensure client has the latest value. client_->ReadyStateChanged(); - - // The ready state affects the effective playback rate so we should update - // the media position state. - UpdateMediaPositionState(); } scoped_refptr<blink::WebAudioSourceProviderImpl> @@ -2933,9 +2946,7 @@ void WebMediaPlayerImpl::UpdatePlayState() { UpdateSmoothnessHelper(); } -void WebMediaPlayerImpl::UpdateMediaPositionState() { - DCHECK(delegate_); - +void WebMediaPlayerImpl::OnTimeUpdate() { // When seeking the current time can go beyond the duration so we should // cap the current time at the duration. base::TimeDelta duration = GetPipelineMediaDuration(); @@ -2950,7 +2961,7 @@ void WebMediaPlayerImpl::UpdateMediaPositionState() { media_session::MediaPosition new_position(effective_playback_rate, duration, current_time); - if (media_position_state_ == new_position) + if (!MediaPositionNeedsUpdate(media_position_state_, new_position)) return; DVLOG(2) << __func__ << "(" << new_position.ToString() << ")"; @@ -3461,6 +3472,11 @@ bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const { if (!HasVideo()) return false; + if (using_media_player_renderer_ && + pipeline_metadata_.natural_size.IsEmpty()) { + return false; + } + if (!is_background_video_playback_enabled_) return true; diff --git a/chromium/media/blink/webmediaplayer_impl.h b/chromium/media/blink/webmediaplayer_impl.h index b62f8cf93b9..f4e48c46f62 100644 --- a/chromium/media/blink/webmediaplayer_impl.h +++ b/chromium/media/blink/webmediaplayer_impl.h @@ -130,7 +130,9 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl void SetRate(double rate) override; void SetVolume(double volume) override; void SetLatencyHint(double seconds) override; + void SetPreservesPitch(bool preserves_pitch) override; void OnRequestPictureInPicture() override; + void OnTimeUpdate() override; void SetSinkId( const blink::WebString& sink_id, blink::WebSetSinkIdCompleteCallback completion_callback) override; @@ -448,21 +450,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl // - enter_pip_callback_, void UpdatePlayState(); - // Calculates the current position state for the media element and notifies - // |delegate_| if it has changed. - // - // Spec: https://wicg.github.io/mediasession/#position-state - // - // This method should be called any time its dependent values change. These - // are: - // - pipeline_controller_->GetMediaDuration() - // - pipeline_media_duration_for_test_ - // - pipeline_controller_->GetMediaTime() - // - playback_rate_ - // - Seeking() / seek_time_ - // - paused_, paused_time_ - void UpdateMediaPositionState(); - // Methods internal to UpdatePlayState(). PlayState UpdatePlayState_ComputePlayState(bool is_flinging, bool can_auto_suspend, @@ -1036,15 +1023,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl // Whether background video optimization is supported on current platform. bool is_background_video_track_optimization_supported_ = true; - // Whether the media in this frame is a remoting media. - // - // Remoting media is a special media that has the media streams are delivered - // to the browser directly from somewhere without any URL request - // (http, file, ...) - // When setting to true, a remoting renderer will be created as the remoting - // target in the client. - bool is_remoting_renderer_enabled_ = false; - base::CancelableOnceClosure have_enough_after_lazy_load_cb_; // State for simplified watch time reporting. diff --git a/chromium/media/blink/webmediaplayer_impl_unittest.cc b/chromium/media/blink/webmediaplayer_impl_unittest.cc index 77dc3344993..d054fef8b92 100644 --- a/chromium/media/blink/webmediaplayer_impl_unittest.cc +++ b/chromium/media/blink/webmediaplayer_impl_unittest.cc @@ -241,6 +241,10 @@ class MockWebMediaPlayerDelegate : public blink::WebMediaPlayerDelegate { DCHECK_EQ(player_id_, player_id); } + void DidBufferUnderflow(int player_id) override { + DCHECK_EQ(player_id_, player_id); + } + bool IsFrameHidden() override { return is_hidden_; } bool IsFrameClosed() override { return is_closed_; } @@ -436,7 +440,7 @@ class WebMediaPlayerImplTest viz::TestContextProvider::Create(), blink::WebMediaPlayer::SurfaceLayerMode::kAlways, is_background_suspend_enabled_, is_background_video_playback_enabled_, - true, false, std::move(demuxer_override), nullptr); + true, std::move(demuxer_override), nullptr); auto compositor = std::make_unique<NiceMock<MockVideoFrameCompositor>>( params->video_frame_compositor_task_runner()); @@ -1545,167 +1549,82 @@ TEST_F(WebMediaPlayerImplTest, AutoplayMuted_SetVolume) { wmpi_->SetVolume(1.0); } -TEST_F(WebMediaPlayerImplTest, MediaPositionState_OnDurationChange) { +TEST_F(WebMediaPlayerImplTest, MediaPositionState_Playing) { InitializeWebMediaPlayerImpl(); + LoadAndWaitForReadyState(kAudioOnlyTestFile, + blink::WebMediaPlayer::kReadyStateHaveFutureData); + wmpi_->SetRate(1.0); + Play(); - testing::Sequence s; EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( delegate_.player_id(), - media_session::MediaPosition(0.0, kAudioOnlyTestFileDuration, - base::TimeDelta()))) - .InSequence(s); - EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( - delegate_.player_id(), - media_session::MediaPosition( - 0.0, kInfiniteDuration, base::TimeDelta()))) - .InSequence(s); - - LoadAndWaitForReadyState(kAudioOnlyTestFile, - blink::WebMediaPlayer::kReadyStateHaveCurrentData); - - SetDuration(kInfiniteDuration); + media_session::MediaPosition(1.0, kAudioOnlyTestFileDuration, + base::TimeDelta()))); + wmpi_->OnTimeUpdate(); } -TEST_F(WebMediaPlayerImplTest, MediaPositionState_PlayPauseSetRate) { +TEST_F(WebMediaPlayerImplTest, MediaPositionState_Paused) { InitializeWebMediaPlayerImpl(); + LoadAndWaitForReadyState(kAudioOnlyTestFile, + blink::WebMediaPlayer::kReadyStateHaveFutureData); + wmpi_->SetRate(1.0); - testing::Sequence s; + // The effective playback rate is 0.0 while paused. EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( delegate_.player_id(), media_session::MediaPosition(0.0, kAudioOnlyTestFileDuration, - base::TimeDelta()))) - .InSequence(s); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(s) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(1.0, position.playback_rate()); - EXPECT_EQ(kAudioOnlyTestFileDuration, position.duration()); - EXPECT_EQ(base::TimeDelta(), - position.GetPositionAtTime(position.last_updated_time())); - }); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange( - delegate_.player_id(), - media_session::MediaPosition(0.0, kAudioOnlyTestFileDuration, - base::TimeDelta()))) - .InSequence(s); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(s) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(2.0, position.playback_rate()); - EXPECT_EQ(kAudioOnlyTestFileDuration, position.duration()); - EXPECT_EQ(base::TimeDelta(), - position.GetPositionAtTime(position.last_updated_time())); - }); - - wmpi_->SetRate(1.0); - LoadAndWaitForReadyState(kAudioOnlyTestFile, - blink::WebMediaPlayer::kReadyStateHaveCurrentData); - - // Play will set the playback rate to 1.0. - Play(); - - // Pause will set the playback rate to 0.0. - Pause(); - - // SetRate will set the playback rate, but it will not affect the position - // state until we have started playing again. - wmpi_->SetRate(2.0); - Play(); + base::TimeDelta()))); + wmpi_->OnTimeUpdate(); } -TEST_F(WebMediaPlayerImplTest, MediaPositionState_Underflow) { +TEST_F(WebMediaPlayerImplTest, MediaPositionState_PositionChange) { InitializeWebMediaPlayerImpl(); - - testing::Sequence sequence; - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(sequence) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(0.0, position.playback_rate()); - }); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(sequence) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(1.0, position.playback_rate()); - }); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(sequence) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(0.0, position.playback_rate()); - }); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(sequence) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(1.0, position.playback_rate()); - }); - - wmpi_->SetRate(1.0); LoadAndWaitForReadyState(kAudioOnlyTestFile, - blink::WebMediaPlayer::kReadyStateHaveCurrentData); - // Play will set the playback rate to 1.0. + blink::WebMediaPlayer::kReadyStateHaveFutureData); + wmpi_->SetRate(0.5); Play(); - // Underflow will set the playback rate to 0.0. - SetReadyState(blink::WebMediaPlayer::kReadyStateHaveCurrentData); + testing::Sequence sequence; + EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( + delegate_.player_id(), + media_session::MediaPosition( + 0.0, kAudioOnlyTestFileDuration, + base::TimeDelta::FromSecondsD(0.1)))) + .InSequence(sequence); + wmpi_->Seek(0.1); + wmpi_->OnTimeUpdate(); - // Leaving the underflow state will restore the playback rate of 1.0. + // If we load enough data to resume playback the position should be updated. + EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( + delegate_.player_id(), + media_session::MediaPosition( + 0.5, kAudioOnlyTestFileDuration, + base::TimeDelta::FromSecondsD(0.1)))) + .InSequence(sequence); SetReadyState(blink::WebMediaPlayer::kReadyStateHaveFutureData); + wmpi_->OnTimeUpdate(); + + // No media time progress -> no MediaPositionState change. + wmpi_->OnTimeUpdate(); } -TEST_F(WebMediaPlayerImplTest, MediaPositionState_Seeking) { +TEST_F(WebMediaPlayerImplTest, MediaPositionState_Underflow) { InitializeWebMediaPlayerImpl(); + LoadAndWaitForReadyState(kAudioOnlyTestFile, + blink::WebMediaPlayer::kReadyStateHaveFutureData); + wmpi_->SetRate(1.0); + Play(); - testing::Sequence s; + // Underflow will set the effective playback rate to 0.0. EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( delegate_.player_id(), media_session::MediaPosition(0.0, kAudioOnlyTestFileDuration, - base::TimeDelta()))) - .InSequence(s); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(s) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(1.0, position.playback_rate()); - EXPECT_EQ(kAudioOnlyTestFileDuration, position.duration()); - EXPECT_EQ(base::TimeDelta(), - position.GetPositionAtTime(position.last_updated_time())); - }); - EXPECT_CALL(delegate_, - DidPlayerMediaPositionStateChange(delegate_.player_id(), _)) - .InSequence(s) - .WillOnce([](auto id, auto position) { - EXPECT_EQ(0.0, position.playback_rate()); - EXPECT_EQ(kAudioOnlyTestFileDuration, position.duration()); - EXPECT_EQ(base::TimeDelta(), - position.GetPositionAtTime(position.last_updated_time())); - }); - EXPECT_CALL(delegate_, DidPlayerMediaPositionStateChange( - delegate_.player_id(), - media_session::MediaPosition( - 0.0, kAudioOnlyTestFileDuration, - base::TimeDelta::FromMilliseconds(100)))) - .InSequence(s); - - wmpi_->SetRate(1.0); - LoadAndWaitForReadyState(kAudioOnlyTestFile, - blink::WebMediaPlayer::kReadyStateHaveCurrentData); - Play(); - - // Seek forward 100ms will result in the position to be updated. - wmpi_->Seek(0.1); - - // If we trigger another update to the position state the new position should - // be used. - Pause(); + base::TimeDelta()))); + SetReadyState(blink::WebMediaPlayer::kReadyStateHaveCurrentData); + wmpi_->OnTimeUpdate(); } TEST_F(WebMediaPlayerImplTest, NoStreams) { @@ -2194,7 +2113,8 @@ TEST_F(WebMediaPlayerImplTest, MemDumpReporting) { } // Verify that a demuxer override is used when specified. -TEST_F(WebMediaPlayerImplTest, DemuxerOverride) { +// TODO(https://crbug.com/1084476): This test is flaky. +TEST_F(WebMediaPlayerImplTest, DISABLED_DemuxerOverride) { std::unique_ptr<MockDemuxer> demuxer = std::make_unique<NiceMock<MockDemuxer>>(); StrictMock<MockDemuxerStream> stream(DemuxerStream::AUDIO); diff --git a/chromium/media/blink/webmediaplayer_params.cc b/chromium/media/blink/webmediaplayer_params.cc index a9dede964a4..e1a715c18f3 100644 --- a/chromium/media/blink/webmediaplayer_params.cc +++ b/chromium/media/blink/webmediaplayer_params.cc @@ -33,7 +33,6 @@ WebMediaPlayerParams::WebMediaPlayerParams( bool is_background_suspend_enabled, bool is_background_video_playback_enabled, bool is_background_video_track_optimization_supported, - bool is_remoting_renderer_enabled, std::unique_ptr<Demuxer> demuxer_override, std::unique_ptr<PowerStatusHelper> power_status_helper) : defer_load_cb_(defer_load_cb), @@ -58,7 +57,6 @@ WebMediaPlayerParams::WebMediaPlayerParams( is_background_video_playback_enabled), is_background_video_track_optimization_supported_( is_background_video_track_optimization_supported), - is_remoting_renderer_enabled_(is_remoting_renderer_enabled), demuxer_override_(std::move(demuxer_override)), power_status_helper_(std::move(power_status_helper)) {} diff --git a/chromium/media/blink/webmediaplayer_params.h b/chromium/media/blink/webmediaplayer_params.h index 4cc8756d4e2..70db6159b12 100644 --- a/chromium/media/blink/webmediaplayer_params.h +++ b/chromium/media/blink/webmediaplayer_params.h @@ -85,7 +85,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerParams { bool is_background_suspend_enabled, bool is_background_video_play_enabled, bool is_background_video_track_optimization_supported, - bool is_remoting_renderer_enabled, std::unique_ptr<Demuxer> demuxer_override, std::unique_ptr<PowerStatusHelper> power_status_helper); @@ -170,10 +169,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerParams { return is_background_video_track_optimization_supported_; } - bool IsRemotingRendererEnabled() const { - return is_remoting_renderer_enabled_; - } - std::unique_ptr<Demuxer> TakeDemuxerOverride(); std::unique_ptr<PowerStatusHelper> TakePowerStatusHelper() { @@ -208,8 +203,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerParams { bool is_background_video_playback_enabled_ = true; // Whether background video optimization is supported on current platform. bool is_background_video_track_optimization_supported_ = true; - // Whether the media in this frame is a remoting media. - bool is_remoting_renderer_enabled_ = false; // Optional custom demuxer to use instead of the standard demuxers. std::unique_ptr<Demuxer> demuxer_override_; diff --git a/chromium/media/blink/websourcebuffer_impl.cc b/chromium/media/blink/websourcebuffer_impl.cc index 20d841bb4fb..257df4b49ef 100644 --- a/chromium/media/blink/websourcebuffer_impl.cc +++ b/chromium/media/blink/websourcebuffer_impl.cc @@ -66,7 +66,7 @@ WebSourceBufferImpl::WebSourceBufferImpl(const std::string& id, ChunkDemuxer* demuxer) : id_(id), demuxer_(demuxer), - client_(NULL), + client_(nullptr), append_window_end_(kInfiniteDuration) { DCHECK(demuxer_); demuxer_->SetTracksWatcher( @@ -136,7 +136,7 @@ bool WebSourceBufferImpl::Append(const unsigned char* data, append_window_end_, ×tamp_offset_); // Coded frame processing may update the timestamp offset. If the caller - // provides a non-NULL |timestamp_offset| and frame processing changes the + // provides a non-nullptr |timestamp_offset| and frame processing changes the // timestamp offset, report the new offset to the caller. Do not update the // caller's offset otherwise, to preserve any pre-existing value that may have // more than microsecond precision. @@ -200,8 +200,8 @@ void WebSourceBufferImpl::SetAppendWindowEnd(double end) { void WebSourceBufferImpl::RemovedFromMediaSource() { demuxer_->RemoveId(id_); - demuxer_ = NULL; - client_ = NULL; + demuxer_ = nullptr; + client_ = nullptr; } blink::WebMediaPlayer::TrackType mediaTrackTypeToBlink(MediaTrack::Type type) { |