1 #pragma once
2 
3 //Functionality wich is supported by the Decrypter
4 class AP4_CencSingleSampleDecrypter;
5 class AP4_DataBuffer;
6 
7 namespace SSD
8 {
9   struct SSD_PICTURE;
10 
11   //Functionality wich is supported by the Addon
12   class SSD_HOST
13   {
14   public:
15     enum CURLOPTIONS
16     {
17       OPTION_PROTOCOL,
18       OPTION_HEADER
19     };
20     enum CURLPROPERTY
21     {
22       PROPERTY_HEADER
23   };
24     static const uint32_t version = 13;
25 #if defined(ANDROID)
26     virtual void* GetJNIEnv() = 0;
27     virtual int GetSDKVersion() = 0;
28     virtual const char *GetClassName() = 0;
29 #endif
30     virtual const char *GetLibraryPath() const = 0;
31     virtual const char *GetProfilePath() const = 0;
32     virtual void* CURLCreate(const char* strURL) = 0;
33     virtual bool CURLAddOption(void* file, CURLOPTIONS opt, const char* name, const char* value) = 0;
34     virtual const char* CURLGetProperty(void* file, CURLPROPERTY prop, const char *name) = 0;
35     virtual bool CURLOpen(void* file) = 0;
36     virtual size_t ReadFile(void* file, void* lpBuf, size_t uiBufSize) = 0;
37     virtual void CloseFile(void* file) = 0;
38     virtual bool CreateDir(const char* dir) = 0;
39     virtual bool GetBuffer(void* instance, SSD_PICTURE &picture) = 0;
40     virtual void ReleaseBuffer(void* instance, void *buffer) = 0;
41 
42     enum LOGLEVEL
43     {
44       LL_DEBUG,
45       LL_INFO,
46       LL_ERROR
47     };
48 
49     virtual void Log(LOGLEVEL level, const char *msg) = 0;
50   };
51 
52   /****************************************************************************************************/
53   // keep those values in track with xbmc\addons\kodi-addon-dev-kit\include\kodi\kodi_videocodec_types.h
54   /****************************************************************************************************/
55 
56   enum SSD_VIDEOFORMAT
57   {
58     UnknownVideoFormat = 0,
59     VideoFormatYV12,
60     VideoFormatI420,
61     MaxVideoFormats
62   };
63 
64   struct SSD_VIDEOINITDATA
65   {
66     enum Codec {
67       CodecUnknown = 0,
68       CodecVp8,
69       CodecH264,
70       CodecVp9
71     } codec;
72 
73     enum CodecProfile
74     {
75       CodecProfileUnknown = 0,
76       CodecProfileNotNeeded,
77       H264CodecProfileBaseline,
78       H264CodecProfileMain,
79       H264CodecProfileExtended,
80       H264CodecProfileHigh,
81       H264CodecProfileHigh10,
82       H264CodecProfileHigh422,
83       H264CodecProfileHigh444Predictive
84     } codecProfile;
85 
86     const SSD_VIDEOFORMAT *videoFormats;
87 
88     uint32_t width, height;
89 
90     const uint8_t *extraData;
91     unsigned int extraDataSize;
92   };
93 
94   struct SSD_PICTURE
95   {
96     enum VideoPlane {
97       YPlane = 0,
98       UPlane,
99       VPlane,
100       MaxPlanes = 3,
101     };
102 
103     enum Flags : uint32_t
104     {
105       FLAG_NONE = 0,
106       FLAG_DROP = (1 << 0),
107       FLAG_DRAIN = (1 << 1),
108     };
109 
110     SSD_VIDEOFORMAT videoFormat;
111     uint32_t flags;
112 
113     uint32_t width, height;
114 
115     uint8_t *decodedData;
116     size_t decodedDataSize;
117 
118     uint32_t planeOffsets[VideoPlane::MaxPlanes];
119     uint32_t stride[VideoPlane::MaxPlanes];
120 
121     int64_t pts;
122 
123     void *buffer;
124   };
125 
126   typedef struct SSD_SAMPLE
127   {
128     const uint8_t *data;
129     uint32_t dataSize;
130 
131     int64_t pts;
132 
133     uint16_t numSubSamples; //number of subsamples
134     uint16_t flags; //flags for later use
135 
136     uint16_t *clearBytes; // numSubSamples uint16_t's wich define the size of clear size of a subsample
137     uint32_t *cipherBytes; // numSubSamples uint32_t's wich define the size of cipher size of a subsample
138 
139     uint8_t *iv;  // initialization vector
140     uint8_t *kid; // key id
141   } SSD_SAMPLE;
142 
143   enum SSD_DECODE_RETVAL
144   {
145     VC_NONE = 0,        //< noop
146     VC_ERROR,           //< an error occured, no other messages will be returned
147     VC_BUFFER,          //< the decoder needs more data
148     VC_PICTURE,         //< the decoder got a picture
149     VC_EOF,             //< the decoder signals EOF
150   };
151 
152   class SSD_DECRYPTER
153   {
154   public:
155     struct SSD_CAPS
156     {
157       static const uint32_t SSD_SUPPORTS_DECODING = 1;
158       static const uint32_t SSD_SECURE_PATH = 2;
159       static const uint32_t SSD_ANNEXB_REQUIRED = 4;
160       static const uint32_t SSD_HDCP_RESTRICTED = 8;
161       static const uint32_t SSD_SINGLE_DECRYPT = 16;
162       static const uint32_t SSD_SECURE_DECODER = 32;
163       static const uint32_t SSD_INVALID = 64;
164 
165       static const uint32_t SSD_MEDIA_VIDEO = 1;
166       static const uint32_t SSD_MEDIA_AUDIO = 2;
167 
168       uint16_t flags;
169 
170       /* The following 2 fields are set as followed:
171       - If licenseresponse return hdcp information, hdcpversion is 0 and
172       hdcplimit either 0 (if hdcp is supported) or given value (if hdcpversion is not supported)
173       - if no hdcp information is passed in licenseresponse, we set hdcpversion to the value we support
174       manifest / representation have to check if they are allowed to be played.
175       */
176       uint16_t hdcpVersion; //The HDCP version streams has to be restricted 0,10,20,21,22.....
177       uint32_t hdcpLimit; // If set, streams wich wxh > this value cannot be played.
178     };
179 
180     static const uint8_t CONFIG_PERSISTENTSTORAGE = 1;
181 
182     // Return supported URN if type matches to capabilities, otherwise null
183     virtual const char *SelectKeySytem(const char* keySystem) = 0;
184     virtual bool OpenDRMSystem(const char *licenseURL, const AP4_DataBuffer &serverCertificate, const uint8_t config) = 0;
185     virtual AP4_CencSingleSampleDecrypter *CreateSingleSampleDecrypter(AP4_DataBuffer &pssh, const char *optionalKeyParameter, const uint8_t *defaultkeyid, bool skipSessionMessage) = 0;
186     virtual void DestroySingleSampleDecrypter(AP4_CencSingleSampleDecrypter* decrypter) = 0;
187 
188     virtual void GetCapabilities(AP4_CencSingleSampleDecrypter* decrypter, const uint8_t *keyid, uint32_t media, SSD_DECRYPTER::SSD_CAPS &caps) = 0;
189     virtual bool HasLicenseKey(AP4_CencSingleSampleDecrypter* decrypter, const uint8_t *keyid) = 0;
190     virtual bool HasCdmSession() = 0;
191     virtual std::string GetChallengeB64Data(AP4_CencSingleSampleDecrypter* decrypter) = 0;
192 
193     virtual bool OpenVideoDecoder(AP4_CencSingleSampleDecrypter* decrypter, const SSD_VIDEOINITDATA *initData) = 0;
194     virtual SSD_DECODE_RETVAL DecodeVideo(void* instance, SSD_SAMPLE *sample, SSD_PICTURE *picture) = 0;
195     virtual void ResetVideo() = 0;
196   };
197 }; // namespace
198