1 /**
2 * Copyright 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "LatencyTuningCallback.h"
18
onAudioReady(oboe::AudioStream * oboeStream,void * audioData,int32_t numFrames)19 oboe::DataCallbackResult LatencyTuningCallback::onAudioReady(
20 oboe::AudioStream *oboeStream, void *audioData, int32_t numFrames) {
21 if (oboeStream != mStream) {
22 mStream = oboeStream;
23 mLatencyTuner = std::make_unique<oboe::LatencyTuner>(*oboeStream);
24 }
25 if (mBufferTuneEnabled
26 && mLatencyTuner
27 && oboeStream->getAudioApi() == oboe::AudioApi::AAudio) {
28 mLatencyTuner->tune();
29 }
30 auto underrunCountResult = oboeStream->getXRunCount();
31 int bufferSize = oboeStream->getBufferSizeInFrames();
32 /**
33 * The following output can be seen by running a systrace. Tracing is preferable to logging
34 * inside the callback since tracing does not block.
35 *
36 * See https://developer.android.com/studio/profile/systrace-commandline.html
37 */
38 if (Trace::isEnabled()) Trace::beginSection("numFrames %d, Underruns %d, buffer size %d",
39 numFrames, underrunCountResult.value(), bufferSize);
40 auto result = DefaultDataCallback::onAudioReady(oboeStream, audioData, numFrames);
41 if (Trace::isEnabled()) Trace::endSection();
42 return result;
43 }
44
45
46