blob: 5e4e5f51b4464d8e0a8aeef88c9f47940572e136 [file] [log] [blame]
Mike J. Chen6c929512011-08-15 11:59:47 -07001/*
2 * Copyright (C) 2012 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 __COMMON_CLOCK_H__
18#define __COMMON_CLOCK_H__
19
20#include <stdint.h>
21
22#include <utils/Errors.h>
Mike J. Chen6c929512011-08-15 11:59:47 -070023#include <utils/threads.h>
24
Mathias Agopian26fddcd2017-03-15 14:17:22 -070025#include "LinearTransform.h"
26
Mike J. Chen6c929512011-08-15 11:59:47 -070027namespace android {
28
29class CommonClock {
30 public:
31 CommonClock();
32
33 bool init(uint64_t local_freq);
34
35 status_t localToCommon(int64_t local, int64_t *common_out) const;
36 status_t commonToLocal(int64_t common, int64_t *local_out) const;
37 int64_t localDurationToCommonDuration(int64_t localDur) const;
38 uint64_t getCommonFreq() const { return kCommonFreq; }
39 bool isValid() const { return cur_trans_valid_; }
40 status_t setSlew(int64_t change_time, int32_t ppm);
41 void setBasis(int64_t local, int64_t common);
42 void resetBasis();
43 private:
44 mutable Mutex lock_;
45
46 int32_t cur_slew_;
47 uint32_t local_to_common_freq_numer_;
48 uint32_t local_to_common_freq_denom_;
49
50 LinearTransform duration_trans_;
51 LinearTransform cur_trans_;
52 bool cur_trans_valid_;
53
54 static const uint64_t kCommonFreq = 1000000ull;
55};
56
57} // namespace android
58#endif // __COMMON_CLOCK_H__