blob: fb03b06e4462df51bc109c769eb4fa30fa32ac40 [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>
22
Amy Zhangada92d72021-01-22 16:45:53 -080023#include "TunerFilter.h"
24
Hongguangeae68392021-07-27 20:56:23 -070025using ::aidl::android::hardware::tv::tuner::Result;
Amy Zhangada92d72021-01-22 16:45:53 -080026
Hongguangeae68392021-07-27 20:56:23 -070027namespace aidl {
Amy Zhangada92d72021-01-22 16:45:53 -080028namespace android {
Hongguangeae68392021-07-27 20:56:23 -070029namespace media {
30namespace tv {
31namespace tuner {
Amy Zhangada92d72021-01-22 16:45:53 -080032
Hongguangeae68392021-07-27 20:56:23 -070033TunerDvr::TunerDvr(shared_ptr<IDvr> dvr, DvrType type) {
Amy Zhangada92d72021-01-22 16:45:53 -080034 mDvr = dvr;
Hongguangeae68392021-07-27 20:56:23 -070035 mType = type;
Amy Zhangada92d72021-01-22 16:45:53 -080036}
37
38TunerDvr::~TunerDvr() {
Hongguangeae68392021-07-27 20:56:23 -070039 mDvr = nullptr;
Amy Zhangada92d72021-01-22 16:45:53 -080040}
41
Hongguangeae68392021-07-27 20:56:23 -070042::ndk::ScopedAStatus TunerDvr::getQueueDesc(AidlMQDesc* _aidl_return) {
43 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080044 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070045 return ::ndk::ScopedAStatus::fromServiceSpecificError(
46 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080047 }
48
Hongguangeae68392021-07-27 20:56:23 -070049 return mDvr->getQueueDesc(_aidl_return);
Amy Zhangada92d72021-01-22 16:45:53 -080050}
51
Hongguangeae68392021-07-27 20:56:23 -070052::ndk::ScopedAStatus TunerDvr::configure(const DvrSettings& in_settings) {
53 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080054 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070055 return ::ndk::ScopedAStatus::fromServiceSpecificError(
56 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080057 }
58
Hongguangeae68392021-07-27 20:56:23 -070059 return mDvr->configure(in_settings);
Amy Zhangada92d72021-01-22 16:45:53 -080060}
61
Hongguangeae68392021-07-27 20:56:23 -070062::ndk::ScopedAStatus TunerDvr::attachFilter(const shared_ptr<ITunerFilter>& in_filter) {
63 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080064 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070065 return ::ndk::ScopedAStatus::fromServiceSpecificError(
66 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080067 }
68
Hongguangeae68392021-07-27 20:56:23 -070069 if (in_filter == nullptr) {
70 return ::ndk::ScopedAStatus::fromServiceSpecificError(
71 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080072 }
73
Hongguangeae68392021-07-27 20:56:23 -070074 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
75 if (halFilter == nullptr) {
76 return ::ndk::ScopedAStatus::fromServiceSpecificError(
77 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080078 }
Hongguangeae68392021-07-27 20:56:23 -070079
80 return mDvr->attachFilter(halFilter);
Amy Zhangada92d72021-01-22 16:45:53 -080081}
82
Hongguangeae68392021-07-27 20:56:23 -070083::ndk::ScopedAStatus TunerDvr::detachFilter(const shared_ptr<ITunerFilter>& in_filter) {
84 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -080085 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -070086 return ::ndk::ScopedAStatus::fromServiceSpecificError(
87 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -080088 }
89
Hongguangeae68392021-07-27 20:56:23 -070090 if (in_filter == nullptr) {
91 return ::ndk::ScopedAStatus::fromServiceSpecificError(
92 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080093 }
94
Hongguangeae68392021-07-27 20:56:23 -070095 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
96 if (halFilter == nullptr) {
97 return ::ndk::ScopedAStatus::fromServiceSpecificError(
98 static_cast<int32_t>(Result::INVALID_ARGUMENT));
Amy Zhangada92d72021-01-22 16:45:53 -080099 }
Hongguangeae68392021-07-27 20:56:23 -0700100
101 return mDvr->detachFilter(halFilter);
Amy Zhangada92d72021-01-22 16:45:53 -0800102}
103
Hongguangeae68392021-07-27 20:56:23 -0700104::ndk::ScopedAStatus TunerDvr::start() {
105 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800106 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700107 return ::ndk::ScopedAStatus::fromServiceSpecificError(
108 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800109 }
110
Hongguangeae68392021-07-27 20:56:23 -0700111 return mDvr->start();
Amy Zhangada92d72021-01-22 16:45:53 -0800112}
113
Hongguangeae68392021-07-27 20:56:23 -0700114::ndk::ScopedAStatus TunerDvr::stop() {
115 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800116 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700117 return ::ndk::ScopedAStatus::fromServiceSpecificError(
118 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800119 }
120
Hongguangeae68392021-07-27 20:56:23 -0700121 return mDvr->stop();
Amy Zhangada92d72021-01-22 16:45:53 -0800122}
123
Hongguangeae68392021-07-27 20:56:23 -0700124::ndk::ScopedAStatus TunerDvr::flush() {
125 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800126 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700127 return ::ndk::ScopedAStatus::fromServiceSpecificError(
128 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800129 }
130
Hongguangeae68392021-07-27 20:56:23 -0700131 return mDvr->flush();
Amy Zhangada92d72021-01-22 16:45:53 -0800132}
133
Hongguangeae68392021-07-27 20:56:23 -0700134::ndk::ScopedAStatus TunerDvr::close() {
135 if (mDvr == nullptr) {
Amy Zhangada92d72021-01-22 16:45:53 -0800136 ALOGE("IDvr is not initialized");
Hongguangeae68392021-07-27 20:56:23 -0700137 return ::ndk::ScopedAStatus::fromServiceSpecificError(
138 static_cast<int32_t>(Result::UNAVAILABLE));
Amy Zhangada92d72021-01-22 16:45:53 -0800139 }
140
Hongguangeae68392021-07-27 20:56:23 -0700141 auto status = mDvr->close();
142 mDvr = nullptr;
Amy Zhang14a60e82021-02-11 15:22:52 -0800143
Hongguangeae68392021-07-27 20:56:23 -0700144 return status;
Amy Zhangada92d72021-01-22 16:45:53 -0800145}
146
147/////////////// IDvrCallback ///////////////////////
Hongguangeae68392021-07-27 20:56:23 -0700148::ndk::ScopedAStatus TunerDvr::DvrCallback::onRecordStatus(const RecordStatus status) {
149 if (mTunerDvrCallback != nullptr) {
150 mTunerDvrCallback->onRecordStatus(status);
Amy Zhangada92d72021-01-22 16:45:53 -0800151 }
Hongguangeae68392021-07-27 20:56:23 -0700152 return ndk::ScopedAStatus::ok();
Amy Zhangada92d72021-01-22 16:45:53 -0800153}
154
Hongguangeae68392021-07-27 20:56:23 -0700155::ndk::ScopedAStatus TunerDvr::DvrCallback::onPlaybackStatus(const PlaybackStatus status) {
156 if (mTunerDvrCallback != nullptr) {
157 mTunerDvrCallback->onPlaybackStatus(status);
Amy Zhangada92d72021-01-22 16:45:53 -0800158 }
Hongguangeae68392021-07-27 20:56:23 -0700159 return ndk::ScopedAStatus::ok();
Amy Zhangada92d72021-01-22 16:45:53 -0800160}
Hongguangeae68392021-07-27 20:56:23 -0700161
162} // namespace tuner
163} // namespace tv
164} // namespace media
Amy Zhangada92d72021-01-22 16:45:53 -0800165} // namespace android
Hongguangeae68392021-07-27 20:56:23 -0700166} // namespace aidl