| 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 "TimeFilterClient" |
| 18 | |
| 19 | #include "TimeFilterClient.h" |
| 20 | |
| 21 | #include <aidl/android/hardware/tv/tuner/Constant64Bit.h> |
| 22 | #include <android-base/logging.h> |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include "ClientHelper.h" |
| 26 | |
| 27 | using ::aidl::android::hardware::tv::tuner::Constant64Bit; |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | /////////////// TimeFilterClient /////////////////////// |
| 32 | |
| 33 | TimeFilterClient::TimeFilterClient(shared_ptr<ITunerTimeFilter> tunerTimeFilter) { |
| 34 | mTunerTimeFilter = tunerTimeFilter; |
| 35 | } |
| 36 | |
| 37 | TimeFilterClient::~TimeFilterClient() { |
| 38 | mTunerTimeFilter = nullptr; |
| 39 | } |
| 40 | |
| 41 | Result TimeFilterClient::setTimeStamp(int64_t timeStamp) { |
| 42 | if (mTunerTimeFilter != nullptr) { |
| 43 | Status s = mTunerTimeFilter->setTimeStamp(timeStamp); |
| 44 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 45 | } |
| 46 | |
| 47 | return Result::INVALID_STATE; |
| 48 | } |
| 49 | |
| 50 | Result TimeFilterClient::clearTimeStamp() { |
| 51 | if (mTunerTimeFilter != nullptr) { |
| 52 | Status s = mTunerTimeFilter->clearTimeStamp(); |
| 53 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 54 | } |
| 55 | |
| 56 | return Result::INVALID_STATE; |
| 57 | } |
| 58 | |
| 59 | int64_t TimeFilterClient::getTimeStamp() { |
| 60 | if (mTunerTimeFilter != nullptr) { |
| 61 | int64_t timeStamp; |
| 62 | Status s = mTunerTimeFilter->getTimeStamp(&timeStamp); |
| 63 | if (!s.isOk()) { |
| 64 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
| 65 | } |
| 66 | return timeStamp; |
| 67 | } |
| 68 | |
| 69 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
| 70 | } |
| 71 | |
| 72 | int64_t TimeFilterClient::getSourceTime() { |
| 73 | if (mTunerTimeFilter != nullptr) { |
| 74 | int64_t sourceTime; |
| 75 | Status s = mTunerTimeFilter->getTimeStamp(&sourceTime); |
| 76 | if (!s.isOk()) { |
| 77 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
| 78 | } |
| 79 | return sourceTime; |
| 80 | } |
| 81 | |
| 82 | return static_cast<int64_t>(Constant64Bit::INVALID_PRESENTATION_TIME_STAMP); |
| 83 | } |
| 84 | |
| 85 | Result TimeFilterClient::close() { |
| 86 | if (mTunerTimeFilter != nullptr) { |
| 87 | Status s = mTunerTimeFilter->close(); |
| 88 | mTunerTimeFilter = nullptr; |
| 89 | return ClientHelper::getServiceSpecificErrorCode(s); |
| 90 | } |
| 91 | |
| 92 | return Result::INVALID_STATE; |
| 93 | } |
| 94 | } // namespace android |