Commit 0403c564 authored by Peter Thatcher's avatar Peter Thatcher Committed by Commit Bot

Add WebCodecs blink module

Preparing to implement WebCodecs (https://www.chromestatus.com/feature/5669293909868544).

Also add an impl of VideoFrame and a skeleton class of VideoDecoder.

Bug: 897297
Change-Id: I722ef891c10795e815ce0772b6f1be3afc563d6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946940
Commit-Queue: Peter Thatcher <pthatcher@google.com>
Reviewed-by: default avatarMounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722564}
parent 5fade698
...@@ -143,6 +143,7 @@ jumbo_component("modules") { ...@@ -143,6 +143,7 @@ jumbo_component("modules") {
"//third_party/blink/renderer/modules/video_raf", "//third_party/blink/renderer/modules/video_raf",
"//third_party/blink/renderer/modules/wake_lock", "//third_party/blink/renderer/modules/wake_lock",
"//third_party/blink/renderer/modules/webaudio", "//third_party/blink/renderer/modules/webaudio",
"//third_party/blink/renderer/modules/webcodecs",
"//third_party/blink/renderer/modules/webdatabase", "//third_party/blink/renderer/modules/webdatabase",
"//third_party/blink/renderer/modules/webgl", "//third_party/blink/renderer/modules/webgl",
"//third_party/blink/renderer/modules/webgpu", "//third_party/blink/renderer/modules/webgpu",
......
...@@ -386,6 +386,8 @@ modules_idl_files = ...@@ -386,6 +386,8 @@ modules_idl_files =
"webaudio/script_processor_node.idl", "webaudio/script_processor_node.idl",
"webaudio/stereo_panner_node.idl", "webaudio/stereo_panner_node.idl",
"webaudio/wave_shaper_node.idl", "webaudio/wave_shaper_node.idl",
"webcodecs/video_decoder.idl",
"webcodecs/video_frame.idl",
"webdatabase/database.idl", "webdatabase/database.idl",
"webdatabase/sql_error.idl", "webdatabase/sql_error.idl",
"webdatabase/sql_result_set.idl", "webdatabase/sql_result_set.idl",
...@@ -827,6 +829,7 @@ modules_dictionary_idl_files = ...@@ -827,6 +829,7 @@ modules_dictionary_idl_files =
"webaudio/periodic_wave_options.idl", "webaudio/periodic_wave_options.idl",
"webaudio/stereo_panner_options.idl", "webaudio/stereo_panner_options.idl",
"webaudio/wave_shaper_options.idl", "webaudio/wave_shaper_options.idl",
"webcodecs/video_decoder_init_parameters.idl",
"webgl/webgl_context_attributes.idl", "webgl/webgl_context_attributes.idl",
"webgl/webgl_context_event_init.idl", "webgl/webgl_context_event_init.idl",
"webgpu/gpu_bind_group_binding.idl", "webgpu/gpu_bind_group_binding.idl",
......
# Copyright 2019 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.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("webcodecs") {
sources = [
"video_decoder.cc",
"video_decoder.h",
"video_frame.cc",
"video_frame.h",
]
}
include_rules = [
"+media/base/video_frame.h",
]
mlamouri@chromium.org
sandersd@chromium.org
dalecurtis@chromium.org
# WebCodecs API
This directory will contain the implementation of
https://github.com/WICG/web-codecs/, which is a low-level API for encode and
decode of audio and video.
It will use the existing codec implementations in src/media used by the video
stack, WebRTC, and MediaRecorder, such as media::DecoderFactory,
media::VideoEncodeAccelerator, and media::VideoFrame.
\ No newline at end of file
// Copyright 2019 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/webcodecs/video_decoder.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/writable_stream.h"
#include "third_party/blink/renderer/modules/webcodecs/video_decoder_init_parameters.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
namespace blink {
// static
VideoDecoder* VideoDecoder::Create() {
return MakeGarbageCollected<VideoDecoder>();
}
VideoDecoder::VideoDecoder() = default;
ScriptPromise VideoDecoder::Initialize(
ScriptState* script_state,
const VideoDecoderInitParameters* params) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kNotSupportedError,
"Not implemented yet."));
}
ScriptPromise VideoDecoder::Flush(ScriptState* script_state) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kNotSupportedError,
"Not implemented yet."));
}
void VideoDecoder::Close() {}
ReadableStream* VideoDecoder::readable() const {
return nullptr;
}
WritableStream* VideoDecoder::writable() const {
return nullptr;
}
void VideoDecoder::Trace(Visitor* visitor) {
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2019 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_WEBCODECS_VIDEO_DECODER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_DECODER_H_
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink {
class ScriptState;
class ReadableStream;
class VideoDecoderInitParameters;
class WritableStream;
class MODULES_EXPORT VideoDecoder final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static VideoDecoder* Create();
VideoDecoder();
ScriptPromise Initialize(ScriptState*, const VideoDecoderInitParameters*);
ScriptPromise Flush(ScriptState*);
void Close();
// video_decoder.idl implementation.
ReadableStream* readable() const;
WritableStream* writable() const;
// GarbageCollected override.
void Trace(Visitor*) override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_DECODER_H_
// Copyright 2019 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.
[
Constructor(),
RuntimeEnabled=WebCodecs
] interface VideoDecoder {
[CallWith=ScriptState] Promise<void> Initialize(VideoDecoderInitParameters params);
[CallWith=ScriptState] Promise<void> Flush();
void Close();
readonly attribute WritableStream writable; // of EncodedVideoFrame
readonly attribute ReadableStream readable; // of VideoFrame
};
\ No newline at end of file
// Copyright 2019 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.
dictionary VideoDecoderInitParameters {
DOMString codec;
DOMString profile;
// These are the "coded size", not the "visible size"
unsigned long width;
unsigned long height;
};
\ No newline at end of file
// Copyright 2019 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/webcodecs/video_frame.h"
#include <utility>
#include "media/base/video_frame.h"
namespace blink {
VideoFrame::VideoFrame(scoped_refptr<media::VideoFrame> frame)
: frame_(std::move(frame)) {
DCHECK(frame_);
}
scoped_refptr<media::VideoFrame> VideoFrame::frame() {
return frame_;
}
scoped_refptr<const media::VideoFrame> VideoFrame::frame() const {
return frame_;
}
uint64_t VideoFrame::timestamp() const {
if (!frame_)
return 0;
return frame_->timestamp().InMicroseconds();
}
uint32_t VideoFrame::coded_width() const {
if (!frame_)
return 0;
return frame_->coded_size().width();
}
uint32_t VideoFrame::coded_height() const {
if (!frame_)
return 0;
return frame_->coded_size().height();
}
uint32_t VideoFrame::visible_width() const {
if (!frame_)
return 0;
return frame_->visible_rect().width();
}
uint32_t VideoFrame::visible_height() const {
if (!frame_)
return 0;
return frame_->visible_rect().height();
}
void VideoFrame::release() {
frame_.reset();
}
} // namespace blink
// Copyright 2019 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_WEBCODECS_VIDEO_FRAME_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_FRAME_H_
#include "media/base/video_frame.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/wtf/text/wtf_string.h"
namespace blink {
class MODULES_EXPORT VideoFrame final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
explicit VideoFrame(scoped_refptr<media::VideoFrame> frame);
// video_track_frame.idl implementation.
uint64_t timestamp() const;
uint32_t coded_width() const;
uint32_t coded_height() const;
uint32_t visible_width() const;
uint32_t visible_height() const;
void release();
// Convenience functions
scoped_refptr<media::VideoFrame> frame();
scoped_refptr<const media::VideoFrame> frame() const;
private:
scoped_refptr<media::VideoFrame> frame_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_VIDEO_FRAME_H_
// Copyright 2019 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.
[
RuntimeEnabled=WebCodecs
] interface VideoFrame {
void release();
readonly attribute unsigned long long timestamp; // microseconds
readonly attribute unsigned long coded_width;
readonly attribute unsigned long coded_height;
readonly attribute unsigned long visible_width;
readonly attribute unsigned long visible_height;
};
\ No newline at end of file
...@@ -1787,6 +1787,10 @@ ...@@ -1787,6 +1787,10 @@
name: "WebBluetoothScanning", name: "WebBluetoothScanning",
status: "experimental", status: "experimental",
}, },
{
name: "WebCodecs",
status: "test",
},
{ {
name: "WebGL2ComputeContext", name: "WebGL2ComputeContext",
status: "experimental", status: "experimental",
......
...@@ -633,6 +633,14 @@ _CONFIG = [ ...@@ -633,6 +633,14 @@ _CONFIG = [
'media::.+', 'media::.+',
] ]
}, },
{
'paths': [
'third_party/blink/renderer/modules/webcodecs/',
],
'allowed': [
'media::.+',
]
},
{ {
'paths': [ 'paths': [
'third_party/blink/renderer/modules/encryptedmedia/', 'third_party/blink/renderer/modules/encryptedmedia/',
......
...@@ -8576,6 +8576,23 @@ interface ValidityState ...@@ -8576,6 +8576,23 @@ interface ValidityState
getter valid getter valid
getter valueMissing getter valueMissing
method constructor method constructor
interface VideoDecoder
attribute @@toStringTag
getter readable
getter writable
method Close
method Flush
method Initialize
method constructor
interface VideoFrame
attribute @@toStringTag
getter coded_height
getter coded_width
getter timestamp
getter visible_height
getter visible_width
method constructor
method release
interface VideoPlaybackQuality interface VideoPlaybackQuality
attribute @@toStringTag attribute @@toStringTag
getter corruptedVideoFrames getter corruptedVideoFrames
......
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