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 
21 namespace OHOS {
22 namespace AudioStandard {
23 class LinearPosTimeModel {
24 public:
25     LinearPosTimeModel();
26 
27     bool ConfigSampleRate(int32_t sampleRate);
28 
29     void ResetFrameStamp(uint64_t frame, int64_t nanoTime);
30 
31     bool UpdataFrameStamp(uint64_t frame, int64_t nanoTime);
32 
33     bool GetFrameStamp(uint64_t &frame, int64_t &nanoTime);
34 
35     void SetSpanCount(uint64_t spanCountInFrame);
36 
37     int64_t GetTimeOfPos(uint64_t posInFrame);
38 
39     virtual ~LinearPosTimeModel() = default;
40 private:
41     bool IsReasonable(uint64_t frame, int64_t nanoTime);
42 
43 private:
44     bool isConfiged = false;
45     int32_t sampleRate_ = 0;
46     int64_t nanoTimePerFrame_ = 0;
47     uint64_t spanCountInFrame_ = 0;
48 
49     uint64_t stampFrame_ = 0;
50     int64_t stampNanoTime_ = 0;
51 };
52 } // namespace AudioStandard
53 } // namespace OHOS
54 #endif // LINEAR_POS_TIME_MODEL_H
55