• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #define HST_LOG_TAG "SteadyClock"
17 
18 #include "common/log.h"
19 #include "osal/utils/steady_clock.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace {
24 using namespace std::chrono;
25 }
26 
GetCurrentTimeMs()27 int64_t SteadyClock::GetCurrentTimeMs()
28 {
29     return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
30 }
31 
GetCurrentTimeNanoSec()32 int64_t SteadyClock::GetCurrentTimeNanoSec()
33 {
34     return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count();
35 }
SteadyClock()36 SteadyClock::SteadyClock() : begin_(high_resolution_clock::now())
37 {
38     MEDIA_LOG_D("ctor called.");
39 }
40 
Reset()41 void SteadyClock::Reset()
42 {
43     MEDIA_LOG_D("Reset timer.");
44     begin_ = high_resolution_clock::now();
45 }
46 
ElapsedMilliseconds()47 int64_t SteadyClock::ElapsedMilliseconds()
48 {
49     return duration_cast<milliseconds>(high_resolution_clock::now() - begin_).count();
50 }
51 
ElapsedMicroseconds()52 int64_t SteadyClock::ElapsedMicroseconds()
53 {
54     return duration_cast<microseconds>(high_resolution_clock::now() - begin_).count();
55 }
56 
ElapsedNanoseconds()57 int64_t SteadyClock::ElapsedNanoseconds()
58 {
59     return duration_cast<nanoseconds>(high_resolution_clock::now() - begin_).count();
60 }
61 
ElapsedSeconds()62 int64_t SteadyClock::ElapsedSeconds()
63 {
64     return duration_cast<seconds>(high_resolution_clock::now() - begin_).count();
65 }
66 } // namespace Media
67 } // namespace OHOS
68