Commit a3868446 authored by Eugene Zemtsov's avatar Eugene Zemtsov Committed by Commit Bot

[webcodecs] Update VideoEncoder API shape

1. remove tune() from VideoEncoder
2. Remove promises from VideoEncoder
3. Split init and config

Bug: 1094166
Change-Id: I47b347c89bb11991cdd61f52e0e4a7ce99b8b1d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2244660Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779871}
parent c2018705
......@@ -733,10 +733,10 @@ static_idl_files_in_modules = get_path_info(
"//third_party/blink/renderer/modules/webcodecs/video_decoder.idl",
"//third_party/blink/renderer/modules/webcodecs/video_decoder_init.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder_config.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder_encode_options.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder_init.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder_output_callback.idl",
"//third_party/blink/renderer/modules/webcodecs/video_encoder_tune_options.idl",
"//third_party/blink/renderer/modules/webcodecs/video_frame.idl",
"//third_party/blink/renderer/modules/webcodecs/video_frame_init.idl",
"//third_party/blink/renderer/modules/webcodecs/video_frame_output_callback.idl",
......
......@@ -23,9 +23,9 @@ modules_dictionary_idl_files = [
"image_decoder_init.idl",
"image_frame.idl",
"video_decoder_init.idl",
"video_encoder_config.idl",
"video_encoder_init.idl",
"video_encoder_encode_options.idl",
"video_encoder_tune_options.idl",
"video_frame_init.idl",
"video_track_writer_parameters.idl",
]
......
......@@ -25,8 +25,8 @@ namespace blink {
class ExceptionState;
enum class DOMExceptionCode;
class VideoEncoderConfig;
class VideoEncoderInit;
class VideoEncoderTuneOptions;
class VideoEncoderEncodeOptions;
class Visitor;
......@@ -34,22 +34,24 @@ class MODULES_EXPORT VideoEncoder final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static VideoEncoder* Create(ScriptState*, ExceptionState&);
VideoEncoder(ScriptState*, ExceptionState&);
static VideoEncoder* Create(ScriptState*,
const VideoEncoderInit*,
ExceptionState&);
VideoEncoder(ScriptState*, const VideoEncoderInit*, ExceptionState&);
~VideoEncoder() override;
// video_encoder.idl implementation.
ScriptPromise encode(const VideoFrame* frame,
const VideoEncoderEncodeOptions*,
ExceptionState&);
void encode(const VideoFrame* frame,
const VideoEncoderEncodeOptions*,
ExceptionState&);
ScriptPromise configure(const VideoEncoderInit* init, ExceptionState&);
void configure(const VideoEncoderConfig*, ExceptionState&);
ScriptPromise tune(const VideoEncoderTuneOptions* params, ExceptionState&);
ScriptPromise flush(ExceptionState&);
ScriptPromise close();
void reset(ExceptionState&);
ScriptPromise flush();
void close(ExceptionState&);
// GarbageCollected override.
void Trace(Visitor*) const override;
......@@ -60,27 +62,24 @@ class MODULES_EXPORT VideoEncoder final : public ScriptWrappable {
kConfigure,
kEncode,
kFlush,
kClose,
};
void Trace(Visitor*) const;
DOMException* Reject(DOMExceptionCode code, const String& message);
void Resolve();
Type type;
Member<const VideoEncoderInit> config; // used by kConfigure
Member<const VideoEncoderConfig> config; // used by kConfigure
Member<const VideoFrame> frame; // used by kEncode
Member<const VideoEncoderEncodeOptions> encodeOpts; // used by kEncode
Member<ScriptPromiseResolver> resolver;
Member<ScriptPromiseResolver> resolver; // used by kFlush
};
void CallOutputCallback(EncodedVideoChunk* chunk);
void CallErrorCallback(DOMException* ex);
ScriptPromise EnqueueRequest(Request* request);
void CallErrorCallback(DOMExceptionCode code, const String& message);
void EnqueueRequest(Request* request);
void ProcessRequests();
void ProcessEncode(Request* request);
void ProcessConfigure(Request* request);
void ProcessClose(Request* request);
void ProcessFlush(Request* request);
void MediaEncoderOutputCallback(media::VideoEncoderOutput output);
......
......@@ -9,15 +9,14 @@
RuntimeEnabled=WebCodecs
] interface VideoEncoder {
[CallWith=ScriptState, RaisesException]
constructor();
constructor(VideoEncoderInit init);
// Performs original configuration of the encoder.
// Resolved after configuration is done. It should be called only
// once per encoder instance, before calling any other methods.
[RaisesException]
Promise<void> configure(VideoEncoderInit init);
void configure(VideoEncoderConfig config);
[RaisesException]
// Enqueues a request to encode a frame.
// Results of the encoding (EncodedVideoChunk) are returned via
// the output callback provided in configure().
......@@ -25,23 +24,27 @@
// The output callback can be called before or after the result is resolved.
// Several encoded requests can be resolved before even a single output
// is produced.
Promise<void> encode(VideoFrame frame,
[RaisesException]
void encode(VideoFrame frame,
optional VideoEncoderEncodeOptions options = {});
[RaisesException]
// Enqueues a request to change certain parameters of the encoder.
// Resolved after the parameters are adjusted.
// All following encode requests will be executed according to
// the new parameters.
// Should be preceded by flush().
Promise<void> tune(VideoEncoderTuneOptions options);
// Enqueues a request to produce outputs for all already encoded frames.
// Resolved after emitting outputs for all previously encoded frames.
[RaisesException]
Promise<void> flush();
// Discard all pending work and current encoder configuration.
//
// Output for earlier encoding requests will not be emitted.
// The next encoded frame will be a keyframe.
// Required a configure() to be call to set configuration once again.
[RaisesException]
void reset();
// Enqueues a request to shut down the encoder and free its resources.
// Resolved after all resources are released and all following requests
// rejected.
Promise<void> close();
[RaisesException]
void close();
};
......@@ -4,7 +4,10 @@
// https://github.com/WICG/web-codecs
dictionary VideoEncoderTuneOptions {
dictionary VideoEncoderConfig {
required DOMString codec;
DOMString profile;
unsigned long long bitrate;
double framerate;
......
......@@ -5,11 +5,6 @@
// https://github.com/WICG/web-codecs
dictionary VideoEncoderInit {
required DOMString codec;
DOMString profile;
required VideoEncoderTuneOptions tuneOptions;
// Called whenever there is a new encoded video chunk available.
required VideoEncoderOutputCallback output;
......
......@@ -28,24 +28,26 @@ async function createFrame(width, height, ts) {
}
promise_test(async function() {
const tune = {
const init = {
output : () => { return true; }
};
const params = {
codec : "vp8",
width: 123,
height: 321,
bitrate: 1e6,
framerate: 24
}
const init_params = {
codec : "vp8",
tuneOptions: tune,
output : () => { return true; }
framerate: 24,
};
let encoder = new VideoEncoder();
await encoder.configure(init_params);
encoder = new VideoEncoder(init_params);
tune.width = null;
encoder.configure(init_params).catch(e => {
let encoder = new VideoEncoder(init);
encoder.configure(params);
encoder.close();
encoder = new VideoEncoder(init);
params.width = null;
try {
encoder.configure(params);
} catch (e) {
assert_equals(e.name, "InvalidStateError");
});
};
}, "Initialization");
promise_test(async function() {
......@@ -64,28 +66,27 @@ promise_test(async function() {
frames_processed++;
};
const init_params = {
codec : "vp9",
profile : "vp09.00.10.08",
tuneOptions : {
width : w,
height : h,
bitrate: 10e6,
framerate: 30
},
const init = {
output : process_video_chunk,
error: (e) => { console.log(e.message); }
};
let encoder = new VideoEncoder();
await encoder.configure(init_params);
const params = {
codec : "vp9",
profile : "vp09.00.10.08",
width : w,
height : h,
bitrate: 10e6,
framerate: 30,
};
let encoder = new VideoEncoder(init);
encoder.configure(params);
for (let i = 0; i < frames_to_encode; i++) {
var frame = await createFrame(w, h, i);
let keyframe = (i % 5 == 0);
await encoder.encode(frame, { keyFrame : keyframe});
encoder.encode(frame, { keyFrame : keyframe});
}
await encoder.flush();
await encoder.close();
encoder.close();
assert_equals(frames_processed, frames_to_encode);
}, "EncodeFrame");
......
......@@ -8733,7 +8733,7 @@ interface VideoEncoder
method constructor
method encode
method flush
method tune
method reset
interface VideoFrame
attribute @@toStringTag
getter codedHeight
......
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