1 /* 2 * Copyright (C) 2017-2018 Team Kodi 3 * This file is part of Kodi - https://kodi.tv 4 * 5 * SPDX-License-Identifier: GPL-2.0-or-later 6 * See LICENSES/README.md for more information. 7 */ 8 9 #ifndef C_API_ADDONINSTANCE_VIDEOCODEC_H 10 #define C_API_ADDONINSTANCE_VIDEOCODEC_H 11 12 #include "../addon_base.h" 13 #include "inputstream/demux_packet.h" 14 #include "inputstream/stream_codec.h" 15 #include "inputstream/stream_crypto.h" 16 17 #ifdef __cplusplus 18 extern "C" 19 { 20 #endif /* __cplusplus */ 21 22 //============================================================================ 23 /// @ingroup cpp_kodi_addon_videocodec_Defs 24 /// @brief Return values used by video decoder interface 25 enum VIDEOCODEC_RETVAL 26 { 27 /// @brief Noop 28 VC_NONE = 0, 29 30 /// @brief An error occured, no other messages will be returned 31 VC_ERROR, 32 33 /// @brief The decoder needs more data 34 VC_BUFFER, 35 36 /// @brief The decoder got a picture 37 VC_PICTURE, 38 39 /// @brief The decoder signals EOF 40 VC_EOF, 41 }; 42 //---------------------------------------------------------------------------- 43 44 //============================================================================ 45 /// @ingroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata 46 /// @brief The video stream representations requested by Kodi 47 /// 48 enum VIDEOCODEC_FORMAT 49 { 50 /// @brief Unknown types, this is used to declare the end of a list of 51 /// requested types 52 VIDEOCODEC_FORMAT_UNKNOWN = 0, 53 54 /// @brief YV12 4:2:0 YCrCb planar format 55 VIDEOCODEC_FORMAT_YV12, 56 57 /// @brief These formats are identical to YV12 except that the U and V plane 58 /// order is reversed. 59 VIDEOCODEC_FORMAT_I420, 60 61 /// @brief The maximum value to use in a list. 62 VIDEOCODEC_FORMAT_MAXFORMATS 63 }; 64 //---------------------------------------------------------------------------- 65 66 //============================================================================ 67 /// @ingroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata 68 /// @brief Video codec types that can be requested from Kodi 69 /// 70 enum VIDEOCODEC_TYPE 71 { 72 /// @brief Unknown or other type requested 73 /// 74 VIDEOCODEC_UNKNOWN = 0, 75 76 /// @brief [VP8](https://en.wikipedia.org/wiki/VP8) video coding format 77 /// 78 VIDEOCODEC_VP8, 79 80 /// @brief [Advanced Video Coding (AVC)](https://en.wikipedia.org/wiki/Advanced_Video_Coding), 81 /// also referred to as H.264 or [MPEG-4](https://en.wikipedia.org/wiki/MPEG-4) 82 /// Part 10, Advanced Video Coding (MPEG-4 AVC). 83 VIDEOCODEC_H264, 84 85 /// @brief [VP9](https://en.wikipedia.org/wiki/VP9) video coding format\n 86 /// \n 87 /// VP9 is the successor to VP8 and competes mainly with MPEG's 88 /// [High Efficiency Video Coding](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding) 89 /// (HEVC/H.265). 90 VIDEOCODEC_VP9 91 }; 92 //---------------------------------------------------------------------------- 93 94 //============================================================================ 95 /// @ingroup cpp_kodi_addon_videocodec_Defs_VIDEOCODEC_PICTURE 96 /// @brief YUV Plane identification pointers 97 /// 98 /// YUV is a color encoding system typically used as part of a color image pipeline. 99 /// 100 /// These are used to access stored data in @ref VIDEOCODEC_PICTURE::planeOffsets 101 /// and @ref VIDEOCODEC_PICTURE::stride. 102 /// 103 enum VIDEOCODEC_PLANE 104 { 105 /// @brief "luminance" component Y (equivalent to grey scale) 106 VIDEOCODEC_PICTURE_Y_PLANE = 0, 107 108 /// @brief "chrominance" component U (blue projection) 109 VIDEOCODEC_PICTURE_U_PLANE, 110 111 /// @brief "chrominance" component V (red projection) 112 VIDEOCODEC_PICTURE_V_PLANE, 113 114 /// @brief The maximum value to use in a list. 115 VIDEOCODEC_PICTURE_MAXPLANES = 3, 116 }; 117 //---------------------------------------------------------------------------- 118 119 //============================================================================ 120 /// @ingroup cpp_kodi_addon_videocodec_Defs_VIDEOCODEC_PICTURE 121 /// @brief Video coded process flags, used to perform special operations in 122 /// stream calls. 123 /// 124 /// These are used to access stored data in @ref VIDEOCODEC_PICTURE::flags. 125 /// 126 /// @note These variables are bit flags which are created using "|" can be used together. 127 /// 128 enum VIDEOCODEC_PICTURE_FLAG 129 { 130 /// @brief Empty and nothing defined 131 VIDEOCODEC_PICTURE_FLAG_NONE = 0, 132 133 /// @brief Drop in decoder 134 VIDEOCODEC_PICTURE_FLAG_DROP = (1 << 0), 135 136 /// @brief Squeeze out pictured without feeding new packets 137 VIDEOCODEC_PICTURE_FLAG_DRAIN = (1 << 1), 138 }; 139 //---------------------------------------------------------------------------- 140 141 //============================================================================ 142 /// @defgroup cpp_kodi_addon_videocodec_Defs_VIDEOCODEC_PICTURE struct VIDEOCODEC_PICTURE 143 /// @ingroup cpp_kodi_addon_videocodec_Defs 144 /// @brief Data structure which is given to the addon when a decoding call is made. 145 /// 146 ///@{ 147 struct VIDEOCODEC_PICTURE 148 { 149 /// @brief The video format declared with @ref VIDEOCODEC_FORMAT and to be 150 /// used on the addon. 151 enum VIDEOCODEC_FORMAT videoFormat; 152 153 /// @brief Video coded process flags, used to perform special operations in 154 /// stream calls. 155 /// 156 /// Possible flags are declared here @ref VIDEOCODEC_PICTURE_FLAGS. 157 uint32_t flags; 158 159 /// @brief Picture width. 160 uint32_t width; 161 162 /// @brief Picture height. 163 uint32_t height; 164 165 /// @brief Data to be decoded in the addon. 166 uint8_t* decodedData; 167 168 /// @brief Size of the data given with @ref decodedData 169 size_t decodedDataSize; 170 171 /// @brief YUV color plane calculation array. 172 /// 173 /// This includes the three values of the YUV and can be identified using 174 /// @ref VIDEOCODEC_PLANE. 175 uint32_t planeOffsets[VIDEOCODEC_PICTURE_MAXPLANES]; 176 177 /// @brief YUV color stride calculation array 178 /// 179 /// This includes the three values of the YUV and can be identified using 180 /// @ref VIDEOCODEC_PLANE. 181 uint32_t stride[VIDEOCODEC_PICTURE_MAXPLANES]; 182 183 /// @brief Picture presentation time stamp (PTS). 184 int64_t pts; 185 186 /// @brief This is used to save the related handle from Kodi. 187 /// 188 /// To handle the input stream buffer, this is given by Kodi using 189 /// @ref kodi::addon::CInstanceVideoCodec::GetFrameBuffer and must be 190 /// released again using @ref kodi::addon::CInstanceVideoCodec::ReleaseFrameBuffer. 191 KODI_HANDLE videoBufferHandle; 192 }; 193 ///@} 194 //---------------------------------------------------------------------------- 195 196 struct VIDEOCODEC_INITDATA 197 { 198 enum VIDEOCODEC_TYPE codec; 199 enum STREAMCODEC_PROFILE codecProfile; 200 enum VIDEOCODEC_FORMAT* videoFormats; 201 uint32_t width; 202 uint32_t height; 203 const uint8_t* extraData; 204 unsigned int extraDataSize; 205 struct STREAM_CRYPTO_SESSION cryptoSession; 206 }; 207 208 // this are properties given to the addon on create 209 // at this time we have no parameters for the addon 210 typedef struct AddonProps_VideoCodec 211 { 212 int dummy; 213 } AddonProps_VideoCodec; 214 215 struct AddonInstance_VideoCodec; 216 typedef struct KodiToAddonFuncTable_VideoCodec 217 { 218 KODI_HANDLE addonInstance; 219 220 //! @brief Opens a codec 221 bool(__cdecl* open)(const struct AddonInstance_VideoCodec* instance, 222 struct VIDEOCODEC_INITDATA* initData); 223 224 //! @brief Reconfigures a codec 225 bool(__cdecl* reconfigure)(const struct AddonInstance_VideoCodec* instance, 226 struct VIDEOCODEC_INITDATA* initData); 227 228 //! @brief Feed codec if requested from GetPicture() (return VC_BUFFER) 229 bool(__cdecl* add_data)(const struct AddonInstance_VideoCodec* instance, 230 const struct DEMUX_PACKET* packet); 231 232 //! @brief Get a decoded picture / request new data 233 enum VIDEOCODEC_RETVAL(__cdecl* get_picture)(const struct AddonInstance_VideoCodec* instance, 234 struct VIDEOCODEC_PICTURE* picture); 235 236 //! @brief Get the name of this video decoder 237 const char*(__cdecl* get_name)(const struct AddonInstance_VideoCodec* instance); 238 239 //! @brief Reset the codec 240 void(__cdecl* reset)(const struct AddonInstance_VideoCodec* instance); 241 } KodiToAddonFuncTable_VideoCodec; 242 243 typedef struct AddonToKodiFuncTable_VideoCodec 244 { 245 KODI_HANDLE kodiInstance; 246 bool (*get_frame_buffer)(void* kodiInstance, struct VIDEOCODEC_PICTURE* picture); 247 void (*release_frame_buffer)(void* kodiInstance, void* buffer); 248 } AddonToKodiFuncTable_VideoCodec; 249 250 typedef struct AddonInstance_VideoCodec 251 { 252 struct AddonProps_VideoCodec* props; 253 struct AddonToKodiFuncTable_VideoCodec* toKodi; 254 struct KodiToAddonFuncTable_VideoCodec* toAddon; 255 } AddonInstance_VideoCodec; 256 257 #ifdef __cplusplus 258 } /* extern "C" */ 259 #endif /* __cplusplus */ 260 261 #endif /* !C_API_ADDONINSTANCE_VIDEOCODEC_H */ 262