cdm_wrapper.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file.
48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <map>
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <queue>
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include <string>
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/basictypes.h"
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/api/content_decryption_module.h"
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/cdm_helpers.h"
150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "media/cdm/ppapi/supported_cdm_versions.h"
168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/logging.h"
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace media {
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CdmWrapper wraps different versions of ContentDecryptionModule interfaces and
218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// exposes a common interface to the caller.
228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// The caller should call CdmWrapper::Create() to create a CDM instance.
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CdmWrapper will first try to create a CDM instance that supports the latest
258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CDM interface (ContentDecryptionModule). If such an instance cannot be
268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// created (e.g. an older CDM was loaded), CdmWrapper will try to create a CDM
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// that supports an older version of CDM interface (e.g.
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// ContentDecryptionModule_*). Internally CdmWrapper converts the CdmWrapper
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// calls to corresponding ContentDecryptionModule calls.
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Note that CdmWrapper interface always reflects the latest state of content
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private).
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)//
348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Since this file is highly templated and default implementations are short
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// (just a shim layer in most cases), everything is done in this header file.
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CdmWrapper {
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public:
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  static CdmWrapper* Create(const char* key_system,
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                            uint32_t key_system_size,
408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                            GetCdmHostFunc get_cdm_host_func,
418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                            void* user_data);
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~CdmWrapper() {};
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void CreateSession(uint32_t session_id,
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             const char* content_type,
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             uint32_t content_type_size,
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             const uint8_t* init_data,
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             uint32_t init_data_size) = 0;
50c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void LoadSession(uint32_t session_id,
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           const char* web_session_id,
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           uint32_t web_session_id_size) = 0;
53c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void UpdateSession(uint32_t session_id,
54c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                             const uint8_t* response,
55c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                             uint32_t response_size) = 0;
56c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void ReleaseSession(uint32_t session_id) = 0;
578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void TimerExpired(void* context) = 0;
588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                              cdm::DecryptedBlock* decrypted_buffer) = 0;
608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status InitializeAudioDecoder(
618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::AudioDecoderConfig& audio_decoder_config) = 0;
628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status InitializeVideoDecoder(
638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::VideoDecoderConfig& video_decoder_config) = 0;
648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0;
658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void ResetDecoder(cdm::StreamType decoder_type) = 0;
668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status DecryptAndDecodeFrame(
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::InputBuffer& encrypted_buffer,
688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      cdm::VideoFrame* video_frame) = 0;
698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status DecryptAndDecodeSamples(
708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::InputBuffer& encrypted_buffer,
718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      cdm::AudioFrames* audio_frames) = 0;
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void OnPlatformChallengeResponse(
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::PlatformChallengeResponse& response) = 0;
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void OnQueryOutputProtectionStatus(
758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      uint32_t link_mask,
768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      uint32_t output_protection_mask) = 0;
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) protected:
79c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  CdmWrapper() {}
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private:
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CdmWrapper);
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)};
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Template class that does the CdmWrapper -> CdmInterface conversion. Default
868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// implementations are provided. Any methods that need special treatment should
878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// be specialized.
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <class CdmInterface>
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CdmWrapperImpl : public CdmWrapper {
908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public:
918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  static CdmWrapper* Create(const char* key_system,
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                            uint32_t key_system_size,
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                            GetCdmHostFunc get_cdm_host_func,
948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                            void* user_data) {
958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    void* cdm_instance = ::CreateCdmInstance(
968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        CdmInterface::kVersion, key_system, key_system_size, get_cdm_host_func,
978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        user_data);
988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    if (!cdm_instance)
998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      return NULL;
1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return new CdmWrapperImpl<CdmInterface>(
1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        static_cast<CdmInterface*>(cdm_instance));
1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~CdmWrapperImpl() {
1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->Destroy();
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void CreateSession(uint32_t session_id,
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             const char* content_type,
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             uint32_t content_type_size,
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             const uint8_t* init_data,
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             uint32_t init_data_size) OVERRIDE {
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    cdm_->CreateSession(
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        session_id, content_type, content_type_size, init_data, init_data_size);
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
118c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void LoadSession(uint32_t session_id,
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           const char* web_session_id,
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           uint32_t web_session_id_size) OVERRIDE {
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    cdm_->LoadSession(session_id, web_session_id, web_session_id_size);
1228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
124c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void UpdateSession(uint32_t session_id,
125c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                             const uint8_t* response,
126c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                             uint32_t response_size) OVERRIDE {
127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    cdm_->UpdateSession(session_id, response, response_size);
1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
130c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void ReleaseSession(uint32_t session_id) OVERRIDE {
131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    cdm_->ReleaseSession(session_id);
1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void TimerExpired(void* context) OVERRIDE {
1358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->TimerExpired(context);
1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                              cdm::DecryptedBlock* decrypted_buffer) OVERRIDE {
1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return cdm_->Decrypt(encrypted_buffer, decrypted_buffer);
1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status InitializeAudioDecoder(
1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE {
1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return cdm_->InitializeAudioDecoder(audio_decoder_config);
1468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status InitializeVideoDecoder(
1498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE {
1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return cdm_->InitializeVideoDecoder(video_decoder_config);
1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE {
1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->DeinitializeDecoder(decoder_type);
1558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE {
1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->ResetDecoder(decoder_type);
1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status DecryptAndDecodeFrame(
1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::InputBuffer& encrypted_buffer,
1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      cdm::VideoFrame* video_frame) OVERRIDE {
1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return cdm_->DecryptAndDecodeFrame(encrypted_buffer, video_frame);
1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual cdm::Status DecryptAndDecodeSamples(
1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::InputBuffer& encrypted_buffer,
1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      cdm::AudioFrames* audio_frames) OVERRIDE {
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return cdm_->DecryptAndDecodeSamples(encrypted_buffer, audio_frames);
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void OnPlatformChallengeResponse(
1748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const cdm::PlatformChallengeResponse& response) OVERRIDE {
1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->OnPlatformChallengeResponse(response);
1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void OnQueryOutputProtectionStatus(
1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      uint32_t link_mask,
1808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      uint32_t output_protection_mask) OVERRIDE {
1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    cdm_->OnQueryOutputProtectionStatus(link_mask, output_protection_mask);
1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private:
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) {
1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    PP_DCHECK(cdm_);
1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  CdmInterface* cdm_;
1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl);
1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)};
1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)CdmWrapper* CdmWrapper::Create(const char* key_system,
1951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               uint32_t key_system_size,
1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                               GetCdmHostFunc get_cdm_host_func,
1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                               void* user_data) {
1980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 cdm::ContentDecryptionModule_4::kVersion,
2000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)                 update_code_below);
2010f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Ensure IsSupportedCdmInterfaceVersion() matches this implementation.
2030f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Always update this DCHECK when updating this function.
2040f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // If this check fails, update this function and DCHECK or update
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // IsSupportedCdmInterfaceVersion().
2060f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PP_DCHECK(
207c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion +
208c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                      1) &&
2090f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)      IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion) &&
210c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion -
211c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                      1));
2120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Try to create the CDM using the latest CDM interface version.
2140f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  CdmWrapper* cdm_wrapper =
2158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      CdmWrapperImpl<cdm::ContentDecryptionModule>::Create(
2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)          key_system, key_system_size, get_cdm_host_func, user_data);
2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
218c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // If |cdm_wrapper| is NULL, try to create the CDM using older supported
219c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // versions of the CDM interface.
220c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // No older versions of CDM interface supported.
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  return cdm_wrapper;
2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// stub implementations for new or modified methods that the older CDM interface
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// does not have.
2280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Also update supported_cdm_versions.h.
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                   cdm::ContentDecryptionModule_4::kVersion,
2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)               ensure_cdm_wrapper_templates_have_old_version_support);
2328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}  // namespace media
2348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif  // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
236