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
17#ifndef HDCP_API_H_
18
19#define HDCP_API_H_
20
21#include <utils/Errors.h>
22
23namespace android {
24
25struct HDCPModule {
26    typedef void (*ObserverFunc)(void *cookie, int msg, int ext1, int ext2);
27
28    // The msg argument in calls to the observer notification function.
29    enum {
30        // Sent in response to a call to "HDCPModule::initAsync" once
31        // initialization has either been successfully completed,
32        // i.e. the HDCP session is now fully setup (AKE, Locality Check,
33        // SKE and any authentication with repeaters completed) or failed.
34        // ext1 should be a suitable error code (status_t), ext2 is
35        // unused.
36        HDCP_INITIALIZATION_COMPLETE,
37        HDCP_INITIALIZATION_FAILED,
38
39        // Sent upon completion of a call to "HDCPModule::shutdownAsync".
40        // ext1 should be a suitable error code, ext2 is unused.
41        HDCP_SHUTDOWN_COMPLETE,
42        HDCP_SHUTDOWN_FAILED,
43
44        HDCP_UNAUTHENTICATED_CONNECTION,
45        HDCP_UNAUTHORIZED_CONNECTION,
46        HDCP_REVOKED_CONNECTION,
47        HDCP_TOPOLOGY_EXECEEDED,
48        HDCP_UNKNOWN_ERROR,
49    };
50
51    // Module can call the notification function to signal completion/failure
52    // of asynchronous operations (such as initialization) or out of band
53    // events.
54    HDCPModule(void *cookie, ObserverFunc observerNotify) {};
55
56    virtual ~HDCPModule() {};
57
58    // Request to setup an HDCP session with the specified host listening
59    // on the specified port.
60    virtual status_t initAsync(const char *host, unsigned port) = 0;
61
62    // Request to shutdown the active HDCP session.
63    virtual status_t shutdownAsync() = 0;
64
65    // Encrypt a data according to the HDCP spec. The data is to be
66    // encrypted in-place, only size bytes of data should be read/write,
67    // even if the size is not a multiple of 128 bit (16 bytes).
68    // This operation is to be synchronous, i.e. this call does not return
69    // until outData contains size bytes of encrypted data.
70    // streamCTR will be assigned by the caller (to 0 for the first PES stream,
71    // 1 for the second and so on)
72    // inputCTR will be maintained by the callee for each PES stream.
73    virtual status_t encrypt(
74            const void *inData, size_t size, uint32_t streamCTR,
75            uint64_t *outInputCTR, void *outData) = 0;
76
77private:
78    HDCPModule(const HDCPModule &);
79    HDCPModule &operator=(const HDCPModule &);
80};
81
82}  // namespace android
83
84// A shared library exporting the following method should be included to
85// support HDCP functionality. The shared library must be called
86// "libstagefright_hdcp.so", it will be dynamically loaded into the
87// mediaserver process.
88extern "C" {
89    extern android::HDCPModule *createHDCPModule(
90            void *cookie, android::HDCPModule::ObserverFunc);
91}
92
93#endif  // HDCP_API_H_
94
95