• 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_DEMUX_CLIENT_H_
18 #define _ANDROID_MEDIA_TV_DEMUX_CLIENT_H_
19 
20 #include <aidl/android/media/tv/tuner/ITunerDemux.h>
21 #include <android/hardware/tv/tuner/1.0/IDemux.h>
22 #include <android/hardware/tv/tuner/1.1/types.h>
23 
24 #include "DvrClient.h"
25 #include "ClientHelper.h"
26 #include "DvrClientCallback.h"
27 #include "FilterClient.h"
28 #include "FilterClientCallback.h"
29 #include "FrontendClient.h"
30 #include "TimeFilterClient.h"
31 
32 using Status = ::ndk::ScopedAStatus;
33 using ::aidl::android::media::tv::tuner::ITunerDemux;
34 using ::aidl::android::media::tv::tuner::ITunerTimeFilter;
35 
36 using ::android::hardware::tv::tuner::V1_0::IDemux;
37 using ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
38 using ::android::hardware::tv::tuner::V1_0::DvrType;
39 using ::android::hardware::tv::tuner::V1_0::IDemux;
40 using ::android::hardware::tv::tuner::V1_0::ITimeFilter;
41 
42 using namespace std;
43 
44 const int64_t INVALID_AV_SYNC_TIME = -1;
45 const int INVALID_AV_SYNC_HW_ID = -1;
46 
47 namespace android {
48 
49 struct DemuxClient : public RefBase {
50 
51 public:
52     DemuxClient(shared_ptr<ITunerDemux> tunerDemux);
53     ~DemuxClient();
54 
55     // TODO: remove after migration to Tuner Service is done.
56     void setHidlDemux(sp<IDemux> demux);
57 
58     /**
59      * Set a frontend resource as data input of the demux.
60      */
61     Result setFrontendDataSource(sp<FrontendClient> frontendClient);
62 
63     /**
64      * Open a new filter client.
65      */
66     sp<FilterClient> openFilter(DemuxFilterType type, int bufferSize, sp<FilterClientCallback> cb);
67 
68     /**
69      * Open time filter of the demux.
70      */
71     sp<TimeFilterClient> openTimeFilter();
72 
73     /**
74      * Get hardware sync ID for audio and video.
75      */
76     int getAvSyncHwId(sp<FilterClient> filterClient);
77 
78     /**
79      * Get current time stamp to use for A/V sync.
80      */
81     long getAvSyncTime(int avSyncHwId);
82 
83     /**
84      * Open a DVR (Digital Video Record) client.
85      */
86     sp<DvrClient> openDvr(DvrType dvbType, int bufferSize, sp<DvrClientCallback> cb);
87 
88     /**
89      * Connect Conditional Access Modules (CAM) through Common Interface (CI).
90      */
91     Result connectCiCam(int ciCamId);
92 
93     /**
94      * Disconnect Conditional Access Modules (CAM).
95      */
96     Result disconnectCiCam();
97 
98     /**
99      * Release the Demux Client.
100      */
101     Result close();
102 
103     /**
104      * Get the Aidl demux to set as source.
105      */
getAidlDemuxDemuxClient106     shared_ptr<ITunerDemux> getAidlDemux() { return mTunerDemux; }
107 
setIdDemuxClient108     void setId(int id) { mId = id; }
getIdDemuxClient109     int getId() { return mId; }
110 
111 private:
112     sp<IFilter> openHidlFilter(DemuxFilterType type, int bufferSize, sp<HidlFilterCallback> cb);
113     sp<ITimeFilter> openHidlTimeFilter();
114     sp<IDvr> openHidlDvr(DvrType type, int bufferSize, sp<HidlDvrCallback> cb);
115     int getSubType(DemuxFilterType filterType);
116 
117     /**
118      * An AIDL Tuner Demux Singleton assigned at the first time the Tuner Client
119      * opens a demux. Default null when demux is not opened.
120      */
121     shared_ptr<ITunerDemux> mTunerDemux;
122 
123     /**
124      * A Demux HAL interface that is ready before migrating to the TunerDemux.
125      * This is a temprary interface before Tuner Framework migrates to use TunerService.
126      * Default null when the HAL service does not exist.
127      */
128     sp<IDemux> mDemux;
129 
130     int mId;
131 };
132 }  // namespace android
133 
134 #endif  // _ANDROID_MEDIA_TV_DEMUX_CLIENT_H_
135