summaryrefslogtreecommitdiffstats
path: root/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h')
-rw-r--r--xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h881
1 files changed, 0 insertions, 881 deletions
diff --git a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h b/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h
deleted file mode 100644
index 354806e..0000000
--- a/xbmc/addons/kodi-addon-dev-kit/include/kodi/addon-instance/Inputstream.h
+++ /dev/null
@@ -1,881 +0,0 @@
1/*
2 * Copyright (C) 2005-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/*
12 * Parts with a comment named "internal" are only used inside header and not
13 * used or accessed direct during add-on development!
14 */
15
16#include "../AddonBase.h"
17#include "../StreamCodec.h"
18#include "../StreamCrypto.h"
19
20#ifdef BUILD_KODI_ADDON
21#include "../DemuxPacket.h"
22#include "../InputStreamConstants.h"
23#else
24#include "cores/VideoPlayer/Interface/Addon/DemuxPacket.h"
25#include "cores/VideoPlayer/Interface/Addon/InputStreamConstants.h"
26#endif
27
28//Increment this level always if you add features which can lead to compile failures in the addon
29#define INPUTSTREAM_VERSION_LEVEL 2
30
31#ifdef __cplusplus
32extern "C"
33{
34#endif /* __cplusplus */
35
36 /*!
37 * @brief InputStream add-on capabilities. All capabilities are set to "false" as default.
38 */
39 struct INPUTSTREAM_CAPABILITIES
40 {
41 enum MASKTYPE : uint32_t
42 {
43 /// supports interface IDemux
44 SUPPORTS_IDEMUX = (1 << 0),
45
46 /// supports interface IPosTime
47 SUPPORTS_IPOSTIME = (1 << 1),
48
49 /// supports interface IDisplayTime
50 SUPPORTS_IDISPLAYTIME = (1 << 2),
51
52 /// supports seek
53 SUPPORTS_SEEK = (1 << 3),
54
55 /// supports pause
56 SUPPORTS_PAUSE = (1 << 4),
57
58 /// supports interface ITime
59 SUPPORTS_ITIME = (1 << 5),
60
61 /// supports interface IChapter
62 SUPPORTS_ICHAPTER = (1 << 6),
63 };
64
65 /// set of supported capabilities
66 uint32_t m_mask;
67 };
68
69 /*!
70 * @brief structure of key/value pairs passed to addon on Open()
71 */
72 struct INPUTSTREAM
73 {
74 const char* m_strURL;
75 const char* m_mimeType;
76
77 unsigned int m_nCountInfoValues;
78 struct LISTITEMPROPERTY
79 {
80 const char* m_strKey;
81 const char* m_strValue;
82 } m_ListItemProperties[STREAM_MAX_PROPERTY_COUNT];
83
84 const char* m_libFolder;
85 const char* m_profileFolder;
86 };
87
88 /*!
89 * @brief Array of stream IDs
90 */
91 struct INPUTSTREAM_IDS
92 {
93 static const unsigned int MAX_STREAM_COUNT = 256;
94 unsigned int m_streamCount;
95 unsigned int m_streamIds[MAX_STREAM_COUNT];
96 };
97
98 /*!
99 * @brief MASTERING Metadata
100 */
101 struct INPUTSTREAM_MASTERING_METADATA
102 {
103 double primary_r_chromaticity_x;
104 double primary_r_chromaticity_y;
105 double primary_g_chromaticity_x;
106 double primary_g_chromaticity_y;
107 double primary_b_chromaticity_x;
108 double primary_b_chromaticity_y;
109 double white_point_chromaticity_x;
110 double white_point_chromaticity_y;
111 double luminance_max;
112 double luminance_min;
113 };
114
115 /*!
116 * @brief CONTENTLIGHT Metadata
117 */
118 struct INPUTSTREAM_CONTENTLIGHT_METADATA
119 {
120 uint64_t max_cll;
121 uint64_t max_fall;
122 };
123
124 /*!
125 * @brief stream properties
126 */
127 struct INPUTSTREAM_INFO
128 {
129 enum STREAM_TYPE
130 {
131 TYPE_NONE = 0,
132 TYPE_VIDEO,
133 TYPE_AUDIO,
134 TYPE_SUBTITLE,
135 TYPE_TELETEXT,
136 TYPE_RDS,
137 } m_streamType;
138
139 enum Codec_FEATURES : uint32_t
140 {
141 FEATURE_DECODE = 1
142 };
143 uint32_t m_features;
144
145 enum STREAM_FLAGS : uint32_t
146 {
147 FLAG_NONE = 0x0000,
148 FLAG_DEFAULT = 0x0001,
149 FLAG_DUB = 0x0002,
150 FLAG_ORIGINAL = 0x0004,
151 FLAG_COMMENT = 0x0008,
152 FLAG_LYRICS = 0x0010,
153 FLAG_KARAOKE = 0x0020,
154 FLAG_FORCED = 0x0040,
155 FLAG_HEARING_IMPAIRED = 0x0080,
156 FLAG_VISUAL_IMPAIRED = 0x0100,
157 };
158
159 // Keep in sync with AVColorSpace
160 enum COLORSPACE
161 {
162 COLORSPACE_RGB = 0,
163 COLORSPACE_BT709 = 1,
164 COLORSPACE_UNSPECIFIED = 2,
165 COLORSPACE_UNKNOWN = COLORSPACE_UNSPECIFIED, // compatibility
166 COLORSPACE_RESERVED = 3,
167 COLORSPACE_FCC = 4,
168 COLORSPACE_BT470BG = 5,
169 COLORSPACE_SMPTE170M = 6,
170 COLORSPACE_SMPTE240M = 7,
171 COLORSPACE_YCGCO = 8,
172 COLORSPACE_YCOCG = COLORSPACE_YCGCO,
173 COLORSPACE_BT2020_NCL = 9,
174 COLORSPACE_BT2020_CL = 10,
175 COLORSPACE_SMPTE2085 = 11,
176 COLORSPACE_CHROMA_DERIVED_NCL = 12,
177 COLORSPACE_CHROMA_DERIVED_CL = 13,
178 COLORSPACE_ICTCP = 14,
179 COLORSPACE_MAX
180 };
181
182 // Keep in sync with AVColorPrimaries
183 enum COLORPRIMARIES : int32_t
184 {
185 COLORPRIMARY_RESERVED0 = 0,
186 COLORPRIMARY_BT709 = 1,
187 COLORPRIMARY_UNSPECIFIED = 2,
188 COLORPRIMARY_RESERVED = 3,
189 COLORPRIMARY_BT470M = 4,
190 COLORPRIMARY_BT470BG = 5,
191 COLORPRIMARY_SMPTE170M = 6,
192 COLORPRIMARY_SMPTE240M = 7,
193 COLORPRIMARY_FILM = 8,
194 COLORPRIMARY_BT2020 = 9,
195 COLORPRIMARY_SMPTE428 = 10,
196 COLORPRIMARY_SMPTEST428_1 = COLORPRIMARY_SMPTE428,
197 COLORPRIMARY_SMPTE431 = 11,
198 COLORPRIMARY_SMPTE432 = 12,
199 COLORPRIMARY_JEDEC_P22 = 22,
200 COLORPRIMARY_MAX
201 };
202
203 // Keep in sync with AVColorRange
204 enum COLORRANGE
205 {
206 COLORRANGE_UNKNOWN = 0,
207 COLORRANGE_LIMITED,
208 COLORRANGE_FULLRANGE,
209 COLORRANGE_MAX
210 };
211
212 // keep in sync with AVColorTransferCharacteristic
213 enum COLORTRC : int32_t
214 {
215 COLORTRC_RESERVED0 = 0,
216 COLORTRC_BT709 = 1,
217 COLORTRC_UNSPECIFIED = 2,
218 COLORTRC_RESERVED = 3,
219 COLORTRC_GAMMA22 = 4,
220 COLORTRC_GAMMA28 = 5,
221 COLORTRC_SMPTE170M = 6,
222 COLORTRC_SMPTE240M = 7,
223 COLORTRC_LINEAR = 8,
224 COLORTRC_LOG = 9,
225 COLORTRC_LOG_SQRT = 10,
226 COLORTRC_IEC61966_2_4 = 11,
227 COLORTRC_BT1361_ECG = 12,
228 COLORTRC_IEC61966_2_1 = 13,
229 COLORTRC_BT2020_10 = 14,
230 COLORTRC_BT2020_12 = 15,
231 COLORTRC_SMPTE2084 = 16,
232 COLORTRC_SMPTEST2084 = COLORTRC_SMPTE2084,
233 COLORTRC_SMPTE428 = 17,
234 COLORTRC_SMPTEST428_1 = COLORTRC_SMPTE428,
235 COLORTRC_ARIB_STD_B67 = 18,
236 COLORTRC_MAX
237 };
238
239 uint32_t m_flags;
240
241 char m_name[256]; /*!< @brief (optinal) name of the stream, \0 for default handling */
242 char m_codecName[32]; /*!< @brief (required) name of codec according to ffmpeg */
243 char m_codecInternalName
244 [32]; /*!< @brief (optional) internal name of codec (selectionstream info) */
245 STREAMCODEC_PROFILE m_codecProfile; /*!< @brief (optional) the profile of the codec */
246 unsigned int m_pID; /*!< @brief (required) physical index */
247
248 const uint8_t* m_ExtraData;
249 unsigned int m_ExtraSize;
250
251 char m_language[64]; /*!< @brief RFC 5646 language code (empty string if undefined) */
252
253 unsigned int
254 m_FpsScale; /*!< @brief Scale of 1000 and a rate of 29970 will result in 29.97 fps */
255 unsigned int m_FpsRate;
256 unsigned int m_Height; /*!< @brief height of the stream reported by the demuxer */
257 unsigned int m_Width; /*!< @brief width of the stream reported by the demuxer */
258 float m_Aspect; /*!< @brief display aspect of stream */
259
260
261 unsigned int m_Channels; /*!< @brief (required) amount of channels */
262 unsigned int m_SampleRate; /*!< @brief (required) sample rate */
263 unsigned int m_BitRate; /*!< @brief (required) bit rate */
264 unsigned int m_BitsPerSample; /*!< @brief (required) bits per sample */
265 unsigned int m_BlockAlign;
266
267 CRYPTO_INFO m_cryptoInfo;
268
269 // new in API version 2.0.8
270 unsigned int m_codecFourCC; /*!< @brief Codec If available, the fourcc code codec */
271 COLORSPACE m_colorSpace; /*!< @brief definition of colorspace */
272 COLORRANGE m_colorRange; /*!< @brief color range if available */
273
274 //new in API 2.0.9 / INPUTSTREAM_VERSION_LEVEL 1
275 COLORPRIMARIES m_colorPrimaries;
276 COLORTRC m_colorTransferCharacteristic;
277 INPUTSTREAM_MASTERING_METADATA* m_masteringMetadata; /*!< @brief mastering static Metadata */
278 INPUTSTREAM_CONTENTLIGHT_METADATA*
279 m_contentLightMetadata; /*!< @brief content light static Metadata */
280 };
281
282 struct INPUTSTREAM_TIMES
283 {
284 time_t startTime;
285 double ptsStart;
286 double ptsBegin;
287 double ptsEnd;
288 };
289
290 /*!
291 * @brief "C" ABI Structures to transfer the methods from this to Kodi
292 */
293
294 // this are properties given to the addon on create
295 // at this time we have no parameters for the addon
296 typedef struct AddonProps_InputStream /* internal */
297 {
298 int dummy;
299 } AddonProps_InputStream;
300
301 typedef struct AddonToKodiFuncTable_InputStream /* internal */
302 {
303 KODI_HANDLE kodiInstance;
304 DemuxPacket* (*allocate_demux_packet)(void* kodiInstance, int data_size);
305 DemuxPacket* (*allocate_encrypted_demux_packet)(void* kodiInstance,
306 unsigned int data_size,
307 unsigned int encrypted_subsample_count);
308 void (*free_demux_packet)(void* kodiInstance, DemuxPacket* packet);
309 } AddonToKodiFuncTable_InputStream;
310
311 struct AddonInstance_InputStream;
312 typedef struct KodiToAddonFuncTable_InputStream /* internal */
313 {
314 KODI_HANDLE addonInstance;
315
316 bool(__cdecl* open)(const AddonInstance_InputStream* instance, INPUTSTREAM* props);
317 void(__cdecl* close)(const AddonInstance_InputStream* instance);
318 const char*(__cdecl* get_path_list)(const AddonInstance_InputStream* instance);
319 void(__cdecl* get_capabilities)(const AddonInstance_InputStream* instance,
320 INPUTSTREAM_CAPABILITIES* capabilities);
321
322 // IDemux
323 struct INPUTSTREAM_IDS(__cdecl* get_stream_ids)(const AddonInstance_InputStream* instance);
324 struct INPUTSTREAM_INFO(__cdecl* get_stream)(const AddonInstance_InputStream* instance,
325 int streamid);
326 void(__cdecl* enable_stream)(const AddonInstance_InputStream* instance,
327 int streamid,
328 bool enable);
329 bool(__cdecl* open_stream)(const AddonInstance_InputStream* instance, int streamid);
330 void(__cdecl* demux_reset)(const AddonInstance_InputStream* instance);
331 void(__cdecl* demux_abort)(const AddonInstance_InputStream* instance);
332 void(__cdecl* demux_flush)(const AddonInstance_InputStream* instance);
333 DemuxPacket*(__cdecl* demux_read)(const AddonInstance_InputStream* instance);
334 bool(__cdecl* demux_seek_time)(const AddonInstance_InputStream* instance,
335 double time,
336 bool backwards,
337 double* startpts);
338 void(__cdecl* demux_set_speed)(const AddonInstance_InputStream* instance, int speed);
339 void(__cdecl* set_video_resolution)(const AddonInstance_InputStream* instance,
340 int width,
341 int height);
342
343 // IDisplayTime
344 int(__cdecl* get_total_time)(const AddonInstance_InputStream* instance);
345 int(__cdecl* get_time)(const AddonInstance_InputStream* instance);
346
347 // ITime
348 bool(__cdecl* get_times)(const AddonInstance_InputStream* instance, INPUTSTREAM_TIMES* times);
349
350 // IPosTime
351 bool(__cdecl* pos_time)(const AddonInstance_InputStream* instance, int ms);
352
353 int(__cdecl* read_stream)(const AddonInstance_InputStream* instance,
354 uint8_t* buffer,
355 unsigned int bufferSize);
356 int64_t(__cdecl* seek_stream)(const AddonInstance_InputStream* instance,
357 int64_t position,
358 int whence);
359 int64_t(__cdecl* position_stream)(const AddonInstance_InputStream* instance);
360 int64_t(__cdecl* length_stream)(const AddonInstance_InputStream* instance);
361 bool(__cdecl* is_real_time_stream)(const AddonInstance_InputStream* instance);
362
363 // IChapter
364 int(__cdecl* get_chapter)(const AddonInstance_InputStream* instance);
365 int(__cdecl* get_chapter_count)(const AddonInstance_InputStream* instance);
366 const char*(__cdecl* get_chapter_name)(const AddonInstance_InputStream* instance, int ch);
367 int64_t(__cdecl* get_chapter_pos)(const AddonInstance_InputStream* instance, int ch);
368 bool(__cdecl* seek_chapter)(const AddonInstance_InputStream* instance, int ch);
369
370 int(__cdecl* block_size_stream)(const AddonInstance_InputStream* instance);
371 } KodiToAddonFuncTable_InputStream;
372
373 typedef struct AddonInstance_InputStream /* internal */
374 {
375 AddonProps_InputStream props;
376 AddonToKodiFuncTable_InputStream toKodi;
377 KodiToAddonFuncTable_InputStream toAddon;
378 } AddonInstance_InputStream;
379
380#ifdef __cplusplus
381} /* extern "C" */
382
383namespace kodi
384{
385namespace addon
386{
387
388class ATTRIBUTE_HIDDEN CInstanceInputStream : public IAddonInstance
389{
390public:
391 explicit CInstanceInputStream(KODI_HANDLE instance, const std::string& kodiVersion = "")
392 : IAddonInstance(ADDON_INSTANCE_INPUTSTREAM,
393 !kodiVersion.empty() ? kodiVersion
394 : GetKodiTypeVersion(ADDON_INSTANCE_INPUTSTREAM))
395 {
396 if (CAddonBase::m_interface->globalSingleInstance != nullptr)
397 throw std::logic_error("kodi::addon::CInstanceInputStream: Creation of multiple together "
398 "with single instance way is not allowed!");
399
400 SetAddonStruct(instance, m_kodiVersion);
401 }
402
403 ~CInstanceInputStream() override = default;
404
405 /*!
406 * Open a stream.
407 * @param props
408 * @return True if the stream has been opened successfully, false otherwise.
409 * @remarks
410 */
411 virtual bool Open(INPUTSTREAM& props) = 0;
412
413 /*!
414 * Close an open stream.
415 * @remarks
416 */
417 virtual void Close() = 0;
418
419 /*!
420 * Get Capabilities of this addon.
421 * @param capabilities The add-on's capabilities.
422 * @remarks
423 */
424 virtual void GetCapabilities(INPUTSTREAM_CAPABILITIES& capabilities) = 0;
425
426 /*!
427 * Get IDs of available streams
428 * @remarks
429 */
430 virtual INPUTSTREAM_IDS GetStreamIds() = 0;
431
432 /*!
433 * Get stream properties of a stream.
434 * @param streamid unique id of stream
435 * @return struc of stream properties
436 * @remarks
437 */
438 virtual INPUTSTREAM_INFO GetStream(int streamid) = 0;
439
440 /*!
441 * Enable or disable a stream.
442 * A disabled stream does not send demux packets
443 * @param streamid unique id of stream
444 * @param enable true for enable, false for disable
445 * @remarks
446 */
447 virtual void EnableStream(int streamid, bool enable) = 0;
448
449 /*!
450 * Opens a stream for playback.
451 * @param streamid unique id of stream
452 * @remarks
453 */
454 virtual bool OpenStream(int streamid) = 0;
455
456 /*!
457 * Reset the demultiplexer in the add-on.
458 * @remarks Required if bHandlesDemuxing is set to true.
459 */
460 virtual void DemuxReset() {}
461
462 /*!
463 * Abort the demultiplexer thread in the add-on.
464 * @remarks Required if bHandlesDemuxing is set to true.
465 */
466 virtual void DemuxAbort() {}
467
468 /*!
469 * Flush all data that's currently in the demultiplexer buffer in the add-on.
470 * @remarks Required if bHandlesDemuxing is set to true.
471 */
472 virtual void DemuxFlush() {}
473
474 /*!
475 * Read the next packet from the demultiplexer, if there is one.
476 * @return The next packet.
477 * If there is no next packet, then the add-on should return the
478 * packet created by calling AllocateDemuxPacket(0) on the callback.
479 * If the stream changed and Kodi's player needs to be reinitialised,
480 * then, the add-on should call AllocateDemuxPacket(0) on the
481 * callback, and set the streamid to DMX_SPECIALID_STREAMCHANGE and
482 * return the value.
483 * The add-on should return NULL if an error occurred.
484 * @remarks Return NULL if this add-on won't provide this function.
485 */
486 virtual DemuxPacket* DemuxRead() { return nullptr; }
487
488 /*!
489 * Notify the InputStream addon/demuxer that Kodi wishes to seek the stream by time
490 * Demuxer is required to set stream to an IDR frame
491 * @param time The absolute time since stream start
492 * @param backwards True to seek to keyframe BEFORE time, else AFTER
493 * @param startpts can be updated to point to where display should start
494 * @return True if the seek operation was possible
495 * @remarks Optional, and only used if addon has its own demuxer.
496 */
497 virtual bool DemuxSeekTime(double time, bool backwards, double& startpts) { return false; }
498
499 /*!
500 * Notify the InputStream addon/demuxer that Kodi wishes to change playback speed
501 * @param speed The requested playback speed
502 * @remarks Optional, and only used if addon has its own demuxer.
503 */
504 virtual void DemuxSetSpeed(int speed) {}
505
506 /*!
507 * Sets desired width / height
508 * @param width / hight
509 */
510 virtual void SetVideoResolution(int width, int height) {}
511
512 /*!
513 * Totel time in ms
514 * @remarks
515 */
516 virtual int GetTotalTime() { return -1; }
517
518 /*!
519 * Playing time in ms
520 * @remarks
521 */
522 virtual int GetTime() { return -1; }
523
524 /*!
525 * Get current timing values in PTS scale
526 * @remarks
527 */
528 virtual bool GetTimes(INPUTSTREAM_TIMES& times) { return false; }
529
530 /*!
531 * Positions inputstream to playing time given in ms
532 * @remarks
533 */
534 virtual bool PosTime(int ms) { return false; }
535
536 /*!
537 * Return currently selected chapter
538 * @remarks
539 */
540 virtual int GetChapter() { return -1; };
541
542 /*!
543 * Return number of available chapters
544 * @remarks
545 */
546 virtual int GetChapterCount() { return 0; };
547
548 /*!
549 * Return name of chapter # ch
550 * @remarks
551 */
552 virtual const char* GetChapterName(int ch) { return nullptr; };
553
554 /*!
555 * Return position if chapter # ch in milliseconds
556 * @remarks
557 */
558 virtual int64_t GetChapterPos(int ch) { return 0; };
559
560 /*!
561 * Seek to the beginning of chapter # ch
562 * @remarks
563 */
564 virtual bool SeekChapter(int ch) { return false; };
565
566 /*!
567 * Read from an open stream.
568 * @param buffer The buffer to store the data in.
569 * @param bufferSize The amount of bytes to read.
570 * @return The amount of bytes that were actually read from the stream.
571 * @remarks Return -1 if this add-on won't provide this function.
572 */
573 virtual int ReadStream(uint8_t* buffer, unsigned int bufferSize) { return -1; }
574
575 /*!
576 * Seek in a stream.
577 * @param position The position to seek to.
578 * @param whence ?
579 * @return The new position.
580 * @remarks Return -1 if this add-on won't provide this function.
581 */
582 virtual int64_t SeekStream(int64_t position, int whence = SEEK_SET) { return -1; }
583
584 /*!
585 * @return The position in the stream that's currently being read.
586 * @remarks Return -1 if this add-on won't provide this function.
587 */
588 virtual int64_t PositionStream() { return -1; }
589
590 /*!
591 * @return The total length of the stream that's currently being read.
592 * @remarks Return -1 if this add-on won't provide this function.
593 */
594 virtual int64_t LengthStream() { return -1; }
595
596 /*!
597 * @return Obtain the chunk size to use when reading streams.
598 * @remarks Return 0 if this add-on won't provide this function.
599 */
600 virtual int GetBlockSize() { return 0; }
601
602 /*!
603 * Check for real-time streaming
604 * @return true if current stream is real-time
605 */
606 virtual bool IsRealTimeStream() { return true; }
607
608 /*!
609 * @brief Allocate a demux packet. Free with FreeDemuxPacket
610 * @param dataSize The size of the data that will go into the packet
611 * @return The allocated packet
612 */
613 DemuxPacket* AllocateDemuxPacket(int dataSize)
614 {
615 return m_instanceData->toKodi.allocate_demux_packet(m_instanceData->toKodi.kodiInstance,
616 dataSize);
617 }
618
619 /*!
620 * @brief Allocate a demux packet. Free with FreeDemuxPacket
621 * @param dataSize The size of the data that will go into the packet
622 * @return The allocated packet
623 */
624 DemuxPacket* AllocateEncryptedDemuxPacket(int dataSize, unsigned int encryptedSubsampleCount)
625 {
626 return m_instanceData->toKodi.allocate_encrypted_demux_packet(
627 m_instanceData->toKodi.kodiInstance, dataSize, encryptedSubsampleCount);
628 }
629
630 /*!
631 * @brief Free a packet that was allocated with AllocateDemuxPacket
632 * @param packet The packet to free
633 */
634 void FreeDemuxPacket(DemuxPacket* packet)
635 {
636 return m_instanceData->toKodi.free_demux_packet(m_instanceData->toKodi.kodiInstance, packet);
637 }
638
639private:
640 static int compareVersion(const int v1[3], const int v2[3])
641 {
642 for (unsigned i(0); i < 3; ++i)
643 if (v1[i] != v2[i])
644 return v1[i] - v2[i];
645 return 0;
646 }
647
648 void SetAddonStruct(KODI_HANDLE instance, const std::string& kodiVersion)
649 {
650 if (instance == nullptr)
651 throw std::logic_error("kodi::addon::CInstanceInputStream: Creation with empty addon "
652 "structure not allowed, table must be given from Kodi!");
653 int api[3] = { 0, 0, 0 };
654 sscanf(kodiVersion.c_str(), "%d.%d.%d", &api[0], &api[1], &api[2]);
655
656 m_instanceData = static_cast<AddonInstance_InputStream*>(instance);
657 m_instanceData->toAddon.addonInstance = this;
658 m_instanceData->toAddon.open = ADDON_Open;
659 m_instanceData->toAddon.close = ADDON_Close;
660 m_instanceData->toAddon.get_capabilities = ADDON_GetCapabilities;
661
662 m_instanceData->toAddon.get_stream_ids = ADDON_GetStreamIds;
663 m_instanceData->toAddon.get_stream = ADDON_GetStream;
664 m_instanceData->toAddon.enable_stream = ADDON_EnableStream;
665 m_instanceData->toAddon.open_stream = ADDON_OpenStream;
666 m_instanceData->toAddon.demux_reset = ADDON_DemuxReset;
667 m_instanceData->toAddon.demux_abort = ADDON_DemuxAbort;
668 m_instanceData->toAddon.demux_flush = ADDON_DemuxFlush;
669 m_instanceData->toAddon.demux_read = ADDON_DemuxRead;
670 m_instanceData->toAddon.demux_seek_time = ADDON_DemuxSeekTime;
671 m_instanceData->toAddon.demux_set_speed = ADDON_DemuxSetSpeed;
672 m_instanceData->toAddon.set_video_resolution = ADDON_SetVideoResolution;
673
674 m_instanceData->toAddon.get_total_time = ADDON_GetTotalTime;
675 m_instanceData->toAddon.get_time = ADDON_GetTime;
676
677 m_instanceData->toAddon.get_times = ADDON_GetTimes;
678 m_instanceData->toAddon.pos_time = ADDON_PosTime;
679
680 m_instanceData->toAddon.read_stream = ADDON_ReadStream;
681 m_instanceData->toAddon.seek_stream = ADDON_SeekStream;
682 m_instanceData->toAddon.position_stream = ADDON_PositionStream;
683 m_instanceData->toAddon.length_stream = ADDON_LengthStream;
684 m_instanceData->toAddon.is_real_time_stream = ADDON_IsRealTimeStream;
685
686 int minChapterVersion[3] = { 2, 0, 10 };
687 if (compareVersion(api, minChapterVersion) >= 0)
688 {
689 m_instanceData->toAddon.get_chapter = ADDON_GetChapter;
690 m_instanceData->toAddon.get_chapter_count = ADDON_GetChapterCount;
691 m_instanceData->toAddon.get_chapter_name = ADDON_GetChapterName;
692 m_instanceData->toAddon.get_chapter_pos = ADDON_GetChapterPos;
693 m_instanceData->toAddon.seek_chapter = ADDON_SeekChapter;
694 }
695
696 int minBlockSizeVersion[3] = {2, 0, 12};
697 if (compareVersion(api, minBlockSizeVersion) >= 0)
698 {
699 m_instanceData->toAddon.block_size_stream = ADDON_GetBlockSize;
700 }
701 }
702
703 inline static bool ADDON_Open(const AddonInstance_InputStream* instance, INPUTSTREAM* props)
704 {
705 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->Open(*props);
706 }
707
708 inline static void ADDON_Close(const AddonInstance_InputStream* instance)
709 {
710 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->Close();
711 }
712
713 inline static void ADDON_GetCapabilities(const AddonInstance_InputStream* instance,
714 INPUTSTREAM_CAPABILITIES* capabilities)
715 {
716 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
717 ->GetCapabilities(*capabilities);
718 }
719
720
721 // IDemux
722 inline static struct INPUTSTREAM_IDS ADDON_GetStreamIds(const AddonInstance_InputStream* instance)
723 {
724 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetStreamIds();
725 }
726
727 inline static struct INPUTSTREAM_INFO ADDON_GetStream(const AddonInstance_InputStream* instance,
728 int streamid)
729 {
730 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetStream(streamid);
731 }
732
733 inline static void ADDON_EnableStream(const AddonInstance_InputStream* instance,
734 int streamid,
735 bool enable)
736 {
737 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
738 ->EnableStream(streamid, enable);
739 }
740
741 inline static bool ADDON_OpenStream(const AddonInstance_InputStream* instance, int streamid)
742 {
743 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
744 ->OpenStream(streamid);
745 }
746
747 inline static void ADDON_DemuxReset(const AddonInstance_InputStream* instance)
748 {
749 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->DemuxReset();
750 }
751
752 inline static void ADDON_DemuxAbort(const AddonInstance_InputStream* instance)
753 {
754 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->DemuxAbort();
755 }
756
757 inline static void ADDON_DemuxFlush(const AddonInstance_InputStream* instance)
758 {
759 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->DemuxFlush();
760 }
761
762 inline static DemuxPacket* ADDON_DemuxRead(const AddonInstance_InputStream* instance)
763 {
764 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->DemuxRead();
765 }
766
767 inline static bool ADDON_DemuxSeekTime(const AddonInstance_InputStream* instance,
768 double time,
769 bool backwards,
770 double* startpts)
771 {
772 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
773 ->DemuxSeekTime(time, backwards, *startpts);
774 }
775
776 inline static void ADDON_DemuxSetSpeed(const AddonInstance_InputStream* instance, int speed)
777 {
778 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->DemuxSetSpeed(speed);
779 }
780
781 inline static void ADDON_SetVideoResolution(const AddonInstance_InputStream* instance,
782 int width,
783 int height)
784 {
785 static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
786 ->SetVideoResolution(width, height);
787 }
788
789
790 // IDisplayTime
791 inline static int ADDON_GetTotalTime(const AddonInstance_InputStream* instance)
792 {
793 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetTotalTime();
794 }
795
796 inline static int ADDON_GetTime(const AddonInstance_InputStream* instance)
797 {
798 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetTime();
799 }
800
801 // ITime
802 inline static bool ADDON_GetTimes(const AddonInstance_InputStream* instance,
803 INPUTSTREAM_TIMES* times)
804 {
805 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetTimes(*times);
806 }
807
808 // IPosTime
809 inline static bool ADDON_PosTime(const AddonInstance_InputStream* instance, int ms)
810 {
811 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->PosTime(ms);
812 }
813
814 inline static int ADDON_GetChapter(const AddonInstance_InputStream* instance)
815 {
816 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetChapter();
817 }
818
819 inline static int ADDON_GetChapterCount(const AddonInstance_InputStream* instance)
820 {
821 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetChapterCount();
822 }
823
824 inline static const char* ADDON_GetChapterName(const AddonInstance_InputStream* instance, int ch)
825 {
826 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetChapterName(ch);
827 }
828
829 inline static int64_t ADDON_GetChapterPos(const AddonInstance_InputStream* instance, int ch)
830 {
831 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetChapterPos(ch);
832 }
833
834 inline static bool ADDON_SeekChapter(const AddonInstance_InputStream* instance, int ch)
835 {
836 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->SeekChapter(ch);
837 }
838
839 inline static int ADDON_ReadStream(const AddonInstance_InputStream* instance,
840 uint8_t* buffer,
841 unsigned int bufferSize)
842 {
843 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
844 ->ReadStream(buffer, bufferSize);
845 }
846
847 inline static int64_t ADDON_SeekStream(const AddonInstance_InputStream* instance,
848 int64_t position,
849 int whence)
850 {
851 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)
852 ->SeekStream(position, whence);
853 }
854
855 inline static int64_t ADDON_PositionStream(const AddonInstance_InputStream* instance)
856 {
857 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->PositionStream();
858 }
859
860 inline static int64_t ADDON_LengthStream(const AddonInstance_InputStream* instance)
861 {
862 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->LengthStream();
863 }
864
865 inline static int ADDON_GetBlockSize(const AddonInstance_InputStream* instance)
866 {
867 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->GetBlockSize();
868 }
869
870 inline static bool ADDON_IsRealTimeStream(const AddonInstance_InputStream* instance)
871 {
872 return static_cast<CInstanceInputStream*>(instance->toAddon.addonInstance)->IsRealTimeStream();
873 }
874
875 AddonInstance_InputStream* m_instanceData;
876};
877
878} /* namespace addon */
879} /* namespace kodi */
880
881#endif /* __cplusplus */