• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 #ifndef _ANDROID_MEDIA_TV_DVR_CLIENT_H_
18 #define _ANDROID_MEDIA_TV_DVR_CLIENT_H_
19 
20 #include <aidl/android/media/tv/tuner/BnTunerDvrCallback.h>
21 #include <aidl/android/media/tv/tuner/ITunerDvr.h>
22 #include <android/hardware/tv/tuner/1.0/IDvr.h>
23 #include <android/hardware/tv/tuner/1.0/IDvrCallback.h>
24 #include <android/hardware/tv/tuner/1.1/types.h>
25 #include <fmq/AidlMessageQueue.h>
26 #include <fmq/MessageQueue.h>
27 
28 #include "DvrClientCallback.h"
29 #include "FilterClient.h"
30 
31 using Status = ::ndk::ScopedAStatus;
32 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
33 using ::aidl::android::media::tv::tuner::BnTunerDvrCallback;
34 using ::aidl::android::media::tv::tuner::ITunerDvr;
35 using ::aidl::android::media::tv::tuner::TunerDvrSettings;
36 
37 using ::android::hardware::EventFlag;
38 using ::android::hardware::MQDescriptorSync;
39 using ::android::hardware::MessageQueue;
40 using ::android::hardware::tv::tuner::V1_0::DvrSettings;
41 using ::android::hardware::tv::tuner::V1_0::IDvr;
42 using ::android::hardware::tv::tuner::V1_0::IDvrCallback;
43 
44 using namespace std;
45 
46 namespace android {
47 
48 using MQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;
49 using MQDesc = MQDescriptorSync<uint8_t>;
50 using AidlMQ = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
51 using AidlMQDesc = MQDescriptor<int8_t, SynchronizedReadWrite>;
52 
53 class TunerDvrCallback : public BnTunerDvrCallback {
54 
55 public:
56     TunerDvrCallback(sp<DvrClientCallback> dvrClientCallback);
57 
58     Status onRecordStatus(int status);
59     Status onPlaybackStatus(int status);
60 
61 private:
62     sp<DvrClientCallback> mDvrClientCallback;
63 };
64 
65 struct HidlDvrCallback : public IDvrCallback {
66 
67 public:
68     HidlDvrCallback(sp<DvrClientCallback> dvrClientCallback);
69     virtual Return<void> onRecordStatus(const RecordStatus status);
70     virtual Return<void> onPlaybackStatus(const PlaybackStatus status);
71 
72 private:
73     sp<DvrClientCallback> mDvrClientCallback;
74 };
75 
76 struct DvrClient : public RefBase {
77 
78 public:
79     DvrClient(shared_ptr<ITunerDvr> tunerDvr);
80     ~DvrClient();
81 
82     // TODO: remove after migration to Tuner Service is done.
83     void setHidlDvr(sp<IDvr> dvr);
84 
85     /**
86      * Set the DVR file descriptor.
87      */
88     void setFd(int fd);
89 
90     /**
91      * Read data from file with given size. Return the actual read size.
92      */
93     long readFromFile(long size);
94 
95     /**
96      * Read data from the given buffer with given size. Return the actual read size.
97      */
98     long readFromBuffer(int8_t* buffer, long size);
99 
100     /**
101      * Write data to file with given size. Return the actual write size.
102      */
103     long writeToFile(long size);
104 
105     /**
106      * Write data to the given buffer with given size. Return the actual write size.
107      */
108     long writeToBuffer(int8_t* buffer, long size);
109 
110     /**
111      * Configure the DVR.
112      */
113     Result configure(DvrSettings settings);
114 
115     /**
116      * Attach one filter to DVR interface for recording.
117      */
118     Result attachFilter(sp<FilterClient> filterClient);
119 
120     /**
121      * Detach one filter from the DVR's recording.
122      */
123     Result detachFilter(sp<FilterClient> filterClient);
124 
125     /**
126      * Start DVR.
127      */
128     Result start();
129 
130     /**
131      * Stop DVR.
132      */
133     Result stop();
134 
135     /**
136      * Flush DVR data.
137      */
138     Result flush();
139 
140     /**
141      * close the DVR instance to release resource for DVR.
142      */
143     Result close();
144 
145 private:
146     Result getQueueDesc(MQDesc& dvrMQDesc);
147     TunerDvrSettings getAidlDvrSettingsFromHidl(DvrSettings settings);
148 
149     /**
150      * An AIDL Tuner Dvr Singleton assigned at the first time the Tuner Client
151      * opens a dvr. Default null when dvr is not opened.
152      */
153     shared_ptr<ITunerDvr> mTunerDvr;
154 
155     /**
156      * A Dvr HAL interface that is ready before migrating to the TunerDvr.
157      * This is a temprary interface before Tuner Framework migrates to use TunerService.
158      * Default null when the HAL service does not exist.
159      */
160     sp<IDvr> mDvr;
161 
162     AidlMQ* mDvrMQ;
163     EventFlag* mDvrMQEventFlag;
164     string mFilePath;
165     int mFd;
166 };
167 }  // namespace android
168 
169 #endif  // _ANDROID_MEDIA_TV_DVR_CLIENT_H_
170