11b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber/*
21b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * Copyright (C) 2012 The Android Open Source Project
31b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber *
41b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
51b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * you may not use this file except in compliance with the License.
61b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * You may obtain a copy of the License at
71b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber *
81b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
91b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber *
101b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * Unless required by applicable law or agreed to in writing, software
111b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
121b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * See the License for the specific language governing permissions and
141b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber * limitations under the License.
151b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber */
161b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
171b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber#include <binder/IInterface.h>
181b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber#include <media/hardware/HDCPAPI.h>
191b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber#include <media/stagefright/foundation/ABase.h>
20308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang#include <ui/GraphicBuffer.h>
211b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
221b19c9d120869c3182373a9b06a1ed98898df882Andreas Hubernamespace android {
231b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
241b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberstruct IHDCPObserver : public IInterface {
251b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    DECLARE_META_INTERFACE(HDCPObserver);
261b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
271b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual void notify(
281b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            int msg, int ext1, int ext2, const Parcel *obj) = 0;
291b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
301b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberprivate:
311b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(IHDCPObserver);
321b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber};
331b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
341b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberstruct IHDCP : public IInterface {
351b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    DECLARE_META_INTERFACE(HDCP);
361b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
371b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // Called to specify the observer that receives asynchronous notifications
381b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // from the HDCP implementation to signal completion/failure of asynchronous
391b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // operations (such as initialization) or out of band events.
401b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t setObserver(const sp<IHDCPObserver> &observer) = 0;
411b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
421b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // Request to setup an HDCP session with the specified host listening
431b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // on the specified port.
441b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t initAsync(const char *host, unsigned port) = 0;
451b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
461b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // Request to shutdown the active HDCP session.
471b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t shutdownAsync() = 0;
481b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
49ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    // Returns the capability bitmask of this HDCP session.
50ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    // Possible return values (please refer to HDCAPAPI.h):
51ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt
52ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   from an input byte-array buffer to an output byte-array buffer
53ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from
54ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   a native buffer to an output byte-array buffer. The format of the
55ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   input native buffer is specific to vendor's encoder implementation.
56ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   It is the same format as that used by the encoder when
57ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    //   "storeMetaDataInBuffers" extension is enabled on its output port.
58ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang    virtual uint32_t getCaps() = 0;
59ec3acca4a75fc4adc076b56751124f507b419622Chong Zhang
60a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // ENCRYPTION only:
61a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // Encrypt data according to the HDCP spec. "size" bytes of data are
62a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // available at "inData" (virtual address), "size" may not be a multiple
63a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // of 128 bits (16 bytes). An equal number of encrypted bytes should be
64a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // written to the buffer at "outData" (virtual address).
651b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // This operation is to be synchronous, i.e. this call does not return
661b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // until outData contains size bytes of encrypted data.
671b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // streamCTR will be assigned by the caller (to 0 for the first PES stream,
681b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    // 1 for the second and so on)
69a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
701b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t encrypt(
711b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            const void *inData, size_t size, uint32_t streamCTR,
721b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            uint64_t *outInputCTR, void *outData) = 0;
731b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
74308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // Encrypt data according to the HDCP spec. "size" bytes of data starting
75308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // at location "offset" are available in "buffer" (buffer handle). "size"
76308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // may not be a multiple of 128 bits (16 bytes). An equal number of
77308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // encrypted bytes should be written to the buffer at "outData" (virtual
78308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // address). This operation is to be synchronous, i.e. this call does not
79308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // return until outData contains size bytes of encrypted data.
80308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // streamCTR will be assigned by the caller (to 0 for the first PES stream,
81308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // 1 for the second and so on)
82308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
83308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang    virtual status_t encryptNative(
84308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang            const sp<GraphicBuffer> &graphicBuffer,
85308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang            size_t offset, size_t size, uint32_t streamCTR,
86308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang            uint64_t *outInputCTR, void *outData) = 0;
87308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang
88a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // DECRYPTION only:
89a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // Decrypt data according to the HDCP spec.
90a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // "size" bytes of encrypted data are available at "inData"
91a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
92a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // An equal number of decrypted bytes should be written to the buffer
93a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // at "outData" (virtual address).
94a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // This operation is to be synchronous, i.e. this call does not return
95a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // until outData contains size bytes of decrypted data.
96a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    // Both streamCTR and inputCTR will be provided by the caller.
97a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber    virtual status_t decrypt(
98a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber            const void *inData, size_t size,
99a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber            uint32_t streamCTR, uint64_t inputCTR,
100a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber            void *outData) = 0;
101a6a88d9c445e261972c2433254e0a996336e78a4Andreas Huber
1021b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberprivate:
1031b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    DISALLOW_EVIL_CONSTRUCTORS(IHDCP);
1041b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber};
1051b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
1061b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberstruct BnHDCPObserver : public BnInterface<IHDCPObserver> {
1071b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t onTransact(
1081b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            uint32_t code, const Parcel &data, Parcel *reply,
1091b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            uint32_t flags = 0);
1101b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber};
1111b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
1121b19c9d120869c3182373a9b06a1ed98898df882Andreas Huberstruct BnHDCP : public BnInterface<IHDCP> {
1131b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber    virtual status_t onTransact(
1141b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            uint32_t code, const Parcel &data, Parcel *reply,
1151b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber            uint32_t flags = 0);
1161b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber};
1171b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
1181b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber}  // namespace android
1191b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
1201b19c9d120869c3182373a9b06a1ed98898df882Andreas Huber
121