1 /* 2 * Copyright 2020 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_STREAM_CALLBACK_H 18 #define OBOETESTER_STREAM_CALLBACK_H 19 20 #include <unistd.h> 21 #include <sys/types.h> 22 #include <sys/sysinfo.h> 23 #include "flowgraph/FlowGraphNode.h" 24 #include "oboe/Oboe.h" 25 #include "synth/Synthesizer.h" 26 #include "synth/SynthTools.h" 27 28 class OboeTesterStreamCallback : public oboe::AudioStreamCallback { 29 public: 30 virtual ~OboeTesterStreamCallback() = default; 31 32 // Call this before starting. reset()33 void reset() { 34 mPreviousScheduler = -1; 35 } 36 37 static int64_t getNanoseconds(clockid_t clockId = CLOCK_MONOTONIC); 38 39 /** 40 * Specify a sleep time that will hang the audio periodically. 41 * 42 * @param hangTimeMillis 43 */ setHangTimeMillis(int hangTimeMillis)44 static void setHangTimeMillis(int hangTimeMillis) { 45 mHangTimeMillis = hangTimeMillis; 46 } 47 48 protected: 49 void printScheduler(); 50 void maybeHang(int64_t nowNanos); 51 52 int mPreviousScheduler = -1; 53 static int mHangTimeMillis; 54 int64_t mNextTimeToHang = 0; 55 }; 56 57 58 #endif //OBOETESTER_STREAM_CALLBACK_H 59