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