cdm_adapter.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// Copyright 2013 The Chromium Authors. All rights reserved.
2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// Use of this source code is governed by a BSD-style license that can be
3cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// found in the LICENSE file.
4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com
5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#ifndef MEDIA_CDM_PPAPI_CDM_ADAPTER_H_
6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#define MEDIA_CDM_PPAPI_CDM_ADAPTER_H_
7cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com
8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#include <string>
9cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#include <vector>
108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "base/basictypes.h"
128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "base/compiler_specific.h"
138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "build/build_config.h"
148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "media/cdm/ppapi/api/content_decryption_module.h"
158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "media/cdm/ppapi/cdm_helpers.h"
168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "media/cdm/ppapi/cdm_wrapper.h"
178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "media/cdm/ppapi/linked_ptr.h"
188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/c/pp_stdint.h"
198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/c/private/pp_content_decryptor.h"
208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/completion_callback.h"
218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/private/content_decryptor_private.h"
228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/var.h"
238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/var_array_buffer.h"
248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/utility/completion_callback_factory.h"
258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#if defined(OS_CHROMEOS)
278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/private/output_protection_private.h"
288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "ppapi/cpp/private/platform_verification.h"
298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif
308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#if defined(GetCurrentTime)
328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// winbase.h defines this which messes up calls to Host_5::GetCurrentTime.
338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#undef GetCurrentTime
348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif
358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace media {
378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// GetCdmHostFunc implementation.
398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comvoid* GetCdmHost(int host_interface_version, void* user_data);
408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// An adapter class for abstracting away PPAPI interaction and threading for a
428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com// Content Decryption Module (CDM).
438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass CdmAdapter : public pp::Instance,
448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                   public pp::ContentDecryptor_Private,
458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                   public cdm::Host_4,
468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                   public cdm::Host_5 {
478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com public:
488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  CdmAdapter(PP_Instance instance, pp::Module* module);
498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual ~CdmAdapter();
508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // pp::Instance implementation.
528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    return true;
548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  }
558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // PPP_ContentDecryptor_Private implementation.
578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Note: Results of calls to these methods must be reported through the
588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // PPB_ContentDecryptor_Private interface.
598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void Initialize(const std::string& key_system) OVERRIDE;
608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void CreateSession(uint32_t promise_id,
618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             const std::string& init_data_type,
628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             pp::VarArrayBuffer init_data,
638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             PP_SessionType session_type) OVERRIDE;
648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void LoadSession(uint32_t promise_id,
658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                           const std::string& web_session_id) OVERRIDE;
668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void UpdateSession(uint32_t promise_id,
678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             const std::string& web_session_id,
688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             pp::VarArrayBuffer response) OVERRIDE;
698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void ReleaseSession(uint32_t promise_id,
708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              const std::string& web_session_id) OVERRIDE;
718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void Decrypt(
728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      pp::Buffer_Dev encrypted_buffer,
738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void InitializeAudioDecoder(
758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const PP_AudioDecoderConfig& decoder_config,
768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      pp::Buffer_Dev extra_data_buffer) OVERRIDE;
778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void InitializeVideoDecoder(
788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const PP_VideoDecoderConfig& decoder_config,
798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      pp::Buffer_Dev extra_data_buffer) OVERRIDE;
808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type,
818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                   uint32_t request_id) OVERRIDE;
828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void ResetDecoder(PP_DecryptorStreamType decoder_type,
838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                            uint32_t request_id) OVERRIDE;
848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void DecryptAndDecode(
858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      PP_DecryptorStreamType decoder_type,
868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      pp::Buffer_Dev encrypted_buffer,
878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // cdm::Host_4 and cdm::Host_5 implementation.
908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual cdm::Buffer* Allocate(uint32_t capacity) OVERRIDE;
918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE;
928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // cdm::Host_4 implementation.
948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual double GetCurrentWallTimeInSeconds() OVERRIDE;
958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionCreated(uint32_t session_id,
968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const char* web_session_id,
978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t web_session_id_length) OVERRIDE;
988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionMessage(uint32_t session_id,
998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const char* message,
1008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t message_length,
1018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const char* destination_url,
1028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t destination_url_length) OVERRIDE;
1038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionReady(uint32_t session_id) OVERRIDE;
1048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionClosed(uint32_t session_id) OVERRIDE;
1058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionError(uint32_t session_id,
1068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              cdm::MediaKeyError error_code,
1078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              uint32_t system_code) OVERRIDE;
1088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // cdm::Host_5 implementation.
1108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual cdm::Time GetCurrentTime() OVERRIDE;
1118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnResolveNewSessionPromise(
1128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      uint32_t promise_id,
1138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const char* web_session_id,
1148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      uint32_t web_session_id_length) OVERRIDE;
1158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnResolvePromise(uint32_t promise_id) OVERRIDE;
1168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnRejectPromise(uint32_t promise_id,
1178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               cdm::Error error,
1188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               uint32_t system_code,
1198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               const char* error_message,
1208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               uint32_t error_message_length) OVERRIDE;
1218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionMessage(const char* web_session_id,
1228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t web_session_id_length,
1238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const char* message,
1248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t message_length,
1258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const char* destination_url,
1268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                uint32_t destination_url_length) OVERRIDE;
1278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionKeysChange(const char* web_session_id,
1288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                   uint32_t web_session_id_length,
1298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                   bool has_additional_usable_key);
1308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnExpirationChange(const char* web_session_id,
1318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                  uint32_t web_session_id_length,
1328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                  cdm::Time new_expiry_time);
1338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionReady(const char* web_session_id,
1348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              uint32_t web_session_id_length) OVERRIDE;
1358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionClosed(const char* web_session_id,
1368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               uint32_t web_session_id_length) OVERRIDE;
1378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnSessionError(const char* web_session_id,
1388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              uint32_t web_session_id_length,
1398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              cdm::Error error,
1408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              uint32_t system_code,
1418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              const char* error_message,
1428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                              uint32_t error_message_length) OVERRIDE;
1438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // cdm::Host_4 and cdm::Host_5 implementation.
1458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void SendPlatformChallenge(const char* service_id,
1468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                     uint32_t service_id_length,
1478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                     const char* challenge,
1488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                     uint32_t challenge_length) OVERRIDE;
1498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void EnableOutputProtection(
1508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      uint32_t desired_protection_mask) OVERRIDE;
1518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void QueryOutputProtectionStatus() OVERRIDE;
1528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual void OnDeferredInitializationDone(
1538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      cdm::StreamType stream_type,
1548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      cdm::Status decoder_status) OVERRIDE;
1558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  virtual cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) OVERRIDE;
1568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com private:
1588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // These are reported to UMA server. Do not change the existing values!
1598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  enum OutputProtectionStatus {
1608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    OUTPUT_PROTECTION_QUERIED = 0,
1618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1,
1628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2,
1638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    OUTPUT_PROTECTION_MAX = 3
1648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  };
1658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
1678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame;
1688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames;
1698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  struct SessionError {
1718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    SessionError(cdm::Error error,
1728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                 uint32_t system_code,
1738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                 std::string error_description);
1748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    cdm::Error error;
1758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    uint32_t system_code;
1768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    std::string error_description;
1778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  };
1788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool CreateCdmInstance(const std::string& key_system);
1808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
1818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
1828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // <code>callback_factory_</code> to ensure that calls into
1838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
1848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendPromiseResolvedInternal(int32_t result, uint32_t promise_id);
1858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendPromiseResolvedWithSessionInternal(
1868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      int32_t result,
1878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      uint32_t promise_id,
1888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com      const std::string& web_session_id);
1898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendPromiseRejectedInternal(int32_t result,
1908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                   uint32_t promise_id,
1918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                   const SessionError& error);
1928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendSessionMessageInternal(int32_t result,
1938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                  const std::string& web_session_id,
1948cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                  const std::vector<uint8>& message,
1958cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                  const std::string& destination_url);
1968cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendSessionReadyInternal(int32_t result,
1978cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const std::string& web_session_id);
1988cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendSessionClosedInternal(int32_t result,
1998cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                 const std::string& web_session_id);
2008cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendSessionErrorInternal(int32_t result,
2018cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const std::string& web_session_id,
2028cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                                const SessionError& error);
2038cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void RejectPromise(uint32_t promise_id,
2048cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                     cdm::Error error,
2058cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                     uint32_t system_code,
2068cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                     const std::string& error_message);
2078cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2088cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DeliverBlock(int32_t result,
2098cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const cdm::Status& status,
2108cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const LinkedDecryptedBlock& decrypted_block,
2118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const PP_DecryptTrackingInfo& tracking_info);
2128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DecoderInitializeDone(int32_t result,
2138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             PP_DecryptorStreamType decoder_type,
2148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             uint32_t request_id,
2158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                             bool success);
2168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DecoderDeinitializeDone(int32_t result,
2178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               PP_DecryptorStreamType decoder_type,
2188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                               uint32_t request_id);
2198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DecoderResetDone(int32_t result,
2208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                        PP_DecryptorStreamType decoder_type,
2218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                        uint32_t request_id);
2228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DeliverFrame(int32_t result,
2238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const cdm::Status& status,
2248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const LinkedVideoFrame& video_frame,
2258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    const PP_DecryptTrackingInfo& tracking_info);
2268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void DeliverSamples(int32_t result,
2278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                      const cdm::Status& status,
2288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                      const LinkedAudioFrames& audio_frames,
2298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                      const PP_DecryptTrackingInfo& tracking_info);
2308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Helper for SetTimer().
2328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void TimerExpired(int32_t result, void* context);
2338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool IsValidVideoFrame(const LinkedVideoFrame& video_frame);
2358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#if !defined(NDEBUG)
2378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Logs the given message to the JavaScript console associated with the
2388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // CDM adapter instance. The name of the CDM adapter issuing the log message
2398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // will be automatically prepended to the message.
2408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void LogToConsole(const pp::Var& value);
2418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif  // !defined(NDEBUG)
2428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#if defined(OS_CHROMEOS)
2448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void ReportOutputProtectionUMA(OutputProtectionStatus status);
2458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void ReportOutputProtectionQuery();
2468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void ReportOutputProtectionQueryResult();
2478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void SendPlatformChallengeDone(int32_t result);
2498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void EnableProtectionDone(int32_t result);
2508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  void QueryOutputProtectionStatusDone(int32_t result);
2518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::OutputProtection_Private output_protection_;
2538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::PlatformVerification platform_verification_;
2548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Since PPAPI doesn't provide handlers for CompletionCallbacks with more than
2568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // one output we need to manage our own.  These values are only read by
2578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // SendPlatformChallengeDone().
2588cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::Var signed_data_output_;
2598cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::Var signed_data_signature_output_;
2608cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::Var platform_key_certificate_output_;
2618cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool challenge_in_progress_;
2628cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2638cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Same as above, these are only read by QueryOutputProtectionStatusDone().
2648cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  uint32_t output_link_mask_;
2658cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  uint32_t output_protection_mask_;
2668cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool query_output_protection_in_progress_;
2678cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2688cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // Tracks whether an output protection query and a positive query result (no
2698cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // unprotected external link) have been reported to UMA.
2708cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool uma_for_output_protection_query_reported_;
2718cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool uma_for_output_protection_positive_result_reported_;
2728cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif
2738cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2748cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  PpbBufferAllocator allocator_;
2758cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  pp::CompletionCallbackFactory<CdmAdapter> callback_factory_;
2768cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  linked_ptr<CdmWrapper> cdm_;
2778cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  std::string key_system_;
2788cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2798cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // If the CDM returned kDeferredInitialization during InitializeAudioDecoder()
2808cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // or InitializeVideoDecoder(), the (Audio|Video)DecoderConfig.request_id is
2818cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  // saved for the future call to OnDeferredInitializationDone().
2828cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool deferred_initialize_audio_decoder_;
2838cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  uint32_t deferred_audio_decoder_config_id_;
2848cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  bool deferred_initialize_video_decoder_;
2858cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  uint32_t deferred_video_decoder_config_id_;
2868cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2878cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  DISALLOW_COPY_AND_ASSIGN(CdmAdapter);
2888cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com};
2898cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2908cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}  // namespace media
2918cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
2928cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#endif  // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_
2938cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com