#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/peerconnection/media_stream_remote_video_source.h"
#include <stdint.h>
#include <utility>
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "media/base/timestamp_constants.h"
#include "media/base/video_frame.h"
#include "media/base/video_util.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-blink.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/webrtc/convert_to_webrtc_video_frame_buffer.h"
#include "third_party/blink/renderer/platform/webrtc/track_observer.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_frame_adapter.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/webrtc/api/video/i420_buffer.h"
#include "third_party/webrtc/api/video/recordable_encoded_frame.h"
#include "third_party/webrtc/rtc_base/time_utils.h"
#include "third_party/webrtc/system_wrappers/include/clock.h"
namespace blink {
namespace {
class WebRtcEncodedVideoFrame : public EncodedVideoFrame { … };
}
class MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate
: public WTF::ThreadSafeRefCounted<RemoteVideoSourceDelegate>,
public rtc::VideoSinkInterface<webrtc::VideoFrame>,
public rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame> { … };
MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
RemoteVideoSourceDelegate(
scoped_refptr<base::SequencedTaskRunner> video_task_runner,
VideoCaptureDeliverFrameCB new_frame_callback,
EncodedVideoFrameCB encoded_frame_callback,
VideoCaptureSubCaptureTargetVersionCB
sub_capture_target_version_callback)
: … { … }
MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
~RemoteVideoSourceDelegate() = default;
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame(
const webrtc::VideoFrame& incoming_frame) { … }
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
DoRenderFrameOnIOThread(scoped_refptr<media::VideoFrame> video_frame,
base::TimeTicks estimated_capture_time) { … }
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::OnFrame(
const webrtc::RecordableEncodedFrame& frame) { … }
void MediaStreamRemoteVideoSource::RemoteVideoSourceDelegate::
OnEncodedVideoFrameOnIO(scoped_refptr<EncodedVideoFrame> frame,
base::TimeTicks estimated_capture_time) { … }
MediaStreamRemoteVideoSource::MediaStreamRemoteVideoSource(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<TrackObserver> observer)
: … { … }
MediaStreamRemoteVideoSource::~MediaStreamRemoteVideoSource() { … }
void MediaStreamRemoteVideoSource::OnSourceTerminated() { … }
void MediaStreamRemoteVideoSource::StartSourceImpl(
VideoCaptureDeliverFrameCB frame_callback,
EncodedVideoFrameCB encoded_frame_callback,
VideoCaptureSubCaptureTargetVersionCB sub_capture_target_version_callback,
VideoCaptureNotifyFrameDroppedCB) { … }
void MediaStreamRemoteVideoSource::StopSourceImpl() { … }
rtc::VideoSinkInterface<webrtc::VideoFrame>*
MediaStreamRemoteVideoSource::SinkInterfaceForTesting() { … }
rtc::VideoSinkInterface<webrtc::RecordableEncodedFrame>*
MediaStreamRemoteVideoSource::EncodedSinkInterfaceForTesting() { … }
void MediaStreamRemoteVideoSource::OnChanged(
webrtc::MediaStreamTrackInterface::TrackState state) { … }
bool MediaStreamRemoteVideoSource::SupportsEncodedOutput() const { … }
void MediaStreamRemoteVideoSource::RequestKeyFrame() { … }
base::WeakPtr<MediaStreamVideoSource>
MediaStreamRemoteVideoSource::GetWeakPtr() { … }
void MediaStreamRemoteVideoSource::OnEncodedSinkEnabled() { … }
void MediaStreamRemoteVideoSource::OnEncodedSinkDisabled() { … }
}