chromium/third_party/blink/renderer/modules/mediastream/media_stream_video_track.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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"

#include <string>
#include <utility>

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.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 "media/base/limits.h"
#include "media/capture/video_capture_types.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_sink.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_constraints_util_video_device.h"
#include "third_party/blink/renderer/platform/allow_discouraged_type.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component_impl.h"
#include "third_party/blink/renderer/platform/scheduler/public/main_thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {
namespace {

// A lower-bound for the refresh interval.
constexpr base::TimeDelta kLowerBoundRefreshInterval =;

// This alias mimics the definition of VideoCaptureDeliverFrameCB.
VideoCaptureDeliverFrameInternalCallback;

// This alias mimics the definition of VideoCaptureNotifyFrameDroppedCB.
VideoCaptureNotifyFrameDroppedInternalCallback;

// Mimics blink::EncodedVideoFrameCB
EncodedVideoFrameInternalCallback;

base::TimeDelta ComputeRefreshIntervalFromBounds(
    const base::TimeDelta required_min_refresh_interval,
    const std::optional<double>& min_frame_rate,
    const std::optional<double>& max_frame_rate) {}

void LogVideoFrameDropUMA(media::VideoCaptureFrameDropReason reason,
                          mojom::blink::MediaStreamType stream_type) {}

}  // namespace

// MediaStreamVideoTrack::FrameDeliverer is a helper class used for registering
// VideoCaptureDeliverFrameCB/EncodedVideoFrameCB callbacks on the main render
// thread to receive video frames on the video task runner. Frames are only
// delivered to the sinks if the track is enabled. If the track is disabled, a
// black frame is instead forwarded to the sinks at the same frame rate. A
// disabled track does not forward data to encoded sinks.
class MediaStreamVideoTrack::FrameDeliverer
    : public WTF::ThreadSafeRefCounted<FrameDeliverer> {};

MediaStreamVideoTrack::FrameDeliverer::FrameDropLogState::FrameDropLogState(
    media::VideoCaptureFrameDropReason reason)
    :{}

MediaStreamVideoTrack::FrameDeliverer::FrameDeliverer(
    scoped_refptr<base::SingleThreadTaskRunner> main_render_task_runner,
    scoped_refptr<base::SequencedTaskRunner> video_task_runner,
    base::WeakPtr<MediaStreamVideoTrack> media_stream_video_track,
    base::WeakPtr<MediaStreamVideoSource> media_stream_video_source,
    bool enabled,
    uint32_t sub_capture_target_version)
    :{}

MediaStreamVideoTrack::FrameDeliverer::~FrameDeliverer() {}

void MediaStreamVideoTrack::FrameDeliverer::AddCallback(
    VideoSinkId id,
    VideoCaptureDeliverFrameCB callback) {}

void MediaStreamVideoTrack::FrameDeliverer::AddCallbackOnVideoTaskRunner(
    VideoSinkId id,
    VideoCaptureDeliverFrameInternalCallback callback) {}

void MediaStreamVideoTrack::FrameDeliverer::SetNotifyFrameDroppedCallback(
    VideoSinkId id,
    VideoCaptureNotifyFrameDroppedCB callback) {}

void MediaStreamVideoTrack::FrameDeliverer::
    SetNotifyFrameDroppedCallbackOnVideoTaskRunner(
        VideoSinkId id,
        VideoCaptureNotifyFrameDroppedInternalCallback callback,
        const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {}

void MediaStreamVideoTrack::FrameDeliverer::AddEncodedCallback(
    VideoSinkId id,
    EncodedVideoFrameCB callback) {}

void MediaStreamVideoTrack::FrameDeliverer::AddEncodedCallbackOnVideoTaskRunner(
    VideoSinkId id,
    EncodedVideoFrameInternalCallback callback) {}

void MediaStreamVideoTrack::FrameDeliverer::RemoveCallback(VideoSinkId id) {}

void MediaStreamVideoTrack::FrameDeliverer::RemoveCallbackOnVideoTaskRunner(
    VideoSinkId id,
    const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {}

void MediaStreamVideoTrack::FrameDeliverer::RemoveEncodedCallback(
    VideoSinkId id) {}

void MediaStreamVideoTrack::FrameDeliverer::
    RemoveEncodedCallbackOnVideoTaskRunner(
        VideoSinkId id,
        const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) {}

void MediaStreamVideoTrack::FrameDeliverer::SetEnabled(bool enabled,
                                                       bool await_key_frame) {}

void MediaStreamVideoTrack::FrameDeliverer::SetEnabledOnVideoTaskRunner(
    bool enabled,
    bool await_key_frame) {}

void MediaStreamVideoTrack::FrameDeliverer::SetIsRefreshingForMinFrameRate(
    bool is_refreshing_for_min_frame_rate) {}

void MediaStreamVideoTrack::FrameDeliverer::AddSubCaptureTargetVersionCallback(
    uint32_t sub_capture_target_version,
    base::OnceClosure callback) {}

void MediaStreamVideoTrack::FrameDeliverer::
    RemoveSubCaptureTargetVersionCallback(uint32_t sub_capture_target_version) {}

void MediaStreamVideoTrack::FrameDeliverer::
    SetIsRefreshingForMinFrameRateOnVideoTaskRunner(
        bool is_refreshing_for_min_frame_rate) {}

void MediaStreamVideoTrack::FrameDeliverer::
    AddSubCaptureTargetVersionCallbackOnVideoTaskRunner(
        uint32_t sub_capture_target_version,
        WTF::CrossThreadOnceClosure callback) {}

void MediaStreamVideoTrack::FrameDeliverer::
    RemoveSubCaptureTargetVersionCallbackOnVideoTaskRunner(
        uint32_t sub_capture_target_version) {}

void MediaStreamVideoTrack::FrameDeliverer::DeliverFrameOnVideoTaskRunner(
    scoped_refptr<media::VideoFrame> frame,
    base::TimeTicks estimated_capture_time) {}

void MediaStreamVideoTrack::FrameDeliverer::OnFrameDroppedOnVideoTaskRunner(
    media::VideoCaptureFrameDropReason reason) {}

void MediaStreamVideoTrack::FrameDeliverer::LogFrameDroppedOnVideoTaskRunner(
    media::VideoCaptureFrameDropReason reason) {}

void MediaStreamVideoTrack::FrameDeliverer::MaybeEmitFrameDropLogMessage(
    media::VideoCaptureFrameDropReason reason) {}

void MediaStreamVideoTrack::FrameDeliverer::SetEmitLogMessage(
    base::RepeatingCallback<void(const std::string&)> emit_log_message) {}

void MediaStreamVideoTrack::FrameDeliverer::EmitLogMessage(
    const std::string& message) {}

void MediaStreamVideoTrack::FrameDeliverer::
    DeliverEncodedVideoFrameOnVideoTaskRunner(
        scoped_refptr<EncodedVideoFrame> frame,
        base::TimeTicks estimated_capture_time) {}

void MediaStreamVideoTrack::FrameDeliverer::
    NewSubCaptureTargetVersionOnVideoTaskRunner(
        uint32_t sub_capture_target_version) {}

scoped_refptr<media::VideoFrame>
MediaStreamVideoTrack::FrameDeliverer::GetBlackFrame(
    const media::VideoFrame& reference_frame) {}

// static
WebMediaStreamTrack MediaStreamVideoTrack::CreateVideoTrack(
    MediaStreamVideoSource* source,
    MediaStreamVideoSource::ConstraintsOnceCallback callback,
    bool enabled) {}

// static
WebMediaStreamTrack MediaStreamVideoTrack::CreateVideoTrack(
    MediaStreamVideoSource* source,
    const VideoTrackAdapterSettings& adapter_settings,
    const std::optional<bool>& noise_reduction,
    bool is_screencast,
    const std::optional<double>& min_frame_rate,
    const ImageCaptureDeviceSettings* image_capture_device_settings,
    bool pan_tilt_zoom_allowed,
    MediaStreamVideoSource::ConstraintsOnceCallback callback,
    bool enabled) {}

// static
MediaStreamVideoTrack* MediaStreamVideoTrack::From(
    const MediaStreamComponent* component) {}

MediaStreamVideoTrack::MediaStreamVideoTrack(
    MediaStreamVideoSource* source,
    MediaStreamVideoSource::ConstraintsOnceCallback callback,
    bool enabled)
    :{}

MediaStreamVideoTrack::MediaStreamVideoTrack(
    MediaStreamVideoSource* source,
    const VideoTrackAdapterSettings& adapter_settings,
    const std::optional<bool>& noise_reduction,
    bool is_screen_cast,
    const std::optional<double>& min_frame_rate,
    const ImageCaptureDeviceSettings* image_capture_device_settings,
    bool pan_tilt_zoom_allowed,
    MediaStreamVideoSource::ConstraintsOnceCallback callback,
    bool enabled)
    :{}

MediaStreamVideoTrack::~MediaStreamVideoTrack() {}

std::unique_ptr<MediaStreamTrackPlatform>
MediaStreamVideoTrack::CreateFromComponent(
    const MediaStreamComponent* component,
    const String& id) {}

static void AddSinkInternal(Vector<WebMediaStreamSink*>* sinks,
                            WebMediaStreamSink* sink) {}

static void RemoveSinkInternal(Vector<WebMediaStreamSink*>* sinks,
                               WebMediaStreamSink* sink) {}

void MediaStreamVideoTrack::AddSink(
    WebMediaStreamSink* sink,
    const VideoCaptureDeliverFrameCB& callback,
    MediaStreamVideoSink::IsSecure is_secure,
    MediaStreamVideoSink::UsesAlpha uses_alpha) {}

bool MediaStreamVideoTrack::UsingAlpha() const {}

gfx::Size MediaStreamVideoTrack::GetVideoSize() const {}

void MediaStreamVideoTrack::SetSinkNotifyFrameDroppedCallback(
    WebMediaStreamSink* sink,
    const VideoCaptureNotifyFrameDroppedCB& callback) {}

void MediaStreamVideoTrack::AddEncodedSink(WebMediaStreamSink* sink,
                                           EncodedVideoFrameCB callback) {}

void MediaStreamVideoTrack::RemoveSink(WebMediaStreamSink* sink) {}

void MediaStreamVideoTrack::RemoveEncodedSink(WebMediaStreamSink* sink) {}

void MediaStreamVideoTrack::UpdateSourceHasConsumers() {}

void MediaStreamVideoTrack::SetEnabled(bool enabled) {}

size_t MediaStreamVideoTrack::CountSinks() const {}

size_t MediaStreamVideoTrack::CountEncodedSinks() const {}

void MediaStreamVideoTrack::SetContentHint(
    WebMediaStreamTrack::ContentHintType content_hint) {}

void MediaStreamVideoTrack::StopAndNotify(base::OnceClosure callback) {}

void MediaStreamVideoTrack::GetSettings(
    MediaStreamTrackPlatform::Settings& settings) const {}

MediaStreamTrackPlatform::VideoFrameStats
MediaStreamVideoTrack::GetVideoFrameStats() const {}

MediaStreamTrackPlatform::CaptureHandle
MediaStreamVideoTrack::GetCaptureHandle() {}

void MediaStreamVideoTrack::AddSubCaptureTargetVersionCallback(
    uint32_t sub_capture_target_version,
    base::OnceClosure callback) {}

void MediaStreamVideoTrack::RemoveSubCaptureTargetVersionCallback(
    uint32_t sub_capture_target_version) {}

void MediaStreamVideoTrack::OnReadyStateChanged(
    WebMediaStreamSource::ReadyState state) {}

void MediaStreamVideoTrack::SetMinimumFrameRate(double min_frame_rate) {}

void MediaStreamVideoTrack::SetTrackAdapterSettings(
    const VideoTrackAdapterSettings& settings) {}

void MediaStreamVideoTrack::NotifyConstraintsConfigurationComplete() {}

media::VideoCaptureFormat MediaStreamVideoTrack::GetComputedSourceFormat() {}

void MediaStreamVideoTrack::OnSinkDroppedFrame(
    media::VideoCaptureFrameDropReason reason) {}

void MediaStreamVideoTrack::SetEmitLogMessageForTesting(
    base::RepeatingCallback<void(const std::string&)> emit_log_message) {}

void MediaStreamVideoTrack::StartTimerForRequestingFrames() {}

void MediaStreamVideoTrack::RequestRefreshFrame() {}

void MediaStreamVideoTrack::ResetRefreshTimer() {}

}  // namespace blink