Oboe  1.0
A library for creating real-time audio apps on Android
LatencyTuner.h
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 #ifndef OBOE_LATENCY_TUNER_
18 #define OBOE_LATENCY_TUNER_
19 
20 #include <atomic>
21 #include <cstdint>
22 #include "oboe/Definitions.h"
23 #include "oboe/AudioStream.h"
24 
25 namespace oboe {
26 
41 class LatencyTuner {
42 public:
43 
49  explicit LatencyTuner(AudioStream &stream);
50 
59  Result tune();
60 
69  void requestReset();
70 
71 private:
72 
79  void reset();
80 
81  enum class State {
82  Idle,
83  Active,
84  AtMax,
85  Unsupported
86  } ;
87 
88  // arbitrary number of calls to wait before bumping up the latency
89  static constexpr int32_t kIdleCount = 8;
90 
91  AudioStream &mStream;
92  State mState = State::Idle;
93  int32_t mPreviousXRuns = 0;
94  int32_t mIdleCountDown = 0;
95  std::atomic<int32_t> mLatencyTriggerRequests{0}; // TODO user atomic requester from AAudio
96  std::atomic<int32_t> mLatencyTriggerResponses{0};
97 };
98 
99 } // namespace oboe
100 
101 #endif // OBOE_LATENCY_TUNER_
Result
Definition: Definitions.h:140
Definition: AudioStream.h:42
LatencyTuner(AudioStream &stream)
Definition: LatencyTuner.h:41
Definition: AudioStream.h:29