Commit 5f1112ab authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

[BreakoutBox] Add MediaStreamTrackProcessor

This CL introduces MediaStreamTrackProcessor, an object that allows
exposing a MediaStreamTrack's media frames as a readable stream,
enabling applications to perform custom processing.
This basically allows the creation of a custom sink, in terms of the
model proposed by the Media Capture and Streams spec [1].
A MediaStreamTrackProcessor can be combined with a TransformStream and a
MediaStreamTrackGenerator to effectively insert a processing step inside
an existing track.

[1] https://w3c.github.io/mediacapture-main/#the-model-sources-sinks-constraints-and-settings

Bug: 1142955
Change-Id: I2a119f0c2ea9ce50432509286bd0f43758d8a272
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2524322
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarHarald Alvestrand <hta@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826153}
parent 145656d7
......@@ -3055,6 +3055,7 @@ enum WebFeature {
kV8HTMLDialogElement_ShowModal_Method = 3726,
kAdFrameDetected = 3727,
kMediaStreamTrackGenerator = 3728,
kMediaStreamTrackProcessor = 3729,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -1679,6 +1679,8 @@ generated_interface_sources_in_modules = [
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track_event.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track_generator.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track_generator.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track_processor.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track_processor.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_merchant_validation_event.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_merchant_validation_event.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_metadata.cc",
......
......@@ -384,6 +384,7 @@ static_idl_files_in_modules = get_path_info(
"//third_party/blink/renderer/modules/mediastream/media_stream_track_event.idl",
"//third_party/blink/renderer/modules/mediastream/media_stream_track_event_init.idl",
"//third_party/blink/renderer/modules/mediastream/media_stream_track_generator.idl",
"//third_party/blink/renderer/modules/mediastream/media_stream_track_processor.idl",
"//third_party/blink/renderer/modules/mediastream/media_track_capabilities.idl",
"//third_party/blink/renderer/modules/mediastream/media_track_constraint_set.idl",
"//third_party/blink/renderer/modules/mediastream/media_track_constraints.idl",
......
......@@ -349,6 +349,7 @@ source_set("unit_tests") {
"mediastream/media_stream_constraints_util_video_device_test.cc",
"mediastream/media_stream_device_observer_test.cc",
"mediastream/media_stream_track_generator_test.cc",
"mediastream/media_stream_track_processor_test.cc",
"mediastream/media_stream_video_capturer_source_test.cc",
"mediastream/media_stream_video_renderer_sink_test.cc",
"mediastream/media_stream_video_source_test.cc",
......
......@@ -56,6 +56,8 @@ blink_modules_sources("mediastream") {
"media_stream_track_event.h",
"media_stream_track_generator.cc",
"media_stream_track_generator.h",
"media_stream_track_processor.cc",
"media_stream_track_processor.h",
"media_stream_utils.cc",
"media_stream_utils.h",
"media_stream_video_capturer_source.cc",
......
......@@ -11,6 +11,7 @@ modules_idl_files = [
"media_stream_track.idl",
"media_stream_track_event.idl",
"media_stream_track_generator.idl",
"media_stream_track_processor.idl",
"overconstrained_error.idl",
]
......
// Copyright 2020 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/media_stream_track_processor.h"
#include "third_party/blink/public/mojom/web_feature/web_feature.mojom-blink.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/streams/readable_stream.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/media_stream_video_track_underlying_source.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/uuid.h"
namespace blink {
MediaStreamTrackProcessor::MediaStreamTrackProcessor(
ScriptState* script_state,
MediaStreamComponent* input_track)
: input_track_(input_track) {
DCHECK(input_track_);
UseCounter::Count(ExecutionContext::From(script_state),
WebFeature::kMediaStreamTrackProcessor);
}
ReadableStream* MediaStreamTrackProcessor::readable(ScriptState* script_state) {
DCHECK_EQ(input_track_->Source()->GetType(), MediaStreamSource::kTypeVideo);
if (!source_stream_)
CreateVideoSourceStream(script_state);
return source_stream_;
}
void MediaStreamTrackProcessor::CreateVideoSourceStream(
ScriptState* script_state) {
DCHECK(!source_stream_);
video_underlying_source_ =
MakeGarbageCollected<MediaStreamVideoTrackUnderlyingSource>(script_state,
input_track_);
source_stream_ = ReadableStream::CreateWithCountQueueingStrategy(
script_state, video_underlying_source_, /*high_water_mark=*/0);
}
MediaStreamTrackProcessor* MediaStreamTrackProcessor::Create(
ScriptState* script_state,
MediaStreamTrack* track,
ExceptionState& exception_state) {
if (!track) {
exception_state.ThrowDOMException(DOMExceptionCode::kOperationError,
"Input track cannot be null");
return nullptr;
}
if (track->kind() != "video") {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Only video tracks are supported");
return nullptr;
}
if (!script_state->ContextIsValid()) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"The context has been destroyed");
return nullptr;
}
return MakeGarbageCollected<MediaStreamTrackProcessor>(script_state,
track->Component());
}
void MediaStreamTrackProcessor::Trace(Visitor* visitor) const {
visitor->Trace(input_track_);
visitor->Trace(video_underlying_source_);
visitor->Trace(source_stream_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2020 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_MEDIA_STREAM_TRACK_PROCESSOR_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_STREAM_TRACK_PROCESSOR_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/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/impl/heap.h"
namespace blink {
class MediaStreamComponent;
class MediaStreamVideoTrackUnderlyingSource;
class ScriptState;
class ReadableStream;
class MODULES_EXPORT MediaStreamTrackProcessor : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static MediaStreamTrackProcessor* Create(ScriptState*,
MediaStreamTrack*,
ExceptionState&);
MediaStreamTrackProcessor(ScriptState*, MediaStreamComponent*);
MediaStreamTrackProcessor(const MediaStreamTrackProcessor&) = delete;
MediaStreamTrackProcessor& operator=(const MediaStreamTrackProcessor&) =
delete;
// MediaStreamTrackProcessor interface
ReadableStream* readable(ScriptState* script_state);
MediaStreamComponent* input_track() { return input_track_; }
void Trace(Visitor* visitor) const override;
private:
void CreateVideoSourceStream(ScriptState* script_state);
Member<MediaStreamComponent> input_track_;
Member<MediaStreamVideoTrackUnderlyingSource> video_underlying_source_;
Member<ReadableStream> source_stream_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_STREAM_TRACK_PROCESSOR_H_
// Copyright 2020 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.
// See spec in developement at
// https://w3c.github.io/mediacapture-insertable-streams/
[
Exposed=Window,
RuntimeEnabled=MediaStreamInsertableStreams
]
interface MediaStreamTrackProcessor {
[CallWith=ScriptState, RaisesException, MeasureAs=MediaStreamTrackProcessor]
constructor(MediaStreamTrack track);
// This stream returns VideoFrame objects.
// TODO(crbug.com/1142955): Add support for audio.
[CallWith=ScriptState] readonly attribute ReadableStream readable;
// TODO(crbug.com/1142955): Add |writable| attribute that takes control signals.
};
......@@ -5182,6 +5182,10 @@ interface MediaStreamTrackGenerator : MediaStreamTrack
attribute @@toStringTag
getter writable
method constructor
interface MediaStreamTrackProcessor
attribute @@toStringTag
getter readable
method constructor
interface MerchantValidationEvent : Event
attribute @@toStringTag
getter methodName
......
......@@ -30231,6 +30231,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3726" label="V8HTMLDialogElement_ShowModal_Method"/>
<int value="3727" label="AdFrameDetected"/>
<int value="3728" label="MediaStreamTrackGenerator"/>
<int value="3729" label="MediaStreamTrackProcessor"/>
</enum>
<enum name="FeaturePolicyAllowlistType">
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