• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     mTimeFilter = nullptr;
39 }
40 
setTimeStamp(int64_t timeStamp)41 ::ndk::ScopedAStatus TunerTimeFilter::setTimeStamp(int64_t timeStamp) {
42     if (mTimeFilter == nullptr) {
43         ALOGE("ITimeFilter is not initialized");
44         return ::ndk::ScopedAStatus::fromServiceSpecificError(
45                 static_cast<int32_t>(Result::UNAVAILABLE));
46     }
47 
48     return mTimeFilter->setTimeStamp(timeStamp);
49 }
50 
clearTimeStamp()51 ::ndk::ScopedAStatus TunerTimeFilter::clearTimeStamp() {
52     if (mTimeFilter == nullptr) {
53         ALOGE("ITimeFilter is not initialized");
54         return ::ndk::ScopedAStatus::fromServiceSpecificError(
55                 static_cast<int32_t>(Result::UNAVAILABLE));
56     }
57 
58     return mTimeFilter->clearTimeStamp();
59 }
60 
getSourceTime(int64_t * _aidl_return)61 ::ndk::ScopedAStatus TunerTimeFilter::getSourceTime(int64_t* _aidl_return) {
62     if (mTimeFilter == nullptr) {
63         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
64         ALOGE("ITimeFilter is not initialized");
65         return ::ndk::ScopedAStatus::fromServiceSpecificError(
66                 static_cast<int32_t>(Result::UNAVAILABLE));
67     }
68 
69     auto status = mTimeFilter->getSourceTime(_aidl_return);
70     if (!status.isOk()) {
71         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
72     }
73     return status;
74 }
75 
getTimeStamp(int64_t * _aidl_return)76 ::ndk::ScopedAStatus TunerTimeFilter::getTimeStamp(int64_t* _aidl_return) {
77     if (mTimeFilter == nullptr) {
78         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
79         ALOGE("ITimeFilter is not initialized");
80         return ::ndk::ScopedAStatus::fromServiceSpecificError(
81                 static_cast<int32_t>(Result::UNAVAILABLE));
82     }
83 
84     auto status = mTimeFilter->getTimeStamp(_aidl_return);
85     if (!status.isOk()) {
86         *_aidl_return = (int64_t)Constant64Bit::INVALID_PRESENTATION_TIME_STAMP;
87     }
88     return status;
89 }
90 
close()91 ::ndk::ScopedAStatus TunerTimeFilter::close() {
92     if (mTimeFilter == nullptr) {
93         ALOGE("ITimeFilter is not initialized");
94         return ::ndk::ScopedAStatus::fromServiceSpecificError(
95                 static_cast<int32_t>(Result::UNAVAILABLE));
96     }
97 
98     auto status = mTimeFilter->close();
99     mTimeFilter = nullptr;
100 
101     return status;
102 }
103 
104 }  // namespace tuner
105 }  // namespace tv
106 }  // namespace media
107 }  // namespace android
108 }  // namespace aidl
109