chromium/third_party/blink/renderer/modules/mediastream/web_media_player_ms.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/public/web/modules/mediastream/web_media_player_ms.h"

#include <stddef.h>

#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "cc/layers/video_frame_provider_client_impl.h"
#include "cc/layers/video_layer.h"
#include "media/base/media_content_type.h"
#include "media/base/media_log.h"
#include "media/base/video_frame.h"
#include "media/base/video_transformation.h"
#include "media/base/video_types.h"
#include "media/mojo/mojom/media_metrics_provider.mojom.h"
#include "media/video/gpu_memory_buffer_video_frame_pool.h"
#include "services/viz/public/cpp/gpu/context_provider_command_buffer.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_media_player_client.h"
#include "third_party/blink/public/platform/web_media_player_source.h"
#include "third_party/blink/public/platform/web_surface_layer_bridge.h"
#include "third_party/blink/public/web/modules/media/web_media_player_util.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_audio_renderer.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_local_frame_wrapper.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_renderer_factory.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_renderer.h"
#include "third_party/blink/renderer/modules/mediastream/web_media_player_ms_compositor.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_track.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/timer.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_media.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"

namespace WTF {

template <>
struct CrossThreadCopier<viz::SurfaceId>
    : public CrossThreadCopierPassThrough<viz::SurfaceId> {};

}  // namespace WTF

namespace blink {

namespace {

enum class RendererReloadAction {};

bool IsPlayableTrack(MediaStreamComponent* component) {}

const char* LoadTypeToString(WebMediaPlayer::LoadType type) {}

const char* ReadyStateToString(WebMediaPlayer::ReadyState state) {}

const char* NetworkStateToString(WebMediaPlayer::NetworkState state) {}

media::VideoTransformation GetFrameTransformation(
    scoped_refptr<media::VideoFrame> frame) {}

base::TimeDelta GetFrameTime(scoped_refptr<media::VideoFrame> frame) {}

constexpr base::TimeDelta kForceBeginFramesTimeout =;
}  // namespace

#if BUILDFLAG(IS_WIN)
// Since we do not have native GMB support in Windows, using GMBs can cause a
// CPU regression. This is more apparent and can have adverse affects in lower
// resolution content which are defined by these thresholds, see
// https://crbug.com/835752.
// static
const gfx::Size WebMediaPlayerMS::kUseGpuMemoryBufferVideoFramesMinResolution =
    gfx::Size(1920, 1080);
#endif  // BUILDFLAG(IS_WIN)

// FrameDeliverer is responsible for delivering frames received on
// the video task runner by calling of EnqueueFrame() method of |compositor_|.
//
// It is created on the main thread, but methods should be called and class
// should be destructed on the video task runner.
class WebMediaPlayerMS::FrameDeliverer {};

WebMediaPlayerMS::WebMediaPlayerMS(
    WebLocalFrame* frame,
    WebMediaPlayerClient* client,
    WebMediaPlayerDelegate* delegate,
    std::unique_ptr<media::MediaLog> media_log,
    scoped_refptr<base::SingleThreadTaskRunner> main_render_task_runner,
    scoped_refptr<base::SequencedTaskRunner> video_task_runner,
    scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
    scoped_refptr<base::SequencedTaskRunner> media_task_runner,
    scoped_refptr<base::TaskRunner> worker_task_runner,
    media::GpuVideoAcceleratorFactories* gpu_factories,
    const WebString& sink_id,
    CreateSurfaceLayerBridgeCB create_bridge_callback,
    std::unique_ptr<WebVideoFrameSubmitter> submitter,
    bool use_surface_layer)
    :{}

WebMediaPlayerMS::~WebMediaPlayerMS() {}

void WebMediaPlayerMS::OnAudioRenderErrorCallback() {}

WebMediaPlayer::LoadTiming WebMediaPlayerMS::Load(
    LoadType load_type,
    const WebMediaPlayerSource& source,
    CorsMode /*cors_mode*/,
    bool is_cache_disabled) {}

void WebMediaPlayerMS::OnWebLayerUpdated() {}

void WebMediaPlayerMS::RegisterContentsLayer(cc::Layer* layer) {}

void WebMediaPlayerMS::UnregisterContentsLayer(cc::Layer* layer) {}

void WebMediaPlayerMS::OnSurfaceIdUpdated(viz::SurfaceId surface_id) {}

void WebMediaPlayerMS::TrackAdded(const WebString& track_id) {}

void WebMediaPlayerMS::TrackRemoved(const WebString& track_id) {}

void WebMediaPlayerMS::ActiveStateChanged(bool is_active) {}

int WebMediaPlayerMS::GetDelegateId() {}

std::optional<viz::SurfaceId> WebMediaPlayerMS::GetSurfaceId() {}

base::WeakPtr<WebMediaPlayer> WebMediaPlayerMS::AsWeakPtr() {}

void WebMediaPlayerMS::Reload() {}

void WebMediaPlayerMS::ReloadVideo() {}

void WebMediaPlayerMS::ReloadAudio() {}

void WebMediaPlayerMS::Play() {}

void WebMediaPlayerMS::Pause() {}

void WebMediaPlayerMS::ReplaceCurrentFrameWithACopy() {}

void WebMediaPlayerMS::Seek(double seconds) {}

void WebMediaPlayerMS::SetRate(double rate) {}

void WebMediaPlayerMS::SetVolume(double volume) {}

void WebMediaPlayerMS::SetLatencyHint(double seconds) {}

void WebMediaPlayerMS::SetPreservesPitch(bool preserves_pitch) {}

void WebMediaPlayerMS::SetWasPlayedWithUserActivation(
    bool was_played_with_user_activation) {}

void WebMediaPlayerMS::SetShouldPauseWhenFrameIsHidden(
    bool should_pause_when_frame_is_hidden) {}

bool WebMediaPlayerMS::GetShouldPauseWhenFrameIsHidden() {}

void WebMediaPlayerMS::OnRequestPictureInPicture() {}

bool WebMediaPlayerMS::SetSinkId(
    const WebString& sink_id,
    WebSetSinkIdCompleteCallback completion_callback) {}

void WebMediaPlayerMS::SetPreload(WebMediaPlayer::Preload preload) {}

bool WebMediaPlayerMS::HasVideo() const {}

bool WebMediaPlayerMS::HasAudio() const {}

gfx::Size WebMediaPlayerMS::NaturalSize() const {}

gfx::Size WebMediaPlayerMS::VisibleSize() const {}

bool WebMediaPlayerMS::Paused() const {}

bool WebMediaPlayerMS::Seeking() const {}

double WebMediaPlayerMS::Duration() const {}

double WebMediaPlayerMS::CurrentTime() const {}

bool WebMediaPlayerMS::IsEnded() const {}

WebMediaPlayer::NetworkState WebMediaPlayerMS::GetNetworkState() const {}

WebMediaPlayer::ReadyState WebMediaPlayerMS::GetReadyState() const {}

WebString WebMediaPlayerMS::GetErrorMessage() const {}

WebTimeRanges WebMediaPlayerMS::Buffered() const {}

WebTimeRanges WebMediaPlayerMS::Seekable() const {}

void WebMediaPlayerMS::OnFrozen() {}

bool WebMediaPlayerMS::DidLoadingProgress() {}

void WebMediaPlayerMS::Paint(cc::PaintCanvas* canvas,
                             const gfx::Rect& rect,
                             cc::PaintFlags& flags) {}

scoped_refptr<media::VideoFrame> WebMediaPlayerMS::GetCurrentFrameThenUpdate() {}

std::optional<media::VideoFrame::ID> WebMediaPlayerMS::CurrentFrameId() const {}

bool WebMediaPlayerMS::WouldTaintOrigin() const {}

double WebMediaPlayerMS::MediaTimeForTimeValue(double timeValue) const {}

unsigned WebMediaPlayerMS::DecodedFrameCount() const {}

unsigned WebMediaPlayerMS::DroppedFrameCount() const {}

uint64_t WebMediaPlayerMS::AudioDecodedByteCount() const {}

uint64_t WebMediaPlayerMS::VideoDecodedByteCount() const {}

bool WebMediaPlayerMS::HasAvailableVideoFrame() const {}

bool WebMediaPlayerMS::HasReadableVideoFrame() const {}

void WebMediaPlayerMS::OnPageHidden() {}

void WebMediaPlayerMS::SuspendForFrameClosed() {}

void WebMediaPlayerMS::OnPageShown() {}

void WebMediaPlayerMS::OnIdleTimeout() {}

void WebMediaPlayerMS::OnFrameShown() {}

void WebMediaPlayerMS::OnFrameHidden() {}

void WebMediaPlayerMS::SetVolumeMultiplier(double multiplier) {}

void WebMediaPlayerMS::ActivateSurfaceLayerForVideo(
    media::VideoTransformation video_transform) {}

void WebMediaPlayerMS::OnFirstFrameReceived(
    media::VideoTransformation video_transform,
    bool is_opaque) {}

void WebMediaPlayerMS::OnOpacityChanged(bool is_opaque) {}

void WebMediaPlayerMS::OnTransformChanged(
    media::VideoTransformation video_transform) {}

bool WebMediaPlayerMS::IsInPictureInPicture() const {}

void WebMediaPlayerMS::RepaintInternal() {}

void WebMediaPlayerMS::SetNetworkState(WebMediaPlayer::NetworkState state) {}

void WebMediaPlayerMS::SetReadyState(WebMediaPlayer::ReadyState state) {}

media::PaintCanvasVideoRenderer*
WebMediaPlayerMS::GetPaintCanvasVideoRenderer() {}

void WebMediaPlayerMS::ResetCanvasCache() {}

void WebMediaPlayerMS::TriggerResize() {}

void WebMediaPlayerMS::SetGpuMemoryBufferVideoForTesting(
    media::GpuMemoryBufferVideoFramePool* gpu_memory_buffer_pool) {}

void WebMediaPlayerMS::SetMediaStreamRendererFactoryForTesting(
    std::unique_ptr<MediaStreamRendererFactory> renderer_factory) {}

void WebMediaPlayerMS::OnDisplayTypeChanged(DisplayType display_type) {}

void WebMediaPlayerMS::OnNewFramePresentedCallback() {}

void WebMediaPlayerMS::SendLogMessage(const WTF::String& message) const {}

std::unique_ptr<WebMediaPlayer::VideoFramePresentationMetadata>
WebMediaPlayerMS::GetVideoFramePresentationMetadata() {}

void WebMediaPlayerMS::RequestVideoFrameCallback() {}

void WebMediaPlayerMS::StopForceBeginFrames(TimerBase* timer) {}

void WebMediaPlayerMS::MaybeCreateWatchTimeReporter() {}

void WebMediaPlayerMS::UpdateWatchTimeReporterSecondaryProperties() {}

base::TimeDelta WebMediaPlayerMS::GetCurrentTimeInterval() {}

media::PipelineStatistics WebMediaPlayerMS::GetPipelineStatistics() {}

std::optional<media::mojom::MediaStreamType>
WebMediaPlayerMS::GetMediaStreamType() {}

void WebMediaPlayerMS::RegisterFrameSinkHierarchy() {}

void WebMediaPlayerMS::UnregisterFrameSinkHierarchy() {}

}  // namespace blink