From 51cdd13351c1b1b4bf0a1c4f027101a728b6d762 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Thu, 12 Jul 2018 19:38:35 -0700 Subject: [PATCH 1/2] Aaudio: Implement app shareable flag instead of -size hack Test: adb shell data/nativetest64/write_sine/write_sine -pl -m3 -x Bug: 38118159 Change-Id: I2e2fc5801ee9f45565be6f989c0d83d0fdf54618 Signed-off-by: Kevin Rocard --- .../include/core/all-versions/default/Stream.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Stream.h b/audio/core/all-versions/default/include/core/all-versions/default/Stream.h index 6f79429c61..375759dcff 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/Stream.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/Stream.h @@ -163,6 +163,22 @@ Return StreamMmap::createMmapBuffer(int32_t minSizeFrames, size_t frame if (retval == Result::OK) { hidlHandle = native_handle_create(1, 0); hidlHandle->data[0] = halInfo.shared_memory_fd; + + // Negative buffer size frame is a legacy hack to indicate that the buffer + // is shareable to applications before the relevant flag was introduced + bool applicationShareable = + halInfo.flags & AUDIO_MMAP_APPLICATION_SHAREABLE || halInfo.buffer_size_frames < 0; + halInfo.buffer_size_frames = abs(halInfo.buffer_size_frames); +#ifdef AUDIO_HAL_VERSION_2_0 + if (applicationShareable) { + halInfo.buffer_size_frames *= -1; + } +#else + info.flags = + halInfo.flags | (applicationShareable ? MmapBufferFlag::APPLICATION_SHAREABLE + : MmapBufferFlag::NONE); +#endif + info.sharedMemory = hidl_memory("audio_buffer", hidlHandle, frameSize * halInfo.buffer_size_frames); info.bufferSizeFrames = halInfo.buffer_size_frames; From 86910f0fc57bad8c621dff70c267e97a11046200 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Fri, 10 Aug 2018 09:59:55 -0700 Subject: [PATCH 2/2] Audio default HAL: hidl_memory size must be positive hidl_memory size is not used on the framework side but is checked by the hidl framework to be a sensible value. Due to a hack in O and P, the value can be negative, this leads to errors in HIDL. This patch make sure the hidl_memory size is always positive and thus not affected by the hack. Test: adb shell data/nativetest64/write_sine/write_sine -pl -m3 -x Bug: 38118159 Change-Id: Ie53c46c558e8042d74ee32b55219195da82e4bcc Signed-off-by: Kevin Rocard --- .../default/include/core/all-versions/default/Stream.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Stream.h b/audio/core/all-versions/default/include/core/all-versions/default/Stream.h index 375759dcff..7cf12dd433 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/Stream.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/Stream.h @@ -169,6 +169,8 @@ Return StreamMmap::createMmapBuffer(int32_t minSizeFrames, size_t frame bool applicationShareable = halInfo.flags & AUDIO_MMAP_APPLICATION_SHAREABLE || halInfo.buffer_size_frames < 0; halInfo.buffer_size_frames = abs(halInfo.buffer_size_frames); + info.sharedMemory = // hidl_memory size must always be positive + hidl_memory("audio_buffer", hidlHandle, frameSize * halInfo.buffer_size_frames); #ifdef AUDIO_HAL_VERSION_2_0 if (applicationShareable) { halInfo.buffer_size_frames *= -1; @@ -178,9 +180,6 @@ Return StreamMmap::createMmapBuffer(int32_t minSizeFrames, size_t frame halInfo.flags | (applicationShareable ? MmapBufferFlag::APPLICATION_SHAREABLE : MmapBufferFlag::NONE); #endif - - info.sharedMemory = - hidl_memory("audio_buffer", hidlHandle, frameSize * halInfo.buffer_size_frames); info.bufferSizeFrames = halInfo.buffer_size_frames; info.burstSizeFrames = halInfo.burst_size_frames; }