Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CDM_CONTENT_DECRYPTION_MODULE_H_ | 5 #ifndef CDM_CONTENT_DECRYPTION_MODULE_H_ |
| 6 #define CDM_CONTENT_DECRYPTION_MODULE_H_ | 6 #define CDM_CONTENT_DECRYPTION_MODULE_H_ |
| 7 | 7 |
| 8 #if defined(_MSC_VER) | 8 #if defined(_MSC_VER) |
| 9 typedef unsigned char uint8_t; | 9 typedef unsigned char uint8_t; |
| 10 typedef unsigned int uint32_t; | 10 typedef unsigned int uint32_t; |
| 11 typedef int int32_t; | 11 typedef int int32_t; |
| 12 typedef __int64 int64_t; | 12 typedef __int64 int64_t; |
| 13 #else | 13 #else |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 // Define CDM_API so that functionality implemented by the CDM module | 17 // Define CDM_API so that functionality implemented by the CDM module |
| 18 // can be exported to consumers. Note: the implementation lives in | 18 // can be exported to consumers. Note: the implementation lives in |
| 19 // a dynamic library even in a non-component build. | 19 // a dynamic library even in a non-component build. |
| 20 #if defined(WIN32) | 20 #if defined(WIN32) |
| 21 | 21 |
| 22 #if defined(__clang__) | |
| 23 #define CDM_CLASS_API [[clang::lto_visibility_public]] | |
| 24 #else | |
| 25 #define CDM_CLASS_API | |
| 26 #endif | |
| 27 | |
| 22 #if defined(CDM_IMPLEMENTATION) | 28 #if defined(CDM_IMPLEMENTATION) |
| 23 #define CDM_API __declspec(dllexport) | 29 #define CDM_API __declspec(dllexport) |
| 24 #else | 30 #else |
| 25 #define CDM_API __declspec(dllimport) | 31 #define CDM_API __declspec(dllimport) |
| 26 #endif // defined(CDM_IMPLEMENTATION) | 32 #endif // defined(CDM_IMPLEMENTATION) |
| 27 | 33 |
| 28 #else // defined(WIN32) | 34 #else // defined(WIN32) |
| 29 #define CDM_API __attribute__((visibility("default"))) | 35 #define CDM_API __attribute__((visibility("default"))) |
| 36 #define CDM_CLASS_API __attribute__((visibility("default"))) | |
| 30 #endif // defined(WIN32) | 37 #endif // defined(WIN32) |
|
xhwang
2016/05/12 06:54:30
Could you summarize what's discussed in the bug an
krasin
2016/05/16 21:40:10
Done.
| |
| 31 | 38 |
| 32 // The version number must be rolled when the exported functions are updated! | 39 // The version number must be rolled when the exported functions are updated! |
| 33 // If the CDM and the adapter use different versions of these functions, the | 40 // If the CDM and the adapter use different versions of these functions, the |
| 34 // adapter will fail to load or crash! | 41 // adapter will fail to load or crash! |
| 35 #define CDM_MODULE_VERSION 4 | 42 #define CDM_MODULE_VERSION 4 |
| 36 | 43 |
| 37 // Build the versioned entrypoint name. | 44 // Build the versioned entrypoint name. |
| 38 // The extra macros are necessary to expand version to an actual value. | 45 // The extra macros are necessary to expand version to an actual value. |
| 39 #define INITIALIZE_CDM_MODULE \ | 46 #define INITIALIZE_CDM_MODULE \ |
| 40 BUILD_ENTRYPOINT(InitializeCdmModule, CDM_MODULE_VERSION) | 47 BUILD_ENTRYPOINT(InitializeCdmModule, CDM_MODULE_VERSION) |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 | 379 |
| 373 // FileIO interface provides a way for the CDM to store data in a file in | 380 // FileIO interface provides a way for the CDM to store data in a file in |
| 374 // persistent storage. This interface aims only at providing basic read/write | 381 // persistent storage. This interface aims only at providing basic read/write |
| 375 // capabilities and should not be used as a full fledged file IO API. | 382 // capabilities and should not be used as a full fledged file IO API. |
| 376 // Each CDM and origin (e.g. HTTPS, "foo.example.com", 443) combination has | 383 // Each CDM and origin (e.g. HTTPS, "foo.example.com", 443) combination has |
| 377 // its own persistent storage. All instances of a given CDM associated with a | 384 // its own persistent storage. All instances of a given CDM associated with a |
| 378 // given origin share the same persistent storage. | 385 // given origin share the same persistent storage. |
| 379 // Note to implementors of this interface: | 386 // Note to implementors of this interface: |
| 380 // Per-origin storage and the ability for users to clear it are important. | 387 // Per-origin storage and the ability for users to clear it are important. |
| 381 // See http://www.w3.org/TR/encrypted-media/#privacy-storedinfo. | 388 // See http://www.w3.org/TR/encrypted-media/#privacy-storedinfo. |
| 382 class CDM_API FileIO { | 389 class CDM_CLASS_API FileIO { |
| 383 public: | 390 public: |
| 384 // Opens the file with |file_name| for read and write. | 391 // Opens the file with |file_name| for read and write. |
| 385 // FileIOClient::OnOpenComplete() will be called after the opening | 392 // FileIOClient::OnOpenComplete() will be called after the opening |
| 386 // operation finishes. | 393 // operation finishes. |
| 387 // - When the file is opened by a CDM instance, it will be classified as "in | 394 // - When the file is opened by a CDM instance, it will be classified as "in |
| 388 // use". In this case other CDM instances in the same domain may receive | 395 // use". In this case other CDM instances in the same domain may receive |
| 389 // kInUse status when trying to open it. | 396 // kInUse status when trying to open it. |
| 390 // - |file_name| must not contain forward slash ('/') or backslash ('\'), and | 397 // - |file_name| must not contain forward slash ('/') or backslash ('\'), and |
| 391 // must not start with an underscore ('_'). | 398 // must not start with an underscore ('_'). |
| 392 virtual void Open(const char* file_name, uint32_t file_name_size) = 0; | 399 virtual void Open(const char* file_name, uint32_t file_name_size) = 0; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 412 | 419 |
| 413 protected: | 420 protected: |
| 414 FileIO() {} | 421 FileIO() {} |
| 415 virtual ~FileIO() {} | 422 virtual ~FileIO() {} |
| 416 }; | 423 }; |
| 417 | 424 |
| 418 // Responses to FileIO calls. All responses will be called asynchronously. | 425 // Responses to FileIO calls. All responses will be called asynchronously. |
| 419 // When kError is returned, the FileIO object could be in an error state. All | 426 // When kError is returned, the FileIO object could be in an error state. All |
| 420 // following calls (other than Close()) could return kError. The CDM should | 427 // following calls (other than Close()) could return kError. The CDM should |
| 421 // still call Close() to destroy the FileIO object. | 428 // still call Close() to destroy the FileIO object. |
| 422 class CDM_API FileIOClient { | 429 class CDM_CLASS_API FileIOClient { |
| 423 public: | 430 public: |
| 424 enum Status { | 431 enum Status { |
| 425 kSuccess = 0, | 432 kSuccess = 0, |
| 426 kInUse, | 433 kInUse, |
| 427 kError | 434 kError |
| 428 }; | 435 }; |
| 429 | 436 |
| 430 // Response to a FileIO::Open() call with the open |status|. | 437 // Response to a FileIO::Open() call with the open |status|. |
| 431 virtual void OnOpenComplete(Status status) = 0; | 438 virtual void OnOpenComplete(Status status) = 0; |
| 432 | 439 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 453 FileIOClient() {} | 460 FileIOClient() {} |
| 454 virtual ~FileIOClient() {} | 461 virtual ~FileIOClient() {} |
| 455 }; | 462 }; |
| 456 | 463 |
| 457 // ContentDecryptionModule interface that all CDMs need to implement. | 464 // ContentDecryptionModule interface that all CDMs need to implement. |
| 458 // The interface is versioned for backward compatibility. | 465 // The interface is versioned for backward compatibility. |
| 459 // Note: ContentDecryptionModule implementations must use the allocator | 466 // Note: ContentDecryptionModule implementations must use the allocator |
| 460 // provided in CreateCdmInstance() to allocate any Buffer that needs to | 467 // provided in CreateCdmInstance() to allocate any Buffer that needs to |
| 461 // be passed back to the caller. Implementations must call Buffer::Destroy() | 468 // be passed back to the caller. Implementations must call Buffer::Destroy() |
| 462 // when a Buffer is created that will never be returned to the caller. | 469 // when a Buffer is created that will never be returned to the caller. |
| 463 class CDM_API ContentDecryptionModule_7 { | 470 class CDM_CLASS_API ContentDecryptionModule_7 { |
| 464 public: | 471 public: |
| 465 static const int kVersion = 7; | 472 static const int kVersion = 7; |
| 466 typedef Host_7 Host; | 473 typedef Host_7 Host; |
| 467 | 474 |
| 468 // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(), | 475 // SetServerCertificate(), CreateSessionAndGenerateRequest(), LoadSession(), |
| 469 // UpdateSession(), CloseSession(), and RemoveSession() all accept a | 476 // UpdateSession(), CloseSession(), and RemoveSession() all accept a |
| 470 // |promise_id|, which must be passed to the completion Host method | 477 // |promise_id|, which must be passed to the completion Host method |
| 471 // (e.g. Host::OnResolveNewSessionPromise()). | 478 // (e.g. Host::OnResolveNewSessionPromise()). |
| 472 | 479 |
| 473 // Provides a server certificate to be used to encrypt messages to the | 480 // Provides a server certificate to be used to encrypt messages to the |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 ContentDecryptionModule_7() {} | 639 ContentDecryptionModule_7() {} |
| 633 virtual ~ContentDecryptionModule_7() {} | 640 virtual ~ContentDecryptionModule_7() {} |
| 634 }; | 641 }; |
| 635 | 642 |
| 636 // ContentDecryptionModule interface that all CDMs need to implement. | 643 // ContentDecryptionModule interface that all CDMs need to implement. |
| 637 // The interface is versioned for backward compatibility. | 644 // The interface is versioned for backward compatibility. |
| 638 // Note: ContentDecryptionModule implementations must use the allocator | 645 // Note: ContentDecryptionModule implementations must use the allocator |
| 639 // provided in CreateCdmInstance() to allocate any Buffer that needs to | 646 // provided in CreateCdmInstance() to allocate any Buffer that needs to |
| 640 // be passed back to the caller. Implementations must call Buffer::Destroy() | 647 // be passed back to the caller. Implementations must call Buffer::Destroy() |
| 641 // when a Buffer is created that will never be returned to the caller. | 648 // when a Buffer is created that will never be returned to the caller. |
| 642 class CDM_API ContentDecryptionModule_8 { | 649 class CDM_CLASS_API ContentDecryptionModule_8 { |
| 643 public: | 650 public: |
| 644 static const int kVersion = 8; | 651 static const int kVersion = 8; |
| 645 typedef Host_8 Host; | 652 typedef Host_8 Host; |
| 646 | 653 |
| 647 // Initializes the CDM instance, providing information about permitted | 654 // Initializes the CDM instance, providing information about permitted |
| 648 // functionalities. | 655 // functionalities. |
| 649 // If |allow_distinctive_identifier| is false, messages from the CDM, | 656 // If |allow_distinctive_identifier| is false, messages from the CDM, |
| 650 // such as message events, must not contain a Distinctive Identifier, | 657 // such as message events, must not contain a Distinctive Identifier, |
| 651 // even in an encrypted form. | 658 // even in an encrypted form. |
| 652 // If |allow_persistent_state| is false, the CDM must not attempt to | 659 // If |allow_persistent_state| is false, the CDM must not attempt to |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 virtual void Destroy() = 0; | 824 virtual void Destroy() = 0; |
| 818 | 825 |
| 819 protected: | 826 protected: |
| 820 ContentDecryptionModule_8() {} | 827 ContentDecryptionModule_8() {} |
| 821 virtual ~ContentDecryptionModule_8() {} | 828 virtual ~ContentDecryptionModule_8() {} |
| 822 }; | 829 }; |
| 823 | 830 |
| 824 typedef ContentDecryptionModule_8 ContentDecryptionModule; | 831 typedef ContentDecryptionModule_8 ContentDecryptionModule; |
| 825 | 832 |
| 826 // Represents a buffer created by Allocator implementations. | 833 // Represents a buffer created by Allocator implementations. |
| 827 class CDM_API Buffer { | 834 class CDM_CLASS_API Buffer { |
| 828 public: | 835 public: |
| 829 // Destroys the buffer in the same context as it was created. | 836 // Destroys the buffer in the same context as it was created. |
| 830 virtual void Destroy() = 0; | 837 virtual void Destroy() = 0; |
| 831 | 838 |
| 832 virtual uint32_t Capacity() const = 0; | 839 virtual uint32_t Capacity() const = 0; |
| 833 virtual uint8_t* Data() = 0; | 840 virtual uint8_t* Data() = 0; |
| 834 virtual void SetSize(uint32_t size) = 0; | 841 virtual void SetSize(uint32_t size) = 0; |
| 835 virtual uint32_t Size() const = 0; | 842 virtual uint32_t Size() const = 0; |
| 836 | 843 |
| 837 protected: | 844 protected: |
| 838 Buffer() {} | 845 Buffer() {} |
| 839 virtual ~Buffer() {} | 846 virtual ~Buffer() {} |
| 840 | 847 |
| 841 private: | 848 private: |
| 842 Buffer(const Buffer&); | 849 Buffer(const Buffer&); |
| 843 void operator=(const Buffer&); | 850 void operator=(const Buffer&); |
| 844 }; | 851 }; |
| 845 | 852 |
| 846 class CDM_API Host_7 { | 853 class CDM_CLASS_API Host_7 { |
| 847 public: | 854 public: |
| 848 static const int kVersion = 7; | 855 static const int kVersion = 7; |
| 849 | 856 |
| 850 // Returns a Buffer* containing non-zero members upon success, or NULL on | 857 // Returns a Buffer* containing non-zero members upon success, or NULL on |
| 851 // failure. The caller owns the Buffer* after this call. The buffer is not | 858 // failure. The caller owns the Buffer* after this call. The buffer is not |
| 852 // guaranteed to be zero initialized. The capacity of the allocated Buffer | 859 // guaranteed to be zero initialized. The capacity of the allocated Buffer |
| 853 // is guaranteed to be not less than |capacity|. | 860 // is guaranteed to be not less than |capacity|. |
| 854 virtual Buffer* Allocate(uint32_t capacity) = 0; | 861 virtual Buffer* Allocate(uint32_t capacity) = 0; |
| 855 | 862 |
| 856 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms| | 863 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms| |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 973 // if a FileIO object cannot be obtained. Once a valid FileIO object is | 980 // if a FileIO object cannot be obtained. Once a valid FileIO object is |
| 974 // returned, |client| must be valid until FileIO::Close() is called. The | 981 // returned, |client| must be valid until FileIO::Close() is called. The |
| 975 // CDM can call this method multiple times to operate on different files. | 982 // CDM can call this method multiple times to operate on different files. |
| 976 virtual FileIO* CreateFileIO(FileIOClient* client) = 0; | 983 virtual FileIO* CreateFileIO(FileIOClient* client) = 0; |
| 977 | 984 |
| 978 protected: | 985 protected: |
| 979 Host_7() {} | 986 Host_7() {} |
| 980 virtual ~Host_7() {} | 987 virtual ~Host_7() {} |
| 981 }; | 988 }; |
| 982 | 989 |
| 983 class CDM_API Host_8 { | 990 class CDM_CLASS_API Host_8 { |
| 984 public: | 991 public: |
| 985 static const int kVersion = 8; | 992 static const int kVersion = 8; |
| 986 | 993 |
| 987 // Returns a Buffer* containing non-zero members upon success, or NULL on | 994 // Returns a Buffer* containing non-zero members upon success, or NULL on |
| 988 // failure. The caller owns the Buffer* after this call. The buffer is not | 995 // failure. The caller owns the Buffer* after this call. The buffer is not |
| 989 // guaranteed to be zero initialized. The capacity of the allocated Buffer | 996 // guaranteed to be zero initialized. The capacity of the allocated Buffer |
| 990 // is guaranteed to be not less than |capacity|. | 997 // is guaranteed to be not less than |capacity|. |
| 991 virtual Buffer* Allocate(uint32_t capacity) = 0; | 998 virtual Buffer* Allocate(uint32_t capacity) = 0; |
| 992 | 999 |
| 993 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms| | 1000 // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms| |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 // returned, |client| must be valid until FileIO::Close() is called. The | 1118 // returned, |client| must be valid until FileIO::Close() is called. The |
| 1112 // CDM can call this method multiple times to operate on different files. | 1119 // CDM can call this method multiple times to operate on different files. |
| 1113 virtual FileIO* CreateFileIO(FileIOClient* client) = 0; | 1120 virtual FileIO* CreateFileIO(FileIOClient* client) = 0; |
| 1114 | 1121 |
| 1115 protected: | 1122 protected: |
| 1116 Host_8() {} | 1123 Host_8() {} |
| 1117 virtual ~Host_8() {} | 1124 virtual ~Host_8() {} |
| 1118 }; | 1125 }; |
| 1119 | 1126 |
| 1120 // Represents a decrypted block that has not been decoded. | 1127 // Represents a decrypted block that has not been decoded. |
| 1121 class CDM_API DecryptedBlock { | 1128 class CDM_CLASS_API DecryptedBlock { |
| 1122 public: | 1129 public: |
| 1123 virtual void SetDecryptedBuffer(Buffer* buffer) = 0; | 1130 virtual void SetDecryptedBuffer(Buffer* buffer) = 0; |
| 1124 virtual Buffer* DecryptedBuffer() = 0; | 1131 virtual Buffer* DecryptedBuffer() = 0; |
| 1125 | 1132 |
| 1126 // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not, | 1133 // TODO(tomfinegan): Figure out if timestamp is really needed. If it is not, |
| 1127 // we can just pass Buffer pointers around. | 1134 // we can just pass Buffer pointers around. |
| 1128 virtual void SetTimestamp(int64_t timestamp) = 0; | 1135 virtual void SetTimestamp(int64_t timestamp) = 0; |
| 1129 virtual int64_t Timestamp() const = 0; | 1136 virtual int64_t Timestamp() const = 0; |
| 1130 | 1137 |
| 1131 protected: | 1138 protected: |
| 1132 DecryptedBlock() {} | 1139 DecryptedBlock() {} |
| 1133 virtual ~DecryptedBlock() {} | 1140 virtual ~DecryptedBlock() {} |
| 1134 }; | 1141 }; |
| 1135 | 1142 |
| 1136 class CDM_API VideoFrame { | 1143 class CDM_CLASS_API VideoFrame { |
| 1137 public: | 1144 public: |
| 1138 enum VideoPlane { | 1145 enum VideoPlane { |
| 1139 kYPlane = 0, | 1146 kYPlane = 0, |
| 1140 kUPlane = 1, | 1147 kUPlane = 1, |
| 1141 kVPlane = 2, | 1148 kVPlane = 2, |
| 1142 kMaxPlanes = 3, | 1149 kMaxPlanes = 3, |
| 1143 }; | 1150 }; |
| 1144 | 1151 |
| 1145 virtual void SetFormat(VideoFormat format) = 0; | 1152 virtual void SetFormat(VideoFormat format) = 0; |
| 1146 virtual VideoFormat Format() const = 0; | 1153 virtual VideoFormat Format() const = 0; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1169 // multiple audio output buffers, which are serialized into this format: | 1176 // multiple audio output buffers, which are serialized into this format: |
| 1170 // | 1177 // |
| 1171 // |<------------------- serialized audio buffer ------------------->| | 1178 // |<------------------- serialized audio buffer ------------------->| |
| 1172 // | int64_t timestamp | int64_t length | length bytes of audio data | | 1179 // | int64_t timestamp | int64_t length | length bytes of audio data | |
| 1173 // | 1180 // |
| 1174 // For example, with three audio output buffers, the AudioFrames will look | 1181 // For example, with three audio output buffers, the AudioFrames will look |
| 1175 // like this: | 1182 // like this: |
| 1176 // | 1183 // |
| 1177 // |<----------------- AudioFrames ------------------>| | 1184 // |<----------------- AudioFrames ------------------>| |
| 1178 // | audio buffer 0 | audio buffer 1 | audio buffer 2 | | 1185 // | audio buffer 0 | audio buffer 1 | audio buffer 2 | |
| 1179 class CDM_API AudioFrames { | 1186 class CDM_CLASS_API AudioFrames { |
| 1180 public: | 1187 public: |
| 1181 virtual void SetFrameBuffer(Buffer* buffer) = 0; | 1188 virtual void SetFrameBuffer(Buffer* buffer) = 0; |
| 1182 virtual Buffer* FrameBuffer() = 0; | 1189 virtual Buffer* FrameBuffer() = 0; |
| 1183 | 1190 |
| 1184 // The CDM must call this method, providing a valid format, when providing | 1191 // The CDM must call this method, providing a valid format, when providing |
| 1185 // frame buffers. Planar data should be stored end to end; e.g., | 1192 // frame buffers. Planar data should be stored end to end; e.g., |
| 1186 // |ch1 sample1||ch1 sample2|....|ch1 sample_last||ch2 sample1|... | 1193 // |ch1 sample1||ch1 sample2|....|ch1 sample_last||ch2 sample1|... |
| 1187 virtual void SetFormat(AudioFormat format) = 0; | 1194 virtual void SetFormat(AudioFormat format) = 0; |
| 1188 virtual AudioFormat Format() const = 0; | 1195 virtual AudioFormat Format() const = 0; |
| 1189 | 1196 |
| 1190 protected: | 1197 protected: |
| 1191 AudioFrames() {} | 1198 AudioFrames() {} |
| 1192 virtual ~AudioFrames() {} | 1199 virtual ~AudioFrames() {} |
| 1193 }; | 1200 }; |
| 1194 | 1201 |
| 1195 } // namespace cdm | 1202 } // namespace cdm |
| 1196 | 1203 |
| 1197 #endif // CDM_CONTENT_DECRYPTION_MODULE_H_ | 1204 #endif // CDM_CONTENT_DECRYPTION_MODULE_H_ |
| OLD | NEW |