Loading media/libaaudio/fuzzer/libaaudio_fuzzer.cpp +9 −6 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ constexpr int32_t kRandomStringLength = 256; constexpr int32_t kMaxRuns = 100; constexpr int64_t kNanosPerMillisecond = 1000 * 1000; constexpr int32_t kAAudioAttributesTagsMaxSize = 256; constexpr aaudio_direction_t kDirections[] = { AAUDIO_DIRECTION_OUTPUT, AAUDIO_DIRECTION_INPUT, AAUDIO_UNSPECIFIED}; Loading Loading @@ -185,8 +186,8 @@ void LibAaudioFuzzer::invokeAAudioSetAPIs(FuzzedDataProvider &fdp){ AAudioStreamBuilder_setFramesPerDataCallback(mAaudioBuilder, framesPerDataCallback); const size_t tagsNumBytes = fdp.ConsumeIntegralInRange<size_t>( 0, AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE + 10); AAudioStreamBuilder_setTags(mAaudioBuilder, 0, kAAudioAttributesTagsMaxSize + 10); AAudioStreamBuilder_addTag(mAaudioBuilder, (tagsNumBytes == 0 ? nullptr : fdp.ConsumeBytesAsString(tagsNumBytes).c_str())); Loading @@ -200,7 +201,7 @@ void LibAaudioFuzzer::process(const uint8_t *data, size_t size) { int32_t maxFrames = 0; int32_t count = 0; aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN; char tags[AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE + 1]; int numOfTags = 0; invokeAAudioSetAPIs(fdp); Loading Loading @@ -320,7 +321,9 @@ void LibAaudioFuzzer::process(const uint8_t *data, size_t size) { (void)AAudioStream_getBufferSizeInFrames(mAaudioStream); }, [&]() { (void)AAudioStream_getTags(mAaudioStream, tags); char** tags = nullptr; (void)AAudioStream_obtainTags(mAaudioStream, &tags); AAudioStream_releaseTags(mAaudioStream, tags); }, [&]() { (void)AAudioStream_isMMapUsed(mAaudioStream); Loading media/libaaudio/include/system/aaudio/AAudio.h +37 −26 Original line number Diff line number Diff line Loading @@ -27,51 +27,62 @@ extern "C" { #endif /** * The tags string attributes allows OEMs to extend the * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>. * Add one vendor extension tag that the output stream will carry. * * Note that the maximum length includes all tags combined with delimiters and null terminator. * The total size of all added tags, plus one for each tag terminator, must not be greater than * <a href="/reference/android/system/media/audio">AUDIO_ATTRIBUTES_TAGS_MAX_SIZE</a>. * * Note that it matches the equivalent value in * <a href="/reference/android/system/media/audio">AUDIO_ATTRIBUTES_TAGS_MAX_SIZE</a> * in the Android native API. */ #define AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256 /** * Set one or more vendor extension tags that the output stream will carry. * * The tags can be used by the audio policy engine for routing purpose. * The tag can be used by the audio policy engine for routing purpose. * Routing is based on audio attributes, translated into legacy stream type. * The stream types cannot be extended, so the product strategies have been introduced to allow * vendor extension of routing capabilities. * This could, for example, affect how volume and routing is handled for the stream. * * The tags can also be used by a System App to pass vendor specific information through the * The tag can also be used by a System App to pass vendor specific information through the * framework to the HAL. That info could affect routing, ducking or other audio behavior in the HAL. * * By default, audio attributes tags are empty if this method is not called. * * When opening a stream with audio attributes tags, the client should hold * MODIFY_AUDIO_SETTINGS_PRIVILEGED permission. Otherwise, the stream will fail to open. * * @param builder reference provided by AAudio_createStreamBuilder() * @param tags the desired tags to add, which must be UTF-8 format and null-terminated. The size * of the tags must be at most {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. Multiple tags * must be separated by semicolons. * @param tag the desired tag to add, which must be UTF-8 format and null-terminated. * @return {@link #AAUDIO_OK} on success or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the given * tags is null or its length is greater than {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. * tags is null or {@link #AAUDIO_ERROR_OUT_OF_RANGE} if there is not room for more tags. */ aaudio_result_t AAudioStreamBuilder_addTag(AAudioStreamBuilder* _Nonnull builder, const char* _Nonnull tag); /** * Clear all the tags that has been added from calling * {@link #AAudioStreamBuilder_addTag}. * * @param builder reference provided by AAudio_createStreamBuilder() */ void AAudioStreamBuilder_clearTags(AAudioStreamBuilder* _Nonnull builder); /** * Allocate and read the audio attributes' tags for the stream into a buffer. * The client is responsible to free the memory for tags by calling * {@link #AAudioStream_releaseTags} unless the number of tags is 0. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @param tags a pointer to a variable that will be set to a pointer to an array of char* pointers * @return number of tags or * {@link #AAUDIO_ERROR_NO_MEMORY} if it fails to allocate memory for tags. */ aaudio_result_t AAudioStreamBuilder_setTags(AAudioStreamBuilder* _Nonnull builder, const char* _Nonnull tags); int32_t AAudioStream_obtainTags(AAudioStream* _Nonnull stream, char* _Nullable* _Nullable* _Nonnull tags); /** * Read the audio attributes' tags for the stream into a buffer. * The caller is responsible for allocating and freeing the returned data. * Free the memory containing the tags that is allocated when calling * {@link #AAudioStream_obtainTags}. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @param tags pointer to write the value to in UTF-8 that containing OEM extension tags. It must * be sized with {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. * @return {@link #AAUDIO_OK} or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the given tags is null. * @param tags reference provided by AAudioStream_obtainTags() */ aaudio_result_t AAudioStream_getTags(AAudioStream* _Nonnull stream, char* _Nonnull tags); void AAudioStream_releaseTags(AAudioStream* _Nonnull stream, char* _Nonnull * _Nullable tags); #ifdef __cplusplus } Loading media/libaaudio/src/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,7 @@ cc_library { "libaudioclient_aidl_conversion", "libaudiofoundation", "libaudioutils", "libbase", "libbinder", "libcutils", "liblog", Loading media/libaaudio/src/binding/AAudioStreamConfiguration.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& par setUsage(parcelable.usage); static_assert(sizeof(aaudio_content_type_t) == sizeof(parcelable.contentType)); setContentType(parcelable.contentType); setTags(parcelable.tags); setTags(std::set(parcelable.tags.begin(), parcelable.tags.end())); static_assert(sizeof(aaudio_spatialization_behavior_t) == sizeof(parcelable.spatializationBehavior)); setSpatializationBehavior(parcelable.spatializationBehavior); Loading Loading @@ -123,8 +123,8 @@ StreamParameters AAudioStreamConfiguration::parcelable() const { result.usage = getUsage(); static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType)); result.contentType = getContentType(); std::optional<std::string> tags = getTags(); result.tags = tags.has_value() ? tags.value() : ""; auto tags = getTags(); result.tags = std::vector(tags.begin(), tags.end()); static_assert( sizeof(aaudio_spatialization_behavior_t) == sizeof(result.spatializationBehavior)); result.spatializationBehavior = getSpatializationBehavior(); Loading media/libaaudio/src/binding/aidl/aaudio/StreamParameters.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ parcelable StreamParameters { int /* aaudio_direction_t */ direction; // = AAUDIO_DIRECTION_OUTPUT; int /* aaudio_usage_t */ usage; // = AAUDIO_UNSPECIFIED; int /* aaudio_content_type_t */ contentType; // = AAUDIO_UNSPECIFIED; @utf8InCpp String tags; /* UTF8 */ @utf8InCpp String[] tags; /* UTF8 */ int /* aaudio_spatialization_behavior_t */spatializationBehavior; //= AAUDIO_UNSPECIFIED; boolean isContentSpatialized; // = false; int /* aaudio_input_preset_t */ inputPreset; // = AAUDIO_UNSPECIFIED; Loading Loading
media/libaaudio/fuzzer/libaaudio_fuzzer.cpp +9 −6 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ constexpr int32_t kRandomStringLength = 256; constexpr int32_t kMaxRuns = 100; constexpr int64_t kNanosPerMillisecond = 1000 * 1000; constexpr int32_t kAAudioAttributesTagsMaxSize = 256; constexpr aaudio_direction_t kDirections[] = { AAUDIO_DIRECTION_OUTPUT, AAUDIO_DIRECTION_INPUT, AAUDIO_UNSPECIFIED}; Loading Loading @@ -185,8 +186,8 @@ void LibAaudioFuzzer::invokeAAudioSetAPIs(FuzzedDataProvider &fdp){ AAudioStreamBuilder_setFramesPerDataCallback(mAaudioBuilder, framesPerDataCallback); const size_t tagsNumBytes = fdp.ConsumeIntegralInRange<size_t>( 0, AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE + 10); AAudioStreamBuilder_setTags(mAaudioBuilder, 0, kAAudioAttributesTagsMaxSize + 10); AAudioStreamBuilder_addTag(mAaudioBuilder, (tagsNumBytes == 0 ? nullptr : fdp.ConsumeBytesAsString(tagsNumBytes).c_str())); Loading @@ -200,7 +201,7 @@ void LibAaudioFuzzer::process(const uint8_t *data, size_t size) { int32_t maxFrames = 0; int32_t count = 0; aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN; char tags[AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE + 1]; int numOfTags = 0; invokeAAudioSetAPIs(fdp); Loading Loading @@ -320,7 +321,9 @@ void LibAaudioFuzzer::process(const uint8_t *data, size_t size) { (void)AAudioStream_getBufferSizeInFrames(mAaudioStream); }, [&]() { (void)AAudioStream_getTags(mAaudioStream, tags); char** tags = nullptr; (void)AAudioStream_obtainTags(mAaudioStream, &tags); AAudioStream_releaseTags(mAaudioStream, tags); }, [&]() { (void)AAudioStream_isMMapUsed(mAaudioStream); Loading
media/libaaudio/include/system/aaudio/AAudio.h +37 −26 Original line number Diff line number Diff line Loading @@ -27,51 +27,62 @@ extern "C" { #endif /** * The tags string attributes allows OEMs to extend the * <a href="/reference/android/media/AudioAttributes">AudioAttributes</a>. * Add one vendor extension tag that the output stream will carry. * * Note that the maximum length includes all tags combined with delimiters and null terminator. * The total size of all added tags, plus one for each tag terminator, must not be greater than * <a href="/reference/android/system/media/audio">AUDIO_ATTRIBUTES_TAGS_MAX_SIZE</a>. * * Note that it matches the equivalent value in * <a href="/reference/android/system/media/audio">AUDIO_ATTRIBUTES_TAGS_MAX_SIZE</a> * in the Android native API. */ #define AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE 256 /** * Set one or more vendor extension tags that the output stream will carry. * * The tags can be used by the audio policy engine for routing purpose. * The tag can be used by the audio policy engine for routing purpose. * Routing is based on audio attributes, translated into legacy stream type. * The stream types cannot be extended, so the product strategies have been introduced to allow * vendor extension of routing capabilities. * This could, for example, affect how volume and routing is handled for the stream. * * The tags can also be used by a System App to pass vendor specific information through the * The tag can also be used by a System App to pass vendor specific information through the * framework to the HAL. That info could affect routing, ducking or other audio behavior in the HAL. * * By default, audio attributes tags are empty if this method is not called. * * When opening a stream with audio attributes tags, the client should hold * MODIFY_AUDIO_SETTINGS_PRIVILEGED permission. Otherwise, the stream will fail to open. * * @param builder reference provided by AAudio_createStreamBuilder() * @param tags the desired tags to add, which must be UTF-8 format and null-terminated. The size * of the tags must be at most {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. Multiple tags * must be separated by semicolons. * @param tag the desired tag to add, which must be UTF-8 format and null-terminated. * @return {@link #AAUDIO_OK} on success or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the given * tags is null or its length is greater than {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. * tags is null or {@link #AAUDIO_ERROR_OUT_OF_RANGE} if there is not room for more tags. */ aaudio_result_t AAudioStreamBuilder_addTag(AAudioStreamBuilder* _Nonnull builder, const char* _Nonnull tag); /** * Clear all the tags that has been added from calling * {@link #AAudioStreamBuilder_addTag}. * * @param builder reference provided by AAudio_createStreamBuilder() */ void AAudioStreamBuilder_clearTags(AAudioStreamBuilder* _Nonnull builder); /** * Allocate and read the audio attributes' tags for the stream into a buffer. * The client is responsible to free the memory for tags by calling * {@link #AAudioStream_releaseTags} unless the number of tags is 0. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @param tags a pointer to a variable that will be set to a pointer to an array of char* pointers * @return number of tags or * {@link #AAUDIO_ERROR_NO_MEMORY} if it fails to allocate memory for tags. */ aaudio_result_t AAudioStreamBuilder_setTags(AAudioStreamBuilder* _Nonnull builder, const char* _Nonnull tags); int32_t AAudioStream_obtainTags(AAudioStream* _Nonnull stream, char* _Nullable* _Nullable* _Nonnull tags); /** * Read the audio attributes' tags for the stream into a buffer. * The caller is responsible for allocating and freeing the returned data. * Free the memory containing the tags that is allocated when calling * {@link #AAudioStream_obtainTags}. * * @param stream reference provided by AAudioStreamBuilder_openStream() * @param tags pointer to write the value to in UTF-8 that containing OEM extension tags. It must * be sized with {@link #AAUDIO_ATTRIBUTES_TAGS_MAX_SIZE}. * @return {@link #AAUDIO_OK} or {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT} if the given tags is null. * @param tags reference provided by AAudioStream_obtainTags() */ aaudio_result_t AAudioStream_getTags(AAudioStream* _Nonnull stream, char* _Nonnull tags); void AAudioStream_releaseTags(AAudioStream* _Nonnull stream, char* _Nonnull * _Nullable tags); #ifdef __cplusplus } Loading
media/libaaudio/src/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,7 @@ cc_library { "libaudioclient_aidl_conversion", "libaudiofoundation", "libaudioutils", "libbase", "libbinder", "libcutils", "liblog", Loading
media/libaaudio/src/binding/AAudioStreamConfiguration.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ AAudioStreamConfiguration::AAudioStreamConfiguration(const StreamParameters& par setUsage(parcelable.usage); static_assert(sizeof(aaudio_content_type_t) == sizeof(parcelable.contentType)); setContentType(parcelable.contentType); setTags(parcelable.tags); setTags(std::set(parcelable.tags.begin(), parcelable.tags.end())); static_assert(sizeof(aaudio_spatialization_behavior_t) == sizeof(parcelable.spatializationBehavior)); setSpatializationBehavior(parcelable.spatializationBehavior); Loading Loading @@ -123,8 +123,8 @@ StreamParameters AAudioStreamConfiguration::parcelable() const { result.usage = getUsage(); static_assert(sizeof(aaudio_content_type_t) == sizeof(result.contentType)); result.contentType = getContentType(); std::optional<std::string> tags = getTags(); result.tags = tags.has_value() ? tags.value() : ""; auto tags = getTags(); result.tags = std::vector(tags.begin(), tags.end()); static_assert( sizeof(aaudio_spatialization_behavior_t) == sizeof(result.spatializationBehavior)); result.spatializationBehavior = getSpatializationBehavior(); Loading
media/libaaudio/src/binding/aidl/aaudio/StreamParameters.aidl +1 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ parcelable StreamParameters { int /* aaudio_direction_t */ direction; // = AAUDIO_DIRECTION_OUTPUT; int /* aaudio_usage_t */ usage; // = AAUDIO_UNSPECIFIED; int /* aaudio_content_type_t */ contentType; // = AAUDIO_UNSPECIFIED; @utf8InCpp String tags; /* UTF8 */ @utf8InCpp String[] tags; /* UTF8 */ int /* aaudio_spatialization_behavior_t */spatializationBehavior; //= AAUDIO_UNSPECIFIED; boolean isContentSpatialized; // = false; int /* aaudio_input_preset_t */ inputPreset; // = AAUDIO_UNSPECIFIED; Loading