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]: eb57617e55
- [2]: https://cs.android.com/android/platform/superproject/main/+/main:frameworks/av/media/libaudioclient/AudioTrack.cpp;l=289;bpv=1

Change-Id: Ieae7df3f5f003538a0319cc77051322a989b93a8
This commit is contained in:
R0rt1z2
2023-11-15 08:27:07 +01:00
committed by Matsvei Niaverau
parent 1f736c9d1f
commit 79e98e94d5
3 changed files with 87 additions and 28 deletions

View File

@@ -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",
],
}

View File

@@ -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<void *>(&copy));
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<void *>(&copy));
return copy.size();
}
};
} // namespace

View File

@@ -4,39 +4,46 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <android/media/IAudioTrack.h>
#include <android/media/IAudioTrackCallback.h>
#include <gui/SurfaceComposerClient.h>
#include <media/AudioTrack.h>
#include <media/stagefright/MediaMuxer.h>
#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<AudioTrack::IAudioTrackCallback> &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<AudioTrack::IAudioTrackCallback> &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<android::AudioTrack::IAudioTrackCallback> &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<LegacyCallbackWrapper> 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);
}
}