RDK Documentation (Open Sourced RDK Components)
aamp_aes.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 #ifndef _AAMP_AES_H_
21 #define _AAMP_AES_H_
22 
23 /**
24  * @file aamp_aes.h
25  * @brief HLS AES drm decryptor
26  */
27 
28 #include <stddef.h> // for size_t
29 #include "HlsDrmBase.h"
30 #include <openssl/evp.h>
31 #include <memory>
32 
33 /**
34  * @class AesDec
35  * @brief Vanilla AES based DRM management
36  */
37 class AesDec : public HlsDrmBase
38 {
39 public:
40  /**
41  * @fn GetInstance
42  */
43  static std::shared_ptr<AesDec> GetInstance();
44  /**
45  * @fn SetMetaData
46  *
47  * @param aamp AAMP instance to be associated with this decryptor
48  * @param metadata - Ignored
49  *
50  * @retval eDRM_SUCCESS
51  */
52  DrmReturn SetMetaData( PrivateInstanceAAMP *aamp, void* metadata,int trackType, AampLogManager *logObj=NULL);
53  /**
54  * @fn GetState
55  * @retval DRMState
56  */
58  /**
59  * @fn AcquireKey
60  *
61  * @param[in] aamp AAMP instance to be associated with this decryptor
62  * @param[in] metadata Ignored
63  *
64  * @retval None
65  */
66  void AcquireKey( class PrivateInstanceAAMP *aamp, void *metadata,int trackType, AampLogManager *logObj=NULL);
67  /**
68  * @fn SetDecryptInfo
69  *
70  * @param aamp AAMP instance to be associated with this decryptor
71  * @param drmInfo Drm information
72  * @retval eDRM_SUCCESS on success
73  */
74  DrmReturn SetDecryptInfo( PrivateInstanceAAMP *aamp, const struct DrmInfo *drmInfo, AampLogManager *logObj=NULL);
75  /**
76  * @fn Decrypt
77  * @param bucketType Type of bucket for profiling
78  * @param encryptedDataPtr pointer to encyrpted payload
79  * @param encryptedDataLen length in bytes of data pointed to by encryptedDataPtr
80  * @param timeInMs wait time
81  */
82  DrmReturn Decrypt(ProfilerBucketType bucketType, void *encryptedDataPtr, size_t encryptedDataLen, int timeInMs);
83  /**
84  * @fn Release
85  */
86  void Release();
87  /**
88  * @fn CancelKeyWait
89  *
90  */
91  void CancelKeyWait();
92  /**
93  * @fn RestoreKeyState
94  */
95  void RestoreKeyState();
96 
97  /*Functions to support internal operations*/
98  /**
99  * @brief Acquire drm key from URI
100  */
101  void AcquireKey();
102  /**
103  * @fn SignalKeyAcquired
104  */
105  void SignalKeyAcquired();
106  /**
107  * @fn NotifyDRMError
108  * @param drmFailure drm error type
109  */
110  void NotifyDRMError(AAMPTuneFailure drmFailure);
111  /**
112  * @fn SignalDrmError
113  */
114  void SignalDrmError();
115  /**
116  * @fn WaitForKeyAcquireCompleteUnlocked
117  * @param[in] timeInMs timeout
118  * @param[out] err error on failure
119  */
120  void WaitForKeyAcquireCompleteUnlocked(int timeInMs, DrmReturn &err);
121  /**
122  * @fn AesDec
123  *
124  */
125  AesDec();
126  /**
127  * @fn ~AesDec
128  */
129  ~AesDec();
130  AesDec(const AesDec&) = delete;
131  AesDec& operator=(const AesDec&) = delete;
132 
133 private:
134 
135  static std::shared_ptr<AesDec> mInstance;
136  PrivateInstanceAAMP *mpAamp;
137  pthread_cond_t mCond;
138  pthread_mutex_t mMutex;
139 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
140  EVP_CIPHER_CTX *mOpensslCtx;
141 #else
142  EVP_CIPHER_CTX mOpensslCtx;
143 #endif
144  DrmInfo mDrmInfo ;
145  GrowableBuffer mAesKeyBuf;
146  DRMState mDrmState;
147  DRMState mPrevDrmState;
148  std::string mDrmUrl;
149  int mCurlInstance;
150  int mAcquireKeyWaitTime;
151  pthread_t licenseAcquisitionThreadId;
152  bool licenseAcquisitionThreadStarted;
153 };
154 
155 #endif // _AAMP_AES_H_
AesDec::~AesDec
~AesDec()
AesDec Destructor.
Definition: aamp_aes.cpp:443
AesDec::CancelKeyWait
void CancelKeyWait()
Cancel timed_wait operation drm_Decrypt.
Definition: aamp_aes.cpp:373
DrmReturn
DrmReturn
Return values of various functions.
Definition: HlsDrmBase.h:35
AesDec::GetInstance
static std::shared_ptr< AesDec > GetInstance()
Get singleton instance.
Definition: aamp_aes.cpp:407
AesDec::Release
void Release()
Release drm session.
Definition: aamp_aes.cpp:336
AesDec::NotifyDRMError
void NotifyDRMError(AAMPTuneFailure drmFailure)
Notify drm error.
Definition: aamp_aes.cpp:59
AesDec::WaitForKeyAcquireCompleteUnlocked
void WaitForKeyAcquireCompleteUnlocked(int timeInMs, DrmReturn &err)
Wait for key acquisition completion.
Definition: aamp_aes.cpp:255
AesDec::RestoreKeyState
void RestoreKeyState()
Restore key state post cleanup of audio/video TrackState in case DRM data is persisted.
Definition: aamp_aes.cpp:391
AesDec::GetState
DRMState GetState()
GetState Function to get current DRM State.
Definition: aamp_aes.cpp:181
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AesDec::SetDecryptInfo
DrmReturn SetDecryptInfo(PrivateInstanceAAMP *aamp, const struct DrmInfo *drmInfo, AampLogManager *logObj=NULL)
Set information required for decryption.
Definition: aamp_aes.cpp:190
AesDec::SignalKeyAcquired
void SignalKeyAcquired()
Signal key acquired event.
Definition: aamp_aes.cpp:94
HlsDrmBase
Base class of HLS DRM implementations.
Definition: HlsDrmBase.h:59
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
AesDec::Decrypt
DrmReturn Decrypt(ProfilerBucketType bucketType, void *encryptedDataPtr, size_t encryptedDataLen, int timeInMs)
Decrypts an encrypted buffer.
Definition: aamp_aes.cpp:271
AesDec::AesDec
AesDec()
AesDec Constructor.
Definition: aamp_aes.cpp:422
AesDec
Vanilla AES based DRM management.
Definition: aamp_aes.h:37
DRMState
DRMState
States of DRM object.
Definition: HlsDrmBase.h:46
AesDec::SignalDrmError
void SignalDrmError()
Signal drm error.
Definition: aamp_aes.cpp:82
AAMPTuneFailure
AAMPTuneFailure
AAMP playback error codes.
Definition: AampEvent.h:108
GrowableBuffer
Structure of GrowableBuffer.
Definition: AampMemoryUtils.h:39
PrivateInstanceAAMP
Class representing the AAMP player's private instance, which is not exposed to outside world.
Definition: priv_aamp.h:640
ProfilerBucketType
ProfilerBucketType
Bucket types of AAMP profiler.
Definition: AampProfiler.h:43
HlsDrmBase.h
Declaration common to various HLS DRM implementations.
AesDec::AcquireKey
void AcquireKey()
Acquire drm key from URI.
Definition: aamp_aes.cpp:107
AesDec::SetMetaData
DrmReturn SetMetaData(PrivateInstanceAAMP *aamp, void *metadata, int trackType, AampLogManager *logObj=NULL)
Set DRM meta-data. Stub implementation.
Definition: aamp_aes.cpp:164