From 79e98e94d5bcd77e4a252001fda175aa3d5b5d46 Mon Sep 17 00:00:00 2001 From: R0rt1z2 Date: Wed, 15 Nov 2023 08:27:07 +0100 Subject: [PATCH] rosemary: libshim_sink: Port to U * Since commit eb57617 [1], the legacy callback interfaces in the Android AudioTrack system have been deprecated and replaced by a newer callback interface. Consequently, the user parameter, which was previously part of the constructor, has been incorporated into this new interface. * To address the resulting build issues, update the function signatures to match the new methods. Although AOSP provides a wrapper [2] for this purpose, it's declared within an anonymous namespace, effectively making it private to its own translation unit. To work around this limitation, provide a local copy of the wrapper instead. * Also format the shim with `clang-format`. - [1]: https://cs.android.com/android/_/android/platform/frameworks/av/+/eb57617e55adf5eb5d554d1ad6a8d1c4b4e3740b - [2]: https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/media/libaudioclient/AudioTrack.cpp;l=289;bpv=1 Change-Id: Ieae7df3f5f003538a0319cc77051322a989b93a8 --- libshims/Android.bp | 5 +++ libshims/LegacyCallbackWrapper.h | 47 ++++++++++++++++++++++++ libshims/libshim_sink.cpp | 63 ++++++++++++++++++-------------- 3 files changed, 87 insertions(+), 28 deletions(-) create mode 100644 libshims/LegacyCallbackWrapper.h diff --git a/libshims/Android.bp b/libshims/Android.bp index 25464e7..8b104ad 100644 --- a/libshims/Android.bp +++ b/libshims/Android.bp @@ -12,10 +12,15 @@ cc_library_shared { compile_multilib: "64", shared_libs: [ "libaudioclient", + "libgui", + "libstagefright", + "libutils", + "libbinder", ], header_libs: [ "libaudioclient_headers", "libmedia_headers", + "libmediametrics_headers", ], } diff --git a/libshims/LegacyCallbackWrapper.h b/libshims/LegacyCallbackWrapper.h new file mode 100644 index 0000000..198a6e9 --- /dev/null +++ b/libshims/LegacyCallbackWrapper.h @@ -0,0 +1,47 @@ +#pragma once + +using namespace android; + +namespace { +class LegacyCallbackWrapper : public AudioTrack::IAudioTrackCallback { + const AudioTrack::legacy_callback_t mCallback; + void *const mData; + +public: + LegacyCallbackWrapper(AudioTrack::legacy_callback_t callback, void *user) + : mCallback(callback), mData(user) {} + size_t onMoreData(const AudioTrack::Buffer &buffer) override { + AudioTrack::Buffer copy = buffer; + mCallback(AudioTrack::EVENT_MORE_DATA, mData, static_cast(©)); + return copy.size(); + } + void onUnderrun() override { + mCallback(AudioTrack::EVENT_UNDERRUN, mData, nullptr); + } + void onLoopEnd(int32_t loopsRemaining) override { + mCallback(AudioTrack::EVENT_LOOP_END, mData, &loopsRemaining); + } + void onMarker(uint32_t markerPosition) override { + mCallback(AudioTrack::EVENT_MARKER, mData, &markerPosition); + } + void onNewPos(uint32_t newPos) override { + mCallback(AudioTrack::EVENT_NEW_POS, mData, &newPos); + } + void onBufferEnd() override { + mCallback(AudioTrack::EVENT_BUFFER_END, mData, nullptr); + } + void onNewIAudioTrack() override { + mCallback(AudioTrack::EVENT_NEW_IAUDIOTRACK, mData, nullptr); + } + void onStreamEnd() override { + mCallback(AudioTrack::EVENT_STREAM_END, mData, nullptr); + } + size_t onCanWriteMoreData(const AudioTrack::Buffer &buffer) override { + AudioTrack::Buffer copy = buffer; + mCallback(AudioTrack::EVENT_CAN_WRITE_MORE_DATA, mData, + static_cast(©)); + return copy.size(); + } +}; + +} // namespace diff --git a/libshims/libshim_sink.cpp b/libshims/libshim_sink.cpp index 3f490c7..588e209 100644 --- a/libshims/libshim_sink.cpp +++ b/libshims/libshim_sink.cpp @@ -4,39 +4,46 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include +#include +#include #include +#include + +#include "LegacyCallbackWrapper.h" using namespace android; extern "C" { -void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEi15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi( - void *thisptr, audio_stream_type_t streamType, uint32_t sampleRate, - audio_format_t format, audio_channel_mask_t channelMask, size_t frameCount, - audio_output_flags_t flags, - const wp &callback, - int32_t notificationFrames, audio_session_t sessionId, - AudioTrack::transfer_type transferType, - const audio_offload_info_t *offloadInfo, - const AttributionSourceState &attributionSource, - const audio_attributes_t *pAttributes, bool doNotReconnect, - float maxRequiredSpeed, audio_port_handle_t selectedDeviceId); -void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEi15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfiRKNSt3__112basic_stringIcNSM_11char_traitsIcEENSM_9allocatorIcEEEE( - void *thisptr, audio_stream_type_t streamType, uint32_t sampleRate, - audio_format_t format, audio_channel_mask_t channelMask, size_t frameCount, - audio_output_flags_t flags, - const wp &callback, - int32_t notificationFrames, audio_session_t sessionId, - AudioTrack::transfer_type transferType, - const audio_offload_info_t *offloadInfo, - const AttributionSourceState &attributionSource, - const audio_attributes_t *pAttributes, bool doNotReconnect, - float maxRequiredSpeed, audio_port_handle_t selectedDeviceId, - const std::string& /* unknown */) { - _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEi15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi( - thisptr, streamType, sampleRate, format, channelMask, frameCount, flags, - callback, notificationFrames, sessionId, transferType, offloadInfo, - attributionSource, pAttributes, doNotReconnect, maxRequiredSpeed, - selectedDeviceId); +void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tRKNS_2spINS_7IMemoryEEE20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEi15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbf( + void *thisptr, audio_stream_type_t streamType, uint32_t sampleRate, + audio_format_t format, audio_channel_mask_t channelMask, size_t frameCount, + audio_output_flags_t flags, + const android::wp &cbf, + int32_t notificationFrames, audio_session_t sessionId, + android::AudioTrack::transfer_type transferType, + const audio_offload_info_t *offloadInfo, + const AttributionSourceState &attributionSource, + const audio_attributes_t *pAttributes, bool doNotReconnect, + float maxRequiredSpeed, audio_port_handle_t selectedDeviceId); + +void _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tm20audio_output_flags_tPFviPvS5_ES5_i15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbfi( + void *thisptr, audio_stream_type_t streamType, uint32_t sampleRate, + audio_format_t format, audio_channel_mask_t channelMask, size_t frameCount, + audio_output_flags_t flags, android::AudioTrack::legacy_callback_t cbf, + void *user, int32_t notificationFrames, audio_session_t sessionId, + android::AudioTrack::transfer_type transferType, + const audio_offload_info_t *offloadInfo, + const AttributionSourceState &attributionSource, + const audio_attributes_t *pAttributes, bool doNotReconnect, + float maxRequiredSpeed, audio_port_handle_t selectedDeviceId) { + android::wp cbfWrapper = + new LegacyCallbackWrapper(cbf, user); + _ZN7android10AudioTrackC1E19audio_stream_type_tj14audio_format_t20audio_channel_mask_tRKNS_2spINS_7IMemoryEEE20audio_output_flags_tRKNS_2wpINS0_19IAudioTrackCallbackEEEi15audio_session_tNS0_13transfer_typeEPK20audio_offload_info_tRKNS_7content22AttributionSourceStateEPK18audio_attributes_tbf( + thisptr, streamType, sampleRate, format, channelMask, frameCount, flags, + cbfWrapper, notificationFrames, sessionId, transferType, offloadInfo, + attributionSource, pAttributes, doNotReconnect, maxRequiredSpeed, + selectedDeviceId); } }