Line data Source code
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.
4 :
5 : #ifndef CDM_CONTENT_DECRYPTION_MODULE_H_
6 : #define CDM_CONTENT_DECRYPTION_MODULE_H_
7 :
8 : #if defined(_MSC_VER)
9 : typedef unsigned char uint8_t;
10 : typedef unsigned int uint32_t;
11 : typedef int int32_t;
12 : typedef __int64 int64_t;
13 : #else
14 : #include <stdint.h>
15 : #endif
16 :
17 : // Define CDM_EXPORT so that functionality implemented by the CDM module
18 : // can be exported to consumers.
19 : #if defined(WIN32)
20 :
21 : #if defined(CDM_IMPLEMENTATION)
22 : #define CDM_EXPORT __declspec(dllexport)
23 : #else
24 : #define CDM_EXPORT __declspec(dllimport)
25 : #endif // defined(CDM_IMPLEMENTATION)
26 :
27 : #else // defined(WIN32)
28 :
29 : #if defined(CDM_IMPLEMENTATION)
30 : #define CDM_EXPORT __attribute__((visibility("default")))
31 : #else
32 : #define CDM_EXPORT
33 : #endif
34 :
35 : #endif // defined(WIN32)
36 :
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
41 :
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
49 :
50 : extern "C" {
51 : CDM_EXPORT void INITIALIZE_CDM_MODULE();
52 :
53 : CDM_EXPORT void DeinitializeCdmModule();
54 :
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);
60 :
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
67 : // object.
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);
72 :
73 : CDM_EXPORT const char* GetCdmVersion();
74 : }
75 :
76 : namespace cdm {
77 :
78 : class AudioFrames;
79 : class DecryptedBlock;
80 : class VideoFrame;
81 :
82 : class Host_7;
83 : class Host_8;
84 :
85 : enum Status {
86 : kSuccess = 0,
87 : kNeedMoreData, // Decoder needs more data to produce a decoded frame/sample.
88 : kNoKey, // The required decryption key is not available.
89 : kSessionError, // Session management error.
90 : kDecryptError, // Decryption failed.
91 : kDecodeError, // Error decoding audio or video.
92 : kDeferredInitialization // Decoder is not ready for initialization.
93 : };
94 :
95 : // This must at least contain the exceptions defined in the spec:
96 : // https://w3c.github.io/encrypted-media/#exceptions
97 : // The following starts with the list of DOM4 exceptions from:
98 : // http://www.w3.org/TR/dom/#domexception
99 : // Some DOM4 exceptions are not included as they are not expected to be used.
100 : enum Error {
101 : kNotSupportedError = 9,
102 : kInvalidStateError = 11,
103 : kInvalidAccessError = 15,
104 : kQuotaExceededError = 22,
105 :
106 : // Additional exceptions that do not have assigned codes.
107 : // There are other non-EME-specific values, not included in this list.
108 : kUnknownError = 30,
109 :
110 : // Additional values from previous EME versions. They currently have no
111 : // matching DOMException.
112 : kClientError = 100,
113 : kOutputError = 101
114 : };
115 :
116 : // Time is defined as the number of seconds since the
117 : // Epoch (00:00:00 UTC, January 1, 1970).
118 : typedef double Time;
119 :
120 : // An input buffer can be split into several continuous subsamples.
121 : // A SubsampleEntry specifies the number of clear and cipher bytes in each
122 : // subsample. For example, the following buffer has three subsamples:
123 : //
124 : // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
125 : // | clear1 | cipher1 | clear2 | cipher2 | clear3 | cipher3 |
126 : //
127 : // For decryption, all of the cipher bytes in a buffer should be concatenated
128 : // (in the subsample order) into a single logical stream. The clear bytes should
129 : // not be considered as part of decryption.
130 : //
131 : // Stream to decrypt: | cipher1 | cipher2 | cipher3 |
132 : // Decrypted stream: | decrypted1| decrypted2 | decrypted3 |
133 : //
134 : // After decryption, the decrypted bytes should be copied over the position
135 : // of the corresponding cipher bytes in the original buffer to form the output
136 : // buffer. Following the above example, the decrypted buffer should be:
137 : //
138 : // |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
139 : // | clear1 | decrypted1| clear2 | decrypted2 | clear3 | decrypted3 |
140 : //
141 : struct SubsampleEntry {
142 0 : SubsampleEntry(uint32_t clear_bytes, uint32_t cipher_bytes)
143 0 : : clear_bytes(clear_bytes), cipher_bytes(cipher_bytes) {}
144 :
145 : uint32_t clear_bytes;
146 : uint32_t cipher_bytes;
147 : };
148 :
149 : // Represents an input buffer to be decrypted (and possibly decoded). It does
150 : // not own any pointers in this struct. If |iv_size| = 0, the data is
151 : // unencrypted.
152 : struct InputBuffer {
153 0 : InputBuffer()
154 0 : : data(NULL),
155 : data_size(0),
156 : key_id(NULL),
157 : key_id_size(0),
158 : iv(NULL),
159 : iv_size(0),
160 : subsamples(NULL),
161 : num_subsamples(0),
162 0 : timestamp(0) {}
163 :
164 : const uint8_t* data; // Pointer to the beginning of the input data.
165 : uint32_t data_size; // Size (in bytes) of |data|.
166 :
167 : const uint8_t* key_id; // Key ID to identify the decryption key.
168 : uint32_t key_id_size; // Size (in bytes) of |key_id|.
169 :
170 : const uint8_t* iv; // Initialization vector.
171 : uint32_t iv_size; // Size (in bytes) of |iv|.
172 :
173 : const struct SubsampleEntry* subsamples;
174 : uint32_t num_subsamples; // Number of subsamples in |subsamples|.
175 :
176 : int64_t timestamp; // Presentation timestamp in microseconds.
177 : };
178 :
179 : struct AudioDecoderConfig {
180 : enum AudioCodec {
181 : kUnknownAudioCodec = 0,
182 : kCodecVorbis,
183 : kCodecAac
184 : };
185 :
186 : AudioDecoderConfig()
187 : : codec(kUnknownAudioCodec),
188 : channel_count(0),
189 : bits_per_channel(0),
190 : samples_per_second(0),
191 : extra_data(NULL),
192 : extra_data_size(0) {}
193 :
194 : AudioCodec codec;
195 : int32_t channel_count;
196 : int32_t bits_per_channel;
197 : int32_t samples_per_second;
198 :
199 : // Optional byte data required to initialize audio decoders, such as the
200 : // vorbis setup header.
201 : uint8_t* extra_data;
202 : uint32_t extra_data_size;
203 : };
204 :
205 : // Supported sample formats for AudioFrames.
206 : enum AudioFormat {
207 : kUnknownAudioFormat = 0, // Unknown format value. Used for error reporting.
208 : kAudioFormatU8, // Interleaved unsigned 8-bit w/ bias of 128.
209 : kAudioFormatS16, // Interleaved signed 16-bit.
210 : kAudioFormatS32, // Interleaved signed 32-bit.
211 : kAudioFormatF32, // Interleaved float 32-bit.
212 : kAudioFormatPlanarS16, // Signed 16-bit planar.
213 : kAudioFormatPlanarF32, // Float 32-bit planar.
214 : };
215 :
216 : // Surface formats based on FOURCC labels, see: http://www.fourcc.org/yuv.php
217 : enum VideoFormat {
218 : kUnknownVideoFormat = 0, // Unknown format value. Used for error reporting.
219 : kYv12, // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
220 : kI420 // 12bpp YVU planar 1x1 Y, 2x2 UV samples.
221 : };
222 :
223 : struct Size {
224 0 : Size() : width(0), height(0) {}
225 0 : Size(int32_t width, int32_t height) : width(width), height(height) {}
226 :
227 : int32_t width;
228 : int32_t height;
229 : };
230 :
231 : struct VideoDecoderConfig {
232 : enum VideoCodec {
233 : kUnknownVideoCodec = 0,
234 : kCodecVp8,
235 : kCodecH264,
236 : kCodecVp9
237 : };
238 :
239 : enum VideoCodecProfile {
240 : kUnknownVideoCodecProfile = 0,
241 : kProfileNotNeeded,
242 : kH264ProfileBaseline,
243 : kH264ProfileMain,
244 : kH264ProfileExtended,
245 : kH264ProfileHigh,
246 : kH264ProfileHigh10,
247 : kH264ProfileHigh422,
248 : kH264ProfileHigh444Predictive
249 : };
250 :
251 0 : VideoDecoderConfig()
252 0 : : codec(kUnknownVideoCodec),
253 : profile(kUnknownVideoCodecProfile),
254 : format(kUnknownVideoFormat),
255 : extra_data(NULL),
256 0 : extra_data_size(0) {}
257 :
258 : VideoCodec codec;
259 : VideoCodecProfile profile;
260 : VideoFormat format;
261 :
262 : // Width and height of video frame immediately post-decode. Not all pixels
263 : // in this region are valid.
264 : Size coded_size;
265 :
266 : // Optional byte data required to initialize video decoders, such as H.264
267 : // AAVC data.
268 : uint8_t* extra_data;
269 : uint32_t extra_data_size;
270 : };
271 :
272 : enum StreamType {
273 : kStreamTypeAudio = 0,
274 : kStreamTypeVideo = 1
275 : };
276 :
277 : // Structure provided to ContentDecryptionModule::OnPlatformChallengeResponse()
278 : // after a platform challenge was initiated via Host::SendPlatformChallenge().
279 : // All values will be NULL / zero in the event of a challenge failure.
280 : struct PlatformChallengeResponse {
281 : // |challenge| provided during Host::SendPlatformChallenge() combined with
282 : // nonce data and signed with the platform's private key.
283 : const uint8_t* signed_data;
284 : uint32_t signed_data_length;
285 :
286 : // RSASSA-PKCS1-v1_5-SHA256 signature of the |signed_data| block.
287 : const uint8_t* signed_data_signature;
288 : uint32_t signed_data_signature_length;
289 :
290 : // X.509 device specific certificate for the |service_id| requested.
291 : const uint8_t* platform_key_certificate;
292 : uint32_t platform_key_certificate_length;
293 : };
294 :
295 : // Used when passing arrays of binary data. Does not own the referenced data.
296 : struct BinaryData {
297 : BinaryData() : data(NULL), length(0) {}
298 : const uint8_t* data;
299 : uint32_t length;
300 : };
301 :
302 : // The current status of the associated key. The valid types are defined in the
303 : // spec: https://w3c.github.io/encrypted-media/#idl-def-MediaKeyStatus
304 : enum KeyStatus {
305 : kUsable = 0,
306 : kInternalError = 1,
307 : kExpired = 2,
308 : kOutputRestricted = 3,
309 : kOutputDownscaled = 4,
310 : kStatusPending = 5,
311 : kReleased = 6
312 : };
313 :
314 : // Used when passing arrays of key information. Does not own the referenced
315 : // data. |system_code| is an additional error code for unusable keys and
316 : // should be 0 when |status| == kUsable.
317 : struct KeyInformation {
318 : KeyInformation()
319 : : key_id(NULL), key_id_size(0), status(kInternalError), system_code(0) {}
320 : const uint8_t* key_id;
321 : uint32_t key_id_size;
322 : KeyStatus status;
323 : uint32_t system_code;
324 : };
325 :
326 : // Supported output protection methods for use with EnableOutputProtection() and
327 : // returned by OnQueryOutputProtectionStatus().
328 : enum OutputProtectionMethods {
329 : kProtectionNone = 0,
330 : kProtectionHDCP = 1 << 0
331 : };
332 :
333 : // Connected output link types returned by OnQueryOutputProtectionStatus().
334 : enum OutputLinkTypes {
335 : kLinkTypeNone = 0,
336 : kLinkTypeUnknown = 1 << 0,
337 : kLinkTypeInternal = 1 << 1,
338 : kLinkTypeVGA = 1 << 2,
339 : kLinkTypeHDMI = 1 << 3,
340 : kLinkTypeDVI = 1 << 4,
341 : kLinkTypeDisplayPort = 1 << 5,
342 : kLinkTypeNetwork = 1 << 6
343 : };
344 :
345 : // Result of the QueryOutputProtectionStatus() call.
346 : enum QueryResult {
347 : kQuerySucceeded = 0,
348 : kQueryFailed
349 : };
350 :
351 : // The Initialization Data Type. The valid types are defined in the spec:
352 : // http://w3c.github.io/encrypted-media/initdata-format-registry.html#registry
353 : enum InitDataType {
354 : kCenc = 0,
355 : kKeyIds = 1,
356 : kWebM = 2
357 : };
358 :
359 : // The type of session to create. The valid types are defined in the spec:
360 : // https://w3c.github.io/encrypted-media/#idl-def-SessionType
361 : enum SessionType {
362 : kTemporary = 0,
363 : kPersistentLicense = 1,
364 : kPersistentKeyRelease = 2
365 : };
366 :
367 : // The type of the message event. The valid types are defined in the spec:
368 : // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType
369 : enum MessageType {
370 : kLicenseRequest = 0,
371 : kLicenseRenewal = 1,
372 : kLicenseRelease = 2
373 : };
374 :
375 : // FileIO interface provides a way for the CDM to store data in a file in
376 : // persistent storage. This interface aims only at providing basic read/write
377 : // capabilities and should not be used as a full fledged file IO API.
378 : // Each CDM and origin (e.g. HTTPS, "foo.example.com", 443) combination has
379 : // its own persistent storage. All instances of a given CDM associated with a
380 : // given origin share the same persistent storage.
381 : // Note to implementors of this interface:
382 : // Per-origin storage and the ability for users to clear it are important.
383 : // See http://www.w3.org/TR/encrypted-media/#privacy-storedinfo.
384 : class FileIO {
385 : public:
386 : // Opens the file with |file_name| for read and write.
387 : // FileIOClient::OnOpenComplete() will be called after the opening
388 : // operation finishes.
389 : // - When the file is opened by a CDM instance, it will be classified as "in
390 : // use". In this case other CDM instances in the same domain may receive
391 : // kInUse status when trying to open it.
392 : // - |file_name| must not contain forward slash ('/') or backslash ('\'), and
393 : // must not start with an underscore ('_').
394 : virtual void Open(const char* file_name, uint32_t file_name_size) = 0;
395 :
396 : // Reads the contents of the file. FileIOClient::OnReadComplete() will be
397 : // called with the read status. Read() should not be called if a previous
398 : // Read() or Write() call is still pending; otherwise OnReadComplete() will
399 : // be called with kInUse.
400 : virtual void Read() = 0;
401 :
402 : // Writes |data_size| bytes of |data| into the file.
403 : // FileIOClient::OnWriteComplete() will be called with the write status.
404 : // All existing contents in the file will be overwritten. Calling Write() with
405 : // NULL |data| will clear all contents in the file. Write() should not be
406 : // called if a previous Write() or Read() call is still pending; otherwise
407 : // OnWriteComplete() will be called with kInUse.
408 : virtual void Write(const uint8_t* data, uint32_t data_size) = 0;
409 :
410 : // Closes the file if opened, destroys this FileIO object and releases any
411 : // resources allocated. The CDM must call this method when it finished using
412 : // this object. A FileIO object must not be used after Close() is called.
413 : virtual void Close() = 0;
414 :
415 : protected:
416 0 : FileIO() {}
417 0 : virtual ~FileIO() {}
418 : };
419 :
420 : // Responses to FileIO calls. All responses will be called asynchronously.
421 : // When kError is returned, the FileIO object could be in an error state. All
422 : // following calls (other than Close()) could return kError. The CDM should
423 : // still call Close() to destroy the FileIO object.
424 : class FileIOClient {
425 : public:
426 : enum Status {
427 : kSuccess = 0,
428 : kInUse,
429 : kError
430 : };
431 :
432 : // Response to a FileIO::Open() call with the open |status|.
433 : virtual void OnOpenComplete(Status status) = 0;
434 :
435 : // Response to a FileIO::Read() call to provide |data_size| bytes of |data|
436 : // read from the file.
437 : // - kSuccess indicates that all contents of the file has been successfully
438 : // read. In this case, 0 |data_size| means that the file is empty.
439 : // - kInUse indicates that there are other read/write operations pending.
440 : // - kError indicates read failure, e.g. the storage is not open or cannot be
441 : // fully read.
442 : virtual void OnReadComplete(Status status,
443 : const uint8_t* data, uint32_t data_size) = 0;
444 :
445 : // Response to a FileIO::Write() call.
446 : // - kSuccess indicates that all the data has been written into the file
447 : // successfully.
448 : // - kInUse indicates that there are other read/write operations pending.
449 : // - kError indicates write failure, e.g. the storage is not open or cannot be
450 : // fully written. Upon write failure, the contents of the file should be
451 : // regarded as corrupt and should not used.
452 : virtual void OnWriteComplete(Status status) = 0;
453 :
454 : protected:
455 : FileIOClient() {}
456 : virtual ~FileIOClient() {}
457 : };
458 :
459 : // ContentDecryptionModule interface that all CDMs need to implement.
460 : // The interface is versioned for backward compatibility.
461 : // Note: ContentDecryptionModule implementations must use the allocator
462 : // provided in CreateCdmInstance() to allocate any Buffer that needs to
463 : // be passed back to the caller. Implementations must call Buffer::Destroy()
464 : // when a Buffer is created that will never be returned to the caller.
465 : class ContentDecryptionModule_7 {
466 : public:
467 : static const int kVersion = 7;
468 : typedef Host_7 Host;
469 :
470 : // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(),
471 : // UpdateSession(), CloseSession(), and RemoveSession() all accept a
472 : // |promise_id|, which must be passed to the completion Host method
473 : // (e.g. Host::OnResolveNewSessionPromise()).
474 :
475 : // Provides a server certificate to be used to encrypt messages to the
476 : // license server. The CDM must respond by calling either
477 : // Host::OnResolvePromise() or Host::OnRejectPromise().
478 : virtual void SetServerCertificate(uint32_t promise_id,
479 : const uint8_t* server_certificate_data,
480 : uint32_t server_certificate_data_size) = 0;
481 :
482 : // Creates a session given |session_type|, |init_data_type|, and |init_data|.
483 : // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
484 : // or Host::OnRejectPromise().
485 : virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
486 : SessionType session_type,
487 : const char* init_data_type,
488 : uint32_t init_data_type_size,
489 : const uint8_t* init_data,
490 : uint32_t init_data_size) = 0;
491 :
492 : // Loads the session of type |session_type| specified by |session_id|.
493 : // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
494 : // or Host::OnRejectPromise(). If the session is not found, call
495 : // Host::OnResolveNewSessionPromise() with session_id = NULL.
496 : virtual void LoadSession(uint32_t promise_id,
497 : SessionType session_type,
498 : const char* session_id,
499 : uint32_t session_id_size) = 0;
500 :
501 : // Updates the session with |response|. The CDM must respond by calling
502 : // either Host::OnResolvePromise() or Host::OnRejectPromise().
503 : virtual void UpdateSession(uint32_t promise_id,
504 : const char* session_id,
505 : uint32_t session_id_size,
506 : const uint8_t* response,
507 : uint32_t response_size) = 0;
508 :
509 : // Requests that the CDM close the session. The CDM must respond by calling
510 : // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
511 : // has been processed. This may be before the session is closed. Once the
512 : // session is closed, Host::OnSessionClosed() must also be called.
513 : virtual void CloseSession(uint32_t promise_id,
514 : const char* session_id,
515 : uint32_t session_id_size) = 0;
516 :
517 : // Removes any stored session data associated with this session. Will only be
518 : // called for persistent sessions. The CDM must respond by calling either
519 : // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
520 : // been processed.
521 : virtual void RemoveSession(uint32_t promise_id,
522 : const char* session_id,
523 : uint32_t session_id_size) = 0;
524 :
525 : // Performs scheduled operation with |context| when the timer fires.
526 : virtual void TimerExpired(void* context) = 0;
527 :
528 : // Decrypts the |encrypted_buffer|.
529 : //
530 : // Returns kSuccess if decryption succeeded, in which case the callee
531 : // should have filled the |decrypted_buffer| and passed the ownership of
532 : // |data| in |decrypted_buffer| to the caller.
533 : // Returns kNoKey if the CDM did not have the necessary decryption key
534 : // to decrypt.
535 : // Returns kDecryptError if any other error happened.
536 : // If the return value is not kSuccess, |decrypted_buffer| should be ignored
537 : // by the caller.
538 : virtual Status Decrypt(const InputBuffer& encrypted_buffer,
539 : DecryptedBlock* decrypted_buffer) = 0;
540 :
541 : // Initializes the CDM audio decoder with |audio_decoder_config|. This
542 : // function must be called before DecryptAndDecodeSamples() is called.
543 : //
544 : // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
545 : // audio decoder is successfully initialized.
546 : // Returns kSessionError if |audio_decoder_config| is not supported. The CDM
547 : // may still be able to do Decrypt().
548 : // Returns kDeferredInitialization if the CDM is not ready to initialize the
549 : // decoder at this time. Must call Host::OnDeferredInitializationDone() once
550 : // initialization is complete.
551 : virtual Status InitializeAudioDecoder(
552 : const AudioDecoderConfig& audio_decoder_config) = 0;
553 :
554 : // Initializes the CDM video decoder with |video_decoder_config|. This
555 : // function must be called before DecryptAndDecodeFrame() is called.
556 : //
557 : // Returns kSuccess if the |video_decoder_config| is supported and the CDM
558 : // video decoder is successfully initialized.
559 : // Returns kSessionError if |video_decoder_config| is not supported. The CDM
560 : // may still be able to do Decrypt().
561 : // Returns kDeferredInitialization if the CDM is not ready to initialize the
562 : // decoder at this time. Must call Host::OnDeferredInitializationDone() once
563 : // initialization is complete.
564 : virtual Status InitializeVideoDecoder(
565 : const VideoDecoderConfig& video_decoder_config) = 0;
566 :
567 : // De-initializes the CDM decoder and sets it to an uninitialized state. The
568 : // caller can initialize the decoder again after this call to re-initialize
569 : // it. This can be used to reconfigure the decoder if the configuration
570 : // changes.
571 : virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
572 :
573 : // Resets the CDM decoder to an initialized clean state. All internal buffers
574 : // MUST be flushed.
575 : virtual void ResetDecoder(StreamType decoder_type) = 0;
576 :
577 : // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
578 : // |video_frame|. Upon end-of-stream, the caller should call this function
579 : // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
580 : // |video_frame| (|format| == kEmptyVideoFrame) is produced.
581 : //
582 : // Returns kSuccess if decryption and decoding both succeeded, in which case
583 : // the callee will have filled the |video_frame| and passed the ownership of
584 : // |frame_buffer| in |video_frame| to the caller.
585 : // Returns kNoKey if the CDM did not have the necessary decryption key
586 : // to decrypt.
587 : // Returns kNeedMoreData if more data was needed by the decoder to generate
588 : // a decoded frame (e.g. during initialization and end-of-stream).
589 : // Returns kDecryptError if any decryption error happened.
590 : // Returns kDecodeError if any decoding error happened.
591 : // If the return value is not kSuccess, |video_frame| should be ignored by
592 : // the caller.
593 : virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer,
594 : VideoFrame* video_frame) = 0;
595 :
596 : // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
597 : // |audio_frames|. Upon end-of-stream, the caller should call this function
598 : // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
599 : // |audio_frames| is produced.
600 : //
601 : // Returns kSuccess if decryption and decoding both succeeded, in which case
602 : // the callee will have filled |audio_frames| and passed the ownership of
603 : // |data| in |audio_frames| to the caller.
604 : // Returns kNoKey if the CDM did not have the necessary decryption key
605 : // to decrypt.
606 : // Returns kNeedMoreData if more data was needed by the decoder to generate
607 : // audio samples (e.g. during initialization and end-of-stream).
608 : // Returns kDecryptError if any decryption error happened.
609 : // Returns kDecodeError if any decoding error happened.
610 : // If the return value is not kSuccess, |audio_frames| should be ignored by
611 : // the caller.
612 : virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer,
613 : AudioFrames* audio_frames) = 0;
614 :
615 : // Called by the host after a platform challenge was initiated via
616 : // Host::SendPlatformChallenge().
617 : virtual void OnPlatformChallengeResponse(
618 : const PlatformChallengeResponse& response) = 0;
619 :
620 : // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
621 : // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
622 : // is a bit mask of OutputProtectionMethods. If |result| is kQueryFailed,
623 : // then |link_mask| and |output_protection_mask| are undefined and should
624 : // be ignored.
625 : virtual void OnQueryOutputProtectionStatus(
626 : QueryResult result,
627 : uint32_t link_mask,
628 : uint32_t output_protection_mask) = 0;
629 :
630 : // Destroys the object in the same context as it was created.
631 : virtual void Destroy() = 0;
632 :
633 : protected:
634 : ContentDecryptionModule_7() {}
635 : virtual ~ContentDecryptionModule_7() {}
636 : };
637 :
638 : // ContentDecryptionModule interface that all CDMs need to implement.
639 : // The interface is versioned for backward compatibility.
640 : // Note: ContentDecryptionModule implementations must use the allocator
641 : // provided in CreateCdmInstance() to allocate any Buffer that needs to
642 : // be passed back to the caller. Implementations must call Buffer::Destroy()
643 : // when a Buffer is created that will never be returned to the caller.
644 : class ContentDecryptionModule_8 {
645 : public:
646 : static const int kVersion = 8;
647 : typedef Host_8 Host;
648 :
649 : // Initializes the CDM instance, providing information about permitted
650 : // functionalities.
651 : // If |allow_distinctive_identifier| is false, messages from the CDM,
652 : // such as message events, must not contain a Distinctive Identifier,
653 : // even in an encrypted form.
654 : // If |allow_persistent_state| is false, the CDM must not attempt to
655 : // persist state. Calls to CreateFileIO() will fail.
656 : virtual void Initialize(bool allow_distinctive_identifier,
657 : bool allow_persistent_state) = 0;
658 :
659 : // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(),
660 : // UpdateSession(), CloseSession(), and RemoveSession() all accept a
661 : // |promise_id|, which must be passed to the completion Host method
662 : // (e.g. Host::OnResolveNewSessionPromise()).
663 :
664 : // Provides a server certificate to be used to encrypt messages to the
665 : // license server. The CDM must respond by calling either
666 : // Host::OnResolvePromise() or Host::OnRejectPromise().
667 : virtual void SetServerCertificate(uint32_t promise_id,
668 : const uint8_t* server_certificate_data,
669 : uint32_t server_certificate_data_size) = 0;
670 :
671 : // Creates a session given |session_type|, |init_data_type|, and |init_data|.
672 : // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
673 : // or Host::OnRejectPromise().
674 : virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
675 : SessionType session_type,
676 : InitDataType init_data_type,
677 : const uint8_t* init_data,
678 : uint32_t init_data_size) = 0;
679 :
680 : // Loads the session of type |session_type| specified by |session_id|.
681 : // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
682 : // or Host::OnRejectPromise(). If the session is not found, call
683 : // Host::OnResolveNewSessionPromise() with session_id = NULL.
684 : virtual void LoadSession(uint32_t promise_id,
685 : SessionType session_type,
686 : const char* session_id,
687 : uint32_t session_id_size) = 0;
688 :
689 : // Updates the session with |response|. The CDM must respond by calling
690 : // either Host::OnResolvePromise() or Host::OnRejectPromise().
691 : virtual void UpdateSession(uint32_t promise_id,
692 : const char* session_id,
693 : uint32_t session_id_size,
694 : const uint8_t* response,
695 : uint32_t response_size) = 0;
696 :
697 : // Requests that the CDM close the session. The CDM must respond by calling
698 : // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
699 : // has been processed. This may be before the session is closed. Once the
700 : // session is closed, Host::OnSessionClosed() must also be called.
701 : virtual void CloseSession(uint32_t promise_id,
702 : const char* session_id,
703 : uint32_t session_id_size) = 0;
704 :
705 : // Removes any stored session data associated with this session. Will only be
706 : // called for persistent sessions. The CDM must respond by calling either
707 : // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
708 : // been processed.
709 : virtual void RemoveSession(uint32_t promise_id,
710 : const char* session_id,
711 : uint32_t session_id_size) = 0;
712 :
713 : // Performs scheduled operation with |context| when the timer fires.
714 : virtual void TimerExpired(void* context) = 0;
715 :
716 : // Decrypts the |encrypted_buffer|.
717 : //
718 : // Returns kSuccess if decryption succeeded, in which case the callee
719 : // should have filled the |decrypted_buffer| and passed the ownership of
720 : // |data| in |decrypted_buffer| to the caller.
721 : // Returns kNoKey if the CDM did not have the necessary decryption key
722 : // to decrypt.
723 : // Returns kDecryptError if any other error happened.
724 : // If the return value is not kSuccess, |decrypted_buffer| should be ignored
725 : // by the caller.
726 : virtual Status Decrypt(const InputBuffer& encrypted_buffer,
727 : DecryptedBlock* decrypted_buffer) = 0;
728 :
729 : // Initializes the CDM audio decoder with |audio_decoder_config|. This
730 : // function must be called before DecryptAndDecodeSamples() is called.
731 : //
732 : // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
733 : // audio decoder is successfully initialized.
734 : // Returns kSessionError if |audio_decoder_config| is not supported. The CDM
735 : // may still be able to do Decrypt().
736 : // Returns kDeferredInitialization if the CDM is not ready to initialize the
737 : // decoder at this time. Must call Host::OnDeferredInitializationDone() once
738 : // initialization is complete.
739 : virtual Status InitializeAudioDecoder(
740 : const AudioDecoderConfig& audio_decoder_config) = 0;
741 :
742 : // Initializes the CDM video decoder with |video_decoder_config|. This
743 : // function must be called before DecryptAndDecodeFrame() is called.
744 : //
745 : // Returns kSuccess if the |video_decoder_config| is supported and the CDM
746 : // video decoder is successfully initialized.
747 : // Returns kSessionError if |video_decoder_config| is not supported. The CDM
748 : // may still be able to do Decrypt().
749 : // Returns kDeferredInitialization if the CDM is not ready to initialize the
750 : // decoder at this time. Must call Host::OnDeferredInitializationDone() once
751 : // initialization is complete.
752 : virtual Status InitializeVideoDecoder(
753 : const VideoDecoderConfig& video_decoder_config) = 0;
754 :
755 : // De-initializes the CDM decoder and sets it to an uninitialized state. The
756 : // caller can initialize the decoder again after this call to re-initialize
757 : // it. This can be used to reconfigure the decoder if the configuration
758 : // changes.
759 : virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
760 :
761 : // Resets the CDM decoder to an initialized clean state. All internal buffers
762 : // MUST be flushed.
763 : virtual void ResetDecoder(StreamType decoder_type) = 0;
764 :
765 : // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
766 : // |video_frame|. Upon end-of-stream, the caller should call this function
767 : // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
768 : // |video_frame| (|format| == kEmptyVideoFrame) is produced.
769 : //
770 : // Returns kSuccess if decryption and decoding both succeeded, in which case
771 : // the callee will have filled the |video_frame| and passed the ownership of
772 : // |frame_buffer| in |video_frame| to the caller.
773 : // Returns kNoKey if the CDM did not have the necessary decryption key
774 : // to decrypt.
775 : // Returns kNeedMoreData if more data was needed by the decoder to generate
776 : // a decoded frame (e.g. during initialization and end-of-stream).
777 : // Returns kDecryptError if any decryption error happened.
778 : // Returns kDecodeError if any decoding error happened.
779 : // If the return value is not kSuccess, |video_frame| should be ignored by
780 : // the caller.
781 : virtual Status DecryptAndDecodeFrame(const InputBuffer& encrypted_buffer,
782 : VideoFrame* video_frame) = 0;
783 :
784 : // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
785 : // |audio_frames|. Upon end-of-stream, the caller should call this function
786 : // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
787 : // |audio_frames| is produced.
788 : //
789 : // Returns kSuccess if decryption and decoding both succeeded, in which case
790 : // the callee will have filled |audio_frames| and passed the ownership of
791 : // |data| in |audio_frames| to the caller.
792 : // Returns kNoKey if the CDM did not have the necessary decryption key
793 : // to decrypt.
794 : // Returns kNeedMoreData if more data was needed by the decoder to generate
795 : // audio samples (e.g. during initialization and end-of-stream).
796 : // Returns kDecryptError if any decryption error happened.
797 : // Returns kDecodeError if any decoding error happened.
798 : // If the return value is not kSuccess, |audio_frames| should be ignored by
799 : // the caller.
800 : virtual Status DecryptAndDecodeSamples(const InputBuffer& encrypted_buffer,
801 : AudioFrames* audio_frames) = 0;
802 :
803 : // Called by the host after a platform challenge was initiated via
804 : // Host::SendPlatformChallenge().
805 : virtual void OnPlatformChallengeResponse(
806 : const PlatformChallengeResponse& response) = 0;
807 :
808 : // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
809 : // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
810 : // is a bit mask of OutputProtectionMethods. If |result| is kQueryFailed,
811 : // then |link_mask| and |output_protection_mask| are undefined and should
812 : // be ignored.
813 : virtual void OnQueryOutputProtectionStatus(
814 : QueryResult result,
815 : uint32_t link_mask,
816 : uint32_t output_protection_mask) = 0;
817 :
818 : // Destroys the object in the same context as it was created.
819 : virtual void Destroy() = 0;
820 :
821 : protected:
822 : ContentDecryptionModule_8() {}
823 : virtual ~ContentDecryptionModule_8() {}
824 : };
825 :
826 : typedef ContentDecryptionModule_8 ContentDecryptionModule;
827 :
828 : // Represents a buffer created by Allocator implementations.
829 : class Buffer {
830 : public:
831 : // Destroys the buffer in the same context as it was created.
832 : virtual void Destroy() = 0;
833 :
834 : virtual uint32_t Capacity() const = 0;
835 : virtual uint8_t* Data() = 0;
836 : virtual void SetSize(uint32_t size) = 0;
837 : virtual uint32_t Size() const = 0;
838 :
839 : protected:
840 0 : Buffer() {}
841 0 : virtual ~Buffer() {}
842 :
843 : private:
844 : Buffer(const Buffer&);
845 : void operator=(const Buffer&);
846 : };
847 :
848 : class Host_7 {
849 : public:
850 : static const int kVersion = 7;
851 :
852 : // Returns a Buffer* containing non-zero members upon success, or NULL on
853 : // failure. The caller owns the Buffer* after this call. The buffer is not
854 : // guaranteed to be zero initialized. The capacity of the allocated Buffer
855 : // is guaranteed to be not less than |capacity|.
856 : virtual Buffer* Allocate(uint32_t capacity) = 0;
857 :
858 : // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
859 : // from now with |context|.
860 : virtual void SetTimer(int64_t delay_ms, void* context) = 0;
861 :
862 : // Returns the current wall time in seconds.
863 : virtual Time GetCurrentWallTime() = 0;
864 :
865 : // Called by the CDM when a session is created or loaded and the value for the
866 : // MediaKeySession's sessionId attribute is available (|session_id|).
867 : // This must be called before OnSessionMessage() or
868 : // OnSessionKeysChange() is called for the same session. |session_id_size|
869 : // should not include null termination.
870 : // When called in response to LoadSession(), the |session_id| must be the
871 : // same as the |session_id| passed in LoadSession(), or NULL if the
872 : // session could not be loaded.
873 : virtual void OnResolveNewSessionPromise(uint32_t promise_id,
874 : const char* session_id,
875 : uint32_t session_id_size) = 0;
876 :
877 : // Called by the CDM when a session is updated or released.
878 : virtual void OnResolvePromise(uint32_t promise_id) = 0;
879 :
880 : // Called by the CDM when an error occurs as a result of one of the
881 : // ContentDecryptionModule calls that accept a |promise_id|.
882 : // |error| must be specified, |error_message| and |system_code|
883 : // are optional. |error_message_size| should not include null termination.
884 : virtual void OnRejectPromise(uint32_t promise_id,
885 : Error error,
886 : uint32_t system_code,
887 : const char* error_message,
888 : uint32_t error_message_size) = 0;
889 :
890 : // Called by the CDM when it has a message for session |session_id|.
891 : // Size parameters should not include null termination.
892 : // |legacy_destination_url| is only for supporting the prefixed EME API and
893 : // is ignored by unprefixed EME. It should only be non-null if |message_type|
894 : // is kLicenseRenewal.
895 : virtual void OnSessionMessage(const char* session_id,
896 : uint32_t session_id_size,
897 : MessageType message_type,
898 : const char* message,
899 : uint32_t message_size,
900 : const char* legacy_destination_url,
901 : uint32_t legacy_destination_url_length) = 0;
902 :
903 : // Called by the CDM when there has been a change in keys or their status for
904 : // session |session_id|. |has_additional_usable_key| should be set if a
905 : // key is newly usable (e.g. new key available, previously expired key has
906 : // been renewed, etc.) and the browser should attempt to resume playback.
907 : // |key_ids| is the list of key ids for this session along with their
908 : // current status. |key_ids_count| is the number of entries in |key_ids|.
909 : // Size parameter for |session_id| should not include null termination.
910 : virtual void OnSessionKeysChange(const char* session_id,
911 : uint32_t session_id_size,
912 : bool has_additional_usable_key,
913 : const KeyInformation* keys_info,
914 : uint32_t keys_info_count) = 0;
915 :
916 : // Called by the CDM when there has been a change in the expiration time for
917 : // session |session_id|. This can happen as the result of an Update() call
918 : // or some other event. If this happens as a result of a call to Update(),
919 : // it must be called before resolving the Update() promise. |new_expiry_time|
920 : // can be 0 to represent "undefined". Size parameter should not include
921 : // null termination.
922 : virtual void OnExpirationChange(const char* session_id,
923 : uint32_t session_id_size,
924 : Time new_expiry_time) = 0;
925 :
926 : // Called by the CDM when session |session_id| is closed. Size
927 : // parameter should not include null termination.
928 : virtual void OnSessionClosed(const char* session_id,
929 : uint32_t session_id_size) = 0;
930 :
931 : // Called by the CDM when an error occurs in session |session_id|
932 : // unrelated to one of the ContentDecryptionModule calls that accept a
933 : // |promise_id|. |error| must be specified, |error_message| and
934 : // |system_code| are optional. Length parameters should not include null
935 : // termination.
936 : // Note:
937 : // - This method is only for supporting prefixed EME API.
938 : // - This method will be ignored by unprefixed EME. All errors reported
939 : // in this method should probably also be reported by one of other methods.
940 : virtual void OnLegacySessionError(
941 : const char* session_id, uint32_t session_id_length,
942 : Error error,
943 : uint32_t system_code,
944 : const char* error_message, uint32_t error_message_length) = 0;
945 :
946 : // The following are optional methods that may not be implemented on all
947 : // platforms.
948 :
949 : // Sends a platform challenge for the given |service_id|. |challenge| is at
950 : // most 256 bits of data to be signed. Once the challenge has been completed,
951 : // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
952 : // with the signed challenge response and platform certificate. Size
953 : // parameters should not include null termination.
954 : virtual void SendPlatformChallenge(const char* service_id,
955 : uint32_t service_id_size,
956 : const char* challenge,
957 : uint32_t challenge_size) = 0;
958 :
959 : // Attempts to enable output protection (e.g. HDCP) on the display link. The
960 : // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
961 : // status callback is issued, the CDM must call QueryOutputProtectionStatus()
962 : // periodically to ensure the desired protections are applied.
963 : virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
964 :
965 : // Requests the current output protection status. Once the host has the status
966 : // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
967 : virtual void QueryOutputProtectionStatus() = 0;
968 :
969 : // Must be called by the CDM if it returned kDeferredInitialization during
970 : // InitializeAudioDecoder() or InitializeVideoDecoder().
971 : virtual void OnDeferredInitializationDone(StreamType stream_type,
972 : Status decoder_status) = 0;
973 :
974 : // Creates a FileIO object from the host to do file IO operation. Returns NULL
975 : // if a FileIO object cannot be obtained. Once a valid FileIO object is
976 : // returned, |client| must be valid until FileIO::Close() is called. The
977 : // CDM can call this method multiple times to operate on different files.
978 : virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
979 :
980 : protected:
981 : Host_7() {}
982 : virtual ~Host_7() {}
983 : };
984 :
985 : class Host_8 {
986 : public:
987 : static const int kVersion = 8;
988 :
989 : // Returns a Buffer* containing non-zero members upon success, or NULL on
990 : // failure. The caller owns the Buffer* after this call. The buffer is not
991 : // guaranteed to be zero initialized. The capacity of the allocated Buffer
992 : // is guaranteed to be not less than |capacity|.
993 : virtual Buffer* Allocate(uint32_t capacity) = 0;
994 :
995 : // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
996 : // from now with |context|.
997 : virtual void SetTimer(int64_t delay_ms, void* context) = 0;
998 :
999 : // Returns the current wall time in seconds.
1000 : virtual Time GetCurrentWallTime() = 0;
1001 :
1002 : // Called by the CDM when a session is created or loaded and the value for the
1003 : // MediaKeySession's sessionId attribute is available (|session_id|).
1004 : // This must be called before OnSessionMessage() or
1005 : // OnSessionKeysChange() is called for the same session. |session_id_size|
1006 : // should not include null termination.
1007 : // When called in response to LoadSession(), the |session_id| must be the
1008 : // same as the |session_id| passed in LoadSession(), or NULL if the
1009 : // session could not be loaded.
1010 : virtual void OnResolveNewSessionPromise(uint32_t promise_id,
1011 : const char* session_id,
1012 : uint32_t session_id_size) = 0;
1013 :
1014 : // Called by the CDM when a session is updated or released.
1015 : virtual void OnResolvePromise(uint32_t promise_id) = 0;
1016 :
1017 : // Called by the CDM when an error occurs as a result of one of the
1018 : // ContentDecryptionModule calls that accept a |promise_id|.
1019 : // |error| must be specified, |error_message| and |system_code|
1020 : // are optional. |error_message_size| should not include null termination.
1021 : virtual void OnRejectPromise(uint32_t promise_id,
1022 : Error error,
1023 : uint32_t system_code,
1024 : const char* error_message,
1025 : uint32_t error_message_size) = 0;
1026 :
1027 : // Called by the CDM when it has a message for session |session_id|.
1028 : // Size parameters should not include null termination.
1029 : // |legacy_destination_url| is only for supporting the prefixed EME API and
1030 : // is ignored by unprefixed EME. It should only be non-null if |message_type|
1031 : // is kLicenseRenewal.
1032 : virtual void OnSessionMessage(const char* session_id,
1033 : uint32_t session_id_size,
1034 : MessageType message_type,
1035 : const char* message,
1036 : uint32_t message_size,
1037 : const char* legacy_destination_url,
1038 : uint32_t legacy_destination_url_length) = 0;
1039 :
1040 : // Called by the CDM when there has been a change in keys or their status for
1041 : // session |session_id|. |has_additional_usable_key| should be set if a
1042 : // key is newly usable (e.g. new key available, previously expired key has
1043 : // been renewed, etc.) and the browser should attempt to resume playback.
1044 : // |key_ids| is the list of key ids for this session along with their
1045 : // current status. |key_ids_count| is the number of entries in |key_ids|.
1046 : // Size parameter for |session_id| should not include null termination.
1047 : virtual void OnSessionKeysChange(const char* session_id,
1048 : uint32_t session_id_size,
1049 : bool has_additional_usable_key,
1050 : const KeyInformation* keys_info,
1051 : uint32_t keys_info_count) = 0;
1052 :
1053 : // Called by the CDM when there has been a change in the expiration time for
1054 : // session |session_id|. This can happen as the result of an Update() call
1055 : // or some other event. If this happens as a result of a call to Update(),
1056 : // it must be called before resolving the Update() promise. |new_expiry_time|
1057 : // can be 0 to represent "undefined". Size parameter should not include
1058 : // null termination.
1059 : virtual void OnExpirationChange(const char* session_id,
1060 : uint32_t session_id_size,
1061 : Time new_expiry_time) = 0;
1062 :
1063 : // Called by the CDM when session |session_id| is closed. Size
1064 : // parameter should not include null termination.
1065 : virtual void OnSessionClosed(const char* session_id,
1066 : uint32_t session_id_size) = 0;
1067 :
1068 : // Called by the CDM when an error occurs in session |session_id|
1069 : // unrelated to one of the ContentDecryptionModule calls that accept a
1070 : // |promise_id|. |error| must be specified, |error_message| and
1071 : // |system_code| are optional. Length parameters should not include null
1072 : // termination.
1073 : // Note:
1074 : // - This method is only for supporting prefixed EME API.
1075 : // - This method will be ignored by unprefixed EME. All errors reported
1076 : // in this method should probably also be reported by one of other methods.
1077 : virtual void OnLegacySessionError(
1078 : const char* session_id, uint32_t session_id_length,
1079 : Error error,
1080 : uint32_t system_code,
1081 : const char* error_message, uint32_t error_message_length) = 0;
1082 :
1083 : // The following are optional methods that may not be implemented on all
1084 : // platforms.
1085 :
1086 : // Sends a platform challenge for the given |service_id|. |challenge| is at
1087 : // most 256 bits of data to be signed. Once the challenge has been completed,
1088 : // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1089 : // with the signed challenge response and platform certificate. Size
1090 : // parameters should not include null termination.
1091 : virtual void SendPlatformChallenge(const char* service_id,
1092 : uint32_t service_id_size,
1093 : const char* challenge,
1094 : uint32_t challenge_size) = 0;
1095 :
1096 : // Attempts to enable output protection (e.g. HDCP) on the display link. The
1097 : // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1098 : // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1099 : // periodically to ensure the desired protections are applied.
1100 : virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1101 :
1102 : // Requests the current output protection status. Once the host has the status
1103 : // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1104 : virtual void QueryOutputProtectionStatus() = 0;
1105 :
1106 : // Must be called by the CDM if it returned kDeferredInitialization during
1107 : // InitializeAudioDecoder() or InitializeVideoDecoder().
1108 : virtual void OnDeferredInitializationDone(StreamType stream_type,
1109 : Status decoder_status) = 0;
1110 :
1111 : // Creates a FileIO object from the host to do file IO operation. Returns NULL
1112 : // if a FileIO object cannot be obtained. Once a valid FileIO object is
1113 : // returned, |client| must be valid until FileIO::Close() is called. The
1114 : // CDM can call this method multiple times to operate on different files.
1115 : virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1116 :
1117 : protected:
1118 0 : Host_8() {}
1119 0 : virtual ~Host_8() {}
1120 : };
1121 :
1122 : // Represents a decrypted block that has not been decoded.
1123 : class DecryptedBlock {
1124 : public:
1125 : virtual void SetDecryptedBuffer(Buffer* buffer) = 0;
1126 : virtual Buffer* DecryptedBuffer() = 0;
1127 :
1128 : // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not,
1129 : // we can just pass Buffer pointers around.
1130 : virtual void SetTimestamp(int64_t timestamp) = 0;
1131 : virtual int64_t Timestamp() const = 0;
1132 :
1133 : protected:
1134 0 : DecryptedBlock() {}
1135 0 : virtual ~DecryptedBlock() {}
1136 : };
1137 :
1138 : class VideoFrame {
1139 : public:
1140 : enum VideoPlane {
1141 : kYPlane = 0,
1142 : kUPlane = 1,
1143 : kVPlane = 2,
1144 : kMaxPlanes = 3,
1145 : };
1146 :
1147 : virtual void SetFormat(VideoFormat format) = 0;
1148 : virtual VideoFormat Format() const = 0;
1149 :
1150 : virtual void SetSize(cdm::Size size) = 0;
1151 : virtual cdm::Size Size() const = 0;
1152 :
1153 : virtual void SetFrameBuffer(Buffer* frame_buffer) = 0;
1154 : virtual Buffer* FrameBuffer() = 0;
1155 :
1156 : virtual void SetPlaneOffset(VideoPlane plane, uint32_t offset) = 0;
1157 : virtual uint32_t PlaneOffset(VideoPlane plane) = 0;
1158 :
1159 : virtual void SetStride(VideoPlane plane, uint32_t stride) = 0;
1160 : virtual uint32_t Stride(VideoPlane plane) = 0;
1161 :
1162 : virtual void SetTimestamp(int64_t timestamp) = 0;
1163 : virtual int64_t Timestamp() const = 0;
1164 :
1165 : protected:
1166 0 : VideoFrame() {}
1167 0 : virtual ~VideoFrame() {}
1168 : };
1169 :
1170 : // Represents decrypted and decoded audio frames. AudioFrames can contain
1171 : // multiple audio output buffers, which are serialized into this format:
1172 : //
1173 : // |<------------------- serialized audio buffer ------------------->|
1174 : // | int64_t timestamp | int64_t length | length bytes of audio data |
1175 : //
1176 : // For example, with three audio output buffers, the AudioFrames will look
1177 : // like this:
1178 : //
1179 : // |<----------------- AudioFrames ------------------>|
1180 : // | audio buffer 0 | audio buffer 1 | audio buffer 2 |
1181 : class AudioFrames {
1182 : public:
1183 : virtual void SetFrameBuffer(Buffer* buffer) = 0;
1184 : virtual Buffer* FrameBuffer() = 0;
1185 :
1186 : // The CDM must call this method, providing a valid format, when providing
1187 : // frame buffers. Planar data should be stored end to end; e.g.,
1188 : // |ch1 sample1||ch1 sample2|....|ch1 sample_last||ch2 sample1|...
1189 : virtual void SetFormat(AudioFormat format) = 0;
1190 : virtual AudioFormat Format() const = 0;
1191 :
1192 : protected:
1193 : AudioFrames() {}
1194 : virtual ~AudioFrames() {}
1195 : };
1196 :
1197 : } // namespace cdm
1198 :
1199 : #endif // CDM_CONTENT_DECRYPTION_MODULE_H_
|