Commit 8648e968 authored by Eugene Zemtsov's avatar Eugene Zemtsov Committed by Chromium LUCI CQ

webcodecs: IDL files for AudioEncoder

plus some minimal C++ code to make things compile

Bug: 1094179
Change-Id: Idea9b5fec09aeb19be4748c1746178744e5991e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2619621
Commit-Queue: Eugene Zemtsov <eugene@chromium.org>
Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842364}
parent 8e8bd69d
......@@ -3069,6 +3069,7 @@ enum WebFeature {
kSamePartyCookieInclusionOverruledSameSite = 3748,
kEmbedElementWithoutTypeSrcChanged = 3749,
kPaymentHandlerStandardizedPaymentMethodIdentifier = 3750,
kWebCodecsAudioEncoder = 3751,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -13,6 +13,8 @@ generated_callback_function_sources_in_modules = [
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_animator_constructor.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_frame_output_callback.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_frame_output_callback.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_encoded_audio_chunk_output_callback.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_encoded_audio_chunk_output_callback.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_blink_audio_worklet_process_callback.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_blink_audio_worklet_process_callback.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_blink_audio_worklet_processor_constructor.cc",
......@@ -107,6 +109,10 @@ generated_dictionary_sources_in_modules = [
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_android_pay_method_data.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_app_banner_prompt_result.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_app_banner_prompt_result.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_config.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_config.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_init.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder_init.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_buffer_options.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_buffer_options.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_buffer_source_options.cc",
......@@ -1239,6 +1245,8 @@ generated_interface_sources_in_modules = [
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_context.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_decoder.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_decoder.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_encoder.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_destination_node.cc",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_destination_node.h",
"$root_gen_dir/third_party/blink/renderer/bindings/modules/v8/v8_audio_frame.cc",
......
......@@ -743,6 +743,9 @@ static_idl_files_in_modules = get_path_info(
"//third_party/blink/renderer/modules/webcodecs/audio_decoder.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_decoder_config.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_decoder_init.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_encoder.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_encoder_config.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_encoder_init.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_frame.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_frame_init.idl",
"//third_party/blink/renderer/modules/webcodecs/audio_frame_output_callback.idl",
......@@ -756,6 +759,7 @@ static_idl_files_in_modules = get_path_info(
"//third_party/blink/renderer/modules/webcodecs/encoded_audio_chunk_init.idl",
"//third_party/blink/renderer/modules/webcodecs/encoded_video_chunk.idl",
"//third_party/blink/renderer/modules/webcodecs/encoded_video_chunk_init.idl",
"//third_party/blink/renderer/modules/webcodecs/encoded_audio_chunk_output_callback.idl",
"//third_party/blink/renderer/modules/webcodecs/image_decoder.idl",
"//third_party/blink/renderer/modules/webcodecs/image_decoder_init.idl",
"//third_party/blink/renderer/modules/webcodecs/image_frame.idl",
......
......@@ -148,6 +148,8 @@ generated_modules_callback_function_files = [
"$bindings_modules_v8_output_dir/v8_decode_error_callback.h",
"$bindings_modules_v8_output_dir/v8_decode_success_callback.cc",
"$bindings_modules_v8_output_dir/v8_decode_success_callback.h",
"$bindings_modules_v8_output_dir/v8_encoded_audio_chunk_output_callback.cc",
"$bindings_modules_v8_output_dir/v8_encoded_audio_chunk_output_callback.h",
"$bindings_modules_v8_output_dir/v8_idb_observer_callback.cc",
"$bindings_modules_v8_output_dir/v8_idb_observer_callback.h",
"$bindings_modules_v8_output_dir/v8_launch_consumer.cc",
......
......@@ -13,6 +13,8 @@ blink_modules_sources("webcodecs") {
"audio_decoder.h",
"audio_decoder_broker.cc",
"audio_decoder_broker.h",
"audio_encoder.cc",
"audio_encoder.h",
"audio_frame.cc",
"audio_frame.h",
"codec_config_eval.h",
......
// Copyright 2021 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/audio_encoder.h"
namespace blink {
AudioEncoder* AudioEncoder::Create(ScriptState* script_state,
const AudioEncoderInit* init,
ExceptionState& exception_state) {
return MakeGarbageCollected<AudioEncoder>(script_state, init,
exception_state);
}
AudioEncoder::AudioEncoder(ScriptState* script_state,
const AudioEncoderInit* init,
ExceptionState& exception_state)
: ExecutionContextLifecycleObserver(ExecutionContext::From(script_state)) {}
AudioEncoder::~AudioEncoder() = default;
int32_t AudioEncoder::encodeQueueSize() {
return 0;
}
void AudioEncoder::encode(AudioFrame* frame, ExceptionState&) {}
void AudioEncoder::configure(const AudioEncoderConfig*, ExceptionState&) {}
ScriptPromise AudioEncoder::flush(ExceptionState&) {
return ScriptPromise();
}
void AudioEncoder::reset(ExceptionState&) {}
void AudioEncoder::close(ExceptionState&) {}
String AudioEncoder::state() {
return "";
}
void AudioEncoder::ContextDestroyed() {}
void AudioEncoder::Trace(Visitor* visitor) const {
ScriptWrappable::Trace(visitor);
ExecutionContextLifecycleObserver::Trace(visitor);
}
} // namespace blink
// Copyright 2021 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_AUDIO_ENCODER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_AUDIO_ENCODER_H_
#include <memory>
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_codec_state.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_encoded_audio_chunk_output_callback.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_video_encoder_output_callback.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_webcodecs_error_callback.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/webcodecs/audio_frame.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink {
class ExceptionState;
class AudioEncoderConfig;
class AudioEncoderInit;
class MODULES_EXPORT AudioEncoder final
: public ScriptWrappable,
public ActiveScriptWrappable<AudioEncoder>,
public ExecutionContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO();
public:
static AudioEncoder* Create(ScriptState*,
const AudioEncoderInit*,
ExceptionState&);
AudioEncoder(ScriptState*, const AudioEncoderInit*, ExceptionState&);
~AudioEncoder() override;
// audio_encoder.idl implementation.
int32_t encodeQueueSize();
void encode(AudioFrame* frame, ExceptionState&);
void configure(const AudioEncoderConfig*, ExceptionState&);
ScriptPromise flush(ExceptionState&);
void reset(ExceptionState&);
void close(ExceptionState&);
String state();
// ExecutionContextLifecycleObserver override.
void ContextDestroyed() override;
// ScriptWrappable override.
bool HasPendingActivity() const override { return false; }
// GarbageCollected override.
void Trace(Visitor*) const override;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBCODECS_AUDIO_ENCODER_H_
// Copyright 2021 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.
// https://github.com/WICG/web-codecs
[
Exposed=(Window,DedicatedWorker),
RuntimeEnabled=WebCodecs,
ActiveScriptWrappable
] interface AudioEncoder {
[CallWith=ScriptState, RaisesException, MeasureAs=WebCodecsAudioEncoder]
constructor(AudioEncoderInit init);
// The number of pending encode requests. This does not include requests
// that have been sent to the underlying codec.
readonly attribute long encodeQueueSize;
// Enqueues a control message to configure the audio encoder for encoding
// audio frames as described by config.
[RaisesException]
void configure(AudioEncoderConfig config);
// Enqueues a request to encode a frame.
// Results of the encoding (EncodedAudioChunk) are returned via
// the output callback provided in configure().
[RaisesException]
void encode(AudioFrame frame);
// 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.
// Requires configure() to be call to set configuration once again.
[RaisesException]
void reset();
// Enqueues a request to shut down the encoder and free its resources.
[RaisesException]
void close();
// Which state the encoder is in, indicating which methods can be called.
readonly attribute CodecState state;
};
// Copyright 2021 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.
// https://github.com/WICG/web-codecs
dictionary AudioEncoderConfig {
// TODO(chcunningham): reference spec registry.
required DOMString codec;
// Rate of samples per second. 44100, 48000, etc.
required unsigned long sampleRate;
// 1, 2, etc.
required unsigned long numberOfChannels;
};
// Copyright 2021 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.
// https://github.com/WICG/web-codecs
dictionary AudioEncoderInit {
required EncodedAudioChunkOutputCallback output;
required WebCodecsErrorCallback error;
};
// Copyright 2021 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.
// https://github.com/WICG/web-codecs
[RuntimeEnabled=WebCodecs]
callback EncodedAudioChunkOutputCallback = void(EncodedAudioChunk output);
......@@ -4,6 +4,7 @@
modules_idl_files = [
"audio_decoder.idl",
"audio_encoder.idl",
"audio_frame.idl",
"encoded_video_chunk.idl",
"encoded_audio_chunk.idl",
......@@ -17,6 +18,7 @@ modules_idl_files = [
modules_callback_function_idl_files = [
"audio_frame_output_callback.idl",
"encoded_audio_chunk_output_callback.idl",
"video_encoder_output_callback.idl",
"video_frame_output_callback.idl",
"webcodecs_error_callback.idl",
......@@ -25,6 +27,8 @@ modules_callback_function_idl_files = [
modules_dictionary_idl_files = [
"audio_decoder_config.idl",
"audio_decoder_init.idl",
"audio_encoder_config.idl",
"audio_encoder_init.idl",
"avc_encoder_config.idl",
"encoded_video_chunk_init.idl",
"encoded_audio_chunk_init.idl",
......
......@@ -12,26 +12,18 @@
[CallWith=ScriptState, RaisesException, MeasureAs=WebCodecsVideoEncoder]
constructor(VideoEncoderInit init);
// The number of pending encode requests. This does not include requests that
// have been sent to the underlying codec.
//
// Applications can minimize underflow by enqueueing encode requests until
// |encodeQueueSize| is greater than a constant.
// The number of pending encode requests. This does not include requests
// that have been sent to the underlying codec.
readonly attribute long encodeQueueSize;
// 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.
// Enqueues a control message to configure the video encoder for encoding
// frames as described by config.
[RaisesException]
void configure(VideoEncoderConfig config);
// Enqueues a request to encode a frame.
// Results of the encoding (EncodedVideoChunk) are returned via
// the output callback provided in configure().
// Resolved when encoded processed the given frame.
// 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.
[RaisesException]
void encode(VideoFrame frame,
optional VideoEncoderEncodeOptions options = {});
......@@ -46,13 +38,11 @@
//
// 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.
// Requires 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.
[RaisesException]
void close();
......
......@@ -26,6 +26,16 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method decode
[Worker] method flush
[Worker] method reset
[Worker] interface AudioEncoder
[Worker] attribute @@toStringTag
[Worker] getter encodeQueueSize
[Worker] getter state
[Worker] method close
[Worker] method configure
[Worker] method constructor
[Worker] method encode
[Worker] method flush
[Worker] method reset
[Worker] interface AudioFrame
[Worker] attribute @@toStringTag
[Worker] getter buffer
......
......@@ -285,6 +285,16 @@ interface AudioDestinationNode : AudioNode
attribute @@toStringTag
getter maxChannelCount
method constructor
interface AudioEncoder
attribute @@toStringTag
getter encodeQueueSize
getter state
method close
method configure
method constructor
method encode
method flush
method reset
interface AudioFrame
attribute @@toStringTag
getter buffer
......
......@@ -30825,6 +30825,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3748" label="SamePartyCookieInclusionOverruledSameSite"/>
<int value="3749" label="EmbedElementWithoutTypeSrcChanged"/>
<int value="3750" label="PaymentHandlerStandardizedPaymentMethodIdentifier"/>
<int value="3751" label="WebCodecsAudioEncoder"/>
</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