LCOV - code coverage report
Current view: top level - dom/media/gmp - ChromiumCDMAdapter.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 4 46 8.7 %
Date: 2017-07-14 16:53:18 Functions: 1 6 16.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "ChromiumCDMAdapter.h"
       7             : #include "content_decryption_module.h"
       8             : #include "VideoUtils.h"
       9             : #include "gmp-api/gmp-entrypoints.h"
      10             : #include "gmp-api/gmp-decryption.h"
      11             : #include "gmp-api/gmp-video-codec.h"
      12             : #include "gmp-api/gmp-platform.h"
      13             : #include "WidevineUtils.h"
      14             : #include "GMPLog.h"
      15             : 
      16             : // Declared in WidevineAdapter.cpp.
      17             : extern const GMPPlatformAPI* sPlatform;
      18             : 
      19             : namespace mozilla {
      20             : 
      21             : void
      22           0 : ChromiumCDMAdapter::SetAdaptee(PRLibrary* aLib)
      23             : {
      24           0 :   mLib = aLib;
      25           0 : }
      26             : 
      27             : void*
      28           0 : ChromiumCdmHost(int aHostInterfaceVersion, void* aUserData)
      29             : {
      30           0 :   CDM_LOG("ChromiumCdmHostFunc(%d, %p)", aHostInterfaceVersion, aUserData);
      31           0 :   if (aHostInterfaceVersion != cdm::Host_8::kVersion) {
      32           0 :     return nullptr;
      33             :   }
      34           0 :   return static_cast<cdm::Host_8*>(aUserData);
      35             : }
      36             : 
      37             : #define STRINGIFY(s) _STRINGIFY(s)
      38             : #define _STRINGIFY(s) #s
      39             : 
      40             : GMPErr
      41           0 : ChromiumCDMAdapter::GMPInit(const GMPPlatformAPI* aPlatformAPI)
      42             : {
      43           0 :   CDM_LOG("ChromiumCDMAdapter::GMPInit");
      44           0 :   sPlatform = aPlatformAPI;
      45           0 :   if (!mLib) {
      46           0 :     return GMPGenericErr;
      47             :   }
      48             : 
      49           0 :   auto init = reinterpret_cast<decltype(::INITIALIZE_CDM_MODULE)*>(
      50           0 :     PR_FindFunctionSymbol(mLib, STRINGIFY(INITIALIZE_CDM_MODULE)));
      51           0 :   if (!init) {
      52           0 :     return GMPGenericErr;
      53             :   }
      54             : 
      55           0 :   CDM_LOG(STRINGIFY(INITIALIZE_CDM_MODULE)"()");
      56           0 :   init();
      57             : 
      58           0 :   return GMPNoErr;
      59             : }
      60             : 
      61             : GMPErr
      62           0 : ChromiumCDMAdapter::GMPGetAPI(const char* aAPIName,
      63             :                               void* aHostAPI,
      64             :                               void** aPluginAPI,
      65             :                               uint32_t aDecryptorId)
      66             : {
      67           0 :   CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p",
      68             :           aAPIName,
      69             :           aHostAPI,
      70             :           aPluginAPI,
      71             :           aDecryptorId,
      72             :           this);
      73           0 :   if (!strcmp(aAPIName, CHROMIUM_CDM_API)) {
      74             :     auto create = reinterpret_cast<decltype(::CreateCdmInstance)*>(
      75           0 :       PR_FindFunctionSymbol(mLib, "CreateCdmInstance"));
      76           0 :     if (!create) {
      77           0 :       CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p "
      78             :               "FAILED to find CreateCdmInstance",
      79             :               aAPIName,
      80             :               aHostAPI,
      81             :               aPluginAPI,
      82             :               aDecryptorId,
      83             :               this);
      84           0 :       return GMPGenericErr;
      85             :     }
      86             : 
      87             :     auto cdm = reinterpret_cast<cdm::ContentDecryptionModule*>(
      88           0 :       create(cdm::ContentDecryptionModule::kVersion,
      89             :              kEMEKeySystemWidevine.get(),
      90             :              kEMEKeySystemWidevine.Length(),
      91             :              &ChromiumCdmHost,
      92           0 :              aHostAPI));
      93           0 :     if (!cdm) {
      94           0 :       CDM_LOG("ChromiumCDMAdapter::GMPGetAPI(%s, 0x%p, 0x%p, %u) this=0x%p "
      95             :               "FAILED to create cdm",
      96             :               aAPIName,
      97             :               aHostAPI,
      98             :               aPluginAPI,
      99             :               aDecryptorId,
     100             :               this);
     101           0 :       return GMPGenericErr;
     102             :     }
     103           0 :     CDM_LOG("cdm: 0x%p", cdm);
     104           0 :     *aPluginAPI = cdm;
     105             :   }
     106           0 :   return *aPluginAPI ? GMPNoErr : GMPNotImplementedErr;
     107             : }
     108             : 
     109             : void
     110           0 : ChromiumCDMAdapter::GMPShutdown()
     111             : {
     112           0 :   CDM_LOG("ChromiumCDMAdapter::GMPShutdown()");
     113             : 
     114             :   decltype(::DeinitializeCdmModule)* deinit;
     115           0 :   deinit = (decltype(deinit))(PR_FindFunctionSymbol(mLib, "DeinitializeCdmModule"));
     116           0 :   if (deinit) {
     117           0 :     CDM_LOG("DeinitializeCdmModule()");
     118           0 :     deinit();
     119             :   }
     120           0 : }
     121             : 
     122             : /* static */
     123             : bool
     124           1 : ChromiumCDMAdapter::Supports(int32_t aModuleVersion,
     125             :                              int32_t aInterfaceVersion,
     126             :                              int32_t aHostVersion)
     127             : {
     128           1 :   return aModuleVersion == CDM_MODULE_VERSION &&
     129           2 :          aInterfaceVersion == cdm::ContentDecryptionModule::kVersion &&
     130           1 :          aHostVersion == cdm::Host_8::kVersion;
     131             : }
     132             : 
     133             : } // namespace mozilla

Generated by: LCOV version 1.13