blob: 8776f7e8a53de4f8a35aff7841ca79188120490f [file] [log] [blame]
Amy Zhangada92d72021-01-22 16:45:53 -08001/**
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 "TunerDvr"
18
Amy Zhangada92d72021-01-22 16:45:53 -080019#include "TunerDvr.h"
Hongguangeae68392021-07-27 20:56:23 -070020
21#include <aidl/android/hardware/tv/tuner/Result.h>
Hongguang34a479e2021-10-04 16:14:47 -070022#include <utils/Log.h>
Hongguangeae68392021-07-27 20:56:23 -070023
Amy Zhangada92d72021-01-22 16:45:53 -080024#include "TunerFilter.h"
25
Hongguangeae68392021-07-27 20:56:23 -070026using ::aidl::android::hardware::tv::tuner::Result;
Amy Zhangada92d72021-01-22 16:45:53 -080027
Hongguangeae68392021-07-27 20:56:23 -070028namespace aidl {
Amy Zhangada92d72021-01-22 16:45:53 -080029namespace android {
Hongguangeae68392021-07-27 20:56:23 -070030namespace media {
31namespace tv {
32namespace tuner {
Amy Zhangada92d72021-01-22 16:45:53 -080033
Hongguangeae68392021-07-27 20:56:23 -070034TunerDvr::TunerDvr(shared_ptr<IDvr> dvr, DvrType type) {
Amy Zhangada92d72021-01-22 16:45:53 -080035 mDvr = dvr;
Hongguangeae68392021-07-27 20:56:23 -070036 mType = type;
Amy Zhangada92d72021-01-22 16:45:53 -080037}
38
39TunerDvr::~TunerDvr() {
Hongguangeae68392021-07-27 20:56:23 -070040 mDvr = nullptr;
Amy Zhangada92d72021-01-22 16:45:53 -080041}
42
Hongguangeae68392021-07-27 20:56:23 -070043::ndk::ScopedAStatus TunerDvr::getQueueDesc(AidlMQDesc* _aidl_return) {
44 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080045 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070046 return ::ndk::ScopedAStatus::fromServiceSpecificError(
47 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080048 }
49
Hongguangeae68392021-07-27 20:56:23 -070050 return mDvr->getQueueDesc(_aidl_return);
Amy Zhangada92d72021-01-22 16:45:53 -080051}
52
Hongguangeae68392021-07-27 20:56:23 -070053::ndk::ScopedAStatus TunerDvr::configure(const DvrSettings& in_settings) {
54 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080055 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070056 return ::ndk::ScopedAStatus::fromServiceSpecificError(
57 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080058 }
59
Hongguangeae68392021-07-27 20:56:23 -070060 return mDvr->configure(in_settings);
Amy Zhangada92d72021-01-22 16:45:53 -080061}
62
Hongguangeae68392021-07-27 20:56:23 -070063::ndk::ScopedAStatus TunerDvr::attachFilter(const shared_ptr<ITunerFilter>& in_filter) {
64 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080065 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070066 return ::ndk::ScopedAStatus::fromServiceSpecificError(
67 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080068 }
69
Hongguangeae68392021-07-27 20:56:23 -070070 if (in_filter == nullptr) {
71 return ::ndk::ScopedAStatus::fromServiceSpecificError(
72 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080073 }
74
Hongguangeae68392021-07-27 20:56:23 -070075 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
76 if (halFilter == nullptr) {
77 return ::ndk::ScopedAStatus::fromServiceSpecificError(
78 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080079 }
Hongguangeae68392021-07-27 20:56:23 -070080
81 return mDvr->attachFilter(halFilter);
Amy Zhangada92d72021-01-22 16:45:53 -080082}
83
Hongguangeae68392021-07-27 20:56:23 -070084::ndk::ScopedAStatus TunerDvr::detachFilter(const shared_ptr<ITunerFilter>& in_filter) {
85 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080086 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070087 return ::ndk::ScopedAStatus::fromServiceSpecificError(
88 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080089 }
90
Hongguangeae68392021-07-27 20:56:23 -070091 if (in_filter == nullptr) {
92 return ::ndk::ScopedAStatus::fromServiceSpecificError(
93 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080094 }
95
Hongguangeae68392021-07-27 20:56:23 -070096 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
97 if (halFilter == nullptr) {
98 return ::ndk::ScopedAStatus::fromServiceSpecificError(
99 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -0800100 }
Hongguangeae68392021-07-27 20:56:23 -0700101
102 return mDvr->detachFilter(halFilter);
Amy Zhangada92d72021-01-22 16:45:53 -0800103}
104
Hongguangeae68392021-07-27 20:56:23 -0700105::ndk::ScopedAStatus TunerDvr::start() {
106 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800107 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700108 return ::ndk::ScopedAStatus::fromServiceSpecificError(
109 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800110 }
111
Hongguangeae68392021-07-27 20:56:23 -0700112 return mDvr->start();
Amy Zhangada92d72021-01-22 16:45:53 -0800113}
114
Hongguangeae68392021-07-27 20:56:23 -0700115::ndk::ScopedAStatus TunerDvr::stop() {
116 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800117 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700118 return ::ndk::ScopedAStatus::fromServiceSpecificError(
119 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800120 }
121
Hongguangeae68392021-07-27 20:56:23 -0700122 return mDvr->stop();
Amy Zhangada92d72021-01-22 16:45:53 -0800123}
124
Hongguangeae68392021-07-27 20:56:23 -0700125::ndk::ScopedAStatus TunerDvr::flush() {
126 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800127 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700128 return ::ndk::ScopedAStatus::fromServiceSpecificError(
129 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800130 }
131
Hongguangeae68392021-07-27 20:56:23 -0700132 return mDvr->flush();
Amy Zhangada92d72021-01-22 16:45:53 -0800133}
134
Hongguangeae68392021-07-27 20:56:23 -0700135::ndk::ScopedAStatus TunerDvr::close() {
136 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800137 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700138 return ::ndk::ScopedAStatus::fromServiceSpecificError(
139 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800140 }
141
Hongguangeae68392021-07-27 20:56:23 -0700142 auto status = mDvr->close();
143 mDvr = nullptr;
Amy Zhang14a60e82021-02-11 15:22:52 -0800144
Hongguangeae68392021-07-27 20:56:23 -0700145 return status;
Amy Zhangada92d72021-01-22 16:45:53 -0800146}
147
148/////////////// IDvrCallback ///////////////////////
Hongguangeae68392021-07-27 20:56:23 -0700149::ndk::ScopedAStatus TunerDvr::DvrCallback::onRecordStatus(const RecordStatus status) {
150 if (mTunerDvrCallback != nullptr) {
151 mTunerDvrCallback->onRecordStatus(status);
Amy Zhangada92d72021-01-22 16:45:53 -0800152 }
Hongguangeae68392021-07-27 20:56:23 -0700153 return ndk::ScopedAStatus::ok();
Amy Zhangada92d72021-01-22 16:45:53 -0800154}
155
Hongguangeae68392021-07-27 20:56:23 -0700156::ndk::ScopedAStatus TunerDvr::DvrCallback::onPlaybackStatus(const PlaybackStatus status) {
157 if (mTunerDvrCallback != nullptr) {
158 mTunerDvrCallback->onPlaybackStatus(status);
Amy Zhangada92d72021-01-22 16:45:53 -0800159 }
Hongguangeae68392021-07-27 20:56:23 -0700160 return ndk::ScopedAStatus::ok();
Amy Zhangada92d72021-01-22 16:45:53 -0800161}
Hongguangeae68392021-07-27 20:56:23 -0700162
163} // namespace tuner
164} // namespace tv
165} // namespace media
Amy Zhangada92d72021-01-22 16:45:53 -0800166} // namespace android
Hongguangeae68392021-07-27 20:56:23 -0700167} // namespace aidl