-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic shell of TransferredMediaStreamTrack
Add a subclass of MediaStreamTrack which can be created synchronously when receiving a transfer, but when a full MediaStreamTrack instance has been asynchronously set up, will proxy all JS calls to it. A refactoring to make MediaStreamTrack just an interface which both TransferredMediaStreamTrack and the current Impl directly subclass is being working on in crrev.com/c/3570541 Change-Id: Ib676713d003475e32d1a6e819d7bc92bd66c3aaf Bug: 1288839 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3568372 Reviewed-by: Palak Agarwal <agpalak@chromium.org> Auto-Submit: Tony Herre <toprice@chromium.org> Commit-Queue: Tony Herre <toprice@chromium.org> Cr-Commit-Position: refs/heads/main@{#988983}
- Loading branch information
Tony Herre
authored and
Chromium LUCI CQ
committed
Apr 5, 2022
1 parent
1814473
commit 43b28c5
Showing
5 changed files
with
302 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
211 changes: 211 additions & 0 deletions
211
third_party/blink/renderer/modules/mediastream/transferred_media_stream_track.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/modules/mediastream/transferred_media_stream_track.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/callback_helpers.h" | ||
#include "base/strings/stringprintf.h" | ||
#include "build/build_config.h" | ||
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_track.h" | ||
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h" | ||
#include "third_party/blink/public/web/modules/mediastream/media_stream_video_source.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_capture_handle_change_event.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_capture_handle_change_event_init.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_double_range.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_long_range.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_capabilities.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_constraints.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_settings.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_point_2d.h" | ||
#include "third_party/blink/renderer/core/dom/dom_exception.h" | ||
#include "third_party/blink/renderer/core/dom/events/event.h" | ||
#include "third_party/blink/renderer/core/execution_context/execution_context.h" | ||
#include "third_party/blink/renderer/core/frame/local_dom_window.h" | ||
#include "third_party/blink/renderer/core/frame/local_frame.h" | ||
#include "third_party/blink/renderer/modules/imagecapture/image_capture.h" | ||
#include "third_party/blink/renderer/modules/mediastream/apply_constraints_request.h" | ||
#include "third_party/blink/renderer/modules/mediastream/browser_capture_media_stream_track.h" | ||
#include "third_party/blink/renderer/modules/mediastream/capture_handle_change_event.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_constraints_impl.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_error_state.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_stream.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_stream_track.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_stream_utils.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h" | ||
#include "third_party/blink/renderer/modules/mediastream/overconstrained_error.h" | ||
#include "third_party/blink/renderer/modules/mediastream/processed_local_audio_source.h" | ||
#include "third_party/blink/renderer/modules/mediastream/user_media_controller.h" | ||
#include "third_party/blink/renderer/modules/mediastream/webaudio_media_stream_audio_sink.h" | ||
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h" | ||
#include "third_party/blink/renderer/platform/heap/garbage_collected.h" | ||
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h" | ||
#include "third_party/blink/renderer/platform/mediastream/media_stream_component.h" | ||
#include "third_party/blink/renderer/platform/mediastream/media_stream_web_audio_source.h" | ||
#include "third_party/blink/renderer/platform/runtime_enabled_features.h" | ||
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" | ||
#include "third_party/blink/renderer/platform/wtf/vector.h" | ||
|
||
namespace blink { | ||
|
||
TransferredMediaStreamTrack::TransferredMediaStreamTrack( | ||
ExecutionContext* context) | ||
: MediaStreamTrack(context, | ||
MakeGarbageCollected<MediaStreamComponent>( | ||
MakeGarbageCollected<MediaStreamSource>( | ||
"dummy", | ||
MediaStreamSource::StreamType::kTypeVideo, | ||
"dummy", | ||
false /* remote */))) {} | ||
|
||
String TransferredMediaStreamTrack::kind() const { | ||
if (track_) { | ||
return track_->kind(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return "video"; | ||
} | ||
|
||
String TransferredMediaStreamTrack::id() const { | ||
if (track_) { | ||
return track_->id(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return ""; | ||
} | ||
|
||
String TransferredMediaStreamTrack::label() const { | ||
if (track_) { | ||
return track_->label(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return "dummy"; | ||
} | ||
|
||
bool TransferredMediaStreamTrack::enabled() const { | ||
if (track_) { | ||
return track_->enabled(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return true; | ||
} | ||
|
||
void TransferredMediaStreamTrack::setEnabled(bool enabled) { | ||
if (track_) { | ||
track_->setEnabled(enabled); | ||
} | ||
// TODO(https://crbug.com/1288839): Save and forward to track_ once it's | ||
// initialized. | ||
} | ||
|
||
bool TransferredMediaStreamTrack::muted() const { | ||
if (track_) { | ||
return track_->muted(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return false; | ||
} | ||
|
||
String TransferredMediaStreamTrack::ContentHint() const { | ||
if (track_) { | ||
return track_->ContentHint(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return ""; | ||
} | ||
|
||
void TransferredMediaStreamTrack::SetContentHint(const String& content_hint) { | ||
if (track_) { | ||
track_->SetContentHint(content_hint); | ||
} | ||
// TODO(https://crbug.com/1288839): Save and forward to track_ once it's | ||
// initialized. | ||
} | ||
|
||
String TransferredMediaStreamTrack::readyState() const { | ||
if (track_) { | ||
return track_->readyState(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return "live"; | ||
} | ||
|
||
MediaStreamTrack* TransferredMediaStreamTrack::clone( | ||
ScriptState* script_state) { | ||
if (track_) { | ||
return track_->clone(script_state); | ||
} | ||
// TODO(https://crbug.com/1288839): Create another TransferredMediaStreamTrack | ||
// and call track_->clone() once track_ is initialized. | ||
return nullptr; | ||
} | ||
|
||
void TransferredMediaStreamTrack::stopTrack( | ||
ExecutionContext* execution_context) { | ||
if (track_) { | ||
track_->stopTrack(execution_context); | ||
} | ||
// TODO(https://crbug.com/1288839): Save and forward to track_ once it's | ||
// initialized. | ||
} | ||
|
||
MediaTrackCapabilities* TransferredMediaStreamTrack::getCapabilities() const { | ||
if (track_) { | ||
return track_->getCapabilities(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return MediaTrackCapabilities::Create(); | ||
} | ||
|
||
MediaTrackConstraints* TransferredMediaStreamTrack::getConstraints() const { | ||
if (track_) { | ||
return track_->getConstraints(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return MediaTrackConstraints::Create(); | ||
} | ||
|
||
MediaTrackSettings* TransferredMediaStreamTrack::getSettings() const { | ||
if (track_) { | ||
return track_->getSettings(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return MediaTrackSettings::Create(); | ||
} | ||
|
||
CaptureHandle* TransferredMediaStreamTrack::getCaptureHandle() const { | ||
if (track_) { | ||
return track_->getCaptureHandle(); | ||
} | ||
// TODO(https://crbug.com/1288839): return the transferred value. | ||
return CaptureHandle::Create(); | ||
} | ||
|
||
ScriptPromise TransferredMediaStreamTrack::applyConstraints( | ||
ScriptState* script_state, | ||
const MediaTrackConstraints* constrints) { | ||
if (track_) { | ||
return track_->applyConstraints(script_state, constrints); | ||
} | ||
// TODO(https://crbug.com/1288839): return a promise which resolves once | ||
// track_ is set. | ||
return ScriptPromise(); | ||
} | ||
|
||
void TransferredMediaStreamTrack::setImplementation(MediaStreamTrack* track) { | ||
track_ = track; | ||
// TODO(https://crbug.com/1288839): Replay mutations which have happened | ||
// before this point. Also set up plumbing so that events fired by the | ||
// implementation track are propagated to anything listening to events on this | ||
// object. | ||
} | ||
|
||
void TransferredMediaStreamTrack::Trace(Visitor* visitor) const { | ||
MediaStreamTrack::Trace(visitor); | ||
visitor->Trace(track_); | ||
} | ||
|
||
} // namespace blink |
71 changes: 71 additions & 0 deletions
71
third_party/blink/renderer/modules/mediastream/transferred_media_stream_track.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_TRANSFERRED_MEDIA_STREAM_TRACK_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_TRANSFERRED_MEDIA_STREAM_TRACK_H_ | ||
|
||
#include "build/build_config.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" | ||
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" | ||
#include "third_party/blink/renderer/bindings/modules/v8/v8_capture_handle.h" | ||
#include "third_party/blink/renderer/modules/event_target_modules.h" | ||
#include "third_party/blink/renderer/modules/mediastream/media_stream_track.h" | ||
#include "third_party/blink/renderer/modules/modules_export.h" | ||
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_set.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/frame_scheduler.h" | ||
#include "third_party/blink/renderer/platform/wtf/forward.h" | ||
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" | ||
|
||
namespace blink { | ||
|
||
class MediaTrackCapabilities; | ||
class MediaTrackConstraints; | ||
class MediaTrackSettings; | ||
class ScriptState; | ||
|
||
// A MediaStreamTrack implementation synchronously created when receiving a | ||
// transferred MediaStreamTrack, when the full instance is being asynchronously | ||
// created. Once the asynchronous setup has finished, proxies all calls to the | ||
// full instance. | ||
class MODULES_EXPORT TransferredMediaStreamTrack : public MediaStreamTrack { | ||
public: | ||
explicit TransferredMediaStreamTrack(ExecutionContext*); | ||
|
||
// MediaStreamTrack.idl | ||
String kind() const override; | ||
String id() const override; | ||
String label() const override; | ||
bool enabled() const override; | ||
void setEnabled(bool) override; | ||
bool muted() const override; | ||
String ContentHint() const override; | ||
void SetContentHint(const String&) override; | ||
String readyState() const override; | ||
MediaStreamTrack* clone(ScriptState*) override; | ||
void stopTrack(ExecutionContext*) override; | ||
MediaTrackCapabilities* getCapabilities() const override; | ||
MediaTrackConstraints* getConstraints() const override; | ||
MediaTrackSettings* getSettings() const override; | ||
CaptureHandle* getCaptureHandle() const override; | ||
ScriptPromise applyConstraints(ScriptState*, | ||
const MediaTrackConstraints*) override; | ||
|
||
void setImplementation(MediaStreamTrack* track); | ||
|
||
DEFINE_ATTRIBUTE_EVENT_LISTENER(mute, kMute) | ||
DEFINE_ATTRIBUTE_EVENT_LISTENER(unmute, kUnmute) | ||
DEFINE_ATTRIBUTE_EVENT_LISTENER(ended, kEnded) | ||
DEFINE_ATTRIBUTE_EVENT_LISTENER(capturehandlechange, kCapturehandlechange) | ||
|
||
void Trace(Visitor*) const override; | ||
|
||
private: | ||
Member<MediaStreamTrack> track_; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_TRANSFERRED_MEDIA_STREAM_TRACK_H_ |