summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
diff options
context:
space:
mode:
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.h249
1 files changed, 249 insertions, 0 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
new file mode 100644
index 0000000..12893db
--- /dev/null
+++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/VideoCodec.h
@@ -0,0 +1,249 @@
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#pragma once
10
11#include "../AddonBase.h"
12#include "../StreamCrypto.h"
13#include "../StreamCodec.h"
14
15#ifdef BUILD_KODI_ADDON
16#include "../DemuxPacket.h"
17#else
18#include "cores/VideoPlayer/Interface/Addon/DemuxPacket.h"
19#endif
20
21extern "C"
22{
23 enum VIDEOCODEC_FORMAT
24 {
25 UnknownVideoFormat = 0,
26 VideoFormatYV12,
27 VideoFormatI420,
28 MaxVideoFormats
29 };
30
31
32 struct VIDEOCODEC_INITDATA
33 {
34 enum Codec {
35 CodecUnknown = 0,
36 CodecVp8,
37 CodecH264,
38 CodecVp9
39 } codec;
40
41 STREAMCODEC_PROFILE codecProfile;
42
43 //UnknownVideoFormat is terminator
44 VIDEOCODEC_FORMAT *videoFormats;
45
46 uint32_t width, height;
47
48 const uint8_t *extraData;
49 unsigned int extraDataSize;
50
51 CRYPTO_INFO cryptoInfo;
52 };
53
54 struct VIDEOCODEC_PICTURE
55 {
56 enum VideoPlane {
57 YPlane = 0,
58 UPlane,
59 VPlane,
60 MaxPlanes = 3,
61 };
62
63 enum Flags : uint32_t {
64 FLAG_DROP,
65 FLAG_DRAIN
66 };
67
68 VIDEOCODEC_FORMAT videoFormat;
69 uint32_t flags;
70
71 uint32_t width, height;
72
73 uint8_t *decodedData;
74 size_t decodedDataSize;
75
76 uint32_t planeOffsets[VideoPlane::MaxPlanes];
77 uint32_t stride[VideoPlane::MaxPlanes];
78
79 int64_t pts;
80
81 KODI_HANDLE videoBufferHandle; //< will be passed in release_frame_buffer
82 };
83
84 enum VIDEOCODEC_RETVAL
85 {
86 VC_NONE = 0, //< noop
87 VC_ERROR, //< an error occurred, no other messages will be returned
88 VC_BUFFER, //< the decoder needs more data
89 VC_PICTURE, //< the decoder got a picture
90 VC_EOF, //< the decoder signals EOF
91 };
92
93 // this are properties given to the addon on create
94 // at this time we have no parameters for the addon
95 typedef struct AddonProps_VideoCodec
96 {
97 int dummy;
98 } AddonProps_VideoCodec;
99
100 struct AddonInstance_VideoCodec;
101 typedef struct KodiToAddonFuncTable_VideoCodec
102 {
103 KODI_HANDLE addonInstance;
104
105 //! \brief Opens a codec
106 bool (__cdecl* open) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData);
107
108 //! \brief Reconfigures a codec
109 bool (__cdecl* reconfigure) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData);
110
111 //! \brief Feed codec if requested from GetPicture() (return VC_BUFFER)
112 bool (__cdecl* add_data) (const AddonInstance_VideoCodec* instance, const DemuxPacket *packet);
113
114 //! \brief Get a decoded picture / request new data
115 VIDEOCODEC_RETVAL (__cdecl* get_picture) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_PICTURE *picture);
116
117 //! \brief Get the name of this video decoder
118 const char *(__cdecl* get_name) (const AddonInstance_VideoCodec* instance);
119
120 //! \brief Reset the codec
121 void (__cdecl* reset)(const AddonInstance_VideoCodec* instance);
122 } KodiToAddonFuncTable_VideoCodec;
123
124 typedef struct AddonToKodiFuncTable_VideoCodec
125 {
126 KODI_HANDLE kodiInstance;
127 bool(*get_frame_buffer)(void* kodiInstance, VIDEOCODEC_PICTURE *picture);
128 void(*release_frame_buffer)(void* kodiInstance, void *buffer);
129 } AddonToKodiFuncTable_VideoCodec;
130
131 typedef struct AddonInstance_VideoCodec
132 {
133 AddonProps_VideoCodec* props;
134 AddonToKodiFuncTable_VideoCodec* toKodi;
135 KodiToAddonFuncTable_VideoCodec* toAddon;
136 } AddonInstance_VideoCodec;
137}
138
139namespace kodi
140{
141 namespace addon
142 {
143
144 class ATTRIBUTE_HIDDEN CInstanceVideoCodec : public IAddonInstance
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