blob: 9c8871306e0098f4172d5a5e99ef6807602dbb50 [file] [log] [blame]
jiabin5d116122020-02-12 13:05:44 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware.audio@6.0;
18
19/**
20 * Asynchronous stream out event callback interface. The interface provides
21 * a way for the HAL to notify platform when there are changes, e.g. codec
22 * format change, from the lower layer.
23 */
24interface IStreamOutEventCallback {
25 /**
26 * Codec format changed.
27 *
Andy Hunge6b9c772020-04-30 00:20:48 -070028 * onCodecFormatChanged returns an AudioMetadata object in read-only ByteString format.
29 * It represents the most recent codec format decoded by a HW audio decoder.
30 *
31 * Codec format is an optional message from HW audio decoders. It serves to
32 * notify the application about the codec format and audio objects contained
33 * within the compressed audio stream for control, informational,
34 * and display purposes.
35 *
36 * audioMetadata ByteString is convertible to an AudioMetadata object through
37 * both a C++ and a C API present in Metadata.h [1], or through a Java API present
38 * in AudioMetadata.java [2].
39 *
40 * The ByteString format is a stable format used for parcelling (marshalling) across
41 * JNI, AIDL, and HIDL interfaces. The test for R compatibility for native marshalling
42 * is TEST(metadata_tests, compatibility_R) [3]. The test for R compatibility for JNI
43 * marshalling is android.media.cts.AudioMetadataTest#testCompatibilityR [4].
44 *
45 * R (audio HAL 6.0) defined keys are as follows [2]:
46 * "bitrate", int32
47 * "channel-mask", int32
48 * "mime", string
49 * "sample-rate", int32
50 * "bit-width", int32
51 * "has-atmos", int32
52 * "audio-encoding", int32
53 *
54 * Parceling Format:
55 * All values are native endian order. [1]
56 *
57 * using type_size_t = uint32_t;
58 * using index_size_t = uint32_t;
59 * using datum_size_t = uint32_t;
60 *
61 * Permitted type indexes are
62 * TYPE_NONE = 0, // Reserved
63 * TYPE_INT32 = 1,
64 * TYPE_INT64 = 2,
65 * TYPE_FLOAT = 3,
66 * TYPE_DOUBLE = 4,
67 * TYPE_STRING = 5,
68 * TYPE_DATA = 6, // A data table of <String, Datum>
69 *
70 * Datum = {
71 * (type_size_t) Type (the type index from type_as_value<T>.)
72 * (datum_size_t) Size (size of the Payload)
73 * (byte string) Payload<Type>
74 * }
75 *
76 * The data is specified in native endian order.
77 * Since the size of the Payload is always present, unknown types may be skipped.
78 *
79 * Payload<Fixed-size Primitive_Value>
80 * [ sizeof(Primitive_Value) in raw bytes ]
81 *
82 * Example of Payload<Int32> of 123:
83 * Payload<Int32>
84 * [ value of 123 ] = 0x7b 0x00 0x00 0x00 123
85 *
86 * Payload<String>
87 * [ (index_size_t) length, not including zero terminator.]
88 * [ (length) raw bytes ]
89 *
90 * Example of Payload<String> of std::string("hi"):
91 * [ (index_size_t) length ] = 0x02 0x00 0x00 0x00 2 strlen("hi")
92 * [ raw bytes "hi" ] = 0x68 0x69 "hi"
93 *
94 * Payload<Data>
95 * [ (index_size_t) entries ]
96 * [ raw bytes (entry 1) Key (Payload<String>)
97 * Value (Datum)
98 * ... (until #entries) ]
99 *
100 * Example of Payload<Data> of {{"hello", "world"},
101 * {"value", (int32_t)1000}};
102 * [ (index_size_t) #entries ] = 0x02 0x00 0x00 0x00 2 entries
103 * Key (Payload<String>)
104 * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("hello")
105 * [ raw bytes "hello" ] = 0x68 0x65 0x6c 0x6c 0x6f "hello"
106 * Value (Datum)
107 * [ (type_size_t) type ] = 0x05 0x00 0x00 0x00 5 (TYPE_STRING)
108 * [ (datum_size_t) size ] = 0x09 0x00 0x00 0x00 sizeof(index_size_t) +
109 * strlen("world")
110 * Payload<String>
111 * [ (index_size_t) length ] = 0x05 0x00 0x00 0x00 5 strlen("world")
112 * [ raw bytes "world" ] = 0x77 0x6f 0x72 0x6c 0x64 "world"
113 * Key (Payload<String>)
114 * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("value")
115 * [ raw bytes "value" ] = 0x76 0x61 0x6c 0x75 0x65 "value"
116 * Value (Datum)
117 * [ (type_size_t) type ] = 0x01 0x00 0x00 0x00 1 (TYPE_INT32)
118 * [ (datum_size_t) size ] = 0x04 0x00 0x00 0x00 4 sizeof(int32_t)
119 * Payload<Int32>
120 * [ raw bytes 1000 ] = 0xe8 0x03 0x00 0x00 1000
121 *
122 * The contents of audioMetadata is a Payload<Data>.
123 * An implementation dependent detail is that the Keys are always
124 * stored sorted, so the byte string representation generated is unique.
125 *
126 * Vendor keys are allowed for informational and debugging purposes.
127 * Vendor keys should consist of the vendor company name followed
128 * by a dot; for example, "vendorCompany.someVolume" [2].
129 *
130 * [1] system/media/audio_utils/include/audio_utils/Metadata.h
131 * [2] frameworks/base/media/java/android/media/AudioMetadata.java
132 * [3] system/media/audio_utils/tests/metadata_tests.cpp
133 * [4] cts/tests/tests/media/src/android/media/cts/AudioMetadataTest.java
134 *
jiabin5d116122020-02-12 13:05:44 -0800135 * @param audioMetadata is a buffer containing decoded format changes
136 * reported by codec. The buffer contains data that can be transformed
Andy Hunge6b9c772020-04-30 00:20:48 -0700137 * to audio metadata, which is a C++ object based map.
jiabin5d116122020-02-12 13:05:44 -0800138 */
139 oneway onCodecFormatChanged(vec<uint8_t> audioMetadata);
140};