TimeSource.cpp revision 20111aa043c5f404472bc63b90bc5aad906b1101
120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber/* 220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Copyright (C) 2009 The Android Open Source Project 320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * you may not use this file except in compliance with the License. 620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * You may obtain a copy of the License at 720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 1020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Unless required by applicable law or agreed to in writing, software 1120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * See the License for the specific language governing permissions and 1420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * limitations under the License. 1520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber */ 1620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 1720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <sys/time.h> 1820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 1920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <media/stagefright/TimeSource.h> 2020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 2120111aa043c5f404472bc63b90bc5aad906b1101Andreas Hubernamespace android { 2220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 2320111aa043c5f404472bc63b90bc5aad906b1101Andreas HuberSystemTimeSource::SystemTimeSource() 2420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber : mStartTimeUs(GetSystemTimeUs()) { 2520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber} 2620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 2720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberint64_t SystemTimeSource::getRealTimeUs() { 2820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber return GetSystemTimeUs() - mStartTimeUs; 2920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber} 3020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 3120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber// static 3220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberint64_t SystemTimeSource::GetSystemTimeUs() { 3320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber struct timeval tv; 3420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber gettimeofday(&tv, NULL); 3520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 3620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; 3720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber} 3820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 3920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber} // namespace android 4020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 41