1 /*
2  * Copyright (C) 2019 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 #define LOG_TAG "[email protected]"
18 
19 #include "TimeFilter.h"
20 #include <utils/Log.h>
21 
22 namespace android {
23 namespace hardware {
24 namespace tv {
25 namespace tuner {
26 namespace V1_0 {
27 namespace implementation {
28 
TimeFilter()29 TimeFilter::TimeFilter() {}
30 
TimeFilter(sp<Demux> demux)31 TimeFilter::TimeFilter(sp<Demux> demux) {
32     mDemux = demux;
33 }
34 
~TimeFilter()35 TimeFilter::~TimeFilter() {}
36 
setTimeStamp(uint64_t timeStamp)37 Return<Result> TimeFilter::setTimeStamp(uint64_t timeStamp) {
38     ALOGV("%s", __FUNCTION__);
39     if (timeStamp == INVALID_TIME_STAMP) {
40         return Result::INVALID_ARGUMENT;
41     }
42     mTimeStamp = timeStamp;
43     mBeginTime = time(NULL);
44 
45     return Result::SUCCESS;
46 }
47 
clearTimeStamp()48 Return<Result> TimeFilter::clearTimeStamp() {
49     ALOGV("%s", __FUNCTION__);
50     mTimeStamp = INVALID_TIME_STAMP;
51 
52     return Result::SUCCESS;
53 }
54 
getTimeStamp(getTimeStamp_cb _hidl_cb)55 Return<void> TimeFilter::getTimeStamp(getTimeStamp_cb _hidl_cb) {
56     ALOGV("%s", __FUNCTION__);
57     if (mTimeStamp == INVALID_TIME_STAMP) {
58         _hidl_cb(Result::INVALID_STATE, mTimeStamp);
59     }
60 
61     uint64_t currentTimeStamp = mTimeStamp + difftime(time(NULL), mBeginTime) * 900000;
62     _hidl_cb(Result::SUCCESS, currentTimeStamp);
63     return Void();
64 }
65 
getSourceTime(getSourceTime_cb _hidl_cb)66 Return<void> TimeFilter::getSourceTime(getSourceTime_cb _hidl_cb) {
67     ALOGV("%s", __FUNCTION__);
68 
69     uint64_t time = 0;
70 
71     _hidl_cb(Result::SUCCESS, time);
72     return Void();
73 }
74 
close()75 Return<Result> TimeFilter::close() {
76     ALOGV("%s", __FUNCTION__);
77     mTimeStamp = INVALID_TIME_STAMP;
78 
79     return Result::SUCCESS;
80 }
81 
82 }  // namespace implementation
83 }  // namespace V1_0
84 }  // namespace tuner
85 }  // namespace tv
86 }  // namespace hardware
87 }  // namespace android