1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_DAUDIO_LATENCY_TEST_H 17 #define OHOS_DAUDIO_LATENCY_TEST_H 18 19 #include <vector> 20 21 #include "single_instance.h" 22 23 namespace OHOS { 24 namespace DistributedHardware { 25 class DAudioLatencyTest { 26 DECLARE_SINGLE_INSTANCE_BASE(DAudioLatencyTest); 27 public: 28 int32_t AddPlayTime(const int64_t playBeepTime); 29 int32_t AddRecordTime(const int64_t recordBeepTime); 30 int64_t RecordBeepTime(const uint8_t *base, const int32_t &sizePerFrame, bool &status); 31 bool IsFrameHigh(const int16_t *audioData, const int32_t size, int32_t threshhold); 32 int32_t ComputeLatency(); 33 34 private: 35 DAudioLatencyTest(); 36 ~DAudioLatencyTest(); 37 38 private: 39 constexpr static int32_t TWO_BEEP_TIME_INTERVAL = 900000; // 900ms 40 constexpr static int32_t BEEP_THRESHHOLD = 8000; 41 constexpr static int32_t US_PER_MS = 1000; 42 std::vector<int64_t> playBeepTime_; 43 std::vector<int64_t> captureBeepTime_; 44 int64_t lastPlayTime_ = 0; 45 int64_t lastRecordTime_ = 0; 46 }; 47 } 48 } 49 #endif