blob: 8ef0060eeb612a72d19e82e05cbbeeac7f90762b [file] [log] [blame]
Mikhail Naganov60ced762020-07-23 18:08:26 +00001/*
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@7.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 *
28 * 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 *
Mikhail Naganovd7d25802020-12-22 23:20:57 +000045 * R (audio HAL 6.0) defined keys are as follows [2]:
Mikhail Naganov60ced762020-07-23 18:08:26 +000046 * "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 *
Abhishek Kattic52f06e2020-12-22 13:12:18 +110054 * S (audio HAL 7.0) in addition adds the following keys:
55 * "presentation-id", int32
56 * "program-id", int32
57 * "presentation-content-classifier", int32
58 * presentation-content-classifier key values can be referenced from
59 * frameworks/base/media/java/android/media/AudioPresentation.java
60 * i.e AudioPresentation.ContentClassifier
61 * It can contain any of the below values
62 * CONTENT_UNKNOWN = -1,
63 * CONTENT_MAIN = 0,
64 * CONTENT_MUSIC_AND_EFFECTS = 1,
65 * CONTENT_VISUALLY_IMPAIRED = 2,
66 * CONTENT_HEARING_IMPAIRED = 3,
67 * CONTENT_DIALOG = 4,
68 * CONTENT_COMMENTARY = 5,
69 * CONTENT_EMERGENCY = 6,
70 * CONTENT_VOICEOVER = 7
71 * "presentation-language", string // represents ISO 639-2 (three letter code)
72 *
Mikhail Naganov60ced762020-07-23 18:08:26 +000073 * Parceling Format:
74 * All values are native endian order. [1]
75 *
76 * using type_size_t = uint32_t;
77 * using index_size_t = uint32_t;
78 * using datum_size_t = uint32_t;
79 *
80 * Permitted type indexes are
81 * TYPE_NONE = 0, // Reserved
82 * TYPE_INT32 = 1,
83 * TYPE_INT64 = 2,
84 * TYPE_FLOAT = 3,
85 * TYPE_DOUBLE = 4,
86 * TYPE_STRING = 5,
87 * TYPE_DATA = 6, // A data table of <String, Datum>
88 *
89 * Datum = {
90 * (type_size_t) Type (the type index from type_as_value<T>.)
91 * (datum_size_t) Size (size of the Payload)
92 * (byte string) Payload<Type>
93 * }
94 *
95 * The data is specified in native endian order.
96 * Since the size of the Payload is always present, unknown types may be skipped.
97 *
98 * Payload<Fixed-size Primitive_Value>
99 * [ sizeof(Primitive_Value) in raw bytes ]
100 *
101 * Example of Payload<Int32> of 123:
102 * Payload<Int32>
103 * [ value of 123 ] = 0x7b 0x00 0x00 0x00 123
104 *
105 * Payload<String>
106 * [ (index_size_t) length, not including zero terminator.]
107 * [ (length) raw bytes ]
108 *
109 * Example of Payload<String> of std::string("hi"):
110 * [ (index_size_t) length ] = 0x02 0x00 0x00 0x00 2 strlen("hi")
111 * [ raw bytes "hi" ] = 0x68 0x69 "hi"
112 *
113 * Payload<Data>
114 * [ (index_size_t) entries ]
115 * [ raw bytes (entry 1) Key (Payload<String>)
116 * Value (Datum)
117 * ... (until #entries) ]
118 *
119 * Example of Payload<Data> of {{"hello", "world"},
120 * {"value", (int32_t)1000}};
121 * [ (index_size_t) #entries ] = 0x02 0x00 0x00 0x00 2 entries
122 * Key (Payload<String>)
123 * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("hello")
124 * [ raw bytes "hello" ] = 0x68 0x65 0x6c 0x6c 0x6f "hello"
125 * Value (Datum)
126 * [ (type_size_t) type ] = 0x05 0x00 0x00 0x00 5 (TYPE_STRING)
127 * [ (datum_size_t) size ] = 0x09 0x00 0x00 0x00 sizeof(index_size_t) +
128 * strlen("world")
129 * Payload<String>
130 * [ (index_size_t) length ] = 0x05 0x00 0x00 0x00 5 strlen("world")
131 * [ raw bytes "world" ] = 0x77 0x6f 0x72 0x6c 0x64 "world"
132 * Key (Payload<String>)
133 * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("value")
134 * [ raw bytes "value" ] = 0x76 0x61 0x6c 0x75 0x65 "value"
135 * Value (Datum)
136 * [ (type_size_t) type ] = 0x01 0x00 0x00 0x00 1 (TYPE_INT32)
137 * [ (datum_size_t) size ] = 0x04 0x00 0x00 0x00 4 sizeof(int32_t)
138 * Payload<Int32>
139 * [ raw bytes 1000 ] = 0xe8 0x03 0x00 0x00 1000
140 *
141 * The contents of audioMetadata is a Payload<Data>.
142 * An implementation dependent detail is that the Keys are always
143 * stored sorted, so the byte string representation generated is unique.
144 *
145 * Vendor keys are allowed for informational and debugging purposes.
146 * Vendor keys should consist of the vendor company name followed
147 * by a dot; for example, "vendorCompany.someVolume" [2].
148 *
149 * [1] system/media/audio_utils/include/audio_utils/Metadata.h
150 * [2] frameworks/base/media/java/android/media/AudioMetadata.java
151 * [3] system/media/audio_utils/tests/metadata_tests.cpp
152 * [4] cts/tests/tests/media/src/android/media/cts/AudioMetadataTest.java
153 *
154 * @param audioMetadata is a buffer containing decoded format changes
155 * reported by codec. The buffer contains data that can be transformed
156 * to audio metadata, which is a C++ object based map.
157 */
158 oneway onCodecFormatChanged(vec<uint8_t> audioMetadata);
159};