RDK Documentation (Open Sourced RDK Components)
AampHlsOcdmBridge.cpp
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 2020 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 AampHlsOcdmBridge.cpp
22  * @brief Handles OCDM bridge to validate DRM License
23  */
24 
25 #include "AampHlsOcdmBridge.h"
26 
27 #define DRM_IV_LEN 16
28 
29 using namespace std;
30 
31 
32 AampHlsOcdmBridge::AampHlsOcdmBridge(AampLogManager *logObj, AampDrmSession * aampDrmSession) :
33  m_drmInfo(nullptr),
34  m_aampInstance(nullptr),
35  m_drmSession(aampDrmSession),
36  m_drmState(eDRM_INITIALIZED),
37  m_Mutex(),
38  mLogObj(logObj)
39 {
40  pthread_mutex_init(&m_Mutex, NULL);
41 }
42 
43 
44 AampHlsOcdmBridge::~AampHlsOcdmBridge()
45 {
46  pthread_mutex_destroy(&m_Mutex);
47 }
48 
49 
51 {
52  DrmReturn result = eDRM_ERROR;
53 
54  pthread_mutex_lock(&m_Mutex);
55  m_aampInstance = aamp;
56  m_drmInfo = drmInfo;
57  KeyState eKeyState = m_drmSession->getState();
58  if (eKeyState == KEY_READY)
59  {
60  m_drmState = eDRM_KEY_ACQUIRED;
61  result = eDRM_SUCCESS; //frag_collector ignores the return
62  }
63  pthread_mutex_unlock(&m_Mutex);
64  AAMPLOG_TRACE("DecryptInfo Set\n");
65 
66  return result;
67 }
68 
69 
70 DrmReturn AampHlsOcdmBridge::Decrypt( ProfilerBucketType bucketType, void *encryptedDataPtr, size_t encryptedDataLen,int timeInMs)
71 {
72  DrmReturn result = eDRM_ERROR;
73 
74  pthread_mutex_lock(&m_Mutex);
75  if (m_drmState == eDRM_KEY_ACQUIRED)
76  {
77  AAMPLOG_TRACE("Starting decrypt\n");
78  int retVal = m_drmSession->decrypt(m_drmInfo->iv, DRM_IV_LEN, (const uint8_t *)encryptedDataPtr , encryptedDataLen, NULL);
79  if (retVal)
80  {
81  AAMPLOG_WARN("Decrypt failed err = %d\n", retVal);
82  }
83  else
84  {
85  AAMPLOG_TRACE("Decrypt success\n");
86  result = eDRM_SUCCESS;
87  }
88  }
89  else
90  {
91  AAMPLOG_WARN("Decrypt Called in Incorrect State! DrmState = %d\n", (int)m_drmState);
92  }
93  pthread_mutex_unlock(&m_Mutex);
94 
95  return result;
96 }
97 
98 
100 {
101  AAMPLOG_WARN("Releasing the Opencdm Session\n");
102  m_drmSession->clearDecryptContext();
103 }
104 
105 
107 {
108  //TBD:Unimplemented
109 }
110 
DrmReturn
DrmReturn
Return values of various functions.
Definition: HlsDrmBase.h:35
eDRM_KEY_ACQUIRED
@ eDRM_KEY_ACQUIRED
Definition: HlsDrmBase.h:50
AampDrmSession::clearDecryptContext
virtual void clearDecryptContext()=0
Clear the current session context So that new init data can be bound.
AampHlsOcdmBridge::Decrypt
virtual DrmReturn Decrypt(ProfilerBucketType bucketType, void *encryptedDataPtr, size_t encryptedDataLen, int timeInMs=3000) override
Decrypts an encrypted buffer.
Definition: AampHlsOcdmBridge.cpp:70
DrmInfo::iv
unsigned char * iv
Definition: AampDrmInfo.h:84
AampHlsOcdmBridge::CancelKeyWait
virtual void CancelKeyWait() override
Cancel timed_wait operation drm_Decrypt.
Definition: AampHlsOcdmBridge.cpp:106
AampHlsOcdmBridge.h
Handles OCDM bridge to validate DRM License.
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampDrmSession::decrypt
virtual int decrypt(GstBuffer *keyIDBuffer, GstBuffer *ivBuffer, GstBuffer *buffer, unsigned subSampleCount, GstBuffer *subSamplesBuffer, GstCaps *caps=NULL)
Function to decrypt GStreamer stream buffer.
Definition: AampDrmSession.cpp:55
eDRM_SUCCESS
@ eDRM_SUCCESS
Definition: HlsDrmBase.h:37
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
AampHlsOcdmBridge::Release
virtual void Release() override
Release drm session.
Definition: AampHlsOcdmBridge.cpp:99
AampDrmSession
Base class for DRM sessions.
Definition: AampDrmSession.h:69
AampDrmSession::getState
virtual KeyState getState()=0
Get the current state of DRM Session.
AAMPLOG_TRACE
#define AAMPLOG_TRACE(FORMAT,...)
AAMP logging defines, this can be enabled through setLogLevel() as per the need.
Definition: AampLogManager.h:83
eDRM_INITIALIZED
@ eDRM_INITIALIZED
Definition: HlsDrmBase.h:48
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
AampHlsOcdmBridge::SetDecryptInfo
virtual DrmReturn SetDecryptInfo(PrivateInstanceAAMP *aamp, const struct DrmInfo *drmInfoi, AampLogManager *logObj=NULL) override
Set information required for decryption.
Definition: AampHlsOcdmBridge.cpp:50
ProfilerBucketType
ProfilerBucketType
Bucket types of AAMP profiler.
Definition: AampProfiler.h:43
KEY_READY
@ KEY_READY
Definition: AampDrmSession.h:58
KeyState
KeyState
DRM session states.
Definition: AampDrmSession.h:54
eDRM_ERROR
@ eDRM_ERROR
Definition: HlsDrmBase.h:38