summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2017-07-23 16:59:43 +0200
committermanuel <manuel@mausz.at>2017-07-23 16:59:43 +0200
commit4c3251ec645c8b71820dab7e51e612e5919d4e75 (patch)
tree9533268a93e58fc2e16de1b8ee3fafe3784e5225 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h
parentf44ecaa4f27e7538ddcad66d40e543bffa2d2d86 (diff)
downloadkodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.tar.gz
kodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.tar.bz2
kodi-pvr-build-4c3251ec645c8b71820dab7e51e612e5919d4e75.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h256
1 files changed, 256 insertions, 0 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h
new file mode 100644
index 0000000..710fda0
--- /dev/null
+++ b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/VideoCodec.h
@@ -0,0 +1,256 @@
1/*
2 * Copyright (C) 2017 Team XBMC
3 * http://xbmc.org
4 *
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#pragma once
22
23#include "../AddonBase.h"
24#include "../StreamCrypto.h"
25#include "../StreamCodec.h"
26
27#ifdef BUILD_KODI_ADDON
28#include "../DVDDemuxPacket.h"
29#else
30#include "cores/VideoPlayer/DVDDemuxers/DVDDemuxPacket.h"
31#endif
32
33namespace kodi { namespace addon { class CInstanceVideoCodec; } }
34
35extern "C"
36{
37 enum VIDEOCODEC_FORMAT
38 {
39 UnknownVideoFormat = 0,
40 VideoFormatYV12,
41 VideoFormatI420,
42 MaxVideoFormats
43 };
44
45
46 struct VIDEOCODEC_INITDATA
47 {
48 enum Codec {
49 CodecUnknown = 0,
50 CodecVp8,
51 CodecH264,
52 CodecVp9
53 } codec;
54
55 STREAMCODEC_PROFILE codecProfile;
56
57 //UnknownVideoFormat is terminator
58 VIDEOCODEC_FORMAT *videoFormats;
59
60 uint32_t width, height;
61
62 const uint8_t *extraData;
63 unsigned int extraDataSize;
64
65 CRYPTO_INFO cryptoInfo;
66 };
67
68 struct VIDEOCODEC_PICTURE
69 {
70 enum VideoPlane {
71 YPlane = 0,
72 UPlane,
73 VPlane,
74 MaxPlanes = 3,
75 };
76
77 enum Flags : uint32_t {
78 FLAG_DROP,
79 FLAG_DRAIN
80 };
81
82 VIDEOCODEC_FORMAT videoFormat;
83 uint32_t flags;
84
85 uint32_t width, height;
86
87 uint8_t *decodedData;
88 size_t decodedDataSize;
89
90 uint32_t planeOffsets[VideoPlane::MaxPlanes];
91 uint32_t stride[VideoPlane::MaxPlanes];
92
93 int64_t pts;
94
95 void *buffer; //< will be passed in release_frame_buffer
96 };
97
98 enum VIDEOCODEC_RETVAL
99 {
100 VC_NONE = 0, //< noop
101 VC_ERROR, //< an error occured, no other messages will be returned
102 VC_BUFFER, //< the decoder needs more data
103 VC_PICTURE, //< the decoder got a picture
104 VC_EOF, //< the decoder signals EOF
105 };
106
107 // this are properties given to the addon on create
108 // at this time we have no parameters for the addon
109 typedef struct AddonProps_VideoCodec
110 {
111 int dummy;
112 } AddonProps_VideoCodec;
113
114 struct AddonInstance_VideoCodec;
115 typedef struct KodiToAddonFuncTable_VideoCodec
116 {
117 kodi::addon::CInstanceVideoCodec* addonInstance;
118
119 //! \brief Opens a codec
120 bool (__cdecl* open) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData);
121
122 //! \brief Reconfigures a codec
123 bool (__cdecl* reconfigure) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData);
124
125 //! \brief Feed codec if requested from GetPicture() (return VC_BUFFER)
126 bool (__cdecl* add_data) (const AddonInstance_VideoCodec* instance, const DemuxPacket *packet);
127
128 //! \brief Get a decoded picture / request new data
129 VIDEOCODEC_RETVAL (__cdecl* get_picture) (const AddonInstance_VideoCodec* instance, VIDEOCODEC_PICTURE *picture);
130
131 //! \brief Get the name of this video decoder
132 const char *(__cdecl* get_name) (const AddonInstance_VideoCodec* instance);
133
134 //! \brief Reset the codec
135 void (__cdecl* reset)(const AddonInstance_VideoCodec* instance);
136 } KodiToAddonFuncTable_VideoCodec;
137
138 typedef struct AddonToKodiFuncTable_VideoCodec
139 {
140 KODI_HANDLE kodiInstance;
141 bool(*get_frame_buffer)(void* kodiInstance, VIDEOCODEC_PICTURE *picture);
142 void(*release_frame_buffer)(void* kodiInstance, void *buffer);
143 } AddonToKodiFuncTable_VideoCodec;
144
145 typedef struct AddonInstance_VideoCodec
146 {
147 AddonProps_VideoCodec props;
148 AddonToKodiFuncTable_VideoCodec toKodi;
149 KodiToAddonFuncTable_VideoCodec toAddon;
150 } AddonInstance_VideoCodec;
151}
152
153namespace kodi
154{
155 namespace addon
156 {
157
158 class CInstanceVideoCodec : public IAddonInstance
159 {
160 public:
161 CInstanceVideoCodec(KODI_HANDLE instance)
162 : IAddonInstance(ADDON_INSTANCE_VIDEOCODEC)
163 {
164 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
165 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation of multiple together with single instance way is not allowed!");
166
167 SetAddonStruct(instance);
168 }
169
170 ~CInstanceVideoCodec() override = default;
171
172 //! \copydoc CInstanceVideoCodec::Open
173 virtual bool Open(VIDEOCODEC_INITDATA &initData) { return false; };
174
175 //! \copydoc CInstanceVideoCodec::Reconfigure
176 virtual bool Reconfigure(VIDEOCODEC_INITDATA &initData) { return false; };
177
178 //! \copydoc CInstanceVideoCodec::AddData
179 virtual bool AddData(const DemuxPacket &packet) { return false; };
180
181 //! \copydoc CInstanceVideoCodec::GetPicture
182 virtual VIDEOCODEC_RETVAL GetPicture(VIDEOCODEC_PICTURE &picture) { return VC_ERROR; };
183
184 //! \copydoc CInstanceVideoCodec::GetName
185 virtual const char *GetName() { return nullptr; };
186
187 //! \copydoc CInstanceVideoCodec::Reset
188 virtual void Reset() {};
189
190 /*!
191 * @brief AddonToKodi interface
192 */
193
194 //! \copydoc CInstanceVideoCodec::GetFrameBuffer
195 bool GetFrameBuffer(VIDEOCODEC_PICTURE &picture)
196 {
197 return m_instanceData->toKodi.get_frame_buffer(m_instanceData->toKodi.kodiInstance, &picture);
198 }
199
200 //! \copydoc CInstanceVideoCodec::ReleaseFrameBuffer
201 void ReleaseFrameBuffer(void *buffer)
202 {
203 return m_instanceData->toKodi.release_frame_buffer(m_instanceData->toKodi.kodiInstance, buffer);
204 }
205
206 private:
207 void SetAddonStruct(KODI_HANDLE instance)
208 {
209 if (instance == nullptr)
210 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation with empty addon structure not allowed, table must be given from Kodi!");
211
212 m_instanceData = static_cast<AddonInstance_VideoCodec*>(instance);
213
214 m_instanceData->toAddon.addonInstance = this;
215 m_instanceData->toAddon.open = ADDON_Open;
216 m_instanceData->toAddon.reconfigure = ADDON_Reconfigure;
217 m_instanceData->toAddon.add_data = ADDON_AddData;
218 m_instanceData->toAddon.get_picture = ADDON_GetPicture;
219 m_instanceData->toAddon.get_name = ADDON_GetName;
220 m_instanceData->toAddon.reset = ADDON_Reset;
221 }
222
223 inline static bool ADDON_Open(const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData)
224 {
225 return instance->toAddon.addonInstance->Open(*initData);
226 }
227
228 inline static bool ADDON_Reconfigure(const AddonInstance_VideoCodec* instance, VIDEOCODEC_INITDATA *initData)
229 {
230 return instance->toAddon.addonInstance->Reconfigure(*initData);
231 }
232
233 inline static bool ADDON_AddData(const AddonInstance_VideoCodec* instance, const DemuxPacket *packet)
234 {
235 return instance->toAddon.addonInstance->AddData(*packet);
236 }
237
238 inline static VIDEOCODEC_RETVAL ADDON_GetPicture(const AddonInstance_VideoCodec* instance, VIDEOCODEC_PICTURE *picture)
239 {
240 return instance->toAddon.addonInstance->GetPicture(*picture);
241 }
242
243 inline static const char *ADDON_GetName(const AddonInstance_VideoCodec* instance)
244 {
245 return instance->toAddon.addonInstance->GetName();
246 }
247
248 inline static void ADDON_Reset(const AddonInstance_VideoCodec* instance)
249 {
250 return instance->toAddon.addonInstance->Reset();
251 }
252
253 AddonInstance_VideoCodec* m_instanceData;
254 };
255 } // namespace addon
256} // namespace kodi