RDK Documentation (Open Sourced RDK Components)
AampDrmHelperFactory.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 AampDrmHelperFactory.cpp
22  * @brief DRM Helper Engine
23  */
24 
25 #include <algorithm>
26 #include <regex>
27 
28 #include "AampDrmHelper.h"
29 
30 /* DRM Helper Engine */
31 
32 /* Might want to consider double checked here */
33 
34 /**
35  * @brief Get an instance of the DRM Helper Engine
36  */
38 {
39  static AampDrmHelperEngine instance;
40  return instance;
41 }
42 
43 // Consider a mutex for thesie
44 /**
45  * @brief Register a Helper Factory
46  */
48 {
49  factories.push_back(factory);
50  std::sort(factories.begin(), factories.end(),
51  [](AampDrmHelperFactory* a, AampDrmHelperFactory* b) { return (a->getWeighting() < b->getWeighting()); });
52 }
53 
54 /**
55  * @brief Get the supported OCDM system IDs
56  */
57 void AampDrmHelperEngine::getSystemIds(std::vector<std::string>& ids) const
58 {
59  ids.clear();
60  for (auto f : factories )
61  {
62  f->appendSystemId(ids);
63  }
64 }
65 
66 /**
67  * @brief Build a helper class to support the identified DRM
68  */
69 std::shared_ptr<AampDrmHelper> AampDrmHelperEngine::createHelper(const struct DrmInfo& drmInfo, AampLogManager *logObj) const
70 {
71  for (auto helper : factories)
72  {
73  if (true == helper->isDRM(drmInfo))
74  {
75  return helper->createHelper(drmInfo, logObj);
76  }
77  }
78 
79  return NULL;
80 }
81 
82 /* DRM Helper Factory */
83 /**
84  * @brief AampDrmHelperFactory constructor
85  */
86 AampDrmHelperFactory::AampDrmHelperFactory(int weighting) : mWeighting(weighting)
87 {
89 }
90 
91 /**
92  * @brief Determines whether the helper engine has a DRM helper available for the
93  * specified DrmInfo
94  */
95 bool AampDrmHelperEngine::hasDRM(const struct DrmInfo& drmInfo) const
96 {
97  for (auto helper : factories)
98  {
99  if (true == helper->isDRM(drmInfo))
100  {
101  return true;
102  }
103  }
104 
105  return false;
106 }
107 
AampDrmHelper.h
Implented DRM helper functionalities.
AampDrmHelperEngine::getInstance
static AampDrmHelperEngine & getInstance()
Get an instance of the DRM Helper Engine.
Definition: AampDrmHelperFactory.cpp:37
AampDrmHelperFactory::AampDrmHelperFactory
AampDrmHelperFactory(int weighting=DEFAULT_WEIGHTING)
AampDrmHelperFactory constructor.
Definition: AampDrmHelperFactory.cpp:86
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
DrmInfo
DRM information required to decrypt.
Definition: AampDrmInfo.h:47
AampDrmHelperEngine
Helper Engine for Aamp DRM operations.
Definition: AampDrmHelper.h:299
AampDrmHelperFactory
Helper class to Maintain DRM data.
Definition: AampDrmHelper.h:250
AampDrmHelperEngine::hasDRM
bool hasDRM(const struct DrmInfo &drmInfo) const
Determines whether the helper engine has a DRM helper available for the specified DrmInfo.
Definition: AampDrmHelper.h:308
AampDrmHelperEngine::getSystemIds
void getSystemIds(std::vector< std::string > &ids) const
Get the supported OCDM system IDs.
Definition: AampDrmHelperFactory.cpp:57
AampDrmHelperEngine::registerFactory
void registerFactory(AampDrmHelperFactory *factory)
Register a Helper Factory.
Definition: AampDrmHelperFactory.cpp:47
AampDrmHelperEngine::createHelper
std::shared_ptr< AampDrmHelper > createHelper(const struct DrmInfo &drmInfo, AampLogManager *logObj=NULL) const
Build a helper class to support the identified DRM.
Definition: AampDrmHelperFactory.cpp:69