-
Notifications
You must be signed in to change notification settings - Fork 0
/
AampDRMLicPreFetcher.h
200 lines (179 loc) · 6.31 KB
/
AampDRMLicPreFetcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* If not stated otherwise in this file or this component's license file the
* following copyright and licenses apply:
*
* Copyright 2023 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _AAMP_LICENSE_PREFETCHER_HPP
#define _AAMP_LICENSE_PREFETCHER_HPP
#include <thread>
#include <deque>
#include <string>
#include <vector>
#include <memory>
#include <array>
#include "AampDrmHelper.h"
#include "AampLogManager.h"
#include "priv_aamp.h"
#include "AampDRMLicPreFetcherInterface.h"
/**
* @brief Structure for storing the pre-fetch data
*
*/
struct LicensePreFetchObject
{
std::shared_ptr<AampDrmHelper> mHelper; /** drm helper for the content protection*/
std::string mPeriodId; /** Period ID*/
uint32_t mAdaptationIdx; /** Adapatation Index*/
MediaType mType; /** Stream type*/
int mId; /** Object ID*/
static int staticId;
/**
* @brief Construct a new License Pre Fetch Object object
*
* @param drmHelper AampDrmHelper shared_ptr
* @param periodId ID of the period to which CP belongs to
* @param adapIdx Index of the adaptation to which CP belongs to
* @param type media type
*/
LicensePreFetchObject(std::shared_ptr<AampDrmHelper> drmHelper, std::string periodId, uint32_t adapIdx, MediaType type): mHelper(drmHelper),
mPeriodId(periodId),
mAdaptationIdx(adapIdx),
mType(type),
mId(staticId++)
{
AAMPLOG_TRACE("Creating new LicensePreFetchObject, id:%d", mId);
}
/**
* @brief Destroy the License Pre Fetch Object object
*
*/
~LicensePreFetchObject()
{
AAMPLOG_TRACE("Deleting LicensePreFetchObject, id:%d", mId);
}
/**
* @brief Compare two LicensePreFetchObject objects
*
* @param other LicensePreFetchObject to be compared to
* @return true if both objects are having same info
* @return false otherwise
*/
bool compare(std::shared_ptr<LicensePreFetchObject> other) const
{
return ((other != nullptr) && mHelper->compare(other->mHelper) && mType == other->mType);
}
};
using LicensePreFetchObjectPtr = std::shared_ptr<LicensePreFetchObject>;
/**
* @brief Class for License PreFetcher module.
* Handles the license pre-fetching responsibilities in a playback for faster tune times
*/
class AampLicensePreFetcher
{
public:
/**
* @brief Default constructor disabled
*/
AampLicensePreFetcher() = delete;
/**
* @brief Construct a new Aamp License Pre Fetcher object
*
* @param logObj Log manager object
* @param aamp PrivateInstanceAAMP instance
* @param fetcherInstance AampLicenseFetcher instance
*/
AampLicensePreFetcher(AampLogManager *logObj, PrivateInstanceAAMP *aamp, AampLicenseFetcher *fetcherInstance);
/**
* @brief Copy constructor disabled
*
*/
AampLicensePreFetcher(const AampLicensePreFetcher&) = delete;
/**
* @brief Assignment operator disabled
*
*/
void operator=(const AampLicensePreFetcher&) = delete;
/**
* @brief Destroy the Aamp License Pre Fetcher object
*
*/
~AampLicensePreFetcher();
/**
* @brief Initialize resources
*
* @return true if successfully initialized
* @return false if error occurred
*/
bool Init();
/**
* @brief Queue a content protection info to be processed later
*
* @param drmHelper AampDrmHelper shared_ptr
* @param periodId ID of the period to which CP belongs to
* @param adapId Index of the adaptation to which CP belongs to
* @param type media type
* @return true if successfully queued
* @return false if error occurred
*/
bool QueueContentProtection(std::shared_ptr<AampDrmHelper> drmHelper, std::string periodId, uint32_t adapIdx, MediaType type);
/**
* @brief De-initialize/free resources
*
* @return true if success
* @return false if failed
*/
bool DeInit();
/**
* @brief Set the Common Key Duration object
*
* @param keyDuration key duration
*/
void SetCommonKeyDuration(int keyDuration) { mCommonKeyDuration = keyDuration; }
/**
* @brief Thread for processing content protection queued using QueueContentProtection
* Thread will be joined when DeInit is called
*
*/
void PreFetchThread();
private:
/**
* @brief To notify DRM failure to player after proper checks
*
* @param fetchObj object for which session creation failed
* @param event drm metadata event object with failure details
*/
void NotifyDrmFailure(LicensePreFetchObjectPtr fetchObj, DrmMetaDataEventPtr event);
/**
* @brief Creates a DRM session for a content protection
*
* @param fetchObj LicensePreFetchObject shared_ptr
* @return true if successfully created DRM session
* @return false if failed
*/
bool CreateDRMSession(LicensePreFetchObjectPtr fetchObj);
std::thread mPreFetchThread; /** Thread for pre-fetching license*/
std::deque<LicensePreFetchObjectPtr> mFetchQueue; /** Queue for storing content protection objects*/
std::mutex mQMutex; /** Mutex for accessing the mFetchQueue*/
std::condition_variable mQCond; /** Conditional variable to notify addition of an obj to mFetchQueue*/
bool mPreFetchThreadStarted; /** Flag denotes if thread started*/
bool mExitLoop; /** Flag denotes if pre-fetch thread has to be exited*/
int mCommonKeyDuration; /** Common key duration for deferred license acquistion*/
std::array<bool, AAMP_TRACK_COUNT> mTrackStatus; /** To mark the status of license acquistion for tracks*/
PrivateInstanceAAMP *mPrivAAMP; /** PrivateInstanceAAMP instance*/
AampLogManager* mLogObj; /** AampLogManager instance */
AampLicenseFetcher *mFetchInstance; /** AampLicenseFetcher instance for notifying DRM session status*/
};
#endif /* _AAMP_LICENSE_PREFETCHER_HPP */