1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CDM_CONTENT_DECRYPTION_MODULE_H_
6 #define CDM_CONTENT_DECRYPTION_MODULE_H_
9 typedef unsigned char uint8_t;
10 typedef unsigned int uint32_t;
12 typedef __int64 int64_t;
17 // Define CDM_EXPORT so that functionality implemented by the CDM module
18 // can be exported to consumers.
21 #if defined(CDM_IMPLEMENTATION)
22 #define CDM_EXPORT __declspec(dllexport)
24 #define CDM_EXPORT __declspec(dllimport)
25 #endif // defined(CDM_IMPLEMENTATION)
27 #else // defined(WIN32)
29 #if defined(CDM_IMPLEMENTATION)
30 #define CDM_EXPORT __attribute__((visibility("default")))
35 #endif // defined(WIN32)
37 // The version number must be rolled when the exported functions are updated!
38 // If the CDM and the adapter use different versions of these functions, the
39 // adapter will fail to load or crash!
40 #define CDM_MODULE_VERSION 4
42 // Build the versioned entrypoint name.
43 // The extra macros are necessary to expand version to an actual value.
44 #define INITIALIZE_CDM_MODULE \
45 BUILD_ENTRYPOINT(InitializeCdmModule, CDM_MODULE_VERSION)
46 #define BUILD_ENTRYPOINT(name, version) \
47 BUILD_ENTRYPOINT_NO_EXPANSION(name, version)
48 #define BUILD_ENTRYPOINT_NO_EXPANSION(name, version) name##_##version
51 CDM_EXPORT void INITIALIZE_CDM_MODULE();
53 CDM_EXPORT void DeinitializeCdmModule();
55 // Returns a pointer to the requested CDM Host interface upon success.
56 // Returns NULL if the requested CDM Host interface is not supported.
57 // The caller should cast the returned pointer to the type matching
58 // |host_interface_version|.
59 typedef void* (*GetCdmHostFunc)(int host_interface_version, void* user_data);
61 // Returns a pointer to the requested CDM upon success.
62 // Returns NULL if an error occurs or the requested |cdm_interface_version| or
63 // |key_system| is not supported or another error occurs.
64 // The caller should cast the returned pointer to the type matching
65 // |cdm_interface_version|.
66 // Caller retains ownership of arguments and must call Destroy() on the returned
68 CDM_EXPORT void* CreateCdmInstance(
69 int cdm_interface_version,
70 const char* key_system, uint32_t key_system_size,
71 GetCdmHostFunc get_cdm_host_func, void* user_data);
73 CDM_EXPORT const char* GetCdmVersion();
79 typedef AudioFrames_2 AudioFrames;
90 kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample.
91 kNoKey, // The required decryption key is not available.
92 kSessionError, // Session management error.
93 kDecryptError, // Decryption failed.
94 kDecodeError, // Error decoding audio or video.
95 kDeferredInitialization // Decoder is not ready for initialization.
98 // This must be consistent with MediaKeyError defined in the spec:
99 // https://dvcs.w3.org/hg/html-media/raw-file/eme-v0.1b/encrypted-media/encrypted-media.html#error-codes
100 // Support the minimum required set with backwards compatible values.
102 kPrefixedUnknownError = 1,
103 kPrefixedClientError = 2,
104 kPrefixedOutputError = 4
107 // This must at least contain the exceptions defined in the spec:
108 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#exceptions
109 // The following starts with the list of DOM4 exceptions from:
110 // http://www.w3.org/TR/dom/#domexception
111 // Some DOM4 exceptions are not included as they are not expected to be used.
113 kNotSupportedError = 9,
114 kInvalidStateError = 11,
115 kInvalidAccessError = 15,
116 kQuotaExceededError = 22,
118 // Additional exceptions that don't have assigned codes.
119 // There are other non-EME-specific values, not included in this list.
122 // Additional values from previous EME versions. They currently have no
123 // matching DOMException.
128 // Time is defined as the number of seconds since the
129 // Epoch (00:00:00 UTC, January 1, 1970).
132 // An input buffer can be split into several continuous subsamples.
133 // A SubsampleEntry specifies the number of clear and cipher bytes in each
134 // subsample. For example, the following buffer has three subsamples:
136 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
137 // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
139 // For decryption, all of the cipher bytes in a buffer should be concatenated
140 // (in the subsample order) into a single logical stream. The clear bytes should
141 // not be considered as part of decryption.
143 // Stream to decrypt: | cipher1 | cipher2 | cipher3 |
144 // Decrypted stream: | decrypted1| decrypted2 | decrypted3 |
146 // After decryption, the decrypted bytes should be copied over the position
147 // of the corresponding cipher bytes in the original buffer to form the output
148 // buffer. Following the above example, the decrypted buffer should be:
150 // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
151 // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 |
153 // TODO(xhwang): Add checks to make sure these structs have fixed layout.
154 struct SubsampleEntry {
155 SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes)
156 : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
158 uint32_t clear_bytes;
159 uint32_t cipher_bytes;
162 // Represents an input buffer to be decrypted (and possibly decoded). It does
163 // not own any pointers in this struct.
164 // Deprecated: New CDM implementations should use InputBuffer.
165 struct InputBuffer_1 {
178 const uint8_t* data; // Pointer to the beginning of the input data.
179 uint32_t data_size; // Size (in bytes) of |data|.
181 uint32_t data_offset; // Number of bytes to be discarded before decryption.
183 const uint8_t* key_id; // Key ID to identify the decryption key.
184 uint32_t key_id_size; // Size (in bytes) of |key_id|.
186 const uint8_t* iv; // Initialization vector.
187 uint32_t iv_size; // Size (in bytes) of |iv|.
189 const struct SubsampleEntry* subsamples;
190 uint32_t num_subsamples; // Number of subsamples in |subsamples|.
192 int64_t timestamp; // Presentation timestamp in microseconds.
195 // Represents an input buffer to be decrypted (and possibly decoded). It does
196 // not own any pointers in this struct. If |iv_size| = 0, the data is
198 struct InputBuffer_2 {
210 const uint8_t* data; // Pointer to the beginning of the input data.
211 uint32_t data_size; // Size (in bytes) of |data|.
213 const uint8_t* key_id; // Key ID to identify the decryption key.
214 uint32_t key_id_size; // Size (in bytes) of |key_id|.
216 const uint8_t* iv; // Initialization vector.
217 uint32_t iv_size; // Size (in bytes) of |iv|.
219 const struct SubsampleEntry* subsamples;
220 uint32_t num_subsamples; // Number of subsamples in |subsamples|.
222 int64_t timestamp; // Presentation timestamp in microseconds.
225 typedef InputBuffer_2 InputBuffer;
227 struct AudioDecoderConfig {
229 kUnknownAudioCodec = 0,
235 : codec(kUnknownAudioCodec),
238 samples_per_second(0),
240 extra_data_size(0) {}
243 int32_t channel_count;
244 int32_t bits_per_channel;
245 int32_t samples_per_second;
247 // Optional byte data required to initialize audio decoders, such as the
248 // vorbis setup header.
250 uint32_t extra_data_size;
253 // Supported sample formats for AudioFrames.
255 kUnknownAudioFormat = 0, // Unknown format value. Used for error reporting.
256 kAudioFormatU8, // Interleaved unsigned 8-bit w/ bias of 128.
257 kAudioFormatS16, // Interleaved signed 16-bit.
258 kAudioFormatS32, // Interleaved signed 32-bit.
259 kAudioFormatF32, // Interleaved float 32-bit.
260 kAudioFormatPlanarS16, // Signed 16-bit planar.
261 kAudioFormatPlanarF32, // Float 32-bit planar.
264 // Surface formats based on FOURCC labels, see: http://www.fourcc.org/yuv.php
266 kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
267 kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
268 kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
272 Size() : width(0), height(0) {}
273 Size(int32_t width, int32_t height) : width(width), height(height) {}
279 struct VideoDecoderConfig {
281 kUnknownVideoCodec = 0,
287 enum VideoCodecProfile {
288 kUnknownVideoCodecProfile = 0,
290 kH264ProfileBaseline,
292 kH264ProfileExtended,
296 kH264ProfileHigh444Predictive
300 : codec(kUnknownVideoCodec),
301 profile(kUnknownVideoCodecProfile),
302 format(kUnknownVideoFormat),
304 extra_data_size(0) {}
307 VideoCodecProfile profile;
310 // Width and height of video frame immediately post-decode. Not all pixels
311 // in this region are valid.
314 // Optional byte data required to initialize video decoders, such as H.264
317 uint32_t extra_data_size;
321 kStreamTypeAudio = 0,
325 // Structure provided to ContentDecryptionModule::OnPlatformChallengeResponse()
326 // after a platform challenge was initiated via Host::SendPlatformChallenge().
327 // All values will be NULL / zero in the event of a challenge failure.
328 struct PlatformChallengeResponse {
329 // |challenge| provided during Host::SendPlatformChallenge() combined with
330 // nonce data and signed with the platform's private key.
331 const uint8_t* signed_data;
332 uint32_t signed_data_length;
334 // RSASSA-PKCS1-v1_5-SHA256 signature of the |signed_data| block.
335 const uint8_t* signed_data_signature;
336 uint32_t signed_data_signature_length;
338 // X.509 device specific certificate for the |service_id| requested.
339 const uint8_t* platform_key_certificate;
340 uint32_t platform_key_certificate_length;
343 // Used when passing arrays of binary data. Does not own the referenced data.
345 BinaryData() : data(NULL), length(0) {}
350 // Supported output protection methods for use with EnableOutputProtection() and
351 // returned by OnQueryOutputProtectionStatus().
352 enum OutputProtectionMethods {
354 kProtectionHDCP = 1 << 0
357 // Connected output link types returned by OnQueryOutputProtectionStatus().
358 enum OutputLinkTypes {
360 kLinkTypeUnknown = 1 << 0,
361 kLinkTypeInternal = 1 << 1,
362 kLinkTypeVGA = 1 << 2,
363 kLinkTypeHDMI = 1 << 3,
364 kLinkTypeDVI = 1 << 4,
365 kLinkTypeDisplayPort = 1 << 5,
366 kLinkTypeNetwork = 1 << 6
369 // The type of session to create. The valid types are defined in the spec:
370 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#dom-sessiontype
376 // FileIO interface provides a way for the CDM to store data in a file in
377 // persistent storage. This interface aims only at providing basic read/write
378 // capabilities and should not be used as a full fledged file IO API.
379 // Each domain (e.g. "example.com") and each CDM has it's own persistent
380 // storage. All instances of a given CDM associated with a given domain share
381 // the same persistent storage.
384 // Opens the file with |file_name| for read and write.
385 // FileIOClient::OnOpenComplete() will be called after the opening
386 // operation finishes.
387 // - When the file is opened by a CDM instance, it will be classified as "in
388 // use". In this case other CDM instances in the same domain may receive
389 // kInUse status when trying to open it.
390 // - |file_name| should not include path separators.
391 virtual void Open(const char* file_name, uint32_t file_name_size) = 0;
393 // Reads the contents of the file. FileIOClient::OnReadComplete() will be
394 // called with the read status. Read() should not be called if a previous
395 // Read() or Write() call is still pending; otherwise OnReadComplete() will
396 // be called with kInUse.
397 virtual void Read() = 0;
399 // Writes |data_size| bytes of |data| into the file.
400 // FileIOClient::OnWriteComplete() will be called with the write status.
401 // All existing contents in the file will be overwritten. Calling Write() with
402 // NULL |data| will clear all contents in the file. Write() should not be
403 // called if a previous Write() or Read() call is still pending; otherwise
404 // OnWriteComplete() will be called with kInUse.
405 virtual void Write(const uint8_t* data, uint32_t data_size) = 0;
407 // Closes the file if opened, destroys this FileIO object and releases any
408 // resources allocated. The CDM must call this method when it finished using
409 // this object. A FileIO object must not be used after Close() is called.
410 virtual void Close() = 0;
417 // Responses to FileIO calls. All responses will be called asynchronously.
426 // Response to a FileIO::Open() call with the open |status|.
427 virtual void OnOpenComplete(Status status) = 0;
429 // Response to a FileIO::Read() call to provide |data_size| bytes of |data|
430 // read from the file.
431 // - kSuccess indicates that all contents of the file has been successfully
432 // read. In this case, 0 |data_size| means that the file is empty.
433 // - kInUse indicates that there are other read/write operations pending.
434 // - kError indicates read failure, e.g. the storage isn't open or cannot be
436 virtual void OnReadComplete(Status status,
437 const uint8_t* data, uint32_t data_size) = 0;
439 // Response to a FileIO::Write() call.
440 // - kSuccess indicates that all the data has been written into the file
442 // - kInUse indicates that there are other read/write operations pending.
443 // - kError indicates write failure, e.g. the storage isn't open or cannot be
444 // fully written. Upon write failure, the contents of the file should be
445 // regarded as corrupt and should not used.
446 virtual void OnWriteComplete(Status status) = 0;
450 virtual ~FileIOClient() {}
453 // ContentDecryptionModule interface that all CDMs need to implement.
454 // The interface is versioned for backward compatibility.
455 // Note: ContentDecryptionModule implementations must use the allocator
456 // provided in CreateCdmInstance() to allocate any Buffer that needs to
457 // be passed back to the caller. Implementations must call Buffer::Destroy()
458 // when a Buffer is created that will never be returned to the caller.
459 class ContentDecryptionModule_4 {
461 static const int kVersion = 4;
464 // CreateSession(), UpdateSession(), and ReleaseSession() get passed a
465 // |session_id| for a MediaKeySession object. It must be used in the reply via
466 // Host methods (e.g. Host::OnSessionMessage()).
467 // Note: |session_id| is different from MediaKeySession's sessionId attribute,
468 // which is referred to as |web_session_id| in this file.
470 // Creates a session given |type| and |init_data|.
471 virtual void CreateSession(
473 const char* type, uint32_t type_size,
474 const uint8_t* init_data, uint32_t init_data_size) = 0;
476 // Loads a session that has |web_session_id|.
477 virtual void LoadSession(
479 const char* web_session_id, uint32_t web_session_id_length) = 0;
481 // Updates the session with |response|.
482 virtual void UpdateSession(
484 const uint8_t* response, uint32_t response_size) = 0;
486 // Releases the resources for the session.
487 virtual void ReleaseSession(uint32_t session_id) = 0;
489 // Performs scheduled operation with |context| when the timer fires.
490 virtual void TimerExpired(void* context) = 0;
492 // Decrypts the |encrypted_buffer|.
494 // Returns kSuccess if decryption succeeded, in which case the callee
495 // should have filled the |decrypted_buffer| and passed the ownership of
496 // |data| in |decrypted_buffer| to the caller.
497 // Returns kNoKey if the CDM did not have the necessary decryption key
499 // Returns kDecryptError if any other error happened.
500 // If the return value is not kSuccess, |decrypted_buffer| should be ignored
502 virtual Status Decrypt(const InputBuffer_1& encrypted_buffer,
503 DecryptedBlock* decrypted_buffer) = 0;
505 // Initializes the CDM audio decoder with |audio_decoder_config|. This
506 // function must be called before DecryptAndDecodeSamples() is called.
508 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
509 // audio decoder is successfully initialized.
510 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM
511 // may still be able to do Decrypt().
512 // Returns kDeferredInitialization if the CDM is not ready to initialize the
513 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
514 // initialization is complete.
515 virtual Status InitializeAudioDecoder(
516 const AudioDecoderConfig& audio_decoder_config) = 0;
518 // Initializes the CDM video decoder with |video_decoder_config|. This
519 // function must be called before DecryptAndDecodeFrame() is called.
521 // Returns kSuccess if the |video_decoder_config| is supported and the CDM
522 // video decoder is successfully initialized.
523 // Returns kSessionError if |video_decoder_config| is not supported. The CDM
524 // may still be able to do Decrypt().
525 // Returns kDeferredInitialization if the CDM is not ready to initialize the
526 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
527 // initialization is complete.
528 virtual Status InitializeVideoDecoder(
529 const VideoDecoderConfig& video_decoder_config) = 0;
531 // De-initializes the CDM decoder and sets it to an uninitialized state. The
532 // caller can initialize the decoder again after this call to re-initialize
533 // it. This can be used to reconfigure the decoder if the configuration
535 virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
537 // Resets the CDM decoder to an initialized clean state. All internal buffers
539 virtual void ResetDecoder(StreamType decoder_type) = 0;
541 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
542 // |video_frame|. Upon end-of-stream, the caller should call this function
543 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
544 // |video_frame| (|format| == kEmptyVideoFrame) is produced.
546 // Returns kSuccess if decryption and decoding both succeeded, in which case
547 // the callee will have filled the |video_frame| and passed the ownership of
548 // |frame_buffer| in |video_frame| to the caller.
549 // Returns kNoKey if the CDM did not have the necessary decryption key
551 // Returns kNeedMoreData if more data was needed by the decoder to generate
552 // a decoded frame (e.g. during initialization and end-of-stream).
553 // Returns kDecryptError if any decryption error happened.
554 // Returns kDecodeError if any decoding error happened.
555 // If the return value is not kSuccess, |video_frame| should be ignored by
557 virtual Status DecryptAndDecodeFrame(const InputBuffer_1& encrypted_buffer,
558 VideoFrame* video_frame) = 0;
560 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
561 // |audio_frames|. Upon end-of-stream, the caller should call this function
562 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
563 // |audio_frames| is produced.
565 // Returns kSuccess if decryption and decoding both succeeded, in which case
566 // the callee will have filled |audio_frames| and passed the ownership of
567 // |data| in |audio_frames| to the caller.
568 // Returns kNoKey if the CDM did not have the necessary decryption key
570 // Returns kNeedMoreData if more data was needed by the decoder to generate
571 // audio samples (e.g. during initialization and end-of-stream).
572 // Returns kDecryptError if any decryption error happened.
573 // Returns kDecodeError if any decoding error happened.
574 // If the return value is not kSuccess, |audio_frames| should be ignored by
576 virtual Status DecryptAndDecodeSamples(const InputBuffer_1& encrypted_buffer,
577 AudioFrames* audio_frames) = 0;
579 // Called by the host after a platform challenge was initiated via
580 // Host::SendPlatformChallenge().
581 virtual void OnPlatformChallengeResponse(
582 const PlatformChallengeResponse& response) = 0;
584 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
585 // |link_mask| is a bit mask of OutputLinkTypes. The |output_protection_mask|
586 // is a bit mask of OutputProtectionMethods, indicating whether all
587 // protectable links in |link_mask| are protected. Protectable links include
588 // HDMI, DVI and DisplayPort.
589 virtual void OnQueryOutputProtectionStatus(
590 uint32_t link_mask, uint32_t output_protection_mask) = 0;
592 // Destroys the object in the same context as it was created.
593 virtual void Destroy() = 0;
596 ContentDecryptionModule_4() {}
597 virtual ~ContentDecryptionModule_4() {}
600 // ContentDecryptionModule interface that all CDMs need to implement.
601 // The interface is versioned for backward compatibility.
602 // Note: ContentDecryptionModule implementations must use the allocator
603 // provided in CreateCdmInstance() to allocate any Buffer that needs to
604 // be passed back to the caller. Implementations must call Buffer::Destroy()
605 // when a Buffer is created that will never be returned to the caller.
606 class ContentDecryptionModule_5 {
608 static const int kVersion = 5;
611 // CreateSession(), LoadSession(), UpdateSession(), and ReleaseSession()
612 // accept a |promise_id|, which must be passed to the completion Host method
613 // (e.g. Host::OnResolveNewSessionPromise()).
615 // Creates a session given |init_data_type|, |init_data| and |session_type|.
616 // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
617 // or Host::OnRejectPromise().
618 virtual void CreateSession(
620 const char* init_data_type, uint32_t init_data_type_size,
621 const uint8_t* init_data, uint32_t init_data_size,
622 SessionType session_type) = 0;
624 // Loads the session with |web_session_id|. The CDM must respond by calling
625 // either Host::OnResolveNewSessionPromise() or Host::OnRejectPromise().
626 // If the session is not found, call Host::OnResolveNewSessionPromise()
627 // with web_session_id = NULL.
628 virtual void LoadSession(
630 const char* web_session_id, uint32_t web_session_id_length) = 0;
632 // Updates the session with |response|. The CDM must respond by calling
633 // either Host::OnResolvePromise() or Host::OnRejectPromise().
634 virtual void UpdateSession(
636 const char* web_session_id, uint32_t web_session_id_length,
637 const uint8_t* response, uint32_t response_size) = 0;
639 // Releases the resources for the session. The CDM must respond by calling
640 // either Host::OnResolvePromise() or Host::OnRejectPromise().
641 // Once the session is closed, Host::OnSessionClosed() must also be called.
642 virtual void ReleaseSession(
644 const char* web_session_id, uint32_t web_session_id_length) = 0;
646 // Provides a server certificate to be used to encrypt messages to the
648 virtual void SetServerCertificate(
650 const uint8_t* server_certificate_data,
651 uint32_t server_certificate_data_size) = 0;
653 // Performs scheduled operation with |context| when the timer fires.
654 virtual void TimerExpired(void* context) = 0;
656 // Decrypts the |encrypted_buffer|.
658 // Returns kSuccess if decryption succeeded, in which case the callee
659 // should have filled the |decrypted_buffer| and passed the ownership of
660 // |data| in |decrypted_buffer| to the caller.
661 // Returns kNoKey if the CDM did not have the necessary decryption key
663 // Returns kDecryptError if any other error happened.
664 // If the return value is not kSuccess, |decrypted_buffer| should be ignored
666 virtual Status Decrypt(const InputBuffer_1& encrypted_buffer,
667 DecryptedBlock* decrypted_buffer) = 0;
669 // Initializes the CDM audio decoder with |audio_decoder_config|. This
670 // function must be called before DecryptAndDecodeSamples() is called.
672 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
673 // audio decoder is successfully initialized.
674 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM
675 // may still be able to do Decrypt().
676 // Returns kDeferredInitialization if the CDM is not ready to initialize the
677 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
678 // initialization is complete.
679 virtual Status InitializeAudioDecoder(
680 const AudioDecoderConfig& audio_decoder_config) = 0;
682 // Initializes the CDM video decoder with |video_decoder_config|. This
683 // function must be called before DecryptAndDecodeFrame() is called.
685 // Returns kSuccess if the |video_decoder_config| is supported and the CDM
686 // video decoder is successfully initialized.
687 // Returns kSessionError if |video_decoder_config| is not supported. The CDM
688 // may still be able to do Decrypt().
689 // Returns kDeferredInitialization if the CDM is not ready to initialize the
690 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
691 // initialization is complete.
692 virtual Status InitializeVideoDecoder(
693 const VideoDecoderConfig& video_decoder_config) = 0;
695 // De-initializes the CDM decoder and sets it to an uninitialized state. The
696 // caller can initialize the decoder again after this call to re-initialize
697 // it. This can be used to reconfigure the decoder if the configuration
699 virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
701 // Resets the CDM decoder to an initialized clean state. All internal buffers
703 virtual void ResetDecoder(StreamType decoder_type) = 0;
705 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
706 // |video_frame|. Upon end-of-stream, the caller should call this function
707 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
708 // |video_frame| (|format| == kEmptyVideoFrame) is produced.
710 // Returns kSuccess if decryption and decoding both succeeded, in which case
711 // the callee will have filled the |video_frame| and passed the ownership of
712 // |frame_buffer| in |video_frame| to the caller.
713 // Returns kNoKey if the CDM did not have the necessary decryption key
715 // Returns kNeedMoreData if more data was needed by the decoder to generate
716 // a decoded frame (e.g. during initialization and end-of-stream).
717 // Returns kDecryptError if any decryption error happened.
718 // Returns kDecodeError if any decoding error happened.
719 // If the return value is not kSuccess, |video_frame| should be ignored by
721 virtual Status DecryptAndDecodeFrame(const InputBuffer_1& encrypted_buffer,
722 VideoFrame* video_frame) = 0;
724 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
725 // |audio_frames|. Upon end-of-stream, the caller should call this function
726 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
727 // |audio_frames| is produced.
729 // Returns kSuccess if decryption and decoding both succeeded, in which case
730 // the callee will have filled |audio_frames| and passed the ownership of
731 // |data| in |audio_frames| to the caller.
732 // Returns kNoKey if the CDM did not have the necessary decryption key
734 // Returns kNeedMoreData if more data was needed by the decoder to generate
735 // audio samples (e.g. during initialization and end-of-stream).
736 // Returns kDecryptError if any decryption error happened.
737 // Returns kDecodeError if any decoding error happened.
738 // If the return value is not kSuccess, |audio_frames| should be ignored by
740 virtual Status DecryptAndDecodeSamples(const InputBuffer_1& encrypted_buffer,
741 AudioFrames* audio_frames) = 0;
743 // Called by the host after a platform challenge was initiated via
744 // Host::SendPlatformChallenge().
745 virtual void OnPlatformChallengeResponse(
746 const PlatformChallengeResponse& response) = 0;
748 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
749 // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
750 // is a bit mask of OutputProtectionMethods.
751 virtual void OnQueryOutputProtectionStatus(
752 uint32_t link_mask, uint32_t output_protection_mask) = 0;
754 // Destroys the object in the same context as it was created.
755 virtual void Destroy() = 0;
758 ContentDecryptionModule_5() {}
759 virtual ~ContentDecryptionModule_5() {}
762 // ContentDecryptionModule interface that all CDMs need to implement.
763 // The interface is versioned for backward compatibility.
764 // Note: ContentDecryptionModule implementations must use the allocator
765 // provided in CreateCdmInstance() to allocate any Buffer that needs to
766 // be passed back to the caller. Implementations must call Buffer::Destroy()
767 // when a Buffer is created that will never be returned to the caller.
768 class ContentDecryptionModule_6 {
770 static const int kVersion = 6;
773 // CreateSession(), LoadSession(), UpdateSession(), and ReleaseSession()
774 // accept a |promise_id|, which must be passed to the completion Host method
775 // (e.g. Host::OnResolveNewSessionPromise()).
777 // Creates a session given |init_data_type|, |init_data| and |session_type|.
778 // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
779 // or Host::OnRejectPromise().
780 virtual void CreateSession(
782 const char* init_data_type, uint32_t init_data_type_size,
783 const uint8_t* init_data, uint32_t init_data_size,
784 SessionType session_type) = 0;
786 // Loads the session with |web_session_id|. The CDM must respond by calling
787 // either Host::OnResolveNewSessionPromise() or Host::OnRejectPromise().
788 // If the session is not found, call Host::OnResolveNewSessionPromise()
789 // with web_session_id = NULL.
790 virtual void LoadSession(
792 const char* web_session_id, uint32_t web_session_id_length) = 0;
794 // Updates the session with |response|. The CDM must respond by calling
795 // either Host::OnResolvePromise() or Host::OnRejectPromise().
796 virtual void UpdateSession(
798 const char* web_session_id, uint32_t web_session_id_length,
799 const uint8_t* response, uint32_t response_size) = 0;
801 // Requests that the CDM close the session. The CDM must respond by calling
802 // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
803 // has been processed. This may be before the session is closed. Once the
804 // session is closed, Host::OnSessionClosed() must also be called.
805 virtual void CloseSession(
807 const char* web_session_id, uint32_t web_session_id_length) = 0;
809 // Removes any stored session data associated with this session. Will only be
810 // called for persistent sessions. The CDM must respond by calling either
811 // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
813 virtual void RemoveSession(
815 const char* web_session_id, uint32_t web_session_id_length) = 0;
817 // Requests the key IDs for keys in the session that the CDM knows are
818 // currently usable to decrypt media data. The CDM must respond by calling
819 // either Host::OnResolveGetUsableKeyIdsPromise() or Host::OnRejectPromise().
820 virtual void GetUsableKeyIds(
822 const char* web_session_id, uint32_t web_session_id_length) = 0;
824 // Provides a server certificate to be used to encrypt messages to the
825 // license server. The CDM must respond by calling either
826 // Host::OnResolvePromise() or Host::OnRejectPromise().
827 virtual void SetServerCertificate(
829 const uint8_t* server_certificate_data,
830 uint32_t server_certificate_data_size) = 0;
832 // Performs scheduled operation with |context| when the timer fires.
833 virtual void TimerExpired(void* context) = 0;
835 // Decrypts the |encrypted_buffer|.
837 // Returns kSuccess if decryption succeeded, in which case the callee
838 // should have filled the |decrypted_buffer| and passed the ownership of
839 // |data| in |decrypted_buffer| to the caller.
840 // Returns kNoKey if the CDM did not have the necessary decryption key
842 // Returns kDecryptError if any other error happened.
843 // If the return value is not kSuccess, |decrypted_buffer| should be ignored
845 virtual Status Decrypt(const InputBuffer& encrypted_buffer,
846 DecryptedBlock* decrypted_buffer) = 0;
848 // Initializes the CDM audio decoder with |audio_decoder_config|. This
849 // function must be called before DecryptAndDecodeSamples() is called.
851 // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
852 // audio decoder is successfully initialized.
853 // Returns kSessionError if |audio_decoder_config| is not supported. The CDM
854 // may still be able to do Decrypt().
855 // Returns kDeferredInitialization if the CDM is not ready to initialize the
856 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
857 // initialization is complete.
858 virtual Status InitializeAudioDecoder(
859 const AudioDecoderConfig& audio_decoder_config) = 0;
861 // Initializes the CDM video decoder with |video_decoder_config|. This
862 // function must be called before DecryptAndDecodeFrame() is called.
864 // Returns kSuccess if the |video_decoder_config| is supported and the CDM
865 // video decoder is successfully initialized.
866 // Returns kSessionError if |video_decoder_config| is not supported. The CDM
867 // may still be able to do Decrypt().
868 // Returns kDeferredInitialization if the CDM is not ready to initialize the
869 // decoder at this time. Must call Host::OnDeferredInitializationDone() once
870 // initialization is complete.
871 virtual Status InitializeVideoDecoder(
872 const VideoDecoderConfig& video_decoder_config) = 0;
874 // De-initializes the CDM decoder and sets it to an uninitialized state. The
875 // caller can initialize the decoder again after this call to re-initialize
876 // it. This can be used to reconfigure the decoder if the configuration
878 virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
880 // Resets the CDM decoder to an initialized clean state. All internal buffers
882 virtual void ResetDecoder(StreamType decoder_type) = 0;
884 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
885 // |video_frame|. Upon end-of-stream, the caller should call this function
886 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
887 // |video_frame| (|format| == kEmptyVideoFrame) is produced.
889 // Returns kSuccess if decryption and decoding both succeeded, in which case
890 // the callee will have filled the |video_frame| and passed the ownership of
891 // |frame_buffer| in |video_frame| to the caller.
892 // Returns kNoKey if the CDM did not have the necessary decryption key
894 // Returns kNeedMoreData if more data was needed by the decoder to generate
895 // a decoded frame (e.g. during initialization and end-of-stream).
896 // Returns kDecryptError if any decryption error happened.
897 // Returns kDecodeError if any decoding error happened.
898 // If the return value is not kSuccess, |video_frame| should be ignored by
900 virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer,
901 VideoFrame* video_frame) = 0;
903 // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
904 // |audio_frames|. Upon end-of-stream, the caller should call this function
905 // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
906 // |audio_frames| is produced.
908 // Returns kSuccess if decryption and decoding both succeeded, in which case
909 // the callee will have filled |audio_frames| and passed the ownership of
910 // |data| in |audio_frames| to the caller.
911 // Returns kNoKey if the CDM did not have the necessary decryption key
913 // Returns kNeedMoreData if more data was needed by the decoder to generate
914 // audio samples (e.g. during initialization and end-of-stream).
915 // Returns kDecryptError if any decryption error happened.
916 // Returns kDecodeError if any decoding error happened.
917 // If the return value is not kSuccess, |audio_frames| should be ignored by
919 virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer,
920 AudioFrames* audio_frames) = 0;
922 // Called by the host after a platform challenge was initiated via
923 // Host::SendPlatformChallenge().
924 virtual void OnPlatformChallengeResponse(
925 const PlatformChallengeResponse& response) = 0;
927 // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
928 // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
929 // is a bit mask of OutputProtectionMethods.
930 virtual void OnQueryOutputProtectionStatus(
931 uint32_t link_mask, uint32_t output_protection_mask) = 0;
933 // Destroys the object in the same context as it was created.
934 virtual void Destroy() = 0;
937 ContentDecryptionModule_6() {}
938 virtual ~ContentDecryptionModule_6() {}
941 typedef ContentDecryptionModule_6 ContentDecryptionModule;
943 // Represents a buffer created by Allocator implementations.
946 // Destroys the buffer in the same context as it was created.
947 virtual void Destroy() = 0;
949 virtual uint32_t Capacity() const = 0;
950 virtual uint8_t* Data() = 0;
951 virtual void SetSize(uint32_t size) = 0;
952 virtual uint32_t Size() const = 0;
959 Buffer(const Buffer&);
960 void operator=(const Buffer&);
965 static const int kVersion = 4;
967 // Returns a Buffer* containing non-zero members upon success, or NULL on
968 // failure. The caller owns the Buffer* after this call. The buffer is not
969 // guaranteed to be zero initialized. The capacity of the allocated Buffer
970 // is guaranteed to be not less than |capacity|.
971 virtual Buffer* Allocate(uint32_t capacity) = 0;
973 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
974 // from now with |context|.
975 virtual void SetTimer(int64_t delay_ms, void* context) = 0;
977 // Returns the current epoch wall time in seconds.
978 virtual double GetCurrentWallTimeInSeconds() = 0;
980 // Called by the CDM when a session is created or loaded and the value for the
981 // MediaKeySession's sessionId attribute is available (|web_session_id|).
982 // This must be called before OnSessionMessage() or OnSessionReady() is called
983 // for |session_id|. |web_session_id_length| should not include null
985 // When called in response to LoadSession(), the |web_session_id| must be the
986 // same as the |web_session_id| passed in LoadSession().
987 virtual void OnSessionCreated(
989 const char* web_session_id, uint32_t web_session_id_length) = 0;
991 // Called by the CDM when it has a message for session |session_id|.
992 // Length parameters should not include null termination.
993 virtual void OnSessionMessage(
995 const char* message, uint32_t message_length,
996 const char* destination_url, uint32_t destination_url_length) = 0;
998 // Called by the CDM when session |session_id| is ready.
999 // Note: "ready" event is deprecated. This is only used for the prefixed EME
1000 // API's "keyAdded" event. Drop this when we deprecate prefixed EME API.
1001 virtual void OnSessionReady(uint32_t session_id) = 0;
1003 // Called by the CDM when session |session_id| is closed.
1004 virtual void OnSessionClosed(uint32_t session_id) = 0;
1006 // Called by the CDM when an error occurs in session |session_id|.
1007 virtual void OnSessionError(uint32_t session_id,
1008 MediaKeyError error_code,
1009 uint32_t system_code) = 0;
1011 // The following are optional methods that may not be implemented on all
1014 // Sends a platform challenge for the given |service_id|. |challenge| is at
1015 // most 256 bits of data to be signed. Once the challenge has been completed,
1016 // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1017 // with the signed challenge response and platform certificate. Length
1018 // parameters should not include null termination.
1019 virtual void SendPlatformChallenge(
1020 const char* service_id, uint32_t service_id_length,
1021 const char* challenge, uint32_t challenge_length) = 0;
1023 // Attempts to enable output protection (e.g. HDCP) on the display link. The
1024 // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1025 // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1026 // periodically to ensure the desired protections are applied.
1027 virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1029 // Requests the current output protection status. Once the host has the status
1030 // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1031 virtual void QueryOutputProtectionStatus() = 0;
1033 // Must be called by the CDM if it returned kDeferredInitialization during
1034 // InitializeAudioDecoder() or InitializeVideoDecoder().
1035 virtual void OnDeferredInitializationDone(StreamType stream_type,
1036 Status decoder_status) = 0;
1038 // Creates a FileIO object from the host to do file IO operation. Returns NULL
1039 // if a FileIO object cannot be obtained. Once a valid FileIO object is
1040 // returned, |client| must be valid until FileIO::Close() is called. The
1041 // CDM can call this method multiple times to operate on different files.
1042 virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1046 virtual ~Host_4() {}
1051 static const int kVersion = 5;
1053 // Returns a Buffer* containing non-zero members upon success, or NULL on
1054 // failure. The caller owns the Buffer* after this call. The buffer is not
1055 // guaranteed to be zero initialized. The capacity of the allocated Buffer
1056 // is guaranteed to be not less than |capacity|.
1057 virtual Buffer* Allocate(uint32_t capacity) = 0;
1059 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
1060 // from now with |context|.
1061 virtual void SetTimer(int64_t delay_ms, void* context) = 0;
1063 // Returns the current wall time in seconds.
1064 virtual Time GetCurrentTime() = 0;
1066 // Called by the CDM when a session is created or loaded and the value for the
1067 // MediaKeySession's sessionId attribute is available (|web_session_id|).
1068 // This must be called before OnSessionMessage() or OnSessionReady() is called
1069 // for the same session. |web_session_id_length| should not include null
1071 // When called in response to LoadSession(), the |web_session_id| must be the
1072 // same as the |web_session_id| passed in LoadSession(), or NULL if the
1073 // session could not be loaded.
1074 virtual void OnResolveNewSessionPromise(
1075 uint32_t promise_id,
1076 const char* web_session_id, uint32_t web_session_id_length) = 0;
1078 // Called by the CDM when a session is updated or released.
1079 virtual void OnResolvePromise(uint32_t promise_id) = 0;
1081 // Called by the CDM when an error occurs as a result of one of the
1082 // ContentDecryptionModule calls that accept a |promise_id|.
1083 // |error| must be specified, |error_message| and |system_code|
1084 // are optional. Length parameters should not include null termination.
1085 virtual void OnRejectPromise(
1086 uint32_t promise_id,
1088 uint32_t system_code,
1089 const char* error_message, uint32_t error_message_length) = 0;
1091 // Called by the CDM when it has a message for session |web_session_id|.
1092 // Length parameters should not include null termination.
1093 virtual void OnSessionMessage(
1094 const char* web_session_id, uint32_t web_session_id_length,
1095 const char* message, uint32_t message_length,
1096 const char* destination_url, uint32_t destination_url_length) = 0;
1098 // Called by the CDM when there has been a change in usable keys for
1099 // session |web_session_id|. |has_additional_usable_key| should be set if a
1100 // key is newly usable (e.g. new key available, previously expired key has
1101 // been renewed, etc.) and the browser should attempt to resume playback.
1102 // Length parameter should not include null termination.
1103 virtual void OnSessionKeysChange(
1104 const char* web_session_id, uint32_t web_session_id_length,
1105 bool has_additional_usable_key) = 0;
1107 // Called by the CDM when there has been a change in the expiration time for
1108 // session |web_session_id|. This can happen as the result of an Update() call
1109 // or some other event. If this happens as a result of a call to Update(),
1110 // it must be called before resolving the Update() promise. |new_expiry_time|
1111 // can be 0 to represent "undefined". Length parameter should not include
1112 // null termination.
1113 virtual void OnExpirationChange(
1114 const char* web_session_id, uint32_t web_session_id_length,
1115 Time new_expiry_time) = 0;
1117 // Called by the CDM when session |web_session_id| is ready.
1118 // Note: "ready" event is deprecated. This is only used for the prefixed EME
1119 // API's "keyAdded" event. Drop this when we deprecate prefixed EME API.
1120 // Length parameter should not include null termination.
1121 virtual void OnSessionReady(
1122 const char* web_session_id, uint32_t web_session_id_length) = 0;
1124 // Called by the CDM when session |web_session_id| is closed. Length
1125 // parameter should not include null termination.
1126 virtual void OnSessionClosed(
1127 const char* web_session_id, uint32_t web_session_id_length) = 0;
1129 // Called by the CDM when an error occurs in session |web_session_id|
1130 // unrelated to one of the ContentDecryptionModule calls that accept a
1131 // |promise_id|. |error| must be specified, |error_message| and
1132 // |system_code| are optional. Length parameters should not include null
1134 virtual void OnSessionError(
1135 const char* web_session_id, uint32_t web_session_id_length,
1137 uint32_t system_code,
1138 const char* error_message, uint32_t error_message_length) = 0;
1140 // The following are optional methods that may not be implemented on all
1143 // Sends a platform challenge for the given |service_id|. |challenge| is at
1144 // most 256 bits of data to be signed. Once the challenge has been completed,
1145 // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1146 // with the signed challenge response and platform certificate. Length
1147 // parameters should not include null termination.
1148 virtual void SendPlatformChallenge(
1149 const char* service_id, uint32_t service_id_length,
1150 const char* challenge, uint32_t challenge_length) = 0;
1152 // Attempts to enable output protection (e.g. HDCP) on the display link. The
1153 // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1154 // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1155 // periodically to ensure the desired protections are applied.
1156 virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1158 // Requests the current output protection status. Once the host has the status
1159 // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1160 virtual void QueryOutputProtectionStatus() = 0;
1162 // Must be called by the CDM if it returned kDeferredInitialization during
1163 // InitializeAudioDecoder() or InitializeVideoDecoder().
1164 virtual void OnDeferredInitializationDone(StreamType stream_type,
1165 Status decoder_status) = 0;
1167 // Creates a FileIO object from the host to do file IO operation. Returns NULL
1168 // if a FileIO object cannot be obtained. Once a valid FileIO object is
1169 // returned, |client| must be valid until FileIO::Close() is called. The
1170 // CDM can call this method multiple times to operate on different files.
1171 virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1175 virtual ~Host_5() {}
1180 static const int kVersion = 6;
1182 // Returns a Buffer* containing non-zero members upon success, or NULL on
1183 // failure. The caller owns the Buffer* after this call. The buffer is not
1184 // guaranteed to be zero initialized. The capacity of the allocated Buffer
1185 // is guaranteed to be not less than |capacity|.
1186 virtual Buffer* Allocate(uint32_t capacity) = 0;
1188 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
1189 // from now with |context|.
1190 virtual void SetTimer(int64_t delay_ms, void* context) = 0;
1192 // Returns the current wall time in seconds.
1193 virtual Time GetCurrentWallTime() = 0;
1195 // Called by the CDM when a session is created or loaded and the value for the
1196 // MediaKeySession's sessionId attribute is available (|web_session_id|).
1197 // This must be called before OnSessionMessage() or OnSessionReady() is called
1198 // for the same session. |web_session_id_length| should not include null
1200 // When called in response to LoadSession(), the |web_session_id| must be the
1201 // same as the |web_session_id| passed in LoadSession(), or NULL if the
1202 // session could not be loaded.
1203 virtual void OnResolveNewSessionPromise(
1204 uint32_t promise_id,
1205 const char* web_session_id, uint32_t web_session_id_length) = 0;
1207 // Called by the CDM when a session is updated or released.
1208 virtual void OnResolvePromise(uint32_t promise_id) = 0;
1210 // Called by the CDM to return a list of key IDs. The caller owns the
1211 // BinaryData array and the values the elements reference.
1212 virtual void OnResolveKeyIdsPromise(
1213 uint32_t promise_id,
1214 const BinaryData* key_ids, uint32_t key_ids_length) = 0;
1216 // Called by the CDM when an error occurs as a result of one of the
1217 // ContentDecryptionModule calls that accept a |promise_id|.
1218 // |error| must be specified, |error_message| and |system_code|
1219 // are optional. Length parameters should not include null termination.
1220 virtual void OnRejectPromise(
1221 uint32_t promise_id,
1223 uint32_t system_code,
1224 const char* error_message, uint32_t error_message_length) = 0;
1226 // Called by the CDM when it has a message for session |web_session_id|.
1227 // Length parameters should not include null termination.
1228 virtual void OnSessionMessage(
1229 const char* web_session_id, uint32_t web_session_id_length,
1230 const char* message, uint32_t message_length,
1231 const char* destination_url, uint32_t destination_url_length) = 0;
1233 // Called by the CDM when there has been a change in usable keys for
1234 // session |web_session_id|. |has_additional_usable_key| should be set if a
1235 // key is newly usable (e.g. new key available, previously expired key has
1236 // been renewed, etc.) and the browser should attempt to resume playback.
1237 // Length parameter should not include null termination.
1238 virtual void OnSessionUsableKeysChange(
1239 const char* web_session_id, uint32_t web_session_id_length,
1240 bool has_additional_usable_key) = 0;
1242 // Called by the CDM when there has been a change in the expiration time for
1243 // session |web_session_id|. This can happen as the result of an Update() call
1244 // or some other event. If this happens as a result of a call to Update(),
1245 // it must be called before resolving the Update() promise. |new_expiry_time|
1246 // can be 0 to represent "undefined". Length parameter should not include
1247 // null termination.
1248 virtual void OnExpirationChange(
1249 const char* web_session_id, uint32_t web_session_id_length,
1250 Time new_expiry_time) = 0;
1252 // Called by the CDM when session |web_session_id| is closed. Length
1253 // parameter should not include null termination.
1254 virtual void OnSessionClosed(
1255 const char* web_session_id, uint32_t web_session_id_length) = 0;
1257 // Called by the CDM when an error occurs in session |web_session_id|
1258 // unrelated to one of the ContentDecryptionModule calls that accept a
1259 // |promise_id|. |error| must be specified, |error_message| and
1260 // |system_code| are optional. Length parameters should not include null
1262 virtual void OnSessionError(
1263 const char* web_session_id, uint32_t web_session_id_length,
1265 uint32_t system_code,
1266 const char* error_message, uint32_t error_message_length) = 0;
1268 // The following are optional methods that may not be implemented on all
1271 // Sends a platform challenge for the given |service_id|. |challenge| is at
1272 // most 256 bits of data to be signed. Once the challenge has been completed,
1273 // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1274 // with the signed challenge response and platform certificate. Length
1275 // parameters should not include null termination.
1276 virtual void SendPlatformChallenge(
1277 const char* service_id, uint32_t service_id_length,
1278 const char* challenge, uint32_t challenge_length) = 0;
1280 // Attempts to enable output protection (e.g. HDCP) on the display link. The
1281 // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1282 // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1283 // periodically to ensure the desired protections are applied.
1284 virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1286 // Requests the current output protection status. Once the host has the status
1287 // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1288 virtual void QueryOutputProtectionStatus() = 0;
1290 // Must be called by the CDM if it returned kDeferredInitialization during
1291 // InitializeAudioDecoder() or InitializeVideoDecoder().
1292 virtual void OnDeferredInitializationDone(StreamType stream_type,
1293 Status decoder_status) = 0;
1295 // Creates a FileIO object from the host to do file IO operation. Returns NULL
1296 // if a FileIO object cannot be obtained. Once a valid FileIO object is
1297 // returned, |client| must be valid until FileIO::Close() is called. The
1298 // CDM can call this method multiple times to operate on different files.
1299 virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1303 virtual ~Host_6() {}
1306 // Represents a decrypted block that has not been decoded.
1307 class DecryptedBlock {
1309 virtual void SetDecryptedBuffer(Buffer* buffer) = 0;
1310 virtual Buffer* DecryptedBuffer() = 0;
1312 // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not,
1313 // we can just pass Buffer pointers around.
1314 virtual void SetTimestamp(int64_t timestamp) = 0;
1315 virtual int64_t Timestamp() const = 0;
1319 virtual ~DecryptedBlock() {}
1331 virtual void SetFormat(VideoFormat format) = 0;
1332 virtual VideoFormat Format() const = 0;
1334 virtual void SetSize(cdm::Size size) = 0;
1335 virtual cdm::Size Size() const = 0;
1337 virtual void SetFrameBuffer(Buffer* frame_buffer) = 0;
1338 virtual Buffer* FrameBuffer() = 0;
1340 virtual void SetPlaneOffset(VideoPlane plane, uint32_t offset) = 0;
1341 virtual uint32_t PlaneOffset(VideoPlane plane) = 0;
1343 virtual void SetStride(VideoPlane plane, uint32_t stride) = 0;
1344 virtual uint32_t Stride(VideoPlane plane) = 0;
1346 virtual void SetTimestamp(int64_t timestamp) = 0;
1347 virtual int64_t Timestamp() const = 0;
1351 virtual ~VideoFrame() {}
1354 // Represents decrypted and decoded audio frames. AudioFrames can contain
1355 // multiple audio output buffers, which are serialized into this format:
1357 // |<------------------- serialized audio buffer ------------------->|
1358 // | int64_t timestamp | int64_t length | length bytes of audio data |
1360 // For example, with three audio output buffers, the AudioFrames will look
1363 // |<----------------- AudioFrames ------------------>|
1364 // | audio buffer 0 | audio buffer 1 | audio buffer 2 |
1365 class AudioFrames_2 {
1367 virtual void SetFrameBuffer(Buffer* buffer) = 0;
1368 virtual Buffer* FrameBuffer() = 0;
1370 // The CDM must call this method, providing a valid format, when providing
1371 // frame buffers. Planar data should be stored end to end; e.g.,
1372 // |ch1 sample1||ch1 sample2|....|ch1 sample_last||ch2 sample1|...
1373 virtual void SetFormat(AudioFormat format) = 0;
1374 virtual AudioFormat Format() const = 0;
1378 virtual ~AudioFrames_2() {}
1383 #endif // CDM_CONTENT_DECRYPTION_MODULE_H_