HDCPAPI.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2012 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef HDCP_API_H_
  17. #define HDCP_API_H_
  18. #include <utils/Errors.h>
  19. #include <system/window.h>
  20. namespace android {
  21. // Two different kinds of modules are covered under the same HDCPModule
  22. // structure below, a module either implements decryption or encryption.
  23. struct HDCPModule {
  24. typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
  25. // The msg argument in calls to the observer notification function.
  26. enum {
  27. // Sent in response to a call to "HDCPModule::initAsync" once
  28. // initialization has either been successfully completed,
  29. // i.e. the HDCP session is now fully setup (AKE, Locality Check,
  30. // SKE and any authentication with repeaters completed) or failed.
  31. // ext1 should be a suitable error code (status_t), ext2 is
  32. // unused for ENCRYPTION and in the case of HDCP_INITIALIZATION_COMPLETE
  33. // holds the local TCP port the module is listening on.
  34. HDCP_INITIALIZATION_COMPLETE,
  35. HDCP_INITIALIZATION_FAILED,
  36. // Sent upon completion of a call to "HDCPModule::shutdownAsync".
  37. // ext1 should be a suitable error code, ext2 is unused.
  38. HDCP_SHUTDOWN_COMPLETE,
  39. HDCP_SHUTDOWN_FAILED,
  40. HDCP_UNAUTHENTICATED_CONNECTION,
  41. HDCP_UNAUTHORIZED_CONNECTION,
  42. HDCP_REVOKED_CONNECTION,
  43. HDCP_TOPOLOGY_EXECEEDED,
  44. HDCP_UNKNOWN_ERROR,
  45. // DECRYPTION only: Indicates that a client has successfully connected,
  46. // a secure session established and the module is ready to accept
  47. // future calls to "decrypt".
  48. HDCP_SESSION_ESTABLISHED,
  49. };
  50. // HDCPModule capability bit masks
  51. enum {
  52. // HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt
  53. // from an input byte-array buffer to an output byte-array buffer
  54. HDCP_CAPS_ENCRYPT = (1 << 0),
  55. // HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from
  56. // a native buffer to an output byte-array buffer. The format of the
  57. // input native buffer is specific to vendor's encoder implementation.
  58. // It is the same format as that used by the encoder when
  59. // "storeMetaDataInBuffers" extension is enabled on its output port.
  60. HDCP_CAPS_ENCRYPT_NATIVE = (1 << 1),
  61. };
  62. // Module can call the notification function to signal completion/failure
  63. // of asynchronous operations (such as initialization) or out of band
  64. // events.
  65. HDCPModule(void *cookie, ObserverFunc observerNotify) {};
  66. virtual ~HDCPModule() {};
  67. // ENCRYPTION: Request to setup an HDCP session with the host specified
  68. // by addr and listening on the specified port.
  69. // DECRYPTION: Request to setup an HDCP session, addr is the interface
  70. // address the module should bind its socket to. port will be 0.
  71. // The module will pick the port to listen on itself and report its choice
  72. // in the "ext2" argument of the HDCP_INITIALIZATION_COMPLETE callback.
  73. virtual status_t initAsync(const char *addr, unsigned port) = 0;
  74. // Request to shutdown the active HDCP session.
  75. virtual status_t shutdownAsync() = 0;
  76. // Returns the capability bitmask of this HDCP session.
  77. virtual uint32_t getCaps() {
  78. return HDCP_CAPS_ENCRYPT;
  79. }
  80. // ENCRYPTION only:
  81. // Encrypt data according to the HDCP spec. "size" bytes of data are
  82. // available at "inData" (virtual address), "size" may not be a multiple
  83. // of 128 bits (16 bytes). An equal number of encrypted bytes should be
  84. // written to the buffer at "outData" (virtual address).
  85. // This operation is to be synchronous, i.e. this call does not return
  86. // until outData contains size bytes of encrypted data.
  87. // streamCTR will be assigned by the caller (to 0 for the first PES stream,
  88. // 1 for the second and so on)
  89. // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
  90. virtual status_t encrypt(
  91. const void *inData, size_t size, uint32_t streamCTR,
  92. uint64_t *outInputCTR, void *outData) {
  93. return INVALID_OPERATION;
  94. }
  95. // Encrypt data according to the HDCP spec. "size" bytes of data starting
  96. // at location "offset" are available in "buffer" (buffer handle). "size"
  97. // may not be a multiple of 128 bits (16 bytes). An equal number of
  98. // encrypted bytes should be written to the buffer at "outData" (virtual
  99. // address). This operation is to be synchronous, i.e. this call does not
  100. // return until outData contains size bytes of encrypted data.
  101. // streamCTR will be assigned by the caller (to 0 for the first PES stream,
  102. // 1 for the second and so on)
  103. // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
  104. virtual status_t encryptNative(
  105. buffer_handle_t buffer, size_t offset, size_t size,
  106. uint32_t streamCTR, uint64_t *outInputCTR, void *outData) {
  107. return INVALID_OPERATION;
  108. }
  109. // DECRYPTION only:
  110. // Decrypt data according to the HDCP spec.
  111. // "size" bytes of encrypted data are available at "inData"
  112. // (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
  113. // An equal number of decrypted bytes should be written to the buffer
  114. // at "outData" (virtual address).
  115. // This operation is to be synchronous, i.e. this call does not return
  116. // until outData contains size bytes of decrypted data.
  117. // Both streamCTR and inputCTR will be provided by the caller.
  118. virtual status_t decrypt(
  119. const void *inData, size_t size,
  120. uint32_t streamCTR, uint64_t inputCTR,
  121. void *outData) {
  122. return INVALID_OPERATION;
  123. }
  124. private:
  125. HDCPModule(const HDCPModule &);
  126. HDCPModule &operator=(const HDCPModule &);
  127. };
  128. } // namespace android
  129. // A shared library exporting the following methods should be included to
  130. // support HDCP functionality. The shared library must be called
  131. // "libstagefright_hdcp.so", it will be dynamically loaded into the
  132. // mediaserver process.
  133. extern "C" {
  134. // Create a module for ENCRYPTION.
  135. extern android::HDCPModule *createHDCPModule(
  136. void *cookie, android::HDCPModule::ObserverFunc);
  137. // Create a module for DECRYPTION.
  138. extern android::HDCPModule *createHDCPModuleForDecryption(
  139. void *cookie, android::HDCPModule::ObserverFunc);
  140. }
  141. #endif // HDCP_API_H_