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 { 22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_FOUNDATION, "SteadyClock" }; 23 } 24 25 namespace OHOS { 26 namespace Media { 27 namespace { 28 using namespace std::chrono; 29 } 30 GetCurrentTimeMs()31int64_t SteadyClock::GetCurrentTimeMs() 32 { 33 return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count(); 34 } 35 GetCurrentTimeNanoSec()36int64_t SteadyClock::GetCurrentTimeNanoSec() 37 { 38 return duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count(); 39 } SteadyClock()40SteadyClock::SteadyClock() : begin_(high_resolution_clock::now()) 41 { 42 MEDIA_LOG_D("ctor called."); 43 } 44 Reset()45void SteadyClock::Reset() 46 { 47 MEDIA_LOG_D("Reset timer."); 48 begin_ = high_resolution_clock::now(); 49 } 50 ElapsedMilliseconds()51int64_t SteadyClock::ElapsedMilliseconds() 52 { 53 return duration_cast<milliseconds>(high_resolution_clock::now() - begin_).count(); 54 } 55 ElapsedMicroseconds()56int64_t SteadyClock::ElapsedMicroseconds() 57 { 58 return duration_cast<microseconds>(high_resolution_clock::now() - begin_).count(); 59 } 60 ElapsedNanoseconds()61int64_t SteadyClock::ElapsedNanoseconds() 62 { 63 return duration_cast<nanoseconds>(high_resolution_clock::now() - begin_).count(); 64 } 65 ElapsedSeconds()66int64_t SteadyClock::ElapsedSeconds() 67 { 68 return duration_cast<seconds>(high_resolution_clock::now() - begin_).count(); 69 } 70 } // namespace Media 71 } // namespace OHOS 72