1 /**
2  * Copyright 2021, 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 "TunerTimeFilter"
18 
19 #include "TunerTimeFilter.h"
20 
21 #include <aidl/android/hardware/tv/tuner/Constant64Bit.h>
22 #include <aidl/android/hardware/tv/tuner/Result.h>
23 
24 using ::aidl::android::hardware::tv::tuner::Constant64Bit;
25 using ::aidl::android::hardware::tv::tuner::Result;
26 
27 namespace aidl {
28 namespace android {
29 namespace media {
30 namespace tv {
31 namespace tuner {
32 
TunerTimeFilter(shared_ptr<ITimeFilter> timeFilter)33 TunerTimeFilter::TunerTimeFilter(shared_ptr<ITimeFilter> timeFilter) {
34     mTimeFilter = timeFilter;
35 }
36 
~TunerTimeFilter()37 TunerTimeFilter::~TunerTimeFilter() {
38     if (!isClosed) {
39         close();
40     }
41     mTimeFilter = nullptr;
42 }
43 
setTimeStamp(int64_t timeStamp)44 ::ndk::ScopedAStatus TunerTimeFilter::setTimeStamp(int64_t timeStamp) {
45     return mTimeFilter->setTimeStamp(timeStamp);
46 }
47 
clearTimeStamp()48 ::ndk::ScopedAStatus TunerTimeFilter::clearTimeStamp() {
49     return mTimeFilter->clearTimeStamp();
50 }
51 
getSourceTime(int64_t * _aidl_return)52 ::ndk::ScopedAStatus TunerTimeFilter::getSourceTime(int64_t* _aidl_return) {
53     auto status = mTimeFilter->getSourceTime(_aidl_return);
54     if (!status.isOk()) {
55         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
56     }
57     return status;
58 }
59 
getTimeStamp(int64_t * _aidl_return)60 ::ndk::ScopedAStatus TunerTimeFilter::getTimeStamp(int64_t* _aidl_return) {
61     auto status = mTimeFilter->getTimeStamp(_aidl_return);
62     if (!status.isOk()) {
63         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
64     }
65     return status;
66 }
67 
close()68 ::ndk::ScopedAStatus TunerTimeFilter::close() {
69     isClosed = true;
70     return mTimeFilter->close();
71 }
72 
73 }  // namespace tuner
74 }  // namespace tv
75 }  // namespace media
76 }  // namespace android
77 }  // namespace aidl
78