Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/content_decryption_module.h
Line
Count
Source (jump to first uncovered line)
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
#include <type_traits>
9
10
#include "content_decryption_module_export.h"
11
#include "content_decryption_module_proxy.h"
12
13
#if defined(_MSC_VER)
14
typedef unsigned char uint8_t;
15
typedef unsigned int uint32_t;
16
typedef int int32_t;
17
typedef __int64 int64_t;
18
#else
19
#include <stdint.h>
20
#endif
21
22
// The version number must be rolled when the exported functions are updated!
23
// If the CDM and the adapter use different versions of these functions, the
24
// adapter will fail to load or crash!
25
0
#define CDM_MODULE_VERSION 4
26
27
// Build the versioned entrypoint name.
28
// The extra macros are necessary to expand version to an actual value.
29
#define INITIALIZE_CDM_MODULE \
30
  BUILD_ENTRYPOINT(InitializeCdmModule, CDM_MODULE_VERSION)
31
#define BUILD_ENTRYPOINT(name, version) \
32
  BUILD_ENTRYPOINT_NO_EXPANSION(name, version)
33
#define BUILD_ENTRYPOINT_NO_EXPANSION(name, version) name##_##version
34
35
// Macro to check that |type| does the following:
36
// 1. is a standard layout.
37
// 2. is trivial.
38
// 3. sizeof(type) matches the expected size in bytes. As some types contain
39
//    pointers, the size is specified for both 32 and 64 bit.
40
#define CHECK_TYPE(type, size_32, size_64)                           \
41
  static_assert(std::is_standard_layout<type>(),                     \
42
                #type " not standard_layout");                       \
43
  static_assert(std::is_trivial<type>(), #type " not trivial");      \
44
  static_assert((sizeof(void*) == 4 && sizeof(type) == size_32) ||   \
45
                    (sizeof(void*) == 8 && sizeof(type) == size_64), \
46
                #type " size mismatch")
47
48
extern "C" {
49
50
CDM_API void INITIALIZE_CDM_MODULE();
51
52
CDM_API void DeinitializeCdmModule();
53
54
// Returns a pointer to the requested CDM Host interface upon success.
55
// Returns NULL if the requested CDM Host interface is not supported.
56
// The caller should cast the returned pointer to the type matching
57
// |host_interface_version|.
58
typedef void* (*GetCdmHostFunc)(int host_interface_version, void* user_data);
59
60
// Returns a pointer to the requested CDM upon success.
61
// Returns NULL if an error occurs or the requested |cdm_interface_version| or
62
// |key_system| is not supported or another error occurs.
63
// The caller should cast the returned pointer to the type matching
64
// |cdm_interface_version|.
65
// Caller retains ownership of arguments and must call Destroy() on the returned
66
// object.
67
CDM_API void* CreateCdmInstance(int cdm_interface_version,
68
                                const char* key_system,
69
                                uint32_t key_system_size,
70
                                GetCdmHostFunc get_cdm_host_func,
71
                                void* user_data);
72
73
CDM_API const char* GetCdmVersion();
74
75
}  // extern "C"
76
77
namespace cdm {
78
79
enum Status : uint32_t {
80
  kSuccess = 0,
81
  kNeedMoreData,  // Decoder needs more data to produce a decoded frame/sample.
82
  kNoKey,         // The required decryption key is not available.
83
  kInitializationError,    // Initialization error.
84
  kDecryptError,           // Decryption failed.
85
  kDecodeError,            // Error decoding audio or video.
86
  kDeferredInitialization  // Decoder is not ready for initialization.
87
};
88
CHECK_TYPE(Status, 4, 4);
89
90
// Exceptions used by the CDM to reject promises.
91
// https://w3c.github.io/encrypted-media/#exceptions
92
enum Exception : uint32_t {
93
  kExceptionTypeError,
94
  kExceptionNotSupportedError,
95
  kExceptionInvalidStateError,
96
  kExceptionQuotaExceededError
97
};
98
CHECK_TYPE(Exception, 4, 4);
99
100
// The encryption scheme. The definitions are from ISO/IEC 23001-7:2016.
101
enum class EncryptionScheme : uint32_t {
102
  kUnencrypted = 0,
103
  kCenc,  // 'cenc' subsample encryption using AES-CTR mode.
104
  kCbcs   // 'cbcs' pattern encryption using AES-CBC mode.
105
};
106
CHECK_TYPE(EncryptionScheme, 4, 4);
107
108
// The pattern used for pattern encryption. Note that ISO/IEC 23001-7:2016
109
// defines each block to be 16-bytes.
110
struct Pattern {
111
  uint32_t crypt_byte_block;  // Count of the encrypted blocks.
112
  uint32_t skip_byte_block;   // Count of the unencrypted blocks.
113
};
114
CHECK_TYPE(Pattern, 8, 8);
115
116
// Time is defined as the number of seconds since the Epoch
117
// (00:00:00 UTC, January 1, 1970), not including any added leap second.
118
// Also see Time definition in spec: https://w3c.github.io/encrypted-media/#time
119
// Note that Time is defined in millisecond accuracy in the spec but in second
120
// accuracy here.
121
typedef double Time;
122
123
// An input buffer can be split into several continuous subsamples.
124
// A SubsampleEntry specifies the number of clear and cipher bytes in each
125
// subsample. For example, the following buffer has three subsamples:
126
//
127
// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
128
// |   clear1   |  cipher1  |  clear2  |   cipher2   | clear3 |    cipher3    |
129
//
130
// For decryption, all of the cipher bytes in a buffer should be concatenated
131
// (in the subsample order) into a single logical stream. The clear bytes should
132
// not be considered as part of decryption.
133
//
134
// Stream to decrypt:   |  cipher1  |   cipher2   |    cipher3    |
135
// Decrypted stream:    | decrypted1|  decrypted2 |   decrypted3  |
136
//
137
// After decryption, the decrypted bytes should be copied over the position
138
// of the corresponding cipher bytes in the original buffer to form the output
139
// buffer. Following the above example, the decrypted buffer should be:
140
//
141
// |<----- subsample1 ----->|<----- subsample2 ----->|<----- subsample3 ----->|
142
// |   clear1   | decrypted1|  clear2  |  decrypted2 | clear3 |   decrypted3  |
143
//
144
struct SubsampleEntry {
145
  uint32_t clear_bytes;
146
  uint32_t cipher_bytes;
147
};
148
CHECK_TYPE(SubsampleEntry, 8, 8);
149
150
// Represents an input buffer to be decrypted (and possibly decoded). It does
151
// not own any pointers in this struct. If |iv_size| = 0, the data is
152
// unencrypted.
153
// Deprecated: New CDM implementations should use InputBuffer_2.
154
struct InputBuffer_1 {
155
  const uint8_t* data;  // Pointer to the beginning of the input data.
156
  uint32_t data_size;   // Size (in bytes) of |data|.
157
158
  const uint8_t* key_id;  // Key ID to identify the decryption key.
159
  uint32_t key_id_size;   // Size (in bytes) of |key_id|.
160
161
  const uint8_t* iv;  // Initialization vector.
162
  uint32_t iv_size;   // Size (in bytes) of |iv|.
163
164
  const struct SubsampleEntry* subsamples;
165
  uint32_t num_subsamples;  // Number of subsamples in |subsamples|.
166
167
  int64_t timestamp;  // Presentation timestamp in microseconds.
168
};
169
CHECK_TYPE(InputBuffer_1, 40, 72);
170
171
// Represents an input buffer to be decrypted (and possibly decoded). It does
172
// not own any pointers in this struct. If |encryption_scheme| = kUnencrypted,
173
// the data is unencrypted.
174
// Note that this struct is organized so that sizeof(InputBuffer_2)
175
// equals the sum of sizeof() all members in both 32-bit and 64-bit compiles.
176
// Padding has been added to keep the fields aligned.
177
struct InputBuffer_2 {
178
  const uint8_t* data;  // Pointer to the beginning of the input data.
179
  uint32_t data_size;   // Size (in bytes) of |data|.
180
181
  EncryptionScheme encryption_scheme;
182
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|.
185
  uint32_t : 32;          // Padding.
186
187
  const uint8_t* iv;  // Initialization vector.
188
  uint32_t iv_size;   // Size (in bytes) of |iv|.
189
  uint32_t : 32;      // Padding.
190
191
  const struct SubsampleEntry* subsamples;
192
  uint32_t num_subsamples;  // Number of subsamples in |subsamples|.
193
  uint32_t : 32;            // Padding.
194
195
  // |pattern| is required if |encryption_scheme| specifies pattern encryption.
196
  Pattern pattern;
197
198
  int64_t timestamp;  // Presentation timestamp in microseconds.
199
};
200
CHECK_TYPE(InputBuffer_2, 64, 80);
201
202
enum AudioCodec : uint32_t { kUnknownAudioCodec = 0, kCodecVorbis, kCodecAac };
203
CHECK_TYPE(AudioCodec, 4, 4);
204
205
// Deprecated: New CDM implementations should use AudioDecoderConfig_2.
206
struct AudioDecoderConfig_1 {
207
  AudioCodec codec;
208
  int32_t channel_count;
209
  int32_t bits_per_channel;
210
  int32_t samples_per_second;
211
212
  // Optional byte data required to initialize audio decoders, such as the
213
  // vorbis setup header.
214
  uint8_t* extra_data;
215
  uint32_t extra_data_size;
216
};
217
CHECK_TYPE(AudioDecoderConfig_1, 24, 32);
218
219
struct AudioDecoderConfig_2 {
220
  AudioCodec codec;
221
  int32_t channel_count;
222
  int32_t bits_per_channel;
223
  int32_t samples_per_second;
224
225
  // Optional byte data required to initialize audio decoders, such as the
226
  // vorbis setup header.
227
  uint8_t* extra_data;
228
  uint32_t extra_data_size;
229
230
  // Encryption scheme.
231
  EncryptionScheme encryption_scheme;
232
};
233
CHECK_TYPE(AudioDecoderConfig_2, 28, 32);
234
235
// Supported sample formats for AudioFrames.
236
enum AudioFormat : uint32_t {
237
  kUnknownAudioFormat = 0,  // Unknown format value. Used for error reporting.
238
  kAudioFormatU8,           // Interleaved unsigned 8-bit w/ bias of 128.
239
  kAudioFormatS16,          // Interleaved signed 16-bit.
240
  kAudioFormatS32,          // Interleaved signed 32-bit.
241
  kAudioFormatF32,          // Interleaved float 32-bit.
242
  kAudioFormatPlanarS16,    // Signed 16-bit planar.
243
  kAudioFormatPlanarF32,    // Float 32-bit planar.
244
};
245
CHECK_TYPE(AudioFormat, 4, 4);
246
247
// Surface formats based on FOURCC labels, see: http://www.fourcc.org/yuv.php
248
// Values are chosen to be consistent with Chromium's VideoPixelFormat values.
249
enum VideoFormat : uint32_t {
250
  kUnknownVideoFormat = 0,  // Unknown format value. Used for error reporting.
251
  kYv12 = 1,                // 12bpp YVU planar 1x1 Y, 2x2 VU samples.
252
  kI420 = 2,                // 12bpp YUV planar 1x1 Y, 2x2 UV samples.
253
254
  // In the following formats, each sample uses 16-bit in storage, while the
255
  // sample value is stored in the least significant N bits where N is
256
  // specified by the number after "P". For example, for YUV420P9, each Y, U,
257
  // and V sample is stored in the least significant 9 bits in a 2-byte block.
258
  kYUV420P9 = 16,
259
  kYUV420P10 = 17,
260
  kYUV422P9 = 18,
261
  kYUV422P10 = 19,
262
  kYUV444P9 = 20,
263
  kYUV444P10 = 21,
264
  kYUV420P12 = 22,
265
  kYUV422P12 = 23,
266
  kYUV444P12 = 24,
267
};
268
CHECK_TYPE(VideoFormat, 4, 4);
269
270
struct Size {
271
  int32_t width;
272
  int32_t height;
273
};
274
CHECK_TYPE(Size, 8, 8);
275
276
enum VideoCodec : uint32_t {
277
  kUnknownVideoCodec = 0,
278
  kCodecVp8,
279
  kCodecH264,
280
  kCodecVp9
281
};
282
CHECK_TYPE(VideoCodec, 4, 4);
283
284
enum VideoCodecProfile : uint32_t {
285
  kUnknownVideoCodecProfile = 0,
286
  kProfileNotNeeded,
287
  kH264ProfileBaseline,
288
  kH264ProfileMain,
289
  kH264ProfileExtended,
290
  kH264ProfileHigh,
291
  kH264ProfileHigh10,
292
  kH264ProfileHigh422,
293
  kH264ProfileHigh444Predictive,
294
  // VP9 Profiles are only passed in starting from CDM_9.
295
  kVP9Profile0,
296
  kVP9Profile1,
297
  kVP9Profile2,
298
  kVP9Profile3
299
};
300
CHECK_TYPE(VideoCodecProfile, 4, 4);
301
302
// Deprecated: New CDM implementations should use VideoDecoderConfig_2.
303
struct VideoDecoderConfig_1 {
304
  VideoCodec codec;
305
  VideoCodecProfile profile;
306
  VideoFormat format;
307
308
  // Width and height of video frame immediately post-decode. Not all pixels
309
  // in this region are valid.
310
  Size coded_size;
311
312
  // Optional byte data required to initialize video decoders, such as H.264
313
  // AAVC data.
314
  uint8_t* extra_data;
315
  uint32_t extra_data_size;
316
};
317
CHECK_TYPE(VideoDecoderConfig_1, 28, 40);
318
319
// Note that this struct is organized so that sizeof(VideoDecoderConfig_2)
320
// equals the sum of sizeof() all members in both 32-bit and 64-bit compiles.
321
// Padding has been added to keep the fields aligned.
322
struct VideoDecoderConfig_2 {
323
  VideoCodec codec;
324
  VideoCodecProfile profile;
325
  VideoFormat format;
326
  uint32_t : 32;  // Padding.
327
328
  // Width and height of video frame immediately post-decode. Not all pixels
329
  // in this region are valid.
330
  Size coded_size;
331
332
  // Optional byte data required to initialize video decoders, such as H.264
333
  // AAVC data.
334
  uint8_t* extra_data;
335
  uint32_t extra_data_size;
336
337
  // Encryption scheme.
338
  EncryptionScheme encryption_scheme;
339
};
340
CHECK_TYPE(VideoDecoderConfig_2, 36, 40);
341
342
enum StreamType : uint32_t { kStreamTypeAudio = 0, kStreamTypeVideo = 1 };
343
CHECK_TYPE(StreamType, 4, 4);
344
345
// Structure provided to ContentDecryptionModule::OnPlatformChallengeResponse()
346
// after a platform challenge was initiated via Host::SendPlatformChallenge().
347
// All values will be NULL / zero in the event of a challenge failure.
348
struct PlatformChallengeResponse {
349
  // |challenge| provided during Host::SendPlatformChallenge() combined with
350
  // nonce data and signed with the platform's private key.
351
  const uint8_t* signed_data;
352
  uint32_t signed_data_length;
353
354
  // RSASSA-PKCS1-v1_5-SHA256 signature of the |signed_data| block.
355
  const uint8_t* signed_data_signature;
356
  uint32_t signed_data_signature_length;
357
358
  // X.509 device specific certificate for the |service_id| requested.
359
  const uint8_t* platform_key_certificate;
360
  uint32_t platform_key_certificate_length;
361
};
362
CHECK_TYPE(PlatformChallengeResponse, 24, 48);
363
364
// The current status of the associated key. The valid types are defined in the
365
// spec: https://w3c.github.io/encrypted-media/#idl-def-MediaKeyStatus
366
enum KeyStatus : uint32_t {
367
  kUsable = 0,
368
  kInternalError = 1,
369
  kExpired = 2,
370
  kOutputRestricted = 3,
371
  kOutputDownscaled = 4,
372
  kStatusPending = 5,
373
  kReleased = 6
374
};
375
CHECK_TYPE(KeyStatus, 4, 4);
376
377
// Used when passing arrays of key information. Does not own the referenced
378
// data. |system_code| is an additional error code for unusable keys and
379
// should be 0 when |status| == kUsable.
380
struct KeyInformation {
381
  const uint8_t* key_id;
382
  uint32_t key_id_size;
383
  KeyStatus status;
384
  uint32_t system_code;
385
};
386
CHECK_TYPE(KeyInformation, 16, 24);
387
388
// Supported output protection methods for use with EnableOutputProtection() and
389
// returned by OnQueryOutputProtectionStatus().
390
enum OutputProtectionMethods : uint32_t {
391
  kProtectionNone = 0,
392
  kProtectionHDCP = 1 << 0
393
};
394
CHECK_TYPE(OutputProtectionMethods, 4, 4);
395
396
// Connected output link types returned by OnQueryOutputProtectionStatus().
397
enum OutputLinkTypes : uint32_t {
398
  kLinkTypeNone = 0,
399
  kLinkTypeUnknown = 1 << 0,
400
  kLinkTypeInternal = 1 << 1,
401
  kLinkTypeVGA = 1 << 2,
402
  kLinkTypeHDMI = 1 << 3,
403
  kLinkTypeDVI = 1 << 4,
404
  kLinkTypeDisplayPort = 1 << 5,
405
  kLinkTypeNetwork = 1 << 6
406
};
407
CHECK_TYPE(OutputLinkTypes, 4, 4);
408
409
// Result of the QueryOutputProtectionStatus() call.
410
enum QueryResult : uint32_t { kQuerySucceeded = 0, kQueryFailed };
411
CHECK_TYPE(QueryResult, 4, 4);
412
413
// The Initialization Data Type. The valid types are defined in the spec:
414
// https://w3c.github.io/encrypted-media/format-registry/initdata/index.html#registry
415
enum InitDataType : uint32_t { kCenc = 0, kKeyIds = 1, kWebM = 2 };
416
CHECK_TYPE(InitDataType, 4, 4);
417
418
// The type of session to create. The valid types are defined in the spec:
419
// https://w3c.github.io/encrypted-media/#idl-def-SessionType
420
enum SessionType : uint32_t {
421
  kTemporary = 0,
422
  kPersistentLicense = 1,
423
  kPersistentKeyRelease = 2
424
};
425
CHECK_TYPE(SessionType, 4, 4);
426
427
// The type of the message event.  The valid types are defined in the spec:
428
// https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType
429
enum MessageType : uint32_t {
430
  kLicenseRequest = 0,
431
  kLicenseRenewal = 1,
432
  kLicenseRelease = 2,
433
  // Only supported by Host_10 and later. On Host_9 and earlier, it's undefined
434
  // behavior. For example, the host can drop the message or send it using
435
  // other message type.
436
  kIndividualizationRequest = 3
437
};
438
CHECK_TYPE(MessageType, 4, 4);
439
440
enum HdcpVersion : uint32_t {
441
  kHdcpVersionNone,
442
  kHdcpVersion1_0,
443
  kHdcpVersion1_1,
444
  kHdcpVersion1_2,
445
  kHdcpVersion1_3,
446
  kHdcpVersion1_4,
447
  kHdcpVersion2_0,
448
  kHdcpVersion2_1,
449
  kHdcpVersion2_2
450
};
451
CHECK_TYPE(HdcpVersion, 4, 4);
452
453
struct Policy {
454
  HdcpVersion min_hdcp_version;
455
};
456
CHECK_TYPE(Policy, 4, 4);
457
458
// Represents a buffer created by Allocator implementations.
459
class CDM_CLASS_API Buffer {
460
 public:
461
  // Destroys the buffer in the same context as it was created.
462
  virtual void Destroy() = 0;
463
464
  virtual uint32_t Capacity() const = 0;
465
  virtual uint8_t* Data() = 0;
466
  virtual void SetSize(uint32_t size) = 0;
467
  virtual uint32_t Size() const = 0;
468
469
 protected:
470
0
  Buffer() {}
471
0
  virtual ~Buffer() {}
472
473
 private:
474
  Buffer(const Buffer&);
475
  void operator=(const Buffer&);
476
};
477
478
// Represents a decrypted block that has not been decoded.
479
class CDM_CLASS_API DecryptedBlock {
480
 public:
481
  virtual void SetDecryptedBuffer(Buffer* buffer) = 0;
482
  virtual Buffer* DecryptedBuffer() = 0;
483
484
  // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not,
485
  // we can just pass Buffer pointers around.
486
  virtual void SetTimestamp(int64_t timestamp) = 0;
487
  virtual int64_t Timestamp() const = 0;
488
489
 protected:
490
  DecryptedBlock() {}
491
  virtual ~DecryptedBlock() {}
492
};
493
494
class CDM_CLASS_API VideoFrame {
495
 public:
496
  enum VideoPlane : uint32_t {
497
    kYPlane = 0,
498
    kUPlane = 1,
499
    kVPlane = 2,
500
    kMaxPlanes = 3,
501
  };
502
503
  virtual void SetFormat(VideoFormat format) = 0;
504
  virtual VideoFormat Format() const = 0;
505
506
  virtual void SetSize(cdm::Size size) = 0;
507
  virtual cdm::Size Size() const = 0;
508
509
  virtual void SetFrameBuffer(Buffer* frame_buffer) = 0;
510
  virtual Buffer* FrameBuffer() = 0;
511
512
  virtual void SetPlaneOffset(VideoPlane plane, uint32_t offset) = 0;
513
  virtual uint32_t PlaneOffset(VideoPlane plane) = 0;
514
515
  virtual void SetStride(VideoPlane plane, uint32_t stride) = 0;
516
  virtual uint32_t Stride(VideoPlane plane) = 0;
517
518
  virtual void SetTimestamp(int64_t timestamp) = 0;
519
  virtual int64_t Timestamp() const = 0;
520
521
 protected:
522
  VideoFrame() {}
523
  virtual ~VideoFrame() {}
524
};
525
526
// Represents decrypted and decoded audio frames. AudioFrames can contain
527
// multiple audio output buffers, which are serialized into this format:
528
//
529
// |<------------------- serialized audio buffer ------------------->|
530
// | int64_t timestamp | int64_t length | length bytes of audio data |
531
//
532
// For example, with three audio output buffers, the AudioFrames will look
533
// like this:
534
//
535
// |<----------------- AudioFrames ------------------>|
536
// | audio buffer 0 | audio buffer 1 | audio buffer 2 |
537
class CDM_CLASS_API AudioFrames {
538
 public:
539
  virtual void SetFrameBuffer(Buffer* buffer) = 0;
540
  virtual Buffer* FrameBuffer() = 0;
541
542
  // The CDM must call this method, providing a valid format, when providing
543
  // frame buffers. Planar data should be stored end to end; e.g.,
544
  // |ch1 sample1||ch1 sample2|....|ch1 sample_last||ch2 sample1|...
545
  virtual void SetFormat(AudioFormat format) = 0;
546
  virtual AudioFormat Format() const = 0;
547
548
 protected:
549
0
  AudioFrames() {}
550
0
  virtual ~AudioFrames() {}
551
};
552
553
// FileIO interface provides a way for the CDM to store data in a file in
554
// persistent storage. This interface aims only at providing basic read/write
555
// capabilities and should not be used as a full fledged file IO API.
556
// Each CDM and origin (e.g. HTTPS, "foo.example.com", 443) combination has
557
// its own persistent storage. All instances of a given CDM associated with a
558
// given origin share the same persistent storage.
559
// Note to implementors of this interface:
560
// Per-origin storage and the ability for users to clear it are important.
561
// See http://www.w3.org/TR/encrypted-media/#privacy-storedinfo.
562
class CDM_CLASS_API FileIO {
563
 public:
564
  // Opens the file with |file_name| for read and write.
565
  // FileIOClient::OnOpenComplete() will be called after the opening
566
  // operation finishes.
567
  // - When the file is opened by a CDM instance, it will be classified as "in
568
  //   use". In this case other CDM instances in the same domain may receive
569
  //   kInUse status when trying to open it.
570
  // - |file_name| must only contain letters (A-Za-z), digits(0-9), or "._-".
571
  //   It must not start with an underscore ('_'), and must be at least 1
572
  //   character and no more than 256 characters long.
573
  virtual void Open(const char* file_name, uint32_t file_name_size) = 0;
574
575
  // Reads the contents of the file. FileIOClient::OnReadComplete() will be
576
  // called with the read status. Read() should not be called if a previous
577
  // Read() or Write() call is still pending; otherwise OnReadComplete() will
578
  // be called with kInUse.
579
  virtual void Read() = 0;
580
581
  // Writes |data_size| bytes of |data| into the file.
582
  // FileIOClient::OnWriteComplete() will be called with the write status.
583
  // All existing contents in the file will be overwritten. Calling Write() with
584
  // NULL |data| will clear all contents in the file. Write() should not be
585
  // called if a previous Write() or Read() call is still pending; otherwise
586
  // OnWriteComplete() will be called with kInUse.
587
  virtual void Write(const uint8_t* data, uint32_t data_size) = 0;
588
589
  // Closes the file if opened, destroys this FileIO object and releases any
590
  // resources allocated. The CDM must call this method when it finished using
591
  // this object. A FileIO object must not be used after Close() is called.
592
  virtual void Close() = 0;
593
594
 protected:
595
0
  FileIO() {}
596
0
  virtual ~FileIO() {}
597
};
598
599
// Responses to FileIO calls. All responses will be called asynchronously.
600
// When kError is returned, the FileIO object could be in an error state. All
601
// following calls (other than Close()) could return kError. The CDM should
602
// still call Close() to destroy the FileIO object.
603
class CDM_CLASS_API FileIOClient {
604
 public:
605
  enum Status : uint32_t { kSuccess = 0, kInUse, kError };
606
607
  // Response to a FileIO::Open() call with the open |status|.
608
  virtual void OnOpenComplete(Status status) = 0;
609
610
  // Response to a FileIO::Read() call to provide |data_size| bytes of |data|
611
  // read from the file.
612
  // - kSuccess indicates that all contents of the file has been successfully
613
  //   read. In this case, 0 |data_size| means that the file is empty.
614
  // - kInUse indicates that there are other read/write operations pending.
615
  // - kError indicates read failure, e.g. the storage is not open or cannot be
616
  //   fully read.
617
  virtual void OnReadComplete(Status status,
618
                              const uint8_t* data,
619
                              uint32_t data_size) = 0;
620
621
  // Response to a FileIO::Write() call.
622
  // - kSuccess indicates that all the data has been written into the file
623
  //   successfully.
624
  // - kInUse indicates that there are other read/write operations pending.
625
  // - kError indicates write failure, e.g. the storage is not open or cannot be
626
  //   fully written. Upon write failure, the contents of the file should be
627
  //   regarded as corrupt and should not used.
628
  virtual void OnWriteComplete(Status status) = 0;
629
630
 protected:
631
0
  FileIOClient() {}
632
0
  virtual ~FileIOClient() {}
633
};
634
635
class CDM_CLASS_API Host_9;
636
class CDM_CLASS_API Host_10;
637
class CDM_CLASS_API Host_11;
638
639
// ContentDecryptionModule interface that all CDMs need to implement.
640
// The interface is versioned for backward compatibility.
641
// Note: ContentDecryptionModule implementations must use the allocator
642
// provided in CreateCdmInstance() to allocate any Buffer that needs to
643
// be passed back to the caller. Implementations must call Buffer::Destroy()
644
// when a Buffer is created that will never be returned to the caller.
645
class CDM_CLASS_API ContentDecryptionModule_9 {
646
 public:
647
  static const int kVersion = 9;
648
  typedef Host_9 Host;
649
650
  // Initializes the CDM instance, providing information about permitted
651
  // functionalities.
652
  // If |allow_distinctive_identifier| is false, messages from the CDM,
653
  // such as message events, must not contain a Distinctive Identifier,
654
  // even in an encrypted form.
655
  // If |allow_persistent_state| is false, the CDM must not attempt to
656
  // persist state. Calls to CreateFileIO() will fail.
657
  virtual void Initialize(bool allow_distinctive_identifier,
658
                          bool allow_persistent_state) = 0;
659
660
  // Gets the key status if the CDM has a hypothetical key with the |policy|.
661
  // The CDM must respond by calling either Host::OnResolveKeyStatusPromise()
662
  // with the result key status or Host::OnRejectPromise() if an unexpected
663
  // error happened or this method is not supported.
664
  virtual void GetStatusForPolicy(uint32_t promise_id,
665
                                  const Policy& policy) = 0;
666
667
  // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(),
668
  // UpdateSession(), CloseSession(), and RemoveSession() all accept a
669
  // |promise_id|, which must be passed to the completion Host method
670
  // (e.g. Host::OnResolveNewSessionPromise()).
671
672
  // Provides a server certificate to be used to encrypt messages to the
673
  // license server. The CDM must respond by calling either
674
  // Host::OnResolvePromise() or Host::OnRejectPromise().
675
  virtual void SetServerCertificate(uint32_t promise_id,
676
                                    const uint8_t* server_certificate_data,
677
                                    uint32_t server_certificate_data_size) = 0;
678
679
  // Creates a session given |session_type|, |init_data_type|, and |init_data|.
680
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
681
  // or Host::OnRejectPromise().
682
  virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
683
                                               SessionType session_type,
684
                                               InitDataType init_data_type,
685
                                               const uint8_t* init_data,
686
                                               uint32_t init_data_size) = 0;
687
688
  // Loads the session of type |session_type| specified by |session_id|.
689
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
690
  // or Host::OnRejectPromise(). If the session is not found, call
691
  // Host::OnResolveNewSessionPromise() with session_id = NULL.
692
  virtual void LoadSession(uint32_t promise_id,
693
                           SessionType session_type,
694
                           const char* session_id,
695
                           uint32_t session_id_size) = 0;
696
697
  // Updates the session with |response|. The CDM must respond by calling
698
  // either Host::OnResolvePromise() or Host::OnRejectPromise().
699
  virtual void UpdateSession(uint32_t promise_id,
700
                             const char* session_id,
701
                             uint32_t session_id_size,
702
                             const uint8_t* response,
703
                             uint32_t response_size) = 0;
704
705
  // Requests that the CDM close the session. The CDM must respond by calling
706
  // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
707
  // has been processed. This may be before the session is closed. Once the
708
  // session is closed, Host::OnSessionClosed() must also be called.
709
  virtual void CloseSession(uint32_t promise_id,
710
                            const char* session_id,
711
                            uint32_t session_id_size) = 0;
712
713
  // Removes any stored session data associated with this session. Will only be
714
  // called for persistent sessions. The CDM must respond by calling either
715
  // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
716
  // been processed.
717
  virtual void RemoveSession(uint32_t promise_id,
718
                             const char* session_id,
719
                             uint32_t session_id_size) = 0;
720
721
  // Performs scheduled operation with |context| when the timer fires.
722
  virtual void TimerExpired(void* context) = 0;
723
724
  // Decrypts the |encrypted_buffer|.
725
  //
726
  // Returns kSuccess if decryption succeeded, in which case the callee
727
  // should have filled the |decrypted_buffer| and passed the ownership of
728
  // |data| in |decrypted_buffer| to the caller.
729
  // Returns kNoKey if the CDM did not have the necessary decryption key
730
  // to decrypt.
731
  // Returns kDecryptError if any other error happened.
732
  // If the return value is not kSuccess, |decrypted_buffer| should be ignored
733
  // by the caller.
734
  virtual Status Decrypt(const InputBuffer_1& encrypted_buffer,
735
                         DecryptedBlock* decrypted_buffer) = 0;
736
737
  // Initializes the CDM audio decoder with |audio_decoder_config|. This
738
  // function must be called before DecryptAndDecodeSamples() is called.
739
  //
740
  // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
741
  // audio decoder is successfully initialized.
742
  // Returns kInitializationError if |audio_decoder_config| is not supported.
743
  // The CDM may still be able to do Decrypt().
744
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
745
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
746
  // initialization is complete.
747
  virtual Status InitializeAudioDecoder(
748
      const AudioDecoderConfig_1& audio_decoder_config) = 0;
749
750
  // Initializes the CDM video decoder with |video_decoder_config|. This
751
  // function must be called before DecryptAndDecodeFrame() is called.
752
  //
753
  // Returns kSuccess if the |video_decoder_config| is supported and the CDM
754
  // video decoder is successfully initialized.
755
  // Returns kInitializationError if |video_decoder_config| is not supported.
756
  // The CDM may still be able to do Decrypt().
757
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
758
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
759
  // initialization is complete.
760
  virtual Status InitializeVideoDecoder(
761
      const VideoDecoderConfig_1& video_decoder_config) = 0;
762
763
  // De-initializes the CDM decoder and sets it to an uninitialized state. The
764
  // caller can initialize the decoder again after this call to re-initialize
765
  // it. This can be used to reconfigure the decoder if the configuration
766
  // changes.
767
  virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
768
769
  // Resets the CDM decoder to an initialized clean state. All internal buffers
770
  // MUST be flushed.
771
  virtual void ResetDecoder(StreamType decoder_type) = 0;
772
773
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
774
  // |video_frame|. Upon end-of-stream, the caller should call this function
775
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
776
  // |video_frame| (|format| == kEmptyVideoFrame) is produced.
777
  //
778
  // Returns kSuccess if decryption and decoding both succeeded, in which case
779
  // the callee will have filled the |video_frame| and passed the ownership of
780
  // |frame_buffer| in |video_frame| to the caller.
781
  // Returns kNoKey if the CDM did not have the necessary decryption key
782
  // to decrypt.
783
  // Returns kNeedMoreData if more data was needed by the decoder to generate
784
  // a decoded frame (e.g. during initialization and end-of-stream).
785
  // Returns kDecryptError if any decryption error happened.
786
  // Returns kDecodeError if any decoding error happened.
787
  // If the return value is not kSuccess, |video_frame| should be ignored by
788
  // the caller.
789
  virtual Status DecryptAndDecodeFrame(const InputBuffer_1& encrypted_buffer,
790
                                       VideoFrame* video_frame) = 0;
791
792
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
793
  // |audio_frames|. Upon end-of-stream, the caller should call this function
794
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
795
  // |audio_frames| is produced.
796
  //
797
  // Returns kSuccess if decryption and decoding both succeeded, in which case
798
  // the callee will have filled |audio_frames| and passed the ownership of
799
  // |data| in |audio_frames| to the caller.
800
  // Returns kNoKey if the CDM did not have the necessary decryption key
801
  // to decrypt.
802
  // Returns kNeedMoreData if more data was needed by the decoder to generate
803
  // audio samples (e.g. during initialization and end-of-stream).
804
  // Returns kDecryptError if any decryption error happened.
805
  // Returns kDecodeError if any decoding error happened.
806
  // If the return value is not kSuccess, |audio_frames| should be ignored by
807
  // the caller.
808
  virtual Status DecryptAndDecodeSamples(const InputBuffer_1& encrypted_buffer,
809
                                         AudioFrames* audio_frames) = 0;
810
811
  // Called by the host after a platform challenge was initiated via
812
  // Host::SendPlatformChallenge().
813
  virtual void OnPlatformChallengeResponse(
814
      const PlatformChallengeResponse& response) = 0;
815
816
  // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
817
  // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
818
  // is a bit mask of OutputProtectionMethods. If |result| is kQueryFailed,
819
  // then |link_mask| and |output_protection_mask| are undefined and should
820
  // be ignored.
821
  virtual void OnQueryOutputProtectionStatus(
822
      QueryResult result,
823
      uint32_t link_mask,
824
      uint32_t output_protection_mask) = 0;
825
826
  // Called by the host after a call to Host::RequestStorageId(). If the
827
  // version of the storage ID requested is available, |storage_id| and
828
  // |storage_id_size| are set appropriately. |version| will be the same as
829
  // what was requested, unless 0 (latest) was requested, in which case
830
  // |version| will be the actual version number for the |storage_id| returned.
831
  // If the requested version is not available, null/zero will be provided as
832
  // |storage_id| and |storage_id_size|, respectively, and |version| should be
833
  // ignored.
834
  virtual void OnStorageId(uint32_t version,
835
                           const uint8_t* storage_id,
836
                           uint32_t storage_id_size) = 0;
837
838
  // Destroys the object in the same context as it was created.
839
  virtual void Destroy() = 0;
840
841
 protected:
842
0
  ContentDecryptionModule_9() {}
843
0
  virtual ~ContentDecryptionModule_9() {}
844
};
845
846
// ContentDecryptionModule interface that all CDMs need to implement.
847
// The interface is versioned for backward compatibility.
848
// Note: ContentDecryptionModule implementations must use the allocator
849
// provided in CreateCdmInstance() to allocate any Buffer that needs to
850
// be passed back to the caller. Implementations must call Buffer::Destroy()
851
// when a Buffer is created that will never be returned to the caller.
852
class CDM_CLASS_API ContentDecryptionModule_10 {
853
 public:
854
  static const int kVersion = 10;
855
  static const bool kIsStable = true;
856
  typedef Host_10 Host;
857
858
  // Initializes the CDM instance, providing information about permitted
859
  // functionalities. The CDM must respond by calling Host::OnInitialized()
860
  // with whether the initialization succeeded. No other calls will be made by
861
  // the host before Host::OnInitialized() returns.
862
  // If |allow_distinctive_identifier| is false, messages from the CDM,
863
  // such as message events, must not contain a Distinctive Identifier,
864
  // even in an encrypted form.
865
  // If |allow_persistent_state| is false, the CDM must not attempt to
866
  // persist state. Calls to CreateFileIO() will fail.
867
  // If |use_hw_secure_codecs| is true, the CDM must ensure the decryption key
868
  // and video buffers (compressed and uncompressed) are securely protected by
869
  // hardware.
870
  virtual void Initialize(bool allow_distinctive_identifier,
871
                          bool allow_persistent_state,
872
                          bool use_hw_secure_codecs) = 0;
873
874
  // Gets the key status if the CDM has a hypothetical key with the |policy|.
875
  // The CDM must respond by calling either Host::OnResolveKeyStatusPromise()
876
  // with the result key status or Host::OnRejectPromise() if an unexpected
877
  // error happened or this method is not supported.
878
  virtual void GetStatusForPolicy(uint32_t promise_id,
879
                                  const Policy& policy) = 0;
880
881
  // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(),
882
  // UpdateSession(), CloseSession(), and RemoveSession() all accept a
883
  // |promise_id|, which must be passed to the completion Host method
884
  // (e.g. Host::OnResolveNewSessionPromise()).
885
886
  // Provides a server certificate to be used to encrypt messages to the
887
  // license server. The CDM must respond by calling either
888
  // Host::OnResolvePromise() or Host::OnRejectPromise().
889
  // If the CDM does not support server certificates, the promise should be
890
  // rejected with kExceptionNotSupportedError. If |server_certificate_data|
891
  // is empty, reject with kExceptionTypeError. Any other error should be
892
  // rejected with kExceptionInvalidStateError or kExceptionQuotaExceededError.
893
  // TODO(crbug.com/796417): Add support for the promise to return true or
894
  // false, rather than using kExceptionNotSupportedError to mean false.
895
  virtual void SetServerCertificate(uint32_t promise_id,
896
                                    const uint8_t* server_certificate_data,
897
                                    uint32_t server_certificate_data_size) = 0;
898
899
  // Creates a session given |session_type|, |init_data_type|, and |init_data|.
900
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
901
  // or Host::OnRejectPromise().
902
  virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
903
                                               SessionType session_type,
904
                                               InitDataType init_data_type,
905
                                               const uint8_t* init_data,
906
                                               uint32_t init_data_size) = 0;
907
908
  // Loads the session of type |session_type| specified by |session_id|.
909
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
910
  // or Host::OnRejectPromise(). If the session is not found, call
911
  // Host::OnResolveNewSessionPromise() with session_id = NULL.
912
  virtual void LoadSession(uint32_t promise_id,
913
                           SessionType session_type,
914
                           const char* session_id,
915
                           uint32_t session_id_size) = 0;
916
917
  // Updates the session with |response|. The CDM must respond by calling
918
  // either Host::OnResolvePromise() or Host::OnRejectPromise().
919
  virtual void UpdateSession(uint32_t promise_id,
920
                             const char* session_id,
921
                             uint32_t session_id_size,
922
                             const uint8_t* response,
923
                             uint32_t response_size) = 0;
924
925
  // Requests that the CDM close the session. The CDM must respond by calling
926
  // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
927
  // has been processed. This may be before the session is closed. Once the
928
  // session is closed, Host::OnSessionClosed() must also be called.
929
  virtual void CloseSession(uint32_t promise_id,
930
                            const char* session_id,
931
                            uint32_t session_id_size) = 0;
932
933
  // Removes any stored session data associated with this session. Will only be
934
  // called for persistent sessions. The CDM must respond by calling either
935
  // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
936
  // been processed.
937
  virtual void RemoveSession(uint32_t promise_id,
938
                             const char* session_id,
939
                             uint32_t session_id_size) = 0;
940
941
  // Performs scheduled operation with |context| when the timer fires.
942
  virtual void TimerExpired(void* context) = 0;
943
944
  // Decrypts the |encrypted_buffer|.
945
  //
946
  // Returns kSuccess if decryption succeeded, in which case the callee
947
  // should have filled the |decrypted_buffer| and passed the ownership of
948
  // |data| in |decrypted_buffer| to the caller.
949
  // Returns kNoKey if the CDM did not have the necessary decryption key
950
  // to decrypt.
951
  // Returns kDecryptError if any other error happened.
952
  // If the return value is not kSuccess, |decrypted_buffer| should be ignored
953
  // by the caller.
954
  virtual Status Decrypt(const InputBuffer_2& encrypted_buffer,
955
                         DecryptedBlock* decrypted_buffer) = 0;
956
957
  // Initializes the CDM audio decoder with |audio_decoder_config|. This
958
  // function must be called before DecryptAndDecodeSamples() is called.
959
  //
960
  // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
961
  // audio decoder is successfully initialized.
962
  // Returns kInitializationError if |audio_decoder_config| is not supported.
963
  // The CDM may still be able to do Decrypt().
964
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
965
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
966
  // initialization is complete.
967
  virtual Status InitializeAudioDecoder(
968
      const AudioDecoderConfig_2& audio_decoder_config) = 0;
969
970
  // Initializes the CDM video decoder with |video_decoder_config|. This
971
  // function must be called before DecryptAndDecodeFrame() is called.
972
  //
973
  // Returns kSuccess if the |video_decoder_config| is supported and the CDM
974
  // video decoder is successfully initialized.
975
  // Returns kInitializationError if |video_decoder_config| is not supported.
976
  // The CDM may still be able to do Decrypt().
977
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
978
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
979
  // initialization is complete.
980
  virtual Status InitializeVideoDecoder(
981
      const VideoDecoderConfig_2& video_decoder_config) = 0;
982
983
  // De-initializes the CDM decoder and sets it to an uninitialized state. The
984
  // caller can initialize the decoder again after this call to re-initialize
985
  // it. This can be used to reconfigure the decoder if the configuration
986
  // changes.
987
  virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
988
989
  // Resets the CDM decoder to an initialized clean state. All internal buffers
990
  // MUST be flushed.
991
  virtual void ResetDecoder(StreamType decoder_type) = 0;
992
993
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
994
  // |video_frame|. Upon end-of-stream, the caller should call this function
995
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
996
  // |video_frame| (|format| == kEmptyVideoFrame) is produced.
997
  //
998
  // Returns kSuccess if decryption and decoding both succeeded, in which case
999
  // the callee will have filled the |video_frame| and passed the ownership of
1000
  // |frame_buffer| in |video_frame| to the caller.
1001
  // Returns kNoKey if the CDM did not have the necessary decryption key
1002
  // to decrypt.
1003
  // Returns kNeedMoreData if more data was needed by the decoder to generate
1004
  // a decoded frame (e.g. during initialization and end-of-stream).
1005
  // Returns kDecryptError if any decryption error happened.
1006
  // Returns kDecodeError if any decoding error happened.
1007
  // If the return value is not kSuccess, |video_frame| should be ignored by
1008
  // the caller.
1009
  virtual Status DecryptAndDecodeFrame(const InputBuffer_2& encrypted_buffer,
1010
                                       VideoFrame* video_frame) = 0;
1011
1012
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
1013
  // |audio_frames|. Upon end-of-stream, the caller should call this function
1014
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
1015
  // |audio_frames| is produced.
1016
  //
1017
  // Returns kSuccess if decryption and decoding both succeeded, in which case
1018
  // the callee will have filled |audio_frames| and passed the ownership of
1019
  // |data| in |audio_frames| to the caller.
1020
  // Returns kNoKey if the CDM did not have the necessary decryption key
1021
  // to decrypt.
1022
  // Returns kNeedMoreData if more data was needed by the decoder to generate
1023
  // audio samples (e.g. during initialization and end-of-stream).
1024
  // Returns kDecryptError if any decryption error happened.
1025
  // Returns kDecodeError if any decoding error happened.
1026
  // If the return value is not kSuccess, |audio_frames| should be ignored by
1027
  // the caller.
1028
  virtual Status DecryptAndDecodeSamples(const InputBuffer_2& encrypted_buffer,
1029
                                         AudioFrames* audio_frames) = 0;
1030
1031
  // Called by the host after a platform challenge was initiated via
1032
  // Host::SendPlatformChallenge().
1033
  virtual void OnPlatformChallengeResponse(
1034
      const PlatformChallengeResponse& response) = 0;
1035
1036
  // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
1037
  // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
1038
  // is a bit mask of OutputProtectionMethods. If |result| is kQueryFailed,
1039
  // then |link_mask| and |output_protection_mask| are undefined and should
1040
  // be ignored.
1041
  virtual void OnQueryOutputProtectionStatus(
1042
      QueryResult result,
1043
      uint32_t link_mask,
1044
      uint32_t output_protection_mask) = 0;
1045
1046
  // Called by the host after a call to Host::RequestStorageId(). If the
1047
  // version of the storage ID requested is available, |storage_id| and
1048
  // |storage_id_size| are set appropriately. |version| will be the same as
1049
  // what was requested, unless 0 (latest) was requested, in which case
1050
  // |version| will be the actual version number for the |storage_id| returned.
1051
  // If the requested version is not available, null/zero will be provided as
1052
  // |storage_id| and |storage_id_size|, respectively, and |version| should be
1053
  // ignored.
1054
  virtual void OnStorageId(uint32_t version,
1055
                           const uint8_t* storage_id,
1056
                           uint32_t storage_id_size) = 0;
1057
1058
  // Destroys the object in the same context as it was created.
1059
  virtual void Destroy() = 0;
1060
1061
 protected:
1062
0
  ContentDecryptionModule_10() {}
1063
0
  virtual ~ContentDecryptionModule_10() {}
1064
};
1065
1066
// ----- Note: CDM interface(s) below still in development and not stable! -----
1067
1068
// ContentDecryptionModule interface that all CDMs need to implement.
1069
// The interface is versioned for backward compatibility.
1070
// Note: ContentDecryptionModule implementations must use the allocator
1071
// provided in CreateCdmInstance() to allocate any Buffer that needs to
1072
// be passed back to the caller. Implementations must call Buffer::Destroy()
1073
// when a Buffer is created that will never be returned to the caller.
1074
class CDM_CLASS_API ContentDecryptionModule_11 {
1075
 public:
1076
  static const int kVersion = 11;
1077
  static const bool kIsStable = false;
1078
  typedef Host_11 Host;
1079
1080
  // Initializes the CDM instance, providing information about permitted
1081
  // functionalities. The CDM must respond by calling Host::OnInitialized()
1082
  // with whether the initialization succeeded. No other calls will be made by
1083
  // the host before Host::OnInitialized() returns.
1084
  // If |allow_distinctive_identifier| is false, messages from the CDM,
1085
  // such as message events, must not contain a Distinctive Identifier,
1086
  // even in an encrypted form.
1087
  // If |allow_persistent_state| is false, the CDM must not attempt to
1088
  // persist state. Calls to CreateFileIO() will fail.
1089
  // If |use_hw_secure_codecs| is true, the CDM must ensure the decryption key
1090
  // and video buffers (compressed and uncompressed) are securely protected by
1091
  // hardware.
1092
  virtual void Initialize(bool allow_distinctive_identifier,
1093
                          bool allow_persistent_state,
1094
                          bool use_hw_secure_codecs) = 0;
1095
1096
  // Gets the key status if the CDM has a hypothetical key with the |policy|.
1097
  // The CDM must respond by calling either Host::OnResolveKeyStatusPromise()
1098
  // with the result key status or Host::OnRejectPromise() if an unexpected
1099
  // error happened or this method is not supported.
1100
  virtual void GetStatusForPolicy(uint32_t promise_id,
1101
                                  const Policy& policy) = 0;
1102
1103
  // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(),
1104
  // UpdateSession(), CloseSession(), and RemoveSession() all accept a
1105
  // |promise_id|, which must be passed to the completion Host method
1106
  // (e.g. Host::OnResolveNewSessionPromise()).
1107
1108
  // Provides a server certificate to be used to encrypt messages to the
1109
  // license server. The CDM must respond by calling either
1110
  // Host::OnResolvePromise() or Host::OnRejectPromise().
1111
  // If the CDM does not support server certificates, the promise should be
1112
  // rejected with kExceptionNotSupportedError. If |server_certificate_data|
1113
  // is empty, reject with kExceptionTypeError. Any other error should be
1114
  // rejected with kExceptionInvalidStateError or kExceptionQuotaExceededError.
1115
  // TODO(crbug.com/796417): Add support for the promise to return true or
1116
  // false, rather than using kExceptionNotSupportedError to mean false.
1117
  virtual void SetServerCertificate(uint32_t promise_id,
1118
                                    const uint8_t* server_certificate_data,
1119
                                    uint32_t server_certificate_data_size) = 0;
1120
1121
  // Creates a session given |session_type|, |init_data_type|, and |init_data|.
1122
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
1123
  // or Host::OnRejectPromise().
1124
  virtual void CreateSessionAndGenerateRequest(uint32_t promise_id,
1125
                                               SessionType session_type,
1126
                                               InitDataType init_data_type,
1127
                                               const uint8_t* init_data,
1128
                                               uint32_t init_data_size) = 0;
1129
1130
  // Loads the session of type |session_type| specified by |session_id|.
1131
  // The CDM must respond by calling either Host::OnResolveNewSessionPromise()
1132
  // or Host::OnRejectPromise(). If the session is not found, call
1133
  // Host::OnResolveNewSessionPromise() with session_id = NULL.
1134
  virtual void LoadSession(uint32_t promise_id,
1135
                           SessionType session_type,
1136
                           const char* session_id,
1137
                           uint32_t session_id_size) = 0;
1138
1139
  // Updates the session with |response|. The CDM must respond by calling
1140
  // either Host::OnResolvePromise() or Host::OnRejectPromise().
1141
  virtual void UpdateSession(uint32_t promise_id,
1142
                             const char* session_id,
1143
                             uint32_t session_id_size,
1144
                             const uint8_t* response,
1145
                             uint32_t response_size) = 0;
1146
1147
  // Requests that the CDM close the session. The CDM must respond by calling
1148
  // either Host::OnResolvePromise() or Host::OnRejectPromise() when the request
1149
  // has been processed. This may be before the session is closed. Once the
1150
  // session is closed, Host::OnSessionClosed() must also be called.
1151
  virtual void CloseSession(uint32_t promise_id,
1152
                            const char* session_id,
1153
                            uint32_t session_id_size) = 0;
1154
1155
  // Removes any stored session data associated with this session. Will only be
1156
  // called for persistent sessions. The CDM must respond by calling either
1157
  // Host::OnResolvePromise() or Host::OnRejectPromise() when the request has
1158
  // been processed.
1159
  virtual void RemoveSession(uint32_t promise_id,
1160
                             const char* session_id,
1161
                             uint32_t session_id_size) = 0;
1162
1163
  // Performs scheduled operation with |context| when the timer fires.
1164
  virtual void TimerExpired(void* context) = 0;
1165
1166
  // Decrypts the |encrypted_buffer|.
1167
  //
1168
  // Returns kSuccess if decryption succeeded, in which case the callee
1169
  // should have filled the |decrypted_buffer| and passed the ownership of
1170
  // |data| in |decrypted_buffer| to the caller.
1171
  // Returns kNoKey if the CDM did not have the necessary decryption key
1172
  // to decrypt.
1173
  // Returns kDecryptError if any other error happened.
1174
  // If the return value is not kSuccess, |decrypted_buffer| should be ignored
1175
  // by the caller.
1176
  virtual Status Decrypt(const InputBuffer_2& encrypted_buffer,
1177
                         DecryptedBlock* decrypted_buffer) = 0;
1178
1179
  // Initializes the CDM audio decoder with |audio_decoder_config|. This
1180
  // function must be called before DecryptAndDecodeSamples() is called.
1181
  //
1182
  // Returns kSuccess if the |audio_decoder_config| is supported and the CDM
1183
  // audio decoder is successfully initialized.
1184
  // Returns kInitializationError if |audio_decoder_config| is not supported.
1185
  // The CDM may still be able to do Decrypt().
1186
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
1187
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
1188
  // initialization is complete.
1189
  virtual Status InitializeAudioDecoder(
1190
      const AudioDecoderConfig_2& audio_decoder_config) = 0;
1191
1192
  // Initializes the CDM video decoder with |video_decoder_config|. This
1193
  // function must be called before DecryptAndDecodeFrame() is called.
1194
  //
1195
  // Returns kSuccess if the |video_decoder_config| is supported and the CDM
1196
  // video decoder is successfully initialized.
1197
  // Returns kInitializationError if |video_decoder_config| is not supported.
1198
  // The CDM may still be able to do Decrypt().
1199
  // Returns kDeferredInitialization if the CDM is not ready to initialize the
1200
  // decoder at this time. Must call Host::OnDeferredInitializationDone() once
1201
  // initialization is complete.
1202
  virtual Status InitializeVideoDecoder(
1203
      const VideoDecoderConfig_2& video_decoder_config) = 0;
1204
1205
  // De-initializes the CDM decoder and sets it to an uninitialized state. The
1206
  // caller can initialize the decoder again after this call to re-initialize
1207
  // it. This can be used to reconfigure the decoder if the configuration
1208
  // changes.
1209
  virtual void DeinitializeDecoder(StreamType decoder_type) = 0;
1210
1211
  // Resets the CDM decoder to an initialized clean state. All internal buffers
1212
  // MUST be flushed.
1213
  virtual void ResetDecoder(StreamType decoder_type) = 0;
1214
1215
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into a
1216
  // |video_frame|. Upon end-of-stream, the caller should call this function
1217
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
1218
  // |video_frame| (|format| == kEmptyVideoFrame) is produced.
1219
  //
1220
  // Returns kSuccess if decryption and decoding both succeeded, in which case
1221
  // the callee will have filled the |video_frame| and passed the ownership of
1222
  // |frame_buffer| in |video_frame| to the caller.
1223
  // Returns kNoKey if the CDM did not have the necessary decryption key
1224
  // to decrypt.
1225
  // Returns kNeedMoreData if more data was needed by the decoder to generate
1226
  // a decoded frame (e.g. during initialization and end-of-stream).
1227
  // Returns kDecryptError if any decryption error happened.
1228
  // Returns kDecodeError if any decoding error happened.
1229
  // If the return value is not kSuccess, |video_frame| should be ignored by
1230
  // the caller.
1231
  virtual Status DecryptAndDecodeFrame(const InputBuffer_2& encrypted_buffer,
1232
                                       VideoFrame* video_frame) = 0;
1233
1234
  // Decrypts the |encrypted_buffer| and decodes the decrypted buffer into
1235
  // |audio_frames|. Upon end-of-stream, the caller should call this function
1236
  // repeatedly with empty |encrypted_buffer| (|data| == NULL) until only empty
1237
  // |audio_frames| is produced.
1238
  //
1239
  // Returns kSuccess if decryption and decoding both succeeded, in which case
1240
  // the callee will have filled |audio_frames| and passed the ownership of
1241
  // |data| in |audio_frames| to the caller.
1242
  // Returns kNoKey if the CDM did not have the necessary decryption key
1243
  // to decrypt.
1244
  // Returns kNeedMoreData if more data was needed by the decoder to generate
1245
  // audio samples (e.g. during initialization and end-of-stream).
1246
  // Returns kDecryptError if any decryption error happened.
1247
  // Returns kDecodeError if any decoding error happened.
1248
  // If the return value is not kSuccess, |audio_frames| should be ignored by
1249
  // the caller.
1250
  virtual Status DecryptAndDecodeSamples(const InputBuffer_2& encrypted_buffer,
1251
                                         AudioFrames* audio_frames) = 0;
1252
1253
  // Called by the host after a platform challenge was initiated via
1254
  // Host::SendPlatformChallenge().
1255
  virtual void OnPlatformChallengeResponse(
1256
      const PlatformChallengeResponse& response) = 0;
1257
1258
  // Called by the host after a call to Host::QueryOutputProtectionStatus(). The
1259
  // |link_mask| is a bit mask of OutputLinkTypes and |output_protection_mask|
1260
  // is a bit mask of OutputProtectionMethods. If |result| is kQueryFailed,
1261
  // then |link_mask| and |output_protection_mask| are undefined and should
1262
  // be ignored.
1263
  virtual void OnQueryOutputProtectionStatus(
1264
      QueryResult result,
1265
      uint32_t link_mask,
1266
      uint32_t output_protection_mask) = 0;
1267
1268
  // Called by the host after a call to Host::RequestStorageId(). If the
1269
  // version of the storage ID requested is available, |storage_id| and
1270
  // |storage_id_size| are set appropriately. |version| will be the same as
1271
  // what was requested, unless 0 (latest) was requested, in which case
1272
  // |version| will be the actual version number for the |storage_id| returned.
1273
  // If the requested version is not available, null/zero will be provided as
1274
  // |storage_id| and |storage_id_size|, respectively, and |version| should be
1275
  // ignored.
1276
  virtual void OnStorageId(uint32_t version,
1277
                           const uint8_t* storage_id,
1278
                           uint32_t storage_id_size) = 0;
1279
1280
  // Destroys the object in the same context as it was created.
1281
  virtual void Destroy() = 0;
1282
1283
 protected:
1284
0
  ContentDecryptionModule_11() {}
1285
0
  virtual ~ContentDecryptionModule_11() {}
1286
};
1287
1288
class CDM_CLASS_API Host_9 {
1289
 public:
1290
  static const int kVersion = 9;
1291
1292
  // Returns a Buffer* containing non-zero members upon success, or NULL on
1293
  // failure. The caller owns the Buffer* after this call. The buffer is not
1294
  // guaranteed to be zero initialized. The capacity of the allocated Buffer
1295
  // is guaranteed to be not less than |capacity|.
1296
  virtual Buffer* Allocate(uint32_t capacity) = 0;
1297
1298
  // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
1299
  // from now with |context|.
1300
  virtual void SetTimer(int64_t delay_ms, void* context) = 0;
1301
1302
  // Returns the current wall time.
1303
  virtual Time GetCurrentWallTime() = 0;
1304
1305
  // Called by the CDM when a key status is available in response to
1306
  // GetStatusForPolicy().
1307
  virtual void OnResolveKeyStatusPromise(uint32_t promise_id,
1308
                                         KeyStatus key_status) = 0;
1309
1310
  // Called by the CDM when a session is created or loaded and the value for the
1311
  // MediaKeySession's sessionId attribute is available (|session_id|).
1312
  // This must be called before OnSessionMessage() or
1313
  // OnSessionKeysChange() is called for the same session. |session_id_size|
1314
  // should not include null termination.
1315
  // When called in response to LoadSession(), the |session_id| must be the
1316
  // same as the |session_id| passed in LoadSession(), or NULL if the
1317
  // session could not be loaded.
1318
  virtual void OnResolveNewSessionPromise(uint32_t promise_id,
1319
                                          const char* session_id,
1320
                                          uint32_t session_id_size) = 0;
1321
1322
  // Called by the CDM when a session is updated or released.
1323
  virtual void OnResolvePromise(uint32_t promise_id) = 0;
1324
1325
  // Called by the CDM when an error occurs as a result of one of the
1326
  // ContentDecryptionModule calls that accept a |promise_id|.
1327
  // |exception| must be specified. |error_message| and |system_code|
1328
  // are optional. |error_message_size| should not include null termination.
1329
  virtual void OnRejectPromise(uint32_t promise_id,
1330
                               Exception exception,
1331
                               uint32_t system_code,
1332
                               const char* error_message,
1333
                               uint32_t error_message_size) = 0;
1334
1335
  // Called by the CDM when it has a message for session |session_id|.
1336
  // Size parameters should not include null termination.
1337
  virtual void OnSessionMessage(const char* session_id,
1338
                                uint32_t session_id_size,
1339
                                MessageType message_type,
1340
                                const char* message,
1341
                                uint32_t message_size) = 0;
1342
1343
  // Called by the CDM when there has been a change in keys or their status for
1344
  // session |session_id|. |has_additional_usable_key| should be set if a
1345
  // key is newly usable (e.g. new key available, previously expired key has
1346
  // been renewed, etc.) and the browser should attempt to resume playback.
1347
  // |keys_info| is the list of key IDs for this session along with their
1348
  // current status. |keys_info_count| is the number of entries in |keys_info|.
1349
  // Size parameter for |session_id| should not include null termination.
1350
  virtual void OnSessionKeysChange(const char* session_id,
1351
                                   uint32_t session_id_size,
1352
                                   bool has_additional_usable_key,
1353
                                   const KeyInformation* keys_info,
1354
                                   uint32_t keys_info_count) = 0;
1355
1356
  // Called by the CDM when there has been a change in the expiration time for
1357
  // session |session_id|. This can happen as the result of an Update() call
1358
  // or some other event. If this happens as a result of a call to Update(),
1359
  // it must be called before resolving the Update() promise. |new_expiry_time|
1360
  // represents the time after which the key(s) in the session will no longer
1361
  // be usable for decryption. It can be 0 if no such time exists or if the
1362
  // license explicitly never expires. Size parameter should not include null
1363
  // termination.
1364
  virtual void OnExpirationChange(const char* session_id,
1365
                                  uint32_t session_id_size,
1366
                                  Time new_expiry_time) = 0;
1367
1368
  // Called by the CDM when session |session_id| is closed. Size
1369
  // parameter should not include null termination.
1370
  virtual void OnSessionClosed(const char* session_id,
1371
                               uint32_t session_id_size) = 0;
1372
1373
  // The following are optional methods that may not be implemented on all
1374
  // platforms.
1375
1376
  // Sends a platform challenge for the given |service_id|. |challenge| is at
1377
  // most 256 bits of data to be signed. Once the challenge has been completed,
1378
  // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1379
  // with the signed challenge response and platform certificate. Size
1380
  // parameters should not include null termination.
1381
  virtual void SendPlatformChallenge(const char* service_id,
1382
                                     uint32_t service_id_size,
1383
                                     const char* challenge,
1384
                                     uint32_t challenge_size) = 0;
1385
1386
  // Attempts to enable output protection (e.g. HDCP) on the display link. The
1387
  // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1388
  // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1389
  // periodically to ensure the desired protections are applied.
1390
  virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1391
1392
  // Requests the current output protection status. Once the host has the status
1393
  // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1394
  virtual void QueryOutputProtectionStatus() = 0;
1395
1396
  // Must be called by the CDM if it returned kDeferredInitialization during
1397
  // InitializeAudioDecoder() or InitializeVideoDecoder().
1398
  virtual void OnDeferredInitializationDone(StreamType stream_type,
1399
                                            Status decoder_status) = 0;
1400
1401
  // Creates a FileIO object from the host to do file IO operation. Returns NULL
1402
  // if a FileIO object cannot be obtained. Once a valid FileIO object is
1403
  // returned, |client| must be valid until FileIO::Close() is called. The
1404
  // CDM can call this method multiple times to operate on different files.
1405
  virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1406
1407
  // Requests a specific version of the storage ID. A storage ID is a stable,
1408
  // device specific ID used by the CDM to securely store persistent data. The
1409
  // ID will be returned by the host via ContentDecryptionModule::OnStorageId().
1410
  // If |version| is 0, the latest version will be returned. All |version|s
1411
  // that are greater than or equal to 0x80000000 are reserved for the CDM and
1412
  // should not be supported or returned by the host. The CDM must not expose
1413
  // the ID outside the client device, even in encrypted form.
1414
  virtual void RequestStorageId(uint32_t version) = 0;
1415
1416
 protected:
1417
0
  Host_9() {}
1418
0
  virtual ~Host_9() {}
1419
};
1420
1421
class CDM_CLASS_API Host_10 {
1422
 public:
1423
  static const int kVersion = 10;
1424
1425
  // Returns a Buffer* containing non-zero members upon success, or NULL on
1426
  // failure. The caller owns the Buffer* after this call. The buffer is not
1427
  // guaranteed to be zero initialized. The capacity of the allocated Buffer
1428
  // is guaranteed to be not less than |capacity|.
1429
  virtual Buffer* Allocate(uint32_t capacity) = 0;
1430
1431
  // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
1432
  // from now with |context|.
1433
  virtual void SetTimer(int64_t delay_ms, void* context) = 0;
1434
1435
  // Returns the current wall time.
1436
  virtual Time GetCurrentWallTime() = 0;
1437
1438
  // Called by the CDM with the result after the CDM instance was initialized.
1439
  virtual void OnInitialized(bool success) = 0;
1440
1441
  // Called by the CDM when a key status is available in response to
1442
  // GetStatusForPolicy().
1443
  virtual void OnResolveKeyStatusPromise(uint32_t promise_id,
1444
                                         KeyStatus key_status) = 0;
1445
1446
  // Called by the CDM when a session is created or loaded and the value for the
1447
  // MediaKeySession's sessionId attribute is available (|session_id|).
1448
  // This must be called before OnSessionMessage() or
1449
  // OnSessionKeysChange() is called for the same session. |session_id_size|
1450
  // should not include null termination.
1451
  // When called in response to LoadSession(), the |session_id| must be the
1452
  // same as the |session_id| passed in LoadSession(), or NULL if the
1453
  // session could not be loaded.
1454
  virtual void OnResolveNewSessionPromise(uint32_t promise_id,
1455
                                          const char* session_id,
1456
                                          uint32_t session_id_size) = 0;
1457
1458
  // Called by the CDM when a session is updated or released.
1459
  virtual void OnResolvePromise(uint32_t promise_id) = 0;
1460
1461
  // Called by the CDM when an error occurs as a result of one of the
1462
  // ContentDecryptionModule calls that accept a |promise_id|.
1463
  // |exception| must be specified. |error_message| and |system_code|
1464
  // are optional. |error_message_size| should not include null termination.
1465
  virtual void OnRejectPromise(uint32_t promise_id,
1466
                               Exception exception,
1467
                               uint32_t system_code,
1468
                               const char* error_message,
1469
                               uint32_t error_message_size) = 0;
1470
1471
  // Called by the CDM when it has a message for session |session_id|.
1472
  // Size parameters should not include null termination.
1473
  virtual void OnSessionMessage(const char* session_id,
1474
                                uint32_t session_id_size,
1475
                                MessageType message_type,
1476
                                const char* message,
1477
                                uint32_t message_size) = 0;
1478
1479
  // Called by the CDM when there has been a change in keys or their status for
1480
  // session |session_id|. |has_additional_usable_key| should be set if a
1481
  // key is newly usable (e.g. new key available, previously expired key has
1482
  // been renewed, etc.) and the browser should attempt to resume playback.
1483
  // |keys_info| is the list of key IDs for this session along with their
1484
  // current status. |keys_info_count| is the number of entries in |keys_info|.
1485
  // Size parameter for |session_id| should not include null termination.
1486
  virtual void OnSessionKeysChange(const char* session_id,
1487
                                   uint32_t session_id_size,
1488
                                   bool has_additional_usable_key,
1489
                                   const KeyInformation* keys_info,
1490
                                   uint32_t keys_info_count) = 0;
1491
1492
  // Called by the CDM when there has been a change in the expiration time for
1493
  // session |session_id|. This can happen as the result of an Update() call
1494
  // or some other event. If this happens as a result of a call to Update(),
1495
  // it must be called before resolving the Update() promise. |new_expiry_time|
1496
  // represents the time after which the key(s) in the session will no longer
1497
  // be usable for decryption. It can be 0 if no such time exists or if the
1498
  // license explicitly never expires. Size parameter should not include null
1499
  // termination.
1500
  virtual void OnExpirationChange(const char* session_id,
1501
                                  uint32_t session_id_size,
1502
                                  Time new_expiry_time) = 0;
1503
1504
  // Called by the CDM when session |session_id| is closed. Size
1505
  // parameter should not include null termination.
1506
  virtual void OnSessionClosed(const char* session_id,
1507
                               uint32_t session_id_size) = 0;
1508
1509
  // The following are optional methods that may not be implemented on all
1510
  // platforms.
1511
1512
  // Sends a platform challenge for the given |service_id|. |challenge| is at
1513
  // most 256 bits of data to be signed. Once the challenge has been completed,
1514
  // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1515
  // with the signed challenge response and platform certificate. Size
1516
  // parameters should not include null termination.
1517
  virtual void SendPlatformChallenge(const char* service_id,
1518
                                     uint32_t service_id_size,
1519
                                     const char* challenge,
1520
                                     uint32_t challenge_size) = 0;
1521
1522
  // Attempts to enable output protection (e.g. HDCP) on the display link. The
1523
  // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1524
  // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1525
  // periodically to ensure the desired protections are applied.
1526
  virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1527
1528
  // Requests the current output protection status. Once the host has the status
1529
  // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1530
  virtual void QueryOutputProtectionStatus() = 0;
1531
1532
  // Must be called by the CDM if it returned kDeferredInitialization during
1533
  // InitializeAudioDecoder() or InitializeVideoDecoder().
1534
  virtual void OnDeferredInitializationDone(StreamType stream_type,
1535
                                            Status decoder_status) = 0;
1536
1537
  // Creates a FileIO object from the host to do file IO operation. Returns NULL
1538
  // if a FileIO object cannot be obtained. Once a valid FileIO object is
1539
  // returned, |client| must be valid until FileIO::Close() is called. The
1540
  // CDM can call this method multiple times to operate on different files.
1541
  virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1542
1543
  // Requests a specific version of the storage ID. A storage ID is a stable,
1544
  // device specific ID used by the CDM to securely store persistent data. The
1545
  // ID will be returned by the host via ContentDecryptionModule::OnStorageId().
1546
  // If |version| is 0, the latest version will be returned. All |version|s
1547
  // that are greater than or equal to 0x80000000 are reserved for the CDM and
1548
  // should not be supported or returned by the host. The CDM must not expose
1549
  // the ID outside the client device, even in encrypted form.
1550
  virtual void RequestStorageId(uint32_t version) = 0;
1551
1552
 protected:
1553
0
  Host_10() {}
1554
0
  virtual ~Host_10() {}
1555
};
1556
1557
class CDM_CLASS_API Host_11 {
1558
 public:
1559
  static const int kVersion = 11;
1560
1561
  // Returns a Buffer* containing non-zero members upon success, or NULL on
1562
  // failure. The caller owns the Buffer* after this call. The buffer is not
1563
  // guaranteed to be zero initialized. The capacity of the allocated Buffer
1564
  // is guaranteed to be not less than |capacity|.
1565
  virtual Buffer* Allocate(uint32_t capacity) = 0;
1566
1567
  // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
1568
  // from now with |context|.
1569
  virtual void SetTimer(int64_t delay_ms, void* context) = 0;
1570
1571
  // Returns the current wall time.
1572
  virtual Time GetCurrentWallTime() = 0;
1573
1574
  // Called by the CDM with the result after the CDM instance was initialized.
1575
  virtual void OnInitialized(bool success) = 0;
1576
1577
  // Called by the CDM when a key status is available in response to
1578
  // GetStatusForPolicy().
1579
  virtual void OnResolveKeyStatusPromise(uint32_t promise_id,
1580
                                         KeyStatus key_status) = 0;
1581
1582
  // Called by the CDM when a session is created or loaded and the value for the
1583
  // MediaKeySession's sessionId attribute is available (|session_id|).
1584
  // This must be called before OnSessionMessage() or
1585
  // OnSessionKeysChange() is called for the same session. |session_id_size|
1586
  // should not include null termination.
1587
  // When called in response to LoadSession(), the |session_id| must be the
1588
  // same as the |session_id| passed in LoadSession(), or NULL if the
1589
  // session could not be loaded.
1590
  virtual void OnResolveNewSessionPromise(uint32_t promise_id,
1591
                                          const char* session_id,
1592
                                          uint32_t session_id_size) = 0;
1593
1594
  // Called by the CDM when a session is updated or released.
1595
  virtual void OnResolvePromise(uint32_t promise_id) = 0;
1596
1597
  // Called by the CDM when an error occurs as a result of one of the
1598
  // ContentDecryptionModule calls that accept a |promise_id|.
1599
  // |exception| must be specified. |error_message| and |system_code|
1600
  // are optional. |error_message_size| should not include null termination.
1601
  virtual void OnRejectPromise(uint32_t promise_id,
1602
                               Exception exception,
1603
                               uint32_t system_code,
1604
                               const char* error_message,
1605
                               uint32_t error_message_size) = 0;
1606
1607
  // Called by the CDM when it has a message for session |session_id|.
1608
  // Size parameters should not include null termination.
1609
  virtual void OnSessionMessage(const char* session_id,
1610
                                uint32_t session_id_size,
1611
                                MessageType message_type,
1612
                                const char* message,
1613
                                uint32_t message_size) = 0;
1614
1615
  // Called by the CDM when there has been a change in keys or their status for
1616
  // session |session_id|. |has_additional_usable_key| should be set if a
1617
  // key is newly usable (e.g. new key available, previously expired key has
1618
  // been renewed, etc.) and the browser should attempt to resume playback.
1619
  // |keys_info| is the list of key IDs for this session along with their
1620
  // current status. |keys_info_count| is the number of entries in |keys_info|.
1621
  // Size parameter for |session_id| should not include null termination.
1622
  virtual void OnSessionKeysChange(const char* session_id,
1623
                                   uint32_t session_id_size,
1624
                                   bool has_additional_usable_key,
1625
                                   const KeyInformation* keys_info,
1626
                                   uint32_t keys_info_count) = 0;
1627
1628
  // Called by the CDM when there has been a change in the expiration time for
1629
  // session |session_id|. This can happen as the result of an Update() call
1630
  // or some other event. If this happens as a result of a call to Update(),
1631
  // it must be called before resolving the Update() promise. |new_expiry_time|
1632
  // represents the time after which the key(s) in the session will no longer
1633
  // be usable for decryption. It can be 0 if no such time exists or if the
1634
  // license explicitly never expires. Size parameter should not include null
1635
  // termination.
1636
  virtual void OnExpirationChange(const char* session_id,
1637
                                  uint32_t session_id_size,
1638
                                  Time new_expiry_time) = 0;
1639
1640
  // Called by the CDM when session |session_id| is closed. Size
1641
  // parameter should not include null termination.
1642
  virtual void OnSessionClosed(const char* session_id,
1643
                               uint32_t session_id_size) = 0;
1644
1645
  // The following are optional methods that may not be implemented on all
1646
  // platforms.
1647
1648
  // Sends a platform challenge for the given |service_id|. |challenge| is at
1649
  // most 256 bits of data to be signed. Once the challenge has been completed,
1650
  // the host will call ContentDecryptionModule::OnPlatformChallengeResponse()
1651
  // with the signed challenge response and platform certificate. Size
1652
  // parameters should not include null termination.
1653
  virtual void SendPlatformChallenge(const char* service_id,
1654
                                     uint32_t service_id_size,
1655
                                     const char* challenge,
1656
                                     uint32_t challenge_size) = 0;
1657
1658
  // Attempts to enable output protection (e.g. HDCP) on the display link. The
1659
  // |desired_protection_mask| is a bit mask of OutputProtectionMethods. No
1660
  // status callback is issued, the CDM must call QueryOutputProtectionStatus()
1661
  // periodically to ensure the desired protections are applied.
1662
  virtual void EnableOutputProtection(uint32_t desired_protection_mask) = 0;
1663
1664
  // Requests the current output protection status. Once the host has the status
1665
  // it will call ContentDecryptionModule::OnQueryOutputProtectionStatus().
1666
  virtual void QueryOutputProtectionStatus() = 0;
1667
1668
  // Must be called by the CDM if it returned kDeferredInitialization during
1669
  // InitializeAudioDecoder() or InitializeVideoDecoder().
1670
  virtual void OnDeferredInitializationDone(StreamType stream_type,
1671
                                            Status decoder_status) = 0;
1672
1673
  // Creates a FileIO object from the host to do file IO operation. Returns NULL
1674
  // if a FileIO object cannot be obtained. Once a valid FileIO object is
1675
  // returned, |client| must be valid until FileIO::Close() is called. The
1676
  // CDM can call this method multiple times to operate on different files.
1677
  virtual FileIO* CreateFileIO(FileIOClient* client) = 0;
1678
1679
  // Requests a CdmProxy that proxies part of CDM functionalities to a different
1680
  // entity, e.g. a hardware CDM module. A CDM instance can have at most one
1681
  // CdmProxy throughout its lifetime, which must be requested and initialized
1682
  // during CDM instance initialization time, i.e. in or after CDM::Initialize()
1683
  // and before OnInitialized() is called, to ensure proper connection of the
1684
  // CdmProxy and the media player (e.g. hardware decoder). The CdmProxy is
1685
  // owned by the host and is guaranteed to be valid throughout the CDM
1686
  // instance's lifetime. The CDM must ensure that the |client| remain valid
1687
  // before the CDM instance is destroyed. Returns null if CdmProxy is not
1688
  // supported, called before CDM::Initialize(), RequestCdmProxy() is called
1689
  // more than once, or called after the CDM instance has been initialized.
1690
  virtual CdmProxy* RequestCdmProxy(CdmProxyClient* client) = 0;
1691
1692
  // Requests a specific version of the storage ID. A storage ID is a stable,
1693
  // device specific ID used by the CDM to securely store persistent data. The
1694
  // ID will be returned by the host via ContentDecryptionModule::OnStorageId().
1695
  // If |version| is 0, the latest version will be returned. All |version|s
1696
  // that are greater than or equal to 0x80000000 are reserved for the CDM and
1697
  // should not be supported or returned by the host. The CDM must not expose
1698
  // the ID outside the client device, even in encrypted form.
1699
  virtual void RequestStorageId(uint32_t version) = 0;
1700
1701
 protected:
1702
0
  Host_11() {}
1703
0
  virtual ~Host_11() {}
1704
};
1705
1706
}  // namespace cdm
1707
1708
#endif  // CDM_CONTENT_DECRYPTION_MODULE_H_