1 /* 2 * Copyright 2023 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 OBOETESTER_TEST_COLD_START_LATENCY_H 18 #define OBOETESTER_TEST_COLD_START_LATENCY_H 19 20 #include "oboe/Oboe.h" 21 #include <thread> 22 23 /** 24 * Test for getting the cold start latency 25 */ 26 class TestColdStartLatency { 27 public: 28 29 int32_t open(bool useInput, bool useLowLatency, bool useMmap, bool useExclusive); 30 int32_t start(); 31 int32_t close(); 32 33 int32_t getColdStartTimeMicros(); 34 getOpenTimeMicros()35 int32_t getOpenTimeMicros() { 36 return (int32_t) (mOpenTimeMicros.load()); 37 } 38 getStartTimeMicros()39 int32_t getStartTimeMicros() { 40 return (int32_t) (mStartTimeMicros.load()); 41 } 42 getDeviceId()43 int32_t getDeviceId() { 44 return mDeviceId; 45 } 46 47 protected: 48 std::atomic<int64_t> mBeginStartNanos{0}; 49 std::atomic<double> mOpenTimeMicros{0}; 50 std::atomic<double> mStartTimeMicros{0}; 51 std::atomic<double> mColdStartTimeMicros{0}; 52 std::atomic<int32_t> mDeviceId{0}; 53 54 private: 55 56 class MyDataCallback : public oboe::AudioStreamDataCallback { public: 57 MyDataCallback()58 MyDataCallback() {} 59 60 oboe::DataCallbackResult onAudioReady( 61 oboe::AudioStream *audioStream, 62 void *audioData, 63 int32_t numFrames) override; 64 private: 65 // For sine generator. 66 float mPhase = 0.0f; 67 static constexpr float kPhaseIncrement = 2.0f * (float) M_PI * 440.0f / 48000.0f; 68 }; 69 70 std::shared_ptr<oboe::AudioStream> mStream; 71 std::shared_ptr<MyDataCallback> mDataCallback; 72 73 static constexpr int kChannelCount = 1; 74 }; 75 76 #endif //OBOETESTER_TEST_COLD_START_LATENCY_H 77