RDK Documentation (Open Sourced RDK Components)
aampoutputprotection.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file aampoutputprotection.h
22  * @brief Output protection management for Aamp
23  */
24 
25 #ifndef aampoutputprotection_h
26 #define aampoutputprotection_h
27 
28 #include <pthread.h>
29 
30 #ifdef IARM_MGR
31 // IARM
32 #include "manager.hpp"
33 #include "host.hpp"
34 #include "videoResolution.hpp"
35 #include "videoOutputPort.hpp"
36 #include "videoOutputPortType.hpp"
37 #include <libIARM.h>
38 #include <libIBus.h>
39 #include "libIBusDaemon.h"
40 #include "dsMgr.h"
41 #include "dsDisplay.h"
42 #include <iarmUtil.h>
43 
44 #else
45 #include <stdint.h>
46 typedef int dsHdcpProtocolVersion_t;
47 #define dsHDCP_VERSION_MAX 30
48 #define dsHDCP_VERSION_2X 22
49 #define dsHDCP_VERSION_1X 14
50 #endif // IARM_MGR
51 
52 #include <stdio.h>
53 #include <gst/gst.h>
54 
55 #ifndef USE_OPENCDM
56 #ifdef USE_PLAYREADY
57 
58 #include <drmbuild_oem.h>
59 #include <drmcommon.h>
60 #include <drmmanager.h>
61 #include <drmmathsafe.h>
62 #include <drmtypes.h>
63 #include <drmerr.h>
64 #endif
65 #endif
66 
67 #undef __in
68 #undef __out
69 #undef __reserved
70 using namespace std;
71 
72 #define UHD_WITDH 3840
73 #define UHD_HEIGHT 2160
74 
75 /**
76  * @class ReferenceCount
77  * @brief Provides reference based memory management
78  */
80 {
81 public:
82 
83  ReferenceCount() : m_refCount(0), m_refCountMutex() {
84  pthread_mutex_init(&m_refCountMutex, NULL);
85  }
86 
87  virtual ~ReferenceCount() {
88  pthread_mutex_destroy(&m_refCountMutex);
89  }
90 
91 
92  uint32_t AddRef() const {
93  pthread_mutex_lock(&m_refCountMutex);
94  m_refCount++;
95  pthread_mutex_unlock(&m_refCountMutex);
96  return m_refCount;
97  }
98 
99 
100  void Release() const {
101  pthread_mutex_lock(&m_refCountMutex);
102  m_refCount--;
103  pthread_mutex_unlock(&m_refCountMutex);
104 
105  if(m_refCount == 0) {
106  delete (ReferenceCount *)this;
107  }
108  }
109 
110 private:
111  mutable pthread_mutex_t m_refCountMutex;
112  mutable int m_refCount;
113 };
114 
115 /**
116  * @class AampOutputProtection
117  * @brief Class to enforce HDCP authentication
118  */
120 {
121 
122 private:
123 #ifndef USE_OPENCDM
124 #ifdef USE_PLAYREADY
125  // Protection levels from CDM
126  struct MinOPLevelsplayReady
127  {
128  DRM_WORD compressedDigitalVideo;
129  DRM_WORD uncompressedDigitalVideo;
130  DRM_WORD analogVideo;
131  DRM_WORD compressedDigitalAudio;
132  DRM_WORD uncompressedDigitalAudio;
133  };
134 #endif
135 #endif
136 
137  pthread_mutex_t m_opProtectMutex;
138 
139 #ifndef USE_OPENCDM
140 #ifdef USE_PLAYREADY
141  MinOPLevelsplayReady m_minOPLevels;
142 #endif
143 #endif
144  int m_sourceWidth;
145  int m_sourceHeight;
146  int m_displayWidth;
147  int m_displayHeight;
148  bool m_isHDCPEnabled;
149  dsHdcpProtocolVersion_t m_hdcpCurrentProtocol;
150  GstElement* m_gstElement;
151 
152  /**
153  * @fn SetHDMIStatus
154  */
155  void SetHDMIStatus();
156  /**
157  * @fn SetResolution
158  * @param width display width
159  * @param height display height
160  */
161  void SetResolution(int width, int height);
162 
163 public:
164  /**
165  * @fn AampOutputProtection
166  */
168  /**
169  * @fn ~AampOutputProtection
170  */
171  virtual ~AampOutputProtection();
172  /**
173  * @brief Copy constructor disabled
174  *
175  */
177  /**
178  * @brief assignment operator disabled
179  *
180  */
181  AampOutputProtection& operator=(const AampOutputProtection&) = delete;
182 
183 #ifndef USE_OPENCDM
184 
185  /**
186  * @brief Get PlayRedy OP levels
187  * @retval m_minOPLevels
188  */
189 #ifdef USE_PLAYREADY
190 
191  MinOPLevelsplayReady* getPlayReadyLevels() { return & m_minOPLevels; }
192  /**
193  * @fn PR_OP_Callback
194  * @param f_pvOutputLevelsData : Pointer to licenses output restrictions information
195  * @param f_dwCallbackType : Type of callback
196  * @param data : Pointer passed from Drm_Reader_Bind, m_minOPLevels
197  */
198  static DRM_RESULT DRM_CALL PR_OP_Callback(const DRM_VOID *f_pvOutputLevelsData,
199  DRM_POLICY_CALLBACK_TYPE f_dwCallbackType,
200  const DRM_VOID *data);
201 #endif
202 #endif
203 
204 #ifdef IARM_MGR
205  // IARM Callbacks
206  /**
207  * @fn HDMIEventHandler
208  * @param owner Owner of the IARM mgr
209  * @param eventId IARM Event ID
210  * @param data HDMI data
211  * @param len Length of the data
212  */
213  static void HDMIEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
214  /**
215  * @fn ResolutionHandler
216  * @param owner Owner of the IARM mgr
217  * @param eventId IARM Event ID
218  * @param data IARM data
219  * @param len Length of the data
220  */
221  static void ResolutionHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
222 #endif //IARM_MGR
223 
224  // State functions
225 
226  /**
227  * @brief Check if HDCP is 2.2
228  * @retval true if 2.2 false otherwise
229  */
230  bool isHDCPConnection2_2() { return m_hdcpCurrentProtocol == dsHDCP_VERSION_2X; }
231  /**
232  * @fn IsSourceUHD
233  * @retval true, if source is UHD, otherwise false
234  */
235  bool IsSourceUHD();
236 
237  /**
238  * @fn GetDisplayResolution
239  * @param[out] width : Display Width
240  * @param[out] height : Display height
241  */
242  void GetDisplayResolution(int &width, int &height);
243 
244  /**
245  * @brief Set GstElement
246  * @param element Gst element to set
247  */
248  void setGstElement(GstElement *element) { m_gstElement = element; }
249 
250  // Singleton for object creation
251 
252  /**
253  * @fn GetAampOutputProcectionInstance
254  * @retval AampOutputProtection object
255  */
256  static AampOutputProtection * GetAampOutputProcectionInstance();
257  /**
258  * @fn IsAampOutputProcectionInstanceActive
259  * @retval true or false
260  */
261  static bool IsAampOutputProcectionInstanceActive();
262 
263 };
264 
265 #endif // aampoutputprotection_h
manager.hpp
It contains class referenced by manager.cpp file.
AampOutputProtection
Class to enforce HDCP authentication.
Definition: aampoutputprotection.h:119
dsHDCP_VERSION_2X
@ dsHDCP_VERSION_2X
Definition: dsTypes.h:406
videoOutputPortType.hpp
It contains structures and class referenced by the videoOutputportTypes.cpp file.
videoResolution.hpp
It contains class and structure refrenced by the videoResolution.cpp file.
libIBus.h
RDK IARM-Bus API Declarations.
AampOutputProtection::setGstElement
void setGstElement(GstElement *element)
Set GstElement.
Definition: aampoutputprotection.h:248
AampOutputProtection::isHDCPConnection2_2
bool isHDCPConnection2_2()
Get PlayRedy OP levels.
Definition: aampoutputprotection.h:230
dsDisplay.h
videoOutputPort.hpp
It contains class and structure refrenced by the videooutputport.cpp file.
ReferenceCount
Provides reference based memory management.
Definition: aampoutputprotection.h:79