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 LINEAR_POS_TIME_MODEL_H 17 #define LINEAR_POS_TIME_MODEL_H 18 19 #include "stdint.h" 20 #include <vector> 21 #include <audio_info.h> 22 23 namespace OHOS { 24 namespace AudioStandard { 25 class LinearPosTimeModel { 26 public: 27 LinearPosTimeModel(); 28 29 bool ConfigSampleRate(int32_t sampleRate); 30 31 void ResetFrameStamp(uint64_t frame, int64_t nanoTime); 32 33 CheckPosTimeRes UpdataFrameStamp(uint64_t frame, int64_t nanoTime); 34 35 bool GetFrameStamp(uint64_t &frame, int64_t &nanoTime); 36 37 void SetSpanCount(uint64_t spanCountInFrame); 38 39 int64_t GetTimeOfPos(uint64_t posInFrame); 40 41 virtual ~LinearPosTimeModel() = default; 42 private: 43 bool IsReasonable(uint64_t frame, int64_t nanoTime); 44 CheckPosTimeRes CheckReasonable(uint64_t frame, int64_t nanoTime); 45 bool CheckPosTimeReasonable(std::pair<uint64_t, int64_t> &pre, std::pair<uint64_t, int64_t> &next); 46 47 private: 48 bool isConfiged = false; 49 int32_t sampleRate_ = 0; 50 int64_t nanoTimePerFrame_ = 0; 51 uint64_t spanCountInFrame_ = 0; 52 53 uint64_t stampFrame_ = 0; 54 int64_t stampNanoTime_ = 0; 55 std::vector<std::pair<uint64_t, int64_t>> posTimeVec_; 56 }; 57 } // namespace AudioStandard 58 } // namespace OHOS 59 #endif // LINEAR_POS_TIME_MODEL_H 60