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