summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2021-03-04 23:36:40 +0100
committermanuel <manuel@mausz.at>2021-03-04 23:36:40 +0100
commit3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f (patch)
tree921f4829b32126f80f9113c124f2e14c0ebce8d9 /xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
parentbe933ef2241d79558f91796cc5b3a161f72ebf9c (diff)
downloadkodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.tar.gz
kodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.tar.bz2
kodi-pvr-build-3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f.zip
sync with upstreamMatrix
Diffstat (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h')
-rw-r--r--xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h651
1 files changed, 433 insertions, 218 deletions
diff --git a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
index 12893db..7cf58a0 100644
--- a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
@@ -9,241 +9,456 @@
9#pragma once 9#pragma once
10 10
11#include "../AddonBase.h" 11#include "../AddonBase.h"
12#include "../StreamCrypto.h" 12#include "../c-api/addon-instance/video_codec.h"
13#include "../StreamCodec.h" 13#include "inputstream/DemuxPacket.h"
14#include "inputstream/StreamCodec.h"
15#include "inputstream/StreamCrypto.h"
14 16
15#ifdef BUILD_KODI_ADDON 17#ifdef __cplusplus
16#include "../DemuxPacket.h"
17#else
18#include "cores/VideoPlayer/Interface/Addon/DemuxPacket.h"
19#endif
20 18
21extern "C" 19namespace kodi
20{
21namespace addon
22{ 22{
23 enum VIDEOCODEC_FORMAT
24 {
25 UnknownVideoFormat = 0,
26 VideoFormatYV12,
27 VideoFormatI420,
28 MaxVideoFormats
29 };
30
31 23
32 struct VIDEOCODEC_INITDATA 24class CInstanceVideoCodec;
25
26//==============================================================================
27/// @defgroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata class VideoCodecInitdata
28/// @ingroup cpp_kodi_addon_videocodec_Defs
29/// @brief Initialization data to open a video codec stream.
30///
31/// ----------------------------------------------------------------------------
32///
33/// @copydetails cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata_Help
34///
35///@{
36class ATTRIBUTE_HIDDEN VideoCodecInitdata
37 : public CStructHdl<VideoCodecInitdata, VIDEOCODEC_INITDATA>
38{
39 /*! \cond PRIVATE */
40 friend class CInstanceVideoCodec;
41 /*! \endcond */
42
43public:
44 /// @defgroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata_Help Value Help
45 /// @ingroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata
46 ///
47 /// <b>The following table contains values that can be set with @ref cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata :</b>
48 /// | Name | Type | Get call
49 /// |------|------|----------
50 /// | **Codec type** | `VIDEOCODEC_TYPE` | @ref VideoCodecInitdata::GetCodecType "GetCodecType"
51 /// | **Codec profile** | `STREAMCODEC_PROFILE` | @ref VideoCodecInitdata::GetCodecProfile "GetCodecProfile"
52 /// | **Video formats** | `std::vector<VIDEOCODEC_FORMAT>` | @ref VideoCodecInitdata::GetVideoFormats "GetVideoFormats"
53 /// | **Width** | `uint32_t` | @ref VideoCodecInitdata::GetWidth "GetWidth"
54 /// | **Height** | `uint32_t` | @ref VideoCodecInitdata::GetHeight "GetHeight"
55 /// | **Extra data** | `const uint8_t*` | @ref VideoCodecInitdata::GetExtraData "GetExtraData"
56 /// | **Extra data size** | `unsigned int` | @ref VideoCodecInitdata::GetExtraDataSize "GetExtraDataSize"
57 /// | **Crypto session** | `kodi::addon::StreamCryptoSession` | @ref VideoCodecInitdata::GetCryptoSession "GetCryptoSession"
58 ///
59
60 /// @addtogroup cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata
61 ///@{
62
63 /// @brief The codec type required by Kodi to process the stream.
64 ///
65 /// See @ref VIDEOCODEC_TYPE for possible values.
66 VIDEOCODEC_TYPE GetCodecType() const { return m_cStructure->codec; }
67
68 /// @brief Used profiles for non-scalable 2D video
69 STREAMCODEC_PROFILE GetCodecProfile() const { return m_cStructure->codecProfile; }
70
71 /// @brief The video stream representations requested by Kodi
72 ///
73 /// This contains a list of the required video formats. One of them has to
74 /// select the addon to return the created image.
75 ///
76 std::vector<VIDEOCODEC_FORMAT> GetVideoFormats() const
33 { 77 {
34 enum Codec { 78 std::vector<VIDEOCODEC_FORMAT> formats;
35 CodecUnknown = 0, 79 unsigned int i = 0;
36 CodecVp8, 80 while (i < VIDEOCODEC_FORMAT_MAXFORMATS &&
37 CodecH264, 81 m_cStructure->videoFormats[i] != VIDEOCODEC_FORMAT_UNKNOWN)
38 CodecVp9 82 formats.emplace_back(m_cStructure->videoFormats[i++]);
39 } codec; 83 if (formats.empty())
40 84 formats.emplace_back(VIDEOCODEC_FORMAT_UNKNOWN);
41 STREAMCODEC_PROFILE codecProfile; 85 return formats;
42 86 }
43 //UnknownVideoFormat is terminator 87
44 VIDEOCODEC_FORMAT *videoFormats; 88 /// @brief Picture width.
45 89 uint32_t GetWidth() const { return m_cStructure->width; }
46 uint32_t width, height; 90
47 91 /// @brief Picture height.
48 const uint8_t *extraData; 92 uint32_t GetHeight() const { return m_cStructure->height; }
49 unsigned int extraDataSize; 93
50 94 /// @brief Depending on the required decoding, additional data given by the stream.
51 CRYPTO_INFO cryptoInfo; 95 const uint8_t* GetExtraData() const { return m_cStructure->extraData; }
52 }; 96
53 97 /// @brief Size of the data given with @ref extraData.
54 struct VIDEOCODEC_PICTURE 98 unsigned int GetExtraDataSize() const { return m_cStructure->extraDataSize; }
99
100 /// @brief **Data to manage stream cryptography**\n
101 /// To get class structure manages any encryption values required in order to have
102 /// them available in their stream processing.
103 ///
104 /// ----------------------------------------------------------------------------
105 ///
106 /// @copydetails cpp_kodi_addon_inputstream_Defs_Info_StreamCryptoSession_Help
107 ///
108 kodi::addon::StreamCryptoSession GetCryptoSession() const { return &m_cStructure->cryptoSession; }
109
110 ///@}
111
112private:
113 VideoCodecInitdata() = delete;
114 VideoCodecInitdata(const VideoCodecInitdata& session) : CStructHdl(session) {}
115 VideoCodecInitdata(const VIDEOCODEC_INITDATA* session) : CStructHdl(session) {}
116 VideoCodecInitdata(VIDEOCODEC_INITDATA* session) : CStructHdl(session) {}
117};
118///@}
119//------------------------------------------------------------------------------
120
121//##############################################################################
122/// @defgroup cpp_kodi_addon_videocodec_Defs Definitions, structures and enumerators
123/// @ingroup cpp_kodi_addon_videocodec
124/// @brief **Video codec add-on general variables**
125///
126/// Used to exchange the available options between Kodi and addon.
127///
128///
129
130//============================================================================
131///
132/// @addtogroup cpp_kodi_addon_videocodec
133/// @brief \cpp_class{ kodi::addon::CInstanceVideoCodec }
134/// **Video codec add-on instance**
135///
136/// This is an addon instance class to add an additional video decoder to Kodi
137/// using addon.
138///
139/// This means that either a new type of decoding can be introduced to an input
140/// stream add-on that requires special types of decoding.
141///
142/// When using the inputstream addon, @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo
143/// to @ref cpp_kodi_addon_inputstream_Defs_Info is used to declare that the
144/// decoder stored in the addon is used.
145///
146/// @note At the moment this can only be used together with input stream addons,
147/// independent use as a codec addon is not yet possible.
148///
149/// Include the header @ref VideoCodec.h "#include <kodi/addon-instance/VideoCodec.h>"
150/// to use this class.
151///
152/// --------------------------------------------------------------------------
153///
154/// **Example:**
155/// This as an example when used together with @ref cpp_kodi_addon_inputstream "kodi::addon::CInstanceInputStream".
156///
157/// ~~~~~~~~~~~~~{.cpp}
158/// #include <kodi/addon-instance/Inputstream.h>
159/// #include <kodi/addon-instance/VideoCodec.h>
160///
161/// class CMyVideoCodec : public kodi::addon::CInstanceVideoCodec
162/// {
163/// public:
164/// CMyVideoCodec(KODI_HANDLE instance, CMyInputstream* inputstream);
165/// ...
166///
167/// private:
168/// CMyInputstream* m_inputstream;
169/// };
170///
171/// CMyVideoCodec::CMyVideoCodec(KODI_HANDLE instance,
172/// const std::string& version,
173/// CMyInputstream* inputstream)
174/// : kodi::addon::CInstanceVideoCodec(instance, version),
175/// m_inputstream(inputstream)
176/// {
177/// ...
178/// }
179/// ...
180///
181/// //----------------------------------------------------------------------
182///
183/// class CMyInputstream : public kodi::addon::CInstanceInputStream
184/// {
185/// public:
186/// CMyInputstream(KODI_HANDLE instance, const std::string& kodiVersion);
187///
188/// ADDON_STATUS CreateInstance(int instanceType,
189/// std::string instanceID,
190/// KODI_HANDLE instance,
191/// const std::string& version,
192/// KODI_HANDLE& addonInstance) override;
193/// ...
194/// };
195///
196/// CMyInputstream::CMyInputstream(KODI_HANDLE instance, const std::string& kodiVersion)
197/// : kodi::addon::CInstanceInputStream(instance, kodiVersion)
198/// {
199/// ...
200/// }
201///
202/// ADDON_STATUS CMyInputstream::CreateInstance(int instanceType,
203/// std::string instanceID,
204/// KODI_HANDLE instance,
205/// const std::string& version,
206/// KODI_HANDLE& addonInstance)
207/// {
208/// if (instanceType == ADDON_INSTANCE_VIDEOCODEC)
209/// {
210/// addonInstance = new CMyVideoCodec(instance, version, this);
211/// return ADDON_STATUS_OK;
212/// }
213/// return ADDON_STATUS_NOT_IMPLEMENTED;
214/// }
215///
216/// ...
217///
218/// //----------------------------------------------------------------------
219///
220/// class CMyAddon : public kodi::addon::CAddonBase
221/// {
222/// public:
223/// CMyAddon() { }
224/// ADDON_STATUS CreateInstance(int instanceType,
225/// std::string instanceID,
226/// KODI_HANDLE instance,
227/// const std::string& version,
228/// KODI_HANDLE& addonInstance) override;
229/// };
230///
231/// // If you use only one instance in your add-on, can be instanceType and
232/// // instanceID ignored
233/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType,
234/// std::string instanceID,
235/// KODI_HANDLE instance,
236/// const std::string& version,
237/// KODI_HANDLE& addonInstance)
238/// {
239/// if (instanceType == ADDON_INSTANCE_INPUTSTREAM)
240/// {
241/// kodi::Log(ADDON_LOG_NOTICE, "Creating my Inputstream");
242/// addonInstance = new CMyInputstream(instance, version);
243/// return ADDON_STATUS_OK;
244/// }
245/// else if (...)
246/// {
247/// ...
248/// }
249/// return ADDON_STATUS_UNKNOWN;
250/// }
251///
252/// ADDONCREATOR(CMyAddon)
253/// ~~~~~~~~~~~~~
254///
255/// The destruction of the example class `CMyInputstream` is called from
256/// Kodi's header. Manually deleting the add-on instance is not required.
257///
258///
259class ATTRIBUTE_HIDDEN CInstanceVideoCodec : public IAddonInstance
260{
261public:
262 //============================================================================
263 /// @ingroup cpp_kodi_addon_videocodec
264 /// @brief Video codec class constructor used to support multiple instance
265 /// types
266 ///
267 /// @param[in] instance The instance value given to <b>`kodi::addon::CAddonBase::CreateInstance(...)`</b>,
268 /// or by a inputstream instance if them declared as parent.
269 /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to
270 /// allow compatibility to older Kodi versions.
271 ///
272 explicit CInstanceVideoCodec(KODI_HANDLE instance, const std::string& kodiVersion = "")
273 : IAddonInstance(ADDON_INSTANCE_VIDEOCODEC,
274 !kodiVersion.empty() ? kodiVersion
275 : GetKodiTypeVersion(ADDON_INSTANCE_VIDEOCODEC))
55 { 276 {
56 enum VideoPlane { 277 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
57 YPlane = 0, 278 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation of multiple together with "
58 UPlane, 279 "single instance way is not allowed!");
59 VPlane, 280
60 MaxPlanes = 3, 281 SetAddonStruct(instance);
61 }; 282 }
62 283 //----------------------------------------------------------------------------
63 enum Flags : uint32_t { 284
64 FLAG_DROP, 285 //============================================================================
65 FLAG_DRAIN 286 /// @ingroup cpp_kodi_addon_videocodec
66 }; 287 /// @brief Destructor
67 288 ///
68 VIDEOCODEC_FORMAT videoFormat; 289 ~CInstanceVideoCodec() override = default;
69 uint32_t flags; 290 //----------------------------------------------------------------------------
70 291
71 uint32_t width, height; 292 //============================================================================
72 293 /// @ingroup cpp_kodi_addon_videocodec
73 uint8_t *decodedData; 294 /// @brief Open the decoder, returns true on success
74 size_t decodedDataSize; 295 ///
75 296 /// Decoders not capable of running multiple instances should return false in case
76 uint32_t planeOffsets[VideoPlane::MaxPlanes]; 297 /// there is already a instance open.
77 uint32_t stride[VideoPlane::MaxPlanes]; 298 ///
78 299 /// @param[in] initData Video codec init data
79 int64_t pts; 300 /// @return true if successfully done
80 301 ///
81 KODI_HANDLE videoBufferHandle; //< will be passed in release_frame_buffer 302 ///
82 }; 303 /// ----------------------------------------------------------------------------
83 304 ///
84 enum VIDEOCODEC_RETVAL 305 /// @copydetails cpp_kodi_addon_videocodec_Defs_VideoCodecInitdata_Help
306 ///
307 virtual bool Open(const kodi::addon::VideoCodecInitdata& initData) { return false; }
308 //----------------------------------------------------------------------------
309
310 //============================================================================
311 /// @ingroup cpp_kodi_addon_videocodec
312 /// @brief Reconfigure the decoder, returns true on success
313 ///
314 /// Decoders not capable of runnung multiple instances may be capable of reconfiguring
315 /// the running instance. If Reconfigure returns false, player will close / open
316 /// the decoder
317 ///
318 /// @param[in] initData Video codec reconfigure data
319 /// @return true if successfully done
320 ///
321 virtual bool Reconfigure(const kodi::addon::VideoCodecInitdata& initData) { return false; }
322 //----------------------------------------------------------------------------
323
324 //============================================================================
325 /// @ingroup cpp_kodi_addon_videocodec
326 /// @brief add data, decoder has to consume the entire packet
327 ///
328 /// @param[in] packet Data to process for decode
329 /// @return true if the packet was consumed or if resubmitting it is useless
330 ///
331 virtual bool AddData(const DEMUX_PACKET& packet) { return false; }
332 //----------------------------------------------------------------------------
333
334 //============================================================================
335 /// @ingroup cpp_kodi_addon_videocodec
336 /// @brief GetPicture controls decoding.
337 ///
338 /// Player calls it on every cycle it can signal a picture, request a buffer,
339 /// or return none, if nothing applies the data is valid until the next
340 /// GetPicture return @ref VC_PICTURE
341 ///
342 /// @param[in,out] Structure which contains the necessary data
343 /// @return The with @ref VIDEOCODEC_RETVAL return values
344 ///
345 virtual VIDEOCODEC_RETVAL GetPicture(VIDEOCODEC_PICTURE& picture) { return VC_ERROR; }
346 //----------------------------------------------------------------------------
347
348 //============================================================================
349 /// @ingroup cpp_kodi_addon_videocodec
350 /// @brief should return codecs name
351 ///
352 /// @return Codec name
353 ///
354 virtual const char* GetName() { return nullptr; }
355 //----------------------------------------------------------------------------
356
357 //============================================================================
358 /// @ingroup cpp_kodi_addon_videocodec
359 /// @brief Reset the decoder
360 ///
361 virtual void Reset() {}
362 //----------------------------------------------------------------------------
363
364 /*!
365 * @brief AddonToKodi interface
366 */
367
368 //============================================================================
369 /// @ingroup cpp_kodi_addon_videocodec
370 /// @brief All picture members can be expected to be set correctly except
371 /// decodedData and pts.
372 ///
373 /// GetFrameBuffer has to set decodedData to a valid memory address and return true.
374 ///
375 /// @param[out] picture The buffer, or unmodified if false is returned
376 /// @return In case buffer allocation fails, it return false.
377 ///
378 /// @note If this returns true, buffer must be freed using @ref ReleaseFrameBuffer().
379 ///
380 /// @remarks Only called from addon itself
381 ///
382 bool GetFrameBuffer(VIDEOCODEC_PICTURE& picture)
85 { 383 {
86 VC_NONE = 0, //< noop 384 return m_instanceData->toKodi->get_frame_buffer(m_instanceData->toKodi->kodiInstance, &picture);
87 VC_ERROR, //< an error occurred, no other messages will be returned 385 }
88 VC_BUFFER, //< the decoder needs more data 386 //----------------------------------------------------------------------------
89 VC_PICTURE, //< the decoder got a picture 387
90 VC_EOF, //< the decoder signals EOF 388 //============================================================================
91 }; 389 ///
92 390 /// @ingroup cpp_kodi_addon_videocodec
93 // this are properties given to the addon on create 391 /// @brief Release the with @ref GetFrameBuffer() given framebuffer.
94 // at this time we have no parameters for the addon 392 ///
95 typedef struct AddonProps_VideoCodec 393 /// @param[in] handle the on @ref VIDEOCODEC_PICTURE.videoBufferHandle defined buffer handle
394 ///
395 /// @remarks Only called from addon itself
396 ///
397 void ReleaseFrameBuffer(void* buffer)
96 { 398 {
97 int dummy; 399 return m_instanceData->toKodi->release_frame_buffer(m_instanceData->toKodi->kodiInstance,
98 } AddonProps_VideoCodec; 400 buffer);
401 }
402 //----------------------------------------------------------------------------
99 403
100 struct AddonInstance_VideoCodec; 404private:
101 typedef struct KodiToAddonFuncTable_VideoCodec 405 void SetAddonStruct(KODI_HANDLE instance)
102 { 406 {
103 KODI_HANDLE addonInstance; 407 if (instance == nullptr)
104 408 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation with empty addon "
105 //! \brief Opens a codec 409 "structure not allowed, table must be given from Kodi!");
106 bool (__cdecl* open) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData); 410
107 411 m_instanceData = static_cast<AddonInstance_VideoCodec*>(instance);
108 //! \brief Reconfigures a codec 412
109 bool (__cdecl* reconfigure) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData); 413 m_instanceData->toAddon->addonInstance = this;
110 414 m_instanceData->toAddon->open = ADDON_Open;
111 //! \brief Feed codec if requested from GetPicture() (return VC_BUFFER) 415 m_instanceData->toAddon->reconfigure = ADDON_Reconfigure;
112 bool (__cdecl* add_data) (const AddonInstance_VideoCodec* instance, const DemuxPacket *packet); 416 m_instanceData->toAddon->add_data = ADDON_AddData;
113 417 m_instanceData->toAddon->get_picture = ADDON_GetPicture;
114 //! \brief Get a decoded picture / request new data 418 m_instanceData->toAddon->get_name = ADDON_GetName;
115 VIDEOCODEC_RETVAL (__cdecl* get_picture) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_PICTURE *picture); 419 m_instanceData->toAddon->reset = ADDON_Reset;
420 }
421
422 inline static bool ADDON_Open(const AddonInstance_VideoCodec* instance,
423 VIDEOCODEC_INITDATA* initData)
424 {
425 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Open(initData);
426 }
116 427
117 //! \brief Get the name of this video decoder 428 inline static bool ADDON_Reconfigure(const AddonInstance_VideoCodec* instance,
118 const char *(__cdecl* get_name) (const AddonInstance_VideoCodec* instance); 429 VIDEOCODEC_INITDATA* initData)
430 {
431 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
432 ->Reconfigure(initData);
433 }
119 434
120 //! \brief Reset the codec 435 inline static bool ADDON_AddData(const AddonInstance_VideoCodec* instance,
121 void (__cdecl* reset)(const AddonInstance_VideoCodec* instance); 436 const DEMUX_PACKET* packet)
122 } KodiToAddonFuncTable_VideoCodec; 437 {
438 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->AddData(*packet);
439 }
123 440
124 typedef struct AddonToKodiFuncTable_VideoCodec 441 inline static VIDEOCODEC_RETVAL ADDON_GetPicture(const AddonInstance_VideoCodec* instance,
442 VIDEOCODEC_PICTURE* picture)
125 { 443 {
126 KODI_HANDLE kodiInstance; 444 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
127 bool(*get_frame_buffer)(void* kodiInstance, VIDEOCODEC_PICTURE *picture); 445 ->GetPicture(*picture);
128 void(*release_frame_buffer)(void* kodiInstance, void *buffer); 446 }
129 } AddonToKodiFuncTable_VideoCodec;
130 447
131 typedef struct AddonInstance_VideoCodec 448 inline static const char* ADDON_GetName(const AddonInstance_VideoCodec* instance)
132 { 449 {
133 AddonProps_VideoCodec* props; 450 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->GetName();
134 AddonToKodiFuncTable_VideoCodec* toKodi; 451 }
135 KodiToAddonFuncTable_VideoCodec* toAddon;
136 } AddonInstance_VideoCodec;
137}
138 452
139namespace kodi 453 inline static void ADDON_Reset(const AddonInstance_VideoCodec* instance)
140{
141 namespace addon
142 { 454 {
455 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Reset();
456 }
457
458 AddonInstance_VideoCodec* m_instanceData;
459};
143 460
144 class ATTRIBUTE_HIDDEN CInstanceVideoCodec : public IAddonInstance 461} // namespace addon
145 {
146 public:
147 explicit CInstanceVideoCodec(KODI_HANDLE instance, const std::string& kodiVersion = "")
148 : IAddonInstance(ADDON_INSTANCE_VIDEOCODEC,
149 !kodiVersion.empty() ? kodiVersion
150 : GetKodiTypeVersion(ADDON_INSTANCE_VIDEOCODEC))
151 {
152 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
153 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation of multiple together with single instance way is not allowed!");
154
155 SetAddonStruct(instance);
156 }
157
158 ~CInstanceVideoCodec() override = default;
159
160 //! \copydoc CInstanceVideoCodec::Open
161 virtual bool Open(VIDEOCODEC_INITDATA &initData) { return false; };
162
163 //! \copydoc CInstanceVideoCodec::Reconfigure
164 virtual bool Reconfigure(VIDEOCODEC_INITDATA &initData) { return false; };
165
166 //! \copydoc CInstanceVideoCodec::AddData
167 virtual bool AddData(const DemuxPacket &packet) { return false; };
168
169 //! \copydoc CInstanceVideoCodec::GetPicture
170 virtual VIDEOCODEC_RETVAL GetPicture(VIDEOCODEC_PICTURE &picture) { return VC_ERROR; };
171
172 //! \copydoc CInstanceVideoCodec::GetName
173 virtual const char *GetName() { return nullptr; };
174
175 //! \copydoc CInstanceVideoCodec::Reset
176 virtual void Reset() {};
177
178 /*!
179 * @brief AddonToKodi interface
180 */
181
182 //! \copydoc CInstanceVideoCodec::GetFrameBuffer
183 bool GetFrameBuffer(VIDEOCODEC_PICTURE &picture)
184 {
185 return m_instanceData->toKodi->get_frame_buffer(m_instanceData->toKodi->kodiInstance,
186 &picture);
187 }
188
189 //! \copydoc CInstanceVideoCodec::ReleaseFrameBuffer
190 void ReleaseFrameBuffer(void *buffer)
191 {
192 return m_instanceData->toKodi->release_frame_buffer(m_instanceData->toKodi->kodiInstance,
193 buffer);
194 }
195
196 private:
197 void SetAddonStruct(KODI_HANDLE instance)
198 {
199 if (instance == nullptr)
200 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation with empty addon structure not allowed, table must be given from Kodi!");
201
202 m_instanceData = static_cast<AddonInstance_VideoCodec*>(instance);
203
204 m_instanceData->toAddon->addonInstance = this;
205 m_instanceData->toAddon->open = ADDON_Open;
206 m_instanceData->toAddon->reconfigure = ADDON_Reconfigure;
207 m_instanceData->toAddon->add_data = ADDON_AddData;
208 m_instanceData->toAddon->get_picture = ADDON_GetPicture;
209 m_instanceData->toAddon->get_name = ADDON_GetName;
210 m_instanceData->toAddon->reset = ADDON_Reset;
211 }
212
213 inline static bool ADDON_Open(const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData)
214 {
215 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Open(*initData);
216 }
217
218 inline static bool ADDON_Reconfigure(const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData)
219 {
220 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
221 ->Reconfigure(*initData);
222 }
223
224 inline static bool ADDON_AddData(const AddonInstance_VideoCodec* instance, const DemuxPacket *packet)
225 {
226 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
227 ->AddData(*packet);
228 }
229
230 inline static VIDEOCODEC_RETVAL ADDON_GetPicture(const AddonInstance_VideoCodec* instance, VIDEOCODEC_PICTURE *picture)
231 {
232 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
233 ->GetPicture(*picture);
234 }
235
236 inline static const char *ADDON_GetName(const AddonInstance_VideoCodec* instance)
237 {
238 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->GetName();
239 }
240
241 inline static void ADDON_Reset(const AddonInstance_VideoCodec* instance)
242 {
243 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Reset();
244 }
245
246 AddonInstance_VideoCodec* m_instanceData;
247 };
248 } // namespace addon
249} // namespace kodi 462} // namespace kodi
463
464#endif /* __cplusplus */