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_ADAPTER_H_
68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#define MEDIA_CDM_PPAPI_CDM_ADAPTER_H_
78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <string>
98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include <vector>
108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/basictypes.h"
128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/compiler_specific.h"
138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "build/build_config.h"
148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/api/content_decryption_module.h"
158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/cdm_helpers.h"
168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/cdm_wrapper.h"
178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/linked_ptr.h"
188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/c/pp_stdint.h"
198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/c/private/pp_content_decryptor.h"
208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/completion_callback.h"
218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/private/content_decryptor_private.h"
228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/var.h"
238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/var_array_buffer.h"
248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/utility/completion_callback_factory.h"
258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(OS_CHROMEOS)
278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/private/output_protection_private.h"
288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/private/platform_verification.h"
298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif
308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace media {
328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// GetCdmHostFunc implementation.
348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void* GetCdmHost(int host_interface_version, void* user_data);
358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// An adapter class for abstracting away PPAPI interaction and threading for a
378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Content Decryption Module (CDM).
388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CdmAdapter : public pp::Instance,
398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                   public pp::ContentDecryptor_Private,
40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                   public cdm::Host_4,
416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                   public cdm::Host_6 {
428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public:
438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  CdmAdapter(PP_Instance instance, pp::Module* module);
448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual ~CdmAdapter();
458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // pp::Instance implementation.
478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return true;
498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // PPP_ContentDecryptor_Private implementation.
528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Note: Results of calls to these methods must be reported through the
538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // PPB_ContentDecryptor_Private interface.
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void Initialize(const std::string& key_system) OVERRIDE;
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void SetServerCertificate(
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      uint32_t promise_id,
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      pp::VarArrayBuffer server_certificate) OVERRIDE;
58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void CreateSession(uint32_t promise_id,
59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             const std::string& init_data_type,
60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             pp::VarArrayBuffer init_data,
61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             PP_SessionType session_type) OVERRIDE;
62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void LoadSession(uint32_t promise_id,
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           const std::string& web_session_id) OVERRIDE;
64f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void UpdateSession(uint32_t promise_id,
65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             const std::string& web_session_id,
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                             pp::VarArrayBuffer response) OVERRIDE;
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void CloseSession(uint32_t promise_id,
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                            const std::string& web_session_id);
696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void RemoveSession(uint32_t promise_id,
701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                             const std::string& web_session_id) OVERRIDE;
716e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void GetUsableKeyIds(uint32_t promise_id,
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                               const std::string& web_session_id) OVERRIDE;
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void Decrypt(
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      pp::Buffer_Dev encrypted_buffer,
758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void InitializeAudioDecoder(
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const PP_AudioDecoderConfig& decoder_config,
788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      pp::Buffer_Dev extra_data_buffer) OVERRIDE;
798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void InitializeVideoDecoder(
808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const PP_VideoDecoderConfig& decoder_config,
818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      pp::Buffer_Dev extra_data_buffer) OVERRIDE;
828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type,
838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                                   uint32_t request_id) OVERRIDE;
848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void ResetDecoder(PP_DecryptorStreamType decoder_type,
858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                            uint32_t request_id) OVERRIDE;
868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void DecryptAndDecode(
878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      PP_DecryptorStreamType decoder_type,
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      pp::Buffer_Dev encrypted_buffer,
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // cdm::Host_4 and cdm::Host_6 implementation.
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual cdm::Buffer* Allocate(uint32_t capacity) OVERRIDE;
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE;
94f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // cdm::Host_4 implementation.
968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  virtual double GetCurrentWallTimeInSeconds() OVERRIDE;
97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnSessionCreated(uint32_t session_id,
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                const char* web_session_id,
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                uint32_t web_session_id_length) OVERRIDE;
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnSessionMessage(uint32_t session_id,
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                const char* message,
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                uint32_t message_length,
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                const char* destination_url,
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                uint32_t destination_url_length) OVERRIDE;
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnSessionReady(uint32_t session_id) OVERRIDE;
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnSessionClosed(uint32_t session_id) OVERRIDE;
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void OnSessionError(uint32_t session_id,
108a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              cdm::MediaKeyError error_code,
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              uint32_t system_code) OVERRIDE;
110f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // cdm::Host_6 implementation.
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual cdm::Time GetCurrentWallTime() OVERRIDE;
113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnResolveNewSessionPromise(
114f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      uint32_t promise_id,
115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const char* web_session_id,
116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      uint32_t web_session_id_length) OVERRIDE;
117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnResolvePromise(uint32_t promise_id) OVERRIDE;
1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnResolveKeyIdsPromise(uint32_t promise_id,
1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                      const cdm::BinaryData* usable_key_ids,
1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                      uint32_t usable_key_ids_length) OVERRIDE;
121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnRejectPromise(uint32_t promise_id,
122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               cdm::Error error,
123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               uint32_t system_code,
124f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               const char* error_message,
125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               uint32_t error_message_length) OVERRIDE;
126f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnSessionMessage(const char* web_session_id,
127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                uint32_t web_session_id_length,
128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                const char* message,
129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                uint32_t message_length,
130f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                const char* destination_url,
131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                uint32_t destination_url_length) OVERRIDE;
1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnSessionUsableKeysChange(
1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const char* web_session_id,
1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      uint32_t web_session_id_length,
1351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      bool has_additional_usable_key) OVERRIDE;
136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnExpirationChange(const char* web_session_id,
137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                  uint32_t web_session_id_length,
1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                  cdm::Time new_expiry_time) OVERRIDE;
139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnSessionClosed(const char* web_session_id,
140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                               uint32_t web_session_id_length) OVERRIDE;
141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void OnSessionError(const char* web_session_id,
142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              uint32_t web_session_id_length,
143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              cdm::Error error,
144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              uint32_t system_code,
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              const char* error_message,
146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                              uint32_t error_message_length) OVERRIDE;
147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // cdm::Host_4 and cdm::Host_6 implementation.
149f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void SendPlatformChallenge(const char* service_id,
150f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                     uint32_t service_id_length,
151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                     const char* challenge,
152f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                     uint32_t challenge_length) OVERRIDE;
153c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void EnableOutputProtection(
154c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      uint32_t desired_protection_mask) OVERRIDE;
155c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void QueryOutputProtectionStatus() OVERRIDE;
156c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  virtual void OnDeferredInitializationDone(
157c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      cdm::StreamType stream_type,
158c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      cdm::Status decoder_status) OVERRIDE;
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) OVERRIDE;
160a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private:
162010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // These are reported to UMA server. Do not change the existing values!
163010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  enum OutputProtectionStatus {
164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    OUTPUT_PROTECTION_QUERIED = 0,
165010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1,
166010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2,
167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    OUTPUT_PROTECTION_MAX = 3
168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  };
169010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame;
1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames;
1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  struct SessionError {
175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    SessionError(cdm::Error error,
176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                 uint32_t system_code,
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                 std::string error_description);
178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    cdm::Error error;
179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    uint32_t system_code;
180f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    std::string error_description;
181f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  };
182f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool CreateCdmInstance(const std::string& key_system);
1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // <code>callback_factory_</code> to ensure that calls into
1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
188f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SendPromiseResolvedInternal(int32_t result, uint32_t promise_id);
189f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SendPromiseResolvedWithSessionInternal(
190f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      int32_t result,
191f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      uint32_t promise_id,
192f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      const std::string& web_session_id);
1936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void SendPromiseResolvedWithUsableKeyIdsInternal(
1946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      int32_t result,
1956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      uint32_t promise_id,
1966e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      std::vector<std::vector<uint8> > key_ids);
197f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SendPromiseRejectedInternal(int32_t result,
198f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   uint32_t promise_id,
199f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                   const SessionError& error);
200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SendSessionMessageInternal(int32_t result,
201f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                  const std::string& web_session_id,
202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                  const std::vector<uint8>& message,
20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                                  const std::string& destination_url);
204f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SendSessionReadyInternal(int32_t result,
205f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                const std::string& web_session_id);
206f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void SendSessionClosedInternal(int32_t result,
207f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                 const std::string& web_session_id);
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void SendSessionErrorInternal(int32_t result,
209f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                const std::string& web_session_id,
210f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                                const SessionError& error);
2116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void SendSessionUsableKeysChangeInternal(int32_t result,
2126e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                           const std::string& web_session_id,
2136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                           bool has_additional_usable_key);
2146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void SendExpirationChangeInternal(int32_t result,
2156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    const std::string& web_session_id,
2166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                    cdm::Time new_expiry_time);
217f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void RejectPromise(uint32_t promise_id,
218f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                     cdm::Error error,
219f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                     uint32_t system_code,
220f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                     const std::string& error_message);
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DeliverBlock(int32_t result,
2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const cdm::Status& status,
2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const LinkedDecryptedBlock& decrypted_block,
2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const PP_DecryptTrackingInfo& tracking_info);
2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DecoderInitializeDone(int32_t result,
2278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                             PP_DecryptorStreamType decoder_type,
2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                             uint32_t request_id,
2298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                             bool success);
2308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DecoderDeinitializeDone(int32_t result,
2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                               PP_DecryptorStreamType decoder_type,
2328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                               uint32_t request_id);
2338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DecoderResetDone(int32_t result,
2348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                        PP_DecryptorStreamType decoder_type,
2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                        uint32_t request_id);
2368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DeliverFrame(int32_t result,
2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const cdm::Status& status,
2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const LinkedVideoFrame& video_frame,
2398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    const PP_DecryptTrackingInfo& tracking_info);
2408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void DeliverSamples(int32_t result,
2418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                      const cdm::Status& status,
2428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                      const LinkedAudioFrames& audio_frames,
2438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                      const PP_DecryptTrackingInfo& tracking_info);
2448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Helper for SetTimer().
2468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void TimerExpired(int32_t result, void* context);
2478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool IsValidVideoFrame(const LinkedVideoFrame& video_frame);
2498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Callback to report |file_size_bytes| of the first file read by FileIO.
2511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void OnFirstFileRead(int32_t file_size_bytes);
2521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if !defined(NDEBUG)
2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Logs the given message to the JavaScript console associated with the
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // CDM adapter instance. The name of the CDM adapter issuing the log message
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // will be automatically prepended to the message.
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void LogToConsole(const pp::Var& value);
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // !defined(NDEBUG)
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#if defined(OS_CHROMEOS)
261010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void ReportOutputProtectionUMA(OutputProtectionStatus status);
262010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void ReportOutputProtectionQuery();
263010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void ReportOutputProtectionQueryResult();
264010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
265116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  struct PepperPlatformChallengeResponse {
266116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    pp::Var signed_data;
267116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    pp::Var signed_data_signature;
268116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    pp::Var platform_key_certificate;
269116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  };
270116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
271116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void SendPlatformChallengeDone(
272116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      int32_t result,
273116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      const linked_ptr<PepperPlatformChallengeResponse>& response);
2748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void EnableProtectionDone(int32_t result);
2758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  void QueryOutputProtectionStatusDone(int32_t result);
2768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  pp::OutputProtection_Private output_protection_;
2788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  pp::PlatformVerification platform_verification_;
2798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  // Same as above, these are only read by QueryOutputProtectionStatusDone().
2818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  uint32_t output_link_mask_;
2828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  uint32_t output_protection_mask_;
2838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  bool query_output_protection_in_progress_;
284010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
285010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Tracks whether an output protection query and a positive query result (no
286010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // unprotected external link) have been reported to UMA.
287010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  bool uma_for_output_protection_query_reported_;
288010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  bool uma_for_output_protection_positive_result_reported_;
2898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif
2908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  PpbBufferAllocator allocator_;
2928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  pp::CompletionCallbackFactory<CdmAdapter> callback_factory_;
2938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  linked_ptr<CdmWrapper> cdm_;
2948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  std::string key_system_;
2958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
2961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // If the CDM returned kDeferredInitialization during InitializeAudioDecoder()
2971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // or InitializeVideoDecoder(), the (Audio|Video)DecoderConfig.request_id is
2981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // saved for the future call to OnDeferredInitializationDone().
2991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool deferred_initialize_audio_decoder_;
3001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  uint32_t deferred_audio_decoder_config_id_;
3011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool deferred_initialize_video_decoder_;
3021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  uint32_t deferred_video_decoder_config_id_;
3031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
3041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  uint32_t last_read_file_size_kb_;
3051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool file_size_uma_reported_;
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
3078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CdmAdapter);
3088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)};
3098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
3108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}  // namespace media
3118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
3128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif  // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_
313