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 * Parceling Format: 55*4d7e907cSAndroid Build Coastguard Worker * All values are native endian order. [1] 56*4d7e907cSAndroid Build Coastguard Worker * 57*4d7e907cSAndroid Build Coastguard Worker * using type_size_t = uint32_t; 58*4d7e907cSAndroid Build Coastguard Worker * using index_size_t = uint32_t; 59*4d7e907cSAndroid Build Coastguard Worker * using datum_size_t = uint32_t; 60*4d7e907cSAndroid Build Coastguard Worker * 61*4d7e907cSAndroid Build Coastguard Worker * Permitted type indexes are 62*4d7e907cSAndroid Build Coastguard Worker * TYPE_NONE = 0, // Reserved 63*4d7e907cSAndroid Build Coastguard Worker * TYPE_INT32 = 1, 64*4d7e907cSAndroid Build Coastguard Worker * TYPE_INT64 = 2, 65*4d7e907cSAndroid Build Coastguard Worker * TYPE_FLOAT = 3, 66*4d7e907cSAndroid Build Coastguard Worker * TYPE_DOUBLE = 4, 67*4d7e907cSAndroid Build Coastguard Worker * TYPE_STRING = 5, 68*4d7e907cSAndroid Build Coastguard Worker * TYPE_DATA = 6, // A data table of <String, Datum> 69*4d7e907cSAndroid Build Coastguard Worker * 70*4d7e907cSAndroid Build Coastguard Worker * Datum = { 71*4d7e907cSAndroid Build Coastguard Worker * (type_size_t) Type (the type index from type_as_value<T>.) 72*4d7e907cSAndroid Build Coastguard Worker * (datum_size_t) Size (size of the Payload) 73*4d7e907cSAndroid Build Coastguard Worker * (byte string) Payload<Type> 74*4d7e907cSAndroid Build Coastguard Worker * } 75*4d7e907cSAndroid Build Coastguard Worker * 76*4d7e907cSAndroid Build Coastguard Worker * The data is specified in native endian order. 77*4d7e907cSAndroid Build Coastguard Worker * Since the size of the Payload is always present, unknown types may be skipped. 78*4d7e907cSAndroid Build Coastguard Worker * 79*4d7e907cSAndroid Build Coastguard Worker * Payload<Fixed-size Primitive_Value> 80*4d7e907cSAndroid Build Coastguard Worker * [ sizeof(Primitive_Value) in raw bytes ] 81*4d7e907cSAndroid Build Coastguard Worker * 82*4d7e907cSAndroid Build Coastguard Worker * Example of Payload<Int32> of 123: 83*4d7e907cSAndroid Build Coastguard Worker * Payload<Int32> 84*4d7e907cSAndroid Build Coastguard Worker * [ value of 123 ] = 0x7b 0x00 0x00 0x00 123 85*4d7e907cSAndroid Build Coastguard Worker * 86*4d7e907cSAndroid Build Coastguard Worker * Payload<String> 87*4d7e907cSAndroid Build Coastguard Worker * [ (index_size_t) length, not including zero terminator.] 88*4d7e907cSAndroid Build Coastguard Worker * [ (length) raw bytes ] 89*4d7e907cSAndroid Build Coastguard Worker * 90*4d7e907cSAndroid Build Coastguard Worker * Example of Payload<String> of std::string("hi"): 91*4d7e907cSAndroid Build Coastguard Worker * [ (index_size_t) length ] = 0x02 0x00 0x00 0x00 2 strlen("hi") 92*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes "hi" ] = 0x68 0x69 "hi" 93*4d7e907cSAndroid Build Coastguard Worker * 94*4d7e907cSAndroid Build Coastguard Worker * Payload<Data> 95*4d7e907cSAndroid Build Coastguard Worker * [ (index_size_t) entries ] 96*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes (entry 1) Key (Payload<String>) 97*4d7e907cSAndroid Build Coastguard Worker * Value (Datum) 98*4d7e907cSAndroid Build Coastguard Worker * ... (until #entries) ] 99*4d7e907cSAndroid Build Coastguard Worker * 100*4d7e907cSAndroid Build Coastguard Worker * Example of Payload<Data> of {{"hello", "world"}, 101*4d7e907cSAndroid Build Coastguard Worker * {"value", (int32_t)1000}}; 102*4d7e907cSAndroid Build Coastguard Worker * [ (index_size_t) #entries ] = 0x02 0x00 0x00 0x00 2 entries 103*4d7e907cSAndroid Build Coastguard Worker * Key (Payload<String>) 104*4d7e907cSAndroid Build Coastguard Worker * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("hello") 105*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes "hello" ] = 0x68 0x65 0x6c 0x6c 0x6f "hello" 106*4d7e907cSAndroid Build Coastguard Worker * Value (Datum) 107*4d7e907cSAndroid Build Coastguard Worker * [ (type_size_t) type ] = 0x05 0x00 0x00 0x00 5 (TYPE_STRING) 108*4d7e907cSAndroid Build Coastguard Worker * [ (datum_size_t) size ] = 0x09 0x00 0x00 0x00 sizeof(index_size_t) + 109*4d7e907cSAndroid Build Coastguard Worker * strlen("world") 110*4d7e907cSAndroid Build Coastguard Worker * Payload<String> 111*4d7e907cSAndroid Build Coastguard Worker * [ (index_size_t) length ] = 0x05 0x00 0x00 0x00 5 strlen("world") 112*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes "world" ] = 0x77 0x6f 0x72 0x6c 0x64 "world" 113*4d7e907cSAndroid Build Coastguard Worker * Key (Payload<String>) 114*4d7e907cSAndroid Build Coastguard Worker * [ index_size_t length ] = 0x05 0x00 0x00 0x00 5 strlen("value") 115*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes "value" ] = 0x76 0x61 0x6c 0x75 0x65 "value" 116*4d7e907cSAndroid Build Coastguard Worker * Value (Datum) 117*4d7e907cSAndroid Build Coastguard Worker * [ (type_size_t) type ] = 0x01 0x00 0x00 0x00 1 (TYPE_INT32) 118*4d7e907cSAndroid Build Coastguard Worker * [ (datum_size_t) size ] = 0x04 0x00 0x00 0x00 4 sizeof(int32_t) 119*4d7e907cSAndroid Build Coastguard Worker * Payload<Int32> 120*4d7e907cSAndroid Build Coastguard Worker * [ raw bytes 1000 ] = 0xe8 0x03 0x00 0x00 1000 121*4d7e907cSAndroid Build Coastguard Worker * 122*4d7e907cSAndroid Build Coastguard Worker * The contents of audioMetadata is a Payload<Data>. 123*4d7e907cSAndroid Build Coastguard Worker * An implementation dependent detail is that the Keys are always 124*4d7e907cSAndroid Build Coastguard Worker * stored sorted, so the byte string representation generated is unique. 125*4d7e907cSAndroid Build Coastguard Worker * 126*4d7e907cSAndroid Build Coastguard Worker * Vendor keys are allowed for informational and debugging purposes. 127*4d7e907cSAndroid Build Coastguard Worker * Vendor keys should consist of the vendor company name followed 128*4d7e907cSAndroid Build Coastguard Worker * by a dot; for example, "vendorCompany.someVolume" [2]. 129*4d7e907cSAndroid Build Coastguard Worker * 130*4d7e907cSAndroid Build Coastguard Worker * [1] system/media/audio_utils/include/audio_utils/Metadata.h 131*4d7e907cSAndroid Build Coastguard Worker * [2] frameworks/base/media/java/android/media/AudioMetadata.java 132*4d7e907cSAndroid Build Coastguard Worker * [3] system/media/audio_utils/tests/metadata_tests.cpp 133*4d7e907cSAndroid Build Coastguard Worker * [4] cts/tests/tests/media/src/android/media/cts/AudioMetadataTest.java 134*4d7e907cSAndroid Build Coastguard Worker * 135*4d7e907cSAndroid Build Coastguard Worker * @param audioMetadata is a buffer containing decoded format changes 136*4d7e907cSAndroid Build Coastguard Worker * reported by codec. The buffer contains data that can be transformed 137*4d7e907cSAndroid Build Coastguard Worker * to audio metadata, which is a C++ object based map. 138*4d7e907cSAndroid Build Coastguard Worker */ 139*4d7e907cSAndroid Build Coastguard Worker oneway onCodecFormatChanged(vec<uint8_t> audioMetadata); 140*4d7e907cSAndroid Build Coastguard Worker}; 141