@@ -55,28 +55,17 @@ bool OboeBridge::open(int32_t sampleRate) {
5555 ->setFormatConversionAllowed (false )
5656 ->setCallback (stabilizedCallback_.get ());
5757
58- LOGI (" Oboe stream: attempting open in Exclusive mode with AAudio (sampleRate=%d)" , sampleRate);
5958 oboe::Result result = builder.openStream (stream_);
6059
6160 if (result != oboe::Result::OK ) {
62- LOGE (" Failed to open Oboe stream in Exclusive mode (%s), falling back to Shared mode" , oboe::convertToText (result));
63- builder.setSharingMode (oboe::SharingMode::Shared);
64- // If falling back to Shared, allow conversion to be more resilient
65- builder.setChannelConversionAllowed (true )
66- ->setFormatConversionAllowed (true )
67- ->setSampleRateConversionQuality (oboe::SampleRateConversionQuality::Medium);
68- result = builder.openStream (stream_);
69- }
70-
71- if (result != oboe::Result::OK ) {
72- LOGE (" Failed to open Oboe stream with AAudio API (%s), falling back to Unspecified API" ,
61+ LOGE (" AAudio open failed (%s), falling back to unspecified API" ,
7362 oboe::convertToText (result));
7463 builder.setAudioApi (oboe::AudioApi::Unspecified);
7564 result = builder.openStream (stream_);
7665 }
7766
7867 if (result != oboe::Result::OK ) {
79- LOGE (" Failed to open Oboe stream with any configuration : %s" , oboe::convertToText (result));
68+ LOGE (" Failed to open Oboe stream: %s" , oboe::convertToText (result));
8069 return false ;
8170 }
8271
@@ -183,6 +172,7 @@ void OboeBridge::setProvider(OboeAudioProvider provider) {
183172oboe::DataCallbackResult OboeBridge::onAudioReady (
184173 oboe::AudioStream* stream, void * audioData, int32_t numFrames) {
185174
175+
186176 OboeAudioProvider provider = provider_.load (std::memory_order_acquire);
187177
188178 if (provider) {
@@ -200,6 +190,7 @@ oboe::DataCallbackResult OboeBridge::onAudioReady(
200190 memset (audioData, 0 , byteCount);
201191 }
202192
193+
203194 uint32_t count = callbackCount_.fetch_add (1 , std::memory_order_relaxed);
204195
205196 if ((count & 127 ) == 0 ) {
@@ -396,3 +387,33 @@ OSU_EXPORT byte nSetThreadAffinity(int coreMask) {
396387 return (sched_setaffinity (0 , sizeof (cpu_set_t ), &cpuset) == 0 ) ? 1 : 0 ;
397388}
398389}
390+
391+ #include < android/performance_hint.h>
392+
393+ extern " C" {
394+ OSU_EXPORT intptr_t nADPFCreateSession (int64_t targetDurationNanos) {
395+ auto manager = APerformanceHint_getManager ();
396+ if (!manager) return 0 ;
397+
398+ int32_t thread_id = gettid ();
399+ return reinterpret_cast <intptr_t >(APerformanceHint_createSession (manager, &thread_id, 1 , targetDurationNanos));
400+ }
401+
402+ OSU_EXPORT void nADPFReportActualDuration (intptr_t sessionPtr, int64_t actualDurationNanos) {
403+ if (sessionPtr) {
404+ APerformanceHint_reportActualWorkDuration (reinterpret_cast <APerformanceHintSession*>(sessionPtr), actualDurationNanos);
405+ }
406+ }
407+
408+ OSU_EXPORT void nADPFUpdateTargetDuration (intptr_t sessionPtr, int64_t targetDurationNanos) {
409+ if (sessionPtr) {
410+ APerformanceHint_updateTargetWorkDuration (reinterpret_cast <APerformanceHintSession*>(sessionPtr), targetDurationNanos);
411+ }
412+ }
413+
414+ OSU_EXPORT void nADPFCloseSession (intptr_t sessionPtr) {
415+ if (sessionPtr) {
416+ APerformanceHint_closeSession (reinterpret_cast <APerformanceHintSession*>(sessionPtr));
417+ }
418+ }
419+ }
0 commit comments