xref: /aosp_15_r20/frameworks/av/services/tuner/hidl/TunerHidlTimeFilter.cpp (revision ec779b8e0859a360c3d303172224686826e6e0e1)
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 "TunerHidlTimeFilter"
18 
19 #include "TunerHidlTimeFilter.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 using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
28 
29 using namespace std;
30 
31 namespace aidl {
32 namespace android {
33 namespace media {
34 namespace tv {
35 namespace tuner {
36 
TunerHidlTimeFilter(sp<HidlITimeFilter> timeFilter)37 TunerHidlTimeFilter::TunerHidlTimeFilter(sp<HidlITimeFilter> timeFilter) {
38     mTimeFilter = timeFilter;
39 }
40 
~TunerHidlTimeFilter()41 TunerHidlTimeFilter::~TunerHidlTimeFilter() {
42     mTimeFilter = nullptr;
43 }
44 
setTimeStamp(int64_t timeStamp)45 ::ndk::ScopedAStatus TunerHidlTimeFilter::setTimeStamp(int64_t timeStamp) {
46     HidlResult status = mTimeFilter->setTimeStamp(static_cast<uint64_t>(timeStamp));
47     if (status != HidlResult::SUCCESS) {
48         return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
49     }
50     return ::ndk::ScopedAStatus::ok();
51 }
52 
clearTimeStamp()53 ::ndk::ScopedAStatus TunerHidlTimeFilter::clearTimeStamp() {
54     HidlResult status = mTimeFilter->clearTimeStamp();
55     if (status != HidlResult::SUCCESS) {
56         return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
57     }
58     return ::ndk::ScopedAStatus::ok();
59 }
60 
getSourceTime(int64_t * _aidl_return)61 ::ndk::ScopedAStatus TunerHidlTimeFilter::getSourceTime(int64_t* _aidl_return) {
62     HidlResult status;
63     mTimeFilter->getSourceTime([&](HidlResult r, uint64_t t) {
64         status = r;
65         *_aidl_return = static_cast<int64_t>(t);
66     });
67     if (status != HidlResult::SUCCESS) {
68         *_aidl_return = static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP);
69         return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
70     }
71     return ::ndk::ScopedAStatus::ok();
72 }
73 
getTimeStamp(int64_t * _aidl_return)74 ::ndk::ScopedAStatus TunerHidlTimeFilter::getTimeStamp(int64_t* _aidl_return) {
75     HidlResult status;
76     mTimeFilter->getTimeStamp([&](HidlResult r, uint64_t t) {
77         status = r;
78         *_aidl_return = static_cast<int64_t>(t);
79     });
80     if (status != HidlResult::SUCCESS) {
81         *_aidl_return = static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP);
82         return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(status));
83     }
84     return ::ndk::ScopedAStatus::ok();
85 }
86 
close()87 ::ndk::ScopedAStatus TunerHidlTimeFilter::close() {
88     HidlResult res = mTimeFilter->close();
89     if (res != HidlResult::SUCCESS) {
90         return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
91     }
92     return ::ndk::ScopedAStatus::ok();
93 }
94 
95 }  // namespace tuner
96 }  // namespace tv
97 }  // namespace media
98 }  // namespace android
99 }  // namespace aidl
100