1 /* 2 * Copyright (c) 2025 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 CAPTURER_CLOCK_H 17 #define CAPTURER_CLOCK_H 18 19 #include <mutex> 20 #include "audio_info.h" 21 22 namespace OHOS { 23 namespace AudioStandard { 24 25 class CapturerClock { 26 public: 27 CapturerClock(uint32_t capturerSampleRate); ~CapturerClock()28 ~CapturerClock() {} 29 30 void Start(); 31 void Stop(); 32 bool GetTimeStampByPosition(uint64_t capturerPos, uint64_t& timestamp); 33 void SetTimeStampByPosition(uint64_t timestamp, uint32_t srcSampleRate, uint64_t posIncSize); 34 private: 35 uint64_t position_ = 0; 36 uint64_t timestamp_ = 0; 37 uint32_t capturerSampleRate_ = 0; 38 uint64_t lastPosInc_ = 0; 39 bool isRunning_ = false; 40 std::mutex clockMtx_; 41 }; 42 43 } // namespace AudioStandard 44 } // namespace OHOS 45 46 #endif // CAPTURER_CLOCK_H 47