[M120 Migration][MM] Framerate calculation
[platform/framework/web/chromium-efl.git] / media / mojo / mojom / audio_encoder.mojom
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.
4
5 module media.mojom;
6
7 import "media/mojo/mojom/media_types.mojom";
8 import "media/mojo/mojom/audio_parameters.mojom";
9 import "mojo/public/mojom/base/time.mojom";
10
11 enum AacOutputFormat { kAAC, kADTS };
12 struct AacAudioEncoderConfig {
13   AacOutputFormat format;
14 };
15
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.
20   AudioCodec codec;
21
22   // Number of channels.
23   uint8 channel_count;
24
25   // Sample rate of the buffer, number of audio samples per second.
26   uint32 sample_rate;
27
28   // Target encoded bitrate - bits per second of playback
29   // 0 - if client has no bitrate preference.
30   uint32 bitrate;
31
32   // AAC specific parts of the config
33   AacAudioEncoderConfig aac;
34 };
35
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;
42
43   // Presentation time of the encoded audio
44   mojo_base.mojom.TimeDelta timestamp;
45
46   // Duration of the encoded audio stretch
47   mojo_base.mojom.TimeDelta duration;
48
49   // Compressed audio data blob (e.g. opus, AAC etc)
50   array<uint8> data;
51 };
52
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
57   // etc.
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);
63
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);
68
69   // Requests all outputs for already encoded frames to be
70   // produced via AudioEncoderClient.EncodedBufferReady().
71   // Returns errors as |status|.
72   Flush() => (EncoderStatus status);
73 };
74
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);
85 };