• 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 "TunerDvr"
18 
19 #include "TunerDvr.h"
20 
21 #include <aidl/android/hardware/tv/tuner/Result.h>
22 #include <utils/Log.h>
23 
24 #include "TunerFilter.h"
25 
26 using ::aidl::android::hardware::tv::tuner::Result;
27 
28 namespace aidl {
29 namespace android {
30 namespace media {
31 namespace tv {
32 namespace tuner {
33 
TunerDvr(shared_ptr<IDvr> dvr,DvrType type)34 TunerDvr::TunerDvr(shared_ptr<IDvr> dvr, DvrType type) {
35     mDvr = dvr;
36     mType = type;
37 }
38 
~TunerDvr()39 TunerDvr::~TunerDvr() {
40     close();
41     mDvr = nullptr;
42 }
43 
getQueueDesc(AidlMQDesc * _aidl_return)44 ::ndk::ScopedAStatus TunerDvr::getQueueDesc(AidlMQDesc* _aidl_return) {
45     return mDvr->getQueueDesc(_aidl_return);
46 }
47 
configure(const DvrSettings & in_settings)48 ::ndk::ScopedAStatus TunerDvr::configure(const DvrSettings& in_settings) {
49     return mDvr->configure(in_settings);
50 }
51 
attachFilter(const shared_ptr<ITunerFilter> & in_filter)52 ::ndk::ScopedAStatus TunerDvr::attachFilter(const shared_ptr<ITunerFilter>& in_filter) {
53     if (in_filter == nullptr) {
54         return ::ndk::ScopedAStatus::fromServiceSpecificError(
55                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
56     }
57 
58     shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
59     if (halFilter == nullptr) {
60         return ::ndk::ScopedAStatus::fromServiceSpecificError(
61                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
62     }
63 
64     return mDvr->attachFilter(halFilter);
65 }
66 
detachFilter(const shared_ptr<ITunerFilter> & in_filter)67 ::ndk::ScopedAStatus TunerDvr::detachFilter(const shared_ptr<ITunerFilter>& in_filter) {
68     if (in_filter == nullptr) {
69         return ::ndk::ScopedAStatus::fromServiceSpecificError(
70                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
71     }
72 
73     shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter();
74     if (halFilter == nullptr) {
75         return ::ndk::ScopedAStatus::fromServiceSpecificError(
76                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
77     }
78 
79     return mDvr->detachFilter(halFilter);
80 }
81 
start()82 ::ndk::ScopedAStatus TunerDvr::start() {
83     return mDvr->start();
84 }
85 
stop()86 ::ndk::ScopedAStatus TunerDvr::stop() {
87     return mDvr->stop();
88 }
89 
flush()90 ::ndk::ScopedAStatus TunerDvr::flush() {
91     return mDvr->flush();
92 }
93 
close()94 ::ndk::ScopedAStatus TunerDvr::close() {
95     return mDvr->close();
96 }
97 
setStatusCheckIntervalHint(const int64_t milliseconds)98 ::ndk::ScopedAStatus TunerDvr::setStatusCheckIntervalHint(const int64_t milliseconds) {
99     if (milliseconds < 0L) {
100         return ::ndk::ScopedAStatus::fromServiceSpecificError(
101                 static_cast<int32_t>(Result::INVALID_ARGUMENT));
102     }
103 
104     ::ndk::ScopedAStatus s = mDvr->setStatusCheckIntervalHint(milliseconds);
105     if (s.getStatus() == STATUS_UNKNOWN_TRANSACTION) {
106         return ::ndk::ScopedAStatus::fromServiceSpecificError(
107                 static_cast<int32_t>(Result::UNAVAILABLE));
108     }
109 
110     return s;
111 }
112 
113 /////////////// IDvrCallback ///////////////////////
onRecordStatus(const RecordStatus status)114 ::ndk::ScopedAStatus TunerDvr::DvrCallback::onRecordStatus(const RecordStatus status) {
115     if (mTunerDvrCallback != nullptr) {
116         mTunerDvrCallback->onRecordStatus(status);
117     }
118     return ndk::ScopedAStatus::ok();
119 }
120 
onPlaybackStatus(const PlaybackStatus status)121 ::ndk::ScopedAStatus TunerDvr::DvrCallback::onPlaybackStatus(const PlaybackStatus status) {
122     if (mTunerDvrCallback != nullptr) {
123         mTunerDvrCallback->onPlaybackStatus(status);
124     }
125     return ndk::ScopedAStatus::ok();
126 }
127 
128 }  // namespace tuner
129 }  // namespace tv
130 }  // namespace media
131 }  // namespace android
132 }  // namespace aidl
133