Commit fce620d7 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Change RemoteMediaStreamTrackAdapter to operate over MediaStreamComponent

... instead of WebMediaStreamTrack.

This is part of the effort to reduce the needless use of
public Blink APIs (wrappers) within renderer/modules.

Drive by, this CL also changes the uses of blink::WebString
to WTF::String.

BUG=704136
R=guidou@chromium.org

Change-Id: I99226ef3efbbf9d85ed3db45df5081e2f23f51ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2246928
Auto-Submit: Antonio Gomes <tonikitoo@igalia.com>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779347}
parent fdb35e20
...@@ -35,9 +35,9 @@ RemoteVideoTrackAdapter::~RemoteVideoTrackAdapter() { ...@@ -35,9 +35,9 @@ RemoteVideoTrackAdapter::~RemoteVideoTrackAdapter() {
if (initialized()) { if (initialized()) {
// TODO(crbug.com/704136): When moving RemoteVideoTrackAdapter out of the // TODO(crbug.com/704136): When moving RemoteVideoTrackAdapter out of the
// public API, make this managed by Oilpan. Note that, the destructor will // public API, make this managed by Oilpan. Note that, the destructor will
// not allowed to touch other on-heap objects like web_track(). // not allowed to touch other on-heap objects like track().
static_cast<MediaStreamRemoteVideoSource*>( static_cast<MediaStreamRemoteVideoSource*>(
web_track()->Source().GetPlatformSource()) track()->Source()->GetPlatformSource())
->OnSourceTerminated(); ->OnSourceTerminated();
} }
} }
...@@ -49,14 +49,15 @@ void RemoteVideoTrackAdapter::InitializeWebVideoTrack( ...@@ -49,14 +49,15 @@ void RemoteVideoTrackAdapter::InitializeWebVideoTrack(
auto video_source_ptr = auto video_source_ptr =
std::make_unique<MediaStreamRemoteVideoSource>(std::move(observer)); std::make_unique<MediaStreamRemoteVideoSource>(std::move(observer));
MediaStreamRemoteVideoSource* video_source = video_source_ptr.get(); MediaStreamRemoteVideoSource* video_source = video_source_ptr.get();
InitializeWebTrack(WebMediaStreamSource::kTypeVideo); InitializeTrack(MediaStreamSource::kTypeVideo);
web_track()->Source().SetPlatformSource(std::move(video_source_ptr)); video_source_ptr->SetOwner(track()->Source());
track()->Source()->SetPlatformSource(std::move(video_source_ptr));
WebMediaStreamSource::Capabilities capabilities; WebMediaStreamSource::Capabilities capabilities;
capabilities.device_id = id(); capabilities.device_id = id();
web_track()->Source().SetCapabilities(capabilities); track()->Source()->SetCapabilities(capabilities);
web_track()->SetPlatformTrack(std::make_unique<MediaStreamVideoTrack>( track()->SetPlatformTrack(std::make_unique<MediaStreamVideoTrack>(
video_source, MediaStreamVideoSource::ConstraintsOnceCallback(), video_source, MediaStreamVideoSource::ConstraintsOnceCallback(),
enabled)); enabled));
} }
...@@ -93,13 +94,13 @@ void RemoteAudioTrackAdapter::Unregister() { ...@@ -93,13 +94,13 @@ void RemoteAudioTrackAdapter::Unregister() {
void RemoteAudioTrackAdapter::InitializeWebAudioTrack( void RemoteAudioTrackAdapter::InitializeWebAudioTrack(
const scoped_refptr<base::SingleThreadTaskRunner>& main_thread) { const scoped_refptr<base::SingleThreadTaskRunner>& main_thread) {
InitializeWebTrack(WebMediaStreamSource::kTypeAudio); InitializeTrack(MediaStreamSource::kTypeAudio);
auto source = std::make_unique<PeerConnectionRemoteAudioSource>( auto source = std::make_unique<PeerConnectionRemoteAudioSource>(
observed_track().get(), main_thread); observed_track().get(), main_thread);
auto* source_ptr = source.get(); auto* source_ptr = source.get();
web_track()->Source().SetPlatformSource( source_ptr->SetOwner(track()->Source());
std::move(source)); // Takes ownership. track()->Source()->SetPlatformSource(std::move(source));
WebMediaStreamSource::Capabilities capabilities; WebMediaStreamSource::Capabilities capabilities;
capabilities.device_id = id(); capabilities.device_id = id();
...@@ -111,9 +112,9 @@ void RemoteAudioTrackAdapter::InitializeWebAudioTrack( ...@@ -111,9 +112,9 @@ void RemoteAudioTrackAdapter::InitializeWebAudioTrack(
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16), // min media::SampleFormatToBitsPerChannel(media::kSampleFormatS16), // min
media::SampleFormatToBitsPerChannel(media::kSampleFormatS16) // max media::SampleFormatToBitsPerChannel(media::kSampleFormatS16) // max
}; };
web_track()->Source().SetCapabilities(capabilities); track()->Source()->SetCapabilities(capabilities);
source_ptr->ConnectToTrack(*(web_track())); source_ptr->ConnectToTrack(track());
} }
void RemoteAudioTrackAdapter::OnChanged() { void RemoteAudioTrackAdapter::OnChanged() {
...@@ -134,12 +135,10 @@ void RemoteAudioTrackAdapter::OnChangedOnMainThread( ...@@ -134,12 +135,10 @@ void RemoteAudioTrackAdapter::OnChangedOnMainThread(
switch (state) { switch (state) {
case webrtc::MediaStreamTrackInterface::kLive: case webrtc::MediaStreamTrackInterface::kLive:
web_track()->Source().SetReadyState( track()->Source()->SetReadyState(MediaStreamSource::kReadyStateLive);
WebMediaStreamSource::kReadyStateLive);
break; break;
case webrtc::MediaStreamTrackInterface::kEnded: case webrtc::MediaStreamTrackInterface::kEnded:
web_track()->Source().SetReadyState( track()->Source()->SetReadyState(MediaStreamSource::kReadyStateEnded);
WebMediaStreamSource::kReadyStateEnded);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
......
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
#include "base/logging.h" #include "base/logging.h"
#include "third_party/blink/public/platform/web_media_stream_source.h" #include "third_party/blink/public/platform/web_media_stream_source.h"
#include "third_party/blink/public/platform/web_media_stream_track.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/wtf/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/blink/renderer/platform/wtf/thread_safe_ref_counted.h"
#include "third_party/webrtc/api/media_stream_interface.h" #include "third_party/webrtc/api/media_stream_interface.h"
...@@ -35,23 +36,23 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter ...@@ -35,23 +36,23 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter
WebRtcMediaStreamTrackType* webrtc_track) WebRtcMediaStreamTrackType* webrtc_track)
: main_thread_(main_thread), : main_thread_(main_thread),
webrtc_track_(webrtc_track), webrtc_track_(webrtc_track),
id_(WebString::FromUTF8(webrtc_track->id())) {} id_(String::FromUTF8(webrtc_track->id())) {}
const scoped_refptr<WebRtcMediaStreamTrackType>& observed_track() { const scoped_refptr<WebRtcMediaStreamTrackType>& observed_track() {
return webrtc_track_; return webrtc_track_;
} }
WebMediaStreamTrack* web_track() { MediaStreamComponent* track() {
DCHECK(main_thread_->BelongsToCurrentThread()); DCHECK(main_thread_->BelongsToCurrentThread());
DCHECK(!web_track_.IsNull()); DCHECK(component_);
return &web_track_; return component_;
} }
WebString id() const { return id_; } String id() const { return id_; }
bool initialized() const { bool initialized() const {
DCHECK(main_thread_->BelongsToCurrentThread()); DCHECK(main_thread_->BelongsToCurrentThread());
return !web_track_.IsNull(); return !!component_;
} }
void Initialize() { void Initialize() {
...@@ -69,14 +70,14 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter ...@@ -69,14 +70,14 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter
DCHECK(main_thread_->BelongsToCurrentThread()); DCHECK(main_thread_->BelongsToCurrentThread());
} }
void InitializeWebTrack(WebMediaStreamSource::Type type) { void InitializeTrack(MediaStreamSource::StreamType type) {
DCHECK(main_thread_->BelongsToCurrentThread()); DCHECK(main_thread_->BelongsToCurrentThread());
DCHECK(web_track_.IsNull()); DCHECK(!component_);
WebMediaStreamSource web_source; auto* source = MakeGarbageCollected<MediaStreamSource>(id_, type, id_,
web_source.Initialize(id_, type, id_, true /* remote */); true /*remote*/);
web_track_.Initialize(id_, web_source); component_ = MakeGarbageCollected<MediaStreamComponent>(id_, source);
DCHECK(!web_track_.IsNull()); DCHECK(component_);
} }
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
...@@ -88,10 +89,10 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter ...@@ -88,10 +89,10 @@ class MODULES_EXPORT RemoteMediaStreamTrackAdapter
private: private:
const scoped_refptr<WebRtcMediaStreamTrackType> webrtc_track_; const scoped_refptr<WebRtcMediaStreamTrackType> webrtc_track_;
WebMediaStreamTrack web_track_; CrossThreadPersistent<MediaStreamComponent> component_;
// const copy of the webrtc track id that allows us to check it from both the // const copy of the webrtc track id that allows us to check it from both the
// main and signaling threads without incurring a synchronous thread hop. // main and signaling threads without incurring a synchronous thread hop.
const WebString id_; const String id_;
DISALLOW_COPY_AND_ASSIGN(RemoteMediaStreamTrackAdapter); DISALLOW_COPY_AND_ASSIGN(RemoteMediaStreamTrackAdapter);
}; };
......
...@@ -267,10 +267,10 @@ void WebRtcMediaStreamTrackAdapter:: ...@@ -267,10 +267,10 @@ void WebRtcMediaStreamTrackAdapter::
if (remote_audio_track_adapter_) { if (remote_audio_track_adapter_) {
remote_audio_track_adapter_->Initialize(); remote_audio_track_adapter_->Initialize();
web_track_ = *remote_audio_track_adapter_->web_track(); web_track_ = remote_audio_track_adapter_->track();
} else { } else {
remote_video_track_adapter_->Initialize(); remote_video_track_adapter_->Initialize();
web_track_ = *remote_video_track_adapter_->web_track(); web_track_ = remote_video_track_adapter_->track();
} }
is_initialized_ = true; is_initialized_ = true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment