HDCPAPI.h revision a8fc772b5b13e359fa73d5867c0f617b8eae4a41
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)(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
38        // Sent upon completion of a call to "HDCPModule::shutdownAsync".
39        // ext1 should be a suitable error code, ext2 is unused.
40        HDCP_SHUTDOWN_COMPLETE,
41    };
42
43    // Module can call the notification function to signal completion/failure
44    // of asynchronous operations (such as initialization) or out of band
45    // events.
46    HDCPModule(ObserverFunc observerNotify);
47
48    virtual ~HDCPModule();
49
50    // Request to setup an HDCP session with the specified host listening
51    // on the specified port.
52    virtual status_t initAsync(const char *host, unsigned port) = 0;
53
54    // Request to shutdown the active HDCP session.
55    virtual status_t shutdownAsync() = 0;
56
57    // Encrypt a data according to the HDCP spec. The data is to be
58    // encrypted in-place, only size bytes of data should be read/write,
59    // even if the size is not a multiple of 128 bit (16 bytes).
60    // This operation is to be synchronous, i.e. this call does not return
61    // until outData contains size bytes of encrypted data.
62    // streamCTR will be assigned by the caller (to 0 for the first PES stream,
63    // 1 for the second and so on)
64    // inputCTR will be maintained by the callee for each PES stream.
65    virtual status_t encrypt(
66            const void *inData, size_t size, uint32_t streamCTR,
67            uint64_t *outInputCTR, void *outData) = 0;
68
69private:
70    HDCPModule(const HDCPModule &);
71    HDCPModule &operator=(const HDCPModule &);
72};
73
74}  // namespace android
75
76// A shared library exporting the following method should be included to
77// support HDCP functionality. The shared library must be called
78// "libstagefright_hdcp.so", it will be dynamically loaded into the
79// mediaserver process.
80extern "C" {
81    extern android::HDCPModule *createHDCPModule();
82}
83
84#endif  // HDCP_API_H_
85
86