Skip to content
This repository was archived by the owner on Jan 26, 2023. It is now read-only.
/ rdk-aamp Public archive

Commit 025ef11

Browse files
anthorntpmaria904
authored and
pmaria904
committed
RDK-37615: [AAMP] Add library mocks and stubs
Reason for change: Add AAMP support library mocks and stubs so that AAMP can be built using the build host compiler aiding the detection of compilation issues. Test Procedure: Build AAMP as described in test/mocks/README.txt. Risks: Low. Signed-off-by: [email protected] Change-Id: I8730b9e5b742de52e9cfa4904bebc5eed9696bde RDK-38097: [AAMP] Fix the DRM cppunit tests Reason for change: Get the Aamp DRM tests building and running. Test Procedure: Run the test/Drm/runtest.sh script. Risks: Low - only minor changes to the Aamp source code. Signed-off-by: [email protected] Change-Id: I07cafcdc6eb166199d5669483710529b93be6e11
1 parent 2fab49b commit 025ef11

37 files changed

+1475
-254
lines changed

AampJsonObject.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ bool AampJsonObject::add(const std::string& name, const std::string& value, cons
8282
return res;
8383
}
8484

85+
/**
86+
* @brief Add a string value
87+
*/
88+
bool AampJsonObject::add(const std::string& name, const char *value, const ENCODING encoding)
89+
{
90+
return add(name, std::string(value), encoding);
91+
}
92+
8593
/**
8694
* @brief Add a vector of string values as a JSON array
8795
*/

AampJsonObject.h

+9
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ class AampJsonObject {
5959
*/
6060
bool add(const std::string& name, const std::string& value, const ENCODING encoding = ENCODING_STRING);
6161

62+
/**
63+
* @fn add
64+
*
65+
* @param name name for the value
66+
* @param value string value to add
67+
* @return true if successfully added, false otherwise
68+
*/
69+
bool add(const std::string& name, const char *value, const ENCODING encoding = ENCODING_STRING);
70+
6271
/**
6372
* @fn add
6473
*

CMakeLists.txt

+69-15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pkg_check_modules(LIBDASH REQUIRED libdash)
3838
pkg_check_modules(OPENSSL REQUIRED openssl)
3939
pkg_check_modules(LIBCJSON REQUIRED libcjson)
4040

41+
include(test/mocks/mocks.cmake NO_POLICY_SCOPE)
42+
4143
if (CMAKE_WPEFRAMEWORK_REQUIRED)
4244
message("CMAKE_WPEFRAMEWORK_REQUIRED set")
4345
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
@@ -157,7 +159,13 @@ if (CMAKE_WPEFRAMEWORK_REQUIRED)
157159
endif()
158160

159161
if(CMAKE_USE_SECCLIENT)
160-
set(SEC_CLIENT_LIB -lSecClient )
162+
if (CMAKE_USE_SECCLIENT_MOCKS)
163+
copy_staging_header_file(sec_client.h)
164+
copy_staging_header_file(sec_security_datatype.h)
165+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/mocks/secClientMocks.cpp)
166+
else()
167+
set(SEC_CLIENT_LIB -lSecClient )
168+
endif()
161169
endif()
162170
if(CMAKE_USE_SECMANAGER)
163171
if (NOT CMAKE_WPEFRAMEWORK_REQUIRED)
@@ -224,6 +232,22 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-multichar -std=c++11 -Wno-non-virtu
224232
if(CMAKE_IARM_MGR)
225233
message("CMAKE_IARM_MGR set")
226234
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DIARM_MGR=1")
235+
236+
if (CMAKE_IARM_MGR_MOCKS)
237+
message("CMAKE_IARM_MGR_MOCKS set, building IARM stubs")
238+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/mocks/iarmMgrMocks.cpp)
239+
set(LIBAAMP_MOCK_DEPENDS -lgmock -lgtest)
240+
find_path(STAGING_INCDIR rdk/iarmbus)
241+
include_directories(${STAGING_INCDIR}/rdk/iarmbus)
242+
find_path(STAGING_INCDIR rdk/tr69hostif)
243+
include_directories(${STAGING_INCDIR}/rdk/tr69hostif)
244+
find_path(STAGING_INCDIR rdk/ds)
245+
include_directories(${STAGING_INCDIR}/rdk/ds
246+
${STAGING_INCDIR}/rdk/ds-hal
247+
${STAGING_INCDIR}/rdk/ds-rpc)
248+
find_path(STAGING_INCDIR rdk/iarmmgrs/ir)
249+
include_directories(${STAGING_INCDIR}/rdk/iarmmgrs/ir)
250+
endif()
227251
endif()
228252

229253
if(CMAKE_PLATFORM_UBUNTU)
@@ -297,7 +321,7 @@ if(CMAKE_USE_OPENCDM OR CMAKE_USE_OPENCDM_ADAPTER)
297321
)
298322
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DDRM_BUILD_PROFILE=DRM_BUILD_PROFILE_OEM -DTARGET_LITTLE_ENDIAN=1 -DTARGET_SUPPORTS_UNALIGNED_DWORD_POINTERS=0")
299323

300-
if(CMAKE_IARM_MGR)
324+
if(CMAKE_IARM_MGR AND NOT CMAKE_IARM_MGR_MOCKS)
301325
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lIARMBus -lds -ldshalcli")
302326
endif()
303327

@@ -321,7 +345,11 @@ if(CMAKE_USE_OPENCDM OR CMAKE_USE_OPENCDM_ADAPTER)
321345
message("Forced RTK ION libraries to ${REALTEK_ION_LIBRARY}")
322346
endif()
323347
link_directories(${REALTEK_ION_LIBRARY})
324-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lion -lrtk_ion")
348+
if (CMAKE_USE_ION_MEMORY_MOCKS)
349+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/mocks/ionMemoryMocks.cpp)
350+
else()
351+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lion -lrtk_ion")
352+
endif()
325353
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DUSE_ION_MEMORY")
326354
set(LIBAAMP_HELP_SOURCES "${LIBAAMP_HELP_SOURCES}" drm/AampIonMemorySystem.cpp)
327355
else()
@@ -368,7 +396,12 @@ if(CMAKE_USE_OPENCDM_ADAPTER)
368396
if(DEFINED SAGE_SVP)
369397
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DCONTENT_4K_SUPPORTED")
370398
endif()
371-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -locdm")
399+
if(CMAKE_USE_OPENCDM_ADAPTER_MOCKS)
400+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/mocks/opencdmMocks.cpp)
401+
set(LIBAAMP_MOCK_DEPENDS -lgmock -lgtest)
402+
else()
403+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -locdm")
404+
endif()
372405
find_path (STAGING_INCDIR opencdm)
373406
include_directories(${STAGING_INCDIR}/opencdm)
374407
find_path (STAGING_INCDIR gstreamer-1.0)
@@ -399,7 +432,11 @@ elseif(CMAKE_CDM_DRM)
399432
set(LIBAAMP_DRM_SOURCES "${LIBAAMP_DRM_SOURCES}" drm/playreadydrmsession.cpp )
400433
set(LIBAAMP_HELP_SOURCES "${LIBAAMP_HELP_SOURCES}" drm/helper/AampPlayReadyHelper.cpp)
401434
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DUSE_PLAYREADY -DDRM_BUILD_PROFILE=DRM_BUILD_PROFILE_OEM -DTARGET_LITTLE_ENDIAN=1 -DTARGET_SUPPORTS_UNALIGNED_DWORD_POINTERS=0")
402-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lplayready")
435+
if(CMAKE_USE_PLAYREADY_MOCKS)
436+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/fakes/playreadyFakes.cpp)
437+
else()
438+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lplayready")
439+
endif()
403440
find_path (STAGING_INCDIR playready)
404441
find_path (STAGING_INCDIR playready/oem/common/inc)
405442
find_path (STAGING_INCDIR playready/oem/ansi/inc)
@@ -411,24 +448,26 @@ elseif(CMAKE_CDM_DRM)
411448
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DUSE_SECAPI_BRCMHW=1")
412449
if(DEFINED SAGE_SVP)
413450
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DUSE_SAGE_SVP -DCONTENT_4K_SUPPORTED")
414-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lsec_api -lb_secbuf -lnexus -lbrcmsvpmeta")
451+
if (NOT CMAKE_USE_SEC_API_MOCKS)
452+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lsec_api -lb_secbuf -lnexus -lbrcmsvpmeta")
453+
endif()
415454
else()
416-
if (CMAKE_USE_PLAYREADY)
455+
if (CMAKE_USE_PLAYREADY AND NOT CMAKE_USE_SEC_API_MOCKS)
417456
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lsec_api")
418-
endif(CMAKE_USE_PLAYREADY)
457+
endif()
419458
endif()
420459
elseif(DEFINED SECAPI_ENGINE_BROADCOM_RAAGA)
421460
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DUSE_SECAPI_BRCMHW=1")
422-
if (CMAKE_USE_PLAYREADY)
461+
if (CMAKE_USE_PLAYREADY AND NOT CMAKE_USE_SEC_API_MOCKS)
423462
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lsec_api")
424463
endif()
425464
else()
426-
if (CMAKE_USE_PLAYREADY)
465+
if (CMAKE_USE_PLAYREADY AND NOT CMAKE_USE_SEC_API_MOCKS)
427466
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lsec_api_crypto")
428467
endif()
429468
endif()
430469

431-
if(CMAKE_IARM_MGR)
470+
if(CMAKE_IARM_MGR AND NOT CMAKE_IARM_MGR_MOCKS)
432471
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lIARMBus -lds -ldshalcli")
433472
endif()
434473
endif()
@@ -443,7 +482,13 @@ if (CMAKE_AAMP_RFC_REQUIRED)
443482
message("AAMP RFC set")
444483
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DAAMP_RFC_ENABLED")
445484
set(LIBAAMP_SOURCES ${LIBAAMP_SOURCES} AampRfc.cpp)
446-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -ltr181api")
485+
if(CMAKE_USE_RFC_MOCKS)
486+
copy_staging_header_file(tr181api.h)
487+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/mocks/rfcMocks.cpp)
488+
set(LIBAAMP_MOCK_DEPENDS -lgmock -lgtest)
489+
else()
490+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -ltr181api")
491+
endif()
447492
endif()
448493

449494
if (CMAKE_RDK_CC_ENABLED)
@@ -454,7 +499,16 @@ if (CMAKE_RDK_CC_ENABLED)
454499
include_directories(closedcaptions/rdk)
455500
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} -DAAMP_RDK_CC_ENABLED")
456501
set(LIBAAMP_SOURCES ${LIBAAMP_SOURCES} closedcaptions/rdk/AampRDKCCManager.cpp)
457-
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lrdkCCReader -lrdkCCManager -lrdkCCGfx -l${DIRECTFB_LIBRARIES}")
502+
if (CMAKE_USE_CC_MANAGER_MOCKS)
503+
find_path(STAGING_INCDIR closedcaption)
504+
include_directories(${STAGING_INCDIR}/closedcaption)
505+
include_directories(${STAGING_INCDIR}/closedcaption/ccGraphics)
506+
include_directories(${STAGING_INCDIR}/closedcaption/ccManager)
507+
set(LIBAAMP_MOCK_SOURCES ${LIBAAMP_MOCK_SOURCES} test/fakes/ccManagerFakes.cpp)
508+
copy_staging_header_file(vlCCConstants.h)
509+
else()
510+
set(LIBAAMP_DEPENDS "${LIBAAMP_DEPENDS} -lrdkCCReader -lrdkCCManager -lrdkCCGfx -l${DIRECTFB_LIBRARIES}")
511+
endif()
458512
endif()
459513

460514
set(AAMP_SUBTEC_CLASS_SOURCES subtec/subtecparser/WebVttSubtecParser.cpp subtec/subtecparser/TtmlSubtecParser.cpp subtec/subtecparser/WebvttSubtecDevParser.cpp)
@@ -501,7 +555,7 @@ endif()
501555

502556
set(LIBAAMP_DEFINES "${LIBAAMP_DEFINES} ${SEC_CONTENT_METADATA_ENABLED}")
503557

504-
set(LIBAAMP_SOURCES "${LIBAAMP_SOURCES}" "${LIBAAMP_DRM_SOURCES}")
558+
set(LIBAAMP_SOURCES "${LIBAAMP_SOURCES}" "${LIBAAMP_DRM_SOURCES}" "${LIBAAMP_MOCK_SOURCES}")
505559

506560
add_library(aamp SHARED ${LIBAAMP_SOURCES} ${LIBAAMP_HELP_SOURCES})
507561
add_executable(aamp-cli ${AAMP_CLI_HEADERS} ${AAMP_CLI_SOURCES})
@@ -567,7 +621,7 @@ endif()
567621

568622
message("LIB_AAMP_DEPENDS is ${LIBAAMP_DEPENDS}")
569623

570-
target_link_libraries(aamp ${LIBAAMP_DEPENDS})
624+
target_link_libraries(aamp ${LIBAAMP_DEPENDS} ${LIBAAMP_MOCK_DEPENDS})
571625

572626
if (CMAKE_WPEFRAMEWORK_REQUIRED)
573627
# Remove compiler flag as it causes compilation issues with wpeframework headers

aampgstplayer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -1524,20 +1524,19 @@ static gboolean bus_message(GstBus * bus, GstMessage * msg, AAMPGstPlayer * _thi
15241524
SetStateWithWarnings(_this->privateContext->pipeline, GST_STATE_PLAYING);
15251525
break;
15261526

1527-
#ifdef TRACE
15281527
case GST_MESSAGE_RESET_TIME: /* Message from pipeline to request resetting its running time */
1528+
#ifdef TRACE
15291529
GstClockTime running_time;
15301530
gst_message_parse_reset_time (msg, &running_time);
15311531
printf("GST_MESSAGE_RESET_TIME %llu\n", (unsigned long long)running_time);
1532-
break;
15331532
#endif
1533+
break;
15341534

15351535
case GST_MESSAGE_STREAM_STATUS:
15361536
case GST_MESSAGE_ELEMENT: // can be used to collect pts, dts, pid
15371537
case GST_MESSAGE_DURATION:
15381538
case GST_MESSAGE_LATENCY:
15391539
case GST_MESSAGE_NEW_CLOCK:
1540-
case GST_MESSAGE_RESET_TIME:
15411540
break;
15421541
case GST_MESSAGE_APPLICATION:
15431542
const GstStructure *msgS;

drm/AampDRMSessionManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ AampDRMSessionManager::~AampDRMSessionManager()
142142
{
143143
clearAccessToken();
144144
clearSessionData();
145+
SAFE_DELETE_ARRAY(drmSessionContexts);
146+
SAFE_DELETE_ARRAY(cachedKeyIDs);
145147
pthread_mutex_destroy(&mDrmSessionLock);
146148
pthread_mutex_destroy(&accessTokenMutex);
147149
pthread_mutex_destroy(&cachedKeyMutex);
@@ -173,8 +175,6 @@ void AampDRMSessionManager::clearSessionData()
173175
cachedKeyIDs[i] = KeyID();
174176
}
175177
}
176-
SAFE_DELETE_ARRAY(drmSessionContexts);
177-
SAFE_DELETE_ARRAY(cachedKeyIDs);
178178
}
179179

180180
/**

drm/AampSharedMemorySystem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/**
3535
* @brief AampSharedMemorySystem constructor
3636
*/
37-
AampSharedMemorySystem::AampSharedMemorySystem(AamplOgManager *logObj): AAMPMemorySystem(logObj) {
37+
AampSharedMemorySystem::AampSharedMemorySystem(AampLogManager *logObj): AAMPMemorySystem(logObj) {
3838
}
3939

4040
/**

drm/aampoutputprotection.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typedef int dsHdcpProtocolVersion_t;
6666

6767
#undef __in
6868
#undef __out
69+
#undef __reserved
6970
using namespace std;
7071

7172
#define UHD_WITDH 3840

drm/helper/AampClearKeyHelper.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,19 @@ void AampClearKeyHelper::generateLicenseRequest(const AampChallengeInfo& challen
9999
licenseRequest.url = challengeInfo.url;
100100
}
101101
}
102-
licenseRequest.payload = challengeInfo.data->getData();
102+
103+
if (NULL != challengeInfo.data)
104+
{
105+
licenseRequest.payload = challengeInfo.data->getData();
106+
}
103107
}
104108

105109
void AampClearKeyHelper::transformLicenseResponse(std::shared_ptr<DrmData> licenseResponse) const
106110
{
107111
// HLS requires the returned key to be transformed into a JWK.
108112
// For DASH it will already be in JWK format
109-
if (mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS)
113+
if ((mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS) ||
114+
(mDrmInfo.mediaFormat == eMEDIAFORMAT_HLS_MP4))
110115
{
111116
std::vector<uint8_t> licenseResponseData(reinterpret_cast<const char*>(licenseResponse->getData().c_str()),
112117
reinterpret_cast<const char*>(licenseResponse->getData().c_str()) + licenseResponse->getDataLength());

drm/helper/AampWidevineDrmHelper.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,18 @@ void AampWidevineDrmHelper::createInitData(std::vector<uint8_t>& initData) const
205205
void AampWidevineDrmHelper::getKey(std::vector<uint8_t>& keyID) const
206206
{
207207
AAMPLOG_WARN("AampWidevineDrmHelper::getKey defaultkey: %d mKeyIDs.size:%d", mDefaultKeySlot, mKeyIDs.size());
208-
if(mDefaultKeySlot >= 0)
208+
if ((mDefaultKeySlot >= 0) && (mDefaultKeySlot < mKeyIDs.size()))
209209
{
210210
keyID = this->mKeyIDs.at(mDefaultKeySlot);
211211
}
212-
else
212+
else if (mKeyIDs.size() > 0)
213213
{
214214
keyID = this->mKeyIDs.at(0);
215215
}
216+
else
217+
{
218+
AAMPLOG_ERR("No key");
219+
}
216220
}
217221

218222
void AampWidevineDrmHelper::getKeys(std::map<int, std::vector<uint8_t>>& keyIDs) const

drm/opencdmsessionadapter.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,17 @@ int AAMPOCDMSessionAdapter::aampDRMProcessKey(DrmData* key, uint32_t timeout)
250250
{
251251
AAMPLOG_INFO("at %p, with %p, %p", this , m_pOpenCDMSystem, m_pOpenCDMSession);
252252
int retValue = -1;
253-
std:string message = key ? key->getData():"";
254-
const uint8_t* keyMessage = reinterpret_cast<const uint8_t*>(&message[0]);
255-
const uint16_t keyMessageLength = key ?key->getDataLength():0;
256-
253+
const uint8_t* keyMessage = NULL;
254+
uint16_t keyMessageLength = 0;
255+
257256
OpenCDMError status = OpenCDMError::ERROR_NONE;
258257

258+
if (key)
259+
{
260+
keyMessage = (const uint8_t *)key->getData().c_str();
261+
keyMessageLength = key->getDataLength();
262+
}
263+
259264
if (keyMessage)
260265
{
261266
AAMPLOG_INFO("Calling opencdm_session_update, key length=%u", keyMessageLength);

drm/playreadydrmsession.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,13 @@ int PlayReadyDRMSession::aampDRMProcessKey(DrmData* key, uint32_t timeout)
570570
#ifdef TRACE_LOG
571571
cout << "aampDRMProcessKey :: Playready check if msg is null" << endl;
572572
#endif
573-
ChkArg(key->getData() && key->getDataLength() > 0);
573+
ChkArg(!key->getData().empty() && key->getDataLength() > 0);
574574

575575
//cout << "PlayreadyProcessResponse" << endl;
576576
drm_res = Drm_LicenseAcq_ProcessResponse(m_ptrAppContext,
577577
DRM_PROCESS_LIC_RESPONSE_SIGNATURE_NOT_REQUIRED,
578578
NULL,
579-
NULL, const_cast<DRM_BYTE *>(key->getData()),
579+
NULL, (DRM_BYTE *)(key->getData().c_str()),
580580
key->getDataLength(), &oLicenseResp);
581581
#ifdef TRACE_LOG
582582
printf("aampDRMProcessKey :: Drm_LicenseAcq_ProcessResponse result : %08x ", drm_res);
@@ -629,7 +629,7 @@ int PlayReadyDRMSession::decrypt(const uint8_t *f_pbIV, uint32_t f_cbIV,
629629
// Source material is UHD
630630
if(!m_pOutputProtection->isHDCPConnection2_2()) {
631631
// UHD and not HDCP 2.2
632-
AAMPLOG_WARN("UHD source but not HDCP 2.2. FAILING decrypt\n",);
632+
AAMPLOG_WARN("UHD source but not HDCP 2.2. FAILING decrypt\n");
633633
return HDCP_COMPLIANCE_CHECK_FAILURE;
634634
}
635635
}

0 commit comments

Comments
 (0)