1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 import "media/mojo/mojom/media_types.mojom";
8 import "media/mojo/mojom/audio_parameters.mojom";
9 import "mojo/public/mojom/base/time.mojom";
11 enum AacOutputFormat { kAAC, kADTS };
12 struct AacAudioEncoderConfig {
13 AacOutputFormat format;
16 // This defines a mojo transport format for media::AudioEncoderConfig.
17 // See media/base/audio_encoder.h for descriptions.
18 struct AudioEncoderConfig {
19 // Audio codec to be used for encoding.
22 // Number of channels.
25 // Sample rate of the buffer, number of audio samples per second.
28 // Target encoded bitrate - bits per second of playback
29 // 0 - if client has no bitrate preference.
32 // AAC specific parts of the config
33 AacAudioEncoderConfig aac;
36 // This defines a mojo transport format for media::EncodedAudioBuffer.
37 // See media/base/audio_encoder.h for descriptions.
38 struct EncodedAudioBuffer {
39 // Parameters of the encoded audio (channel count, sample rate etc)
40 // It might be different from parameters provided in AudioEncoderConfig.
41 AudioParameters params;
43 // Presentation time of the encoded audio
44 mojo_base.mojom.TimeDelta timestamp;
46 // Duration of the encoded audio stretch
47 mojo_base.mojom.TimeDelta duration;
49 // Compressed audio data blob (e.g. opus, AAC etc)
53 // An interface for a platform dependent audio encoder that needs to run in
54 // GPU process. It's called from renderers.
55 interface AudioEncoder {
56 // Initializes encoded with a given |config|, prepares underlying resources
58 // |client| will be use to return encoded data.
59 // This must be called only once before any other Encode() and Flush().
60 // Returns errors as |status|.
61 Initialize(pending_associated_remote<AudioEncoderClient> client,
62 AudioEncoderConfig config) => (EncoderStatus status);
64 // Requests contents of audio |buffer| to be encoded, encoded results
65 // produced via AudioEncoderClient.EncodedBufferReady().
66 // Returns errors as |status|.
67 Encode(AudioBuffer buffer) => (EncoderStatus status);
69 // Requests all outputs for already encoded frames to be
70 // produced via AudioEncoderClient.EncodedBufferReady().
71 // Returns errors as |status|.
72 Flush() => (EncoderStatus status);
75 // A complimentary interface for AudioEncoder, bound
76 // in AudioEncoder.Initialize()
77 // It is used for sending encoded audio back to renderer.
78 interface AudioEncoderClient {
79 // Sends the encoded audio buffer back to the mojo client.
80 // |buffer| - encoded audio binary with timestamp and duration.
81 // |description| - codec specific extra data that is sometimes used to
82 // configure decoders.
83 // Empty, if no extra data comes with this buffer.
84 OnEncodedBufferReady(EncodedAudioBuffer buffer, array<uint8> description);