From 3cb8aa05f8cee9e860cf83531682ff0ed4af6a4f Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 4 Mar 2021 23:36:40 +0100 Subject: sync with upstream --- .../include/kodi/addon-instance/Inputstream.h | 2302 +++++++++++++++----- 1 file changed, 1703 insertions(+), 599 deletions(-) (limited to 'xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h') 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 index 396b92e..c4c7aca 100644 --- a/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h +++ b/xbmc/addons/kodi-dev-kit/include/kodi/addon-instance/Inputstream.h @@ -8,682 +8,1757 @@ #pragma once -/* - * Parts with a comment named "internal" are only used inside header and not - * used or accessed direct during add-on development! - */ - #include "../AddonBase.h" -#include "../StreamCodec.h" -#include "../StreamCrypto.h" +#include "../c-api/addon-instance/inputstream.h" +#include "inputstream/StreamCodec.h" +#include "inputstream/StreamConstants.h" +#include "inputstream/StreamCrypto.h" +#include "inputstream/TimingConstants.h" -#ifdef BUILD_KODI_ADDON -#include "../DemuxPacket.h" -#include "../InputStreamConstants.h" -#else -#include "cores/VideoPlayer/Interface/Addon/DemuxPacket.h" -#include "cores/VideoPlayer/Interface/Addon/InputStreamConstants.h" -#endif +#ifdef __cplusplus -//Increment this level always if you add features which can lead to compile failures in the addon -#define INPUTSTREAM_VERSION_LEVEL 2 +#include -#define INPUTSTREAM_MAX_STREAM_COUNT 256 -#define INPUTSTREAM_MAX_STRING_NAME_SIZE 256 -#define INPUTSTREAM_MAX_STRING_CODEC_SIZE 32 -#define INPUTSTREAM_MAX_STRING_LANGUAGE_SIZE 64 +namespace kodi +{ +namespace addon +{ -#ifdef __cplusplus -extern "C" +//¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ +// "C++" Doxygen group set for the definitions +//{{{ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs Definitions, structures and enumerators +/// @ingroup cpp_kodi_addon_inputstream +/// @brief **Inputstream add-on instance definition values**\n +/// All inputstream functions associated data structures. +/// +/// Used to exchange the available options between Kodi and addon.\n +/// The groups described here correspond to the groups of functions on inputstream +/// instance class. +/// +/// In addition, some of the things described here are also used on the +/// @ref cpp_kodi_addon_videocodec "video codec" addon. +/// + +//############################################################################## +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface 1. Interface +/// @ingroup cpp_kodi_addon_inputstream_Defs +/// @brief **Inputstream add-on general variables**\n +/// Used to exchange the available options between Kodi and addon. +/// + +//############################################################################## +/// @defgroup cpp_kodi_addon_inputstream_Defs_StreamConstants 2. Stream constants +/// @ingroup cpp_kodi_addon_inputstream_Defs +/// @brief **Used to exchange any additional data between the caller and processor.**\n +/// This includes the standardized values, in addition, an addon can also use +/// its own special uses to be exchanged in the same way. +/// +/// These values can be used by other addons (e.g. video addon) or stream files +/// to select the respective inputstream addon and to transfer additional values. +/// +/// ---------------------------------------------------------------------------- +/// +/// **Example:** +/// +/// This example use the @ref STREAM_PROPERTY_INPUTSTREAM on a `*.strm` +/// file to select needed addon and a additional value where related to selected +/// addon itself. +/// +/// ~~~~~~~~~~~~ +/// #KODIPROP:inputstream=inputstream.adaptive +/// #KODIPROP:inputstream.adaptive.manifest_type=mpd +/// http://rdmedia.bbc.co.uk/dash/ondemand/testcard/1/client_manifest-events-multilang.mpd +/// ~~~~~~~~~~~~ +/// +/// These are then given to Kodi and the respectively selected addon by means of +/// his @ref kodi::addon::CInstanceInputStream::Open "Open" call +/// in @ref kodi::addon::InputstreamProperty::GetProperties. +/// +/// The largest possible amount of these `#KODIPROP` values is defined +/// with @ref STREAM_MAX_PROPERTY_COUNT. +/// + +//############################################################################## +/// @defgroup cpp_kodi_addon_inputstream_Defs_TimingConstants 3. Stream timing +/// @ingroup cpp_kodi_addon_inputstream_Defs +/// @brief **Timebase and timestamp definitions.**\n +/// Used to exchange the available options between Kodi and addon. +/// + +//############################################################################## +/// @defgroup cpp_kodi_addon_inputstream_Defs_StreamCodec 4. Stream codec +/// @ingroup cpp_kodi_addon_inputstream_Defs +/// @brief **Inputstream codec control**\n +/// Used to manage stream codec data. +/// + +//############################################################################## +/// @defgroup cpp_kodi_addon_inputstream_Defs_StreamEncryption 5. Stream encryption +/// @ingroup cpp_kodi_addon_inputstream_Defs +/// @brief **Inputstream encryption control**\n +/// Used to manage encrypted streams within addon. +/// + +//}}} +//______________________________________________________________________________ + +class CInstanceInputStream; + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_InputstreamProperty class InputstreamProperty +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief URL and Data of key/value pairs passed to addon on @ref kodi::addon::CInstanceInputStream::Open "Open".\n +/// This is used to have the necessary data of the stream to be opened. +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_InputstreamProperty_Help +/// +/// @warning This data are only given from Kodi to addon and can't be used +/// on other places on addon. +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamProperty + : public CStructHdl { -#endif /* __cplusplus */ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + /*! \endcond */ - /*! - * @brief InputStream add-on capabilities. All capabilities are set to "false" as default. - */ - struct INPUTSTREAM_CAPABILITIES +public: + /// @defgroup cpp_kodi_addon_inputstream_Defs_InputstreamProperty_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_InputstreamProperty + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_InputstreamProperty : + /// | Name | Type | Get call + /// |------|------|---------- + /// | **Stream URL** | `std::string` | @ref InputstreamProperty::GetURL "GetURL" + /// | **Mime type** | `std::string` | @ref InputstreamProperty::GetMimeType "GetMimeType" + /// | **Available amount of properties** | `unsigned int` | @ref InputstreamProperty::GetPropertiesAmount "GetPropertiesAmount" + /// | **List of properties** | `std::map` | @ref InputstreamProperty::GetProperties "GetProperties" + /// | **Get addon library folder** | `std::string` | @ref InputstreamProperty::GetLibFolder "GetLibFolder" + /// | **Get addon profile/user folder** | `std::string` | @ref InputstreamProperty::GetProfileFolder "GetProfileFolder" + + /// @addtogroup cpp_kodi_addon_inputstream_Defs_InputstreamProperty + ///@{ + + /// @brief Stream URL to open. + std::string GetURL() const { return m_cStructure->m_strURL; } + + /// @brief Stream mime type. + std::string GetMimeType() const { return m_cStructure->m_mimeType; } + + /// @brief Amount of available properties. + unsigned int GetPropertiesAmount() const { - enum MASKTYPE : uint32_t + return m_cStructure->m_nCountInfoValues; + } + + /// @brief List of available properties- + const std::map GetProperties() const + { + std::map props; + for (unsigned int i = 0; i < m_cStructure->m_nCountInfoValues; ++i) { - /// supports interface IDemux - SUPPORTS_IDEMUX = (1 << 0), + props.emplace(m_cStructure->m_ListItemProperties[i].m_strKey, + m_cStructure->m_ListItemProperties[i].m_strValue); + } + return props; + } + + /// @brief Get addon library folder. + /// + /// @note As alternative can also @ref kodi::GetAddonPath used. + std::string GetLibFolder() const { return m_cStructure->m_libFolder; } + + /// @brief Get addon profile/user folder. + /// + /// @note As alternative can also @ref kodi::GetBaseUserPath used. + std::string GetProfileFolder() const { return m_cStructure->m_profileFolder; } + + ///@} + +private: + InputstreamProperty() = delete; + InputstreamProperty(const InputstreamProperty& stream) = delete; + InputstreamProperty(const INPUTSTREAM_PROPERTY* stream) : CStructHdl(stream) {} + InputstreamProperty(INPUTSTREAM_PROPERTY* stream) : CStructHdl(stream) {} +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities class InputstreamCapabilities +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief **InputStream add-on capabilities. All capabilities are set to "false" as default.**\n +/// Asked to addon on @ref kodi::addon::CInstanceInputStream::GetCapabilities "GetCapabilities". +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities_Help +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamCapabilities + : public CStructHdl +{ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + /*! \endcond */ - /// supports interface IPosTime - SUPPORTS_IPOSTIME = (1 << 1), +public: + /*! \cond PRIVATE */ + InputstreamCapabilities() = default; + InputstreamCapabilities(const InputstreamCapabilities& stream) : CStructHdl(stream) {} + /*! \endcond */ - /// supports interface IDisplayTime - SUPPORTS_IDISPLAYTIME = (1 << 2), + /// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities : + /// | Name | Type | Set call | Get call + /// |------|------|----------|---------- + /// | **Capabilities bit mask** | `uint32_t` | @ref InputstreamCapabilities::SetMask "SetMask" | @ref InputstreamCapabilities::GetMask "GetMask" - /// supports seek - SUPPORTS_SEEK = (1 << 3), + /// @addtogroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities + ///@{ - /// supports pause - SUPPORTS_PAUSE = (1 << 4), + /// @brief Set of supported capabilities. + void SetMask(uint32_t mask) const { m_cStructure->m_mask = mask; } - /// supports interface ITime - SUPPORTS_ITIME = (1 << 5), + /// @brief Get of supported capabilities. + uint32_t GetMask() const { return m_cStructure->m_mask; } - /// supports interface IChapter - SUPPORTS_ICHAPTER = (1 << 6), - }; + ///@} - /// set of supported capabilities - uint32_t m_mask; - }; +private: + InputstreamCapabilities(const INPUTSTREAM_CAPABILITIES* stream) : CStructHdl(stream) {} + InputstreamCapabilities(INPUTSTREAM_CAPABILITIES* stream) : CStructHdl(stream) {} +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata class InputstreamMasteringMetadata +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief **Mastering metadata.**\n +/// Describes the metadata for [HDR10](https://en.wikipedia.org/wiki/High-dynamic-range_video). +/// +/// Used when video is compressed using [High Efficiency Video Coding (HEVC)](https://en.wikipedia.org/wiki/High_Efficiency_Video_Coding). +/// This is used to describe the capabilities of the display used to master the +/// content and the luminance values of the content. +/// +/// Used on @ref kodi::addon::InputstreamInfo::SetMasteringMetadata and @ref kodi::addon::InputstreamInfo::GetMasteringMetadata. +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata_Help +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamMasteringMetadata + : public CStructHdl +{ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + friend class InputstreamInfo; + /*! \endcond */ - /*! - * @brief structure of key/value pairs passed to addon on Open() - */ - struct INPUTSTREAM +public: + /*! \cond PRIVATE */ + InputstreamMasteringMetadata() = default; + InputstreamMasteringMetadata(const InputstreamMasteringMetadata& stream) : CStructHdl(stream) {} + /*! \endcond */ + + /// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata : + /// | Name | Type | Set call | Get call + /// |------|------|----------|---------- + /// | **Chromaticity X coordinates of the red** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryR_ChromaticityX "SetPrimaryR_ChromaticityX" | @ref InputstreamMasteringMetadata::GetPrimaryR_ChromaticityX "GetPrimaryR_ChromaticityX" + /// | **Chromaticity Y coordinates of the red** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryR_ChromaticityY "SetPrimaryR_ChromaticityY" | @ref InputstreamMasteringMetadata::GetPrimaryR_ChromaticityY "GetPrimaryR_ChromaticityY" + /// | **Chromaticity X coordinates of the green** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryG_ChromaticityX "SetPrimaryG_ChromaticityX" | @ref InputstreamMasteringMetadata::GetPrimaryG_ChromaticityX "GetPrimaryG_ChromaticityX" + /// | **Chromaticity Y coordinates of the green** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryG_ChromaticityY "SetPrimaryG_ChromaticityY" | @ref InputstreamMasteringMetadata::GetPrimaryG_ChromaticityY "GetPrimaryG_ChromaticityY" + /// | **Chromaticity X coordinates of the blue** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryB_ChromaticityX "SetPrimaryB_ChromaticityX" | @ref InputstreamMasteringMetadata::GetPrimaryB_ChromaticityX "GetPrimaryB_ChromaticityX" + /// | **Chromaticity Y coordinates of the blue** | `double` | @ref InputstreamMasteringMetadata::SetPrimaryB_ChromaticityY "SetPrimaryB_ChromaticityY" | @ref InputstreamMasteringMetadata::GetPrimaryB_ChromaticityY "GetPrimaryB_ChromaticityY" + /// | **Chromaticity X coordinates of the white point** | `double` | @ref InputstreamMasteringMetadata::SetWhitePoint_ChromaticityX "SetWhitePoint_ChromaticityX" | @ref InputstreamMasteringMetadata::GetWhitePoint_ChromaticityX "GetWhitePoint_ChromaticityX" + /// | **Chromaticity Y coordinates of the white point** | `double` | @ref InputstreamMasteringMetadata::SetWhitePoint_ChromaticityY "SetWhitePoint_ChromaticityY" | @ref InputstreamMasteringMetadata::GetWhitePoint_ChromaticityY "GetWhitePoint_ChromaticityY" + /// | **Maximum number of bits of the display** | `double` | @ref InputstreamMasteringMetadata::SetLuminanceMax "SetLuminanceMax" | @ref InputstreamMasteringMetadata::GetLuminanceMax "GetLuminanceMax" + /// | **Minimum number of bits of the display** | `double` | @ref InputstreamMasteringMetadata::SetLuminanceMin "SetLuminanceMin" | @ref InputstreamMasteringMetadata::GetLuminanceMin "GetLuminanceMin" + + /// @addtogroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata + ///@{ + + /// @brief Metadata class compare. + /// + /// To compare the metadata with another one. + /// + /// @return true if they equal, false otherwise + bool operator==(const kodi::addon::InputstreamMasteringMetadata& right) const { - const char* m_strURL; - const char* m_mimeType; + if (memcmp(m_cStructure, right.m_cStructure, sizeof(INPUTSTREAM_MASTERING_METADATA)) == 0) + return true; + return false; + } - unsigned int m_nCountInfoValues; - struct LISTITEMPROPERTY - { - const char* m_strKey; - const char* m_strValue; - } m_ListItemProperties[STREAM_MAX_PROPERTY_COUNT]; - - const char* m_libFolder; - const char* m_profileFolder; - }; - - /*! - * @brief Array of stream IDs - */ - struct INPUTSTREAM_IDS - { - unsigned int m_streamCount; - unsigned int m_streamIds[INPUTSTREAM_MAX_STREAM_COUNT]; - }; - - /*! - * @brief MASTERING Metadata - */ - struct INPUTSTREAM_MASTERING_METADATA - { - double primary_r_chromaticity_x; - double primary_r_chromaticity_y; - double primary_g_chromaticity_x; - double primary_g_chromaticity_y; - double primary_b_chromaticity_x; - double primary_b_chromaticity_y; - double white_point_chromaticity_x; - double white_point_chromaticity_y; - double luminance_max; - double luminance_min; - }; - - /*! - * @brief CONTENTLIGHT Metadata - */ - struct INPUTSTREAM_CONTENTLIGHT_METADATA - { - uint64_t max_cll; - uint64_t max_fall; - }; - - /*! - * @brief stream properties - */ - struct INPUTSTREAM_INFO - { - enum STREAM_TYPE - { - TYPE_NONE = 0, - TYPE_VIDEO, - TYPE_AUDIO, - TYPE_SUBTITLE, - TYPE_TELETEXT, - TYPE_RDS, - } m_streamType; - - enum Codec_FEATURES : uint32_t - { - FEATURE_DECODE = 1 - }; - uint32_t m_features; + /// @brief Set the chromaticity coordinates of the red value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// X coordinate. The values are normalized to 50,000. + void SetPrimaryR_ChromaticityX(double value) { m_cStructure->primary_r_chromaticity_x = value; } + + /// @brief Get the chromaticity X coordinates of the red value. + double GetPrimaryR_ChromaticityX() { return m_cStructure->primary_r_chromaticity_x; } + + /// @brief The chromaticity coordinates of the red value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// Y coordinate. The values are normalized to 50,000. + void SetPrimaryR_ChromaticityY(double value) { m_cStructure->primary_r_chromaticity_y = value; } + + /// @brief Get the chromaticity Y coordinates of the red value. + double GetPrimaryR_ChromaticityY() { return m_cStructure->primary_r_chromaticity_y; } + + /// @brief Set the chromaticity coordinates of the green value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// X coordinate. The values are normalized to 50,000. + void SetPrimaryG_ChromaticityX(double value) { m_cStructure->primary_g_chromaticity_x = value; } + + /// @brief Get the chromaticity X coordinates of the green value. + double GetPrimaryG_ChromaticityX() { return m_cStructure->primary_g_chromaticity_x; } + + /// @brief Set the chromaticity coordinates of the green value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// Y coordinate. The values are normalized to 50,000. + void SetPrimaryG_ChromaticityY(double value) { m_cStructure->primary_g_chromaticity_y = value; } + + /// @brief Get the chromaticity Y coordinates of the green value. + double GetPrimaryG_ChromaticityY() { return m_cStructure->primary_g_chromaticity_y; } + + /// @brief The chromaticity coordinates of the blue value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// X coordinate. The values are normalized to 50,000. + void SetPrimaryB_ChromaticityX(double value) { m_cStructure->primary_b_chromaticity_x = value; } + + /// @brief Get the chromaticity X coordinates of the blue value. + double GetPrimaryB_ChromaticityX() { return m_cStructure->primary_b_chromaticity_x; } + + /// @brief The chromaticity coordinates of the blue value in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// Y coordinate. The values are normalized to 50,000. + void SetPrimaryB_ChromaticityY(double value) { m_cStructure->primary_b_chromaticity_y = value; } + + /// @brief Get the chromaticity Y coordinates of the blue value. + double GetPrimaryB_ChromaticityY() { return m_cStructure->primary_b_chromaticity_y; } + + /// @brief Set the chromaticity coordinates of the white point in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// X coordinate. The values are normalized to 50,000. + void SetWhitePoint_ChromaticityX(double value) + { + m_cStructure->white_point_chromaticity_x = value; + } - enum STREAM_FLAGS : uint32_t - { - FLAG_NONE = 0x0000, - FLAG_DEFAULT = 0x0001, - FLAG_DUB = 0x0002, - FLAG_ORIGINAL = 0x0004, - FLAG_COMMENT = 0x0008, - FLAG_LYRICS = 0x0010, - FLAG_KARAOKE = 0x0020, - FLAG_FORCED = 0x0040, - FLAG_HEARING_IMPAIRED = 0x0080, - FLAG_VISUAL_IMPAIRED = 0x0100, - }; - - // Keep in sync with AVColorSpace - enum COLORSPACE - { - COLORSPACE_RGB = 0, - COLORSPACE_BT709 = 1, - COLORSPACE_UNSPECIFIED = 2, - COLORSPACE_UNKNOWN = COLORSPACE_UNSPECIFIED, // compatibility - COLORSPACE_RESERVED = 3, - COLORSPACE_FCC = 4, - COLORSPACE_BT470BG = 5, - COLORSPACE_SMPTE170M = 6, - COLORSPACE_SMPTE240M = 7, - COLORSPACE_YCGCO = 8, - COLORSPACE_YCOCG = COLORSPACE_YCGCO, - COLORSPACE_BT2020_NCL = 9, - COLORSPACE_BT2020_CL = 10, - COLORSPACE_SMPTE2085 = 11, - COLORSPACE_CHROMA_DERIVED_NCL = 12, - COLORSPACE_CHROMA_DERIVED_CL = 13, - COLORSPACE_ICTCP = 14, - COLORSPACE_MAX - }; - - // Keep in sync with AVColorPrimaries - enum COLORPRIMARIES : int32_t - { - COLORPRIMARY_RESERVED0 = 0, - COLORPRIMARY_BT709 = 1, - COLORPRIMARY_UNSPECIFIED = 2, - COLORPRIMARY_RESERVED = 3, - COLORPRIMARY_BT470M = 4, - COLORPRIMARY_BT470BG = 5, - COLORPRIMARY_SMPTE170M = 6, - COLORPRIMARY_SMPTE240M = 7, - COLORPRIMARY_FILM = 8, - COLORPRIMARY_BT2020 = 9, - COLORPRIMARY_SMPTE428 = 10, - COLORPRIMARY_SMPTEST428_1 = COLORPRIMARY_SMPTE428, - COLORPRIMARY_SMPTE431 = 11, - COLORPRIMARY_SMPTE432 = 12, - COLORPRIMARY_JEDEC_P22 = 22, - COLORPRIMARY_MAX - }; - - // Keep in sync with AVColorRange - enum COLORRANGE + /// @brief Get the chromaticity X coordinates of the white point + double GetWhitePoint_ChromaticityX() { return m_cStructure->white_point_chromaticity_x; } + + /// @brief Set the chromaticity coordinates of the white point in the + /// [CIE1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space. + /// + /// Y coordinate. The values are normalized to 50,000. + void SetWhitePoint_ChromaticityY(double value) + { + m_cStructure->white_point_chromaticity_y = value; + } + + /// @brief Get the chromaticity Y coordinates of the white point. + double GetWhitePoint_ChromaticityY() { return m_cStructure->white_point_chromaticity_y; } + + /// @brief Set the maximum number of bits of the display used to master the content. + /// + /// Values are normalized to 10,000. + void SetLuminanceMax(double value) { m_cStructure->luminance_max = value; } + + /// @brief Get the maximum number of bits of the display. + double GetLuminanceMax() { return m_cStructure->luminance_max; } + + /// @brief Set the minimum number of bits of the display used to master the content. + /// + /// Values are normalized to 10,000. + void SetLuminanceMin(double value) { m_cStructure->luminance_min = value; } + + /// @brief Get the minimum number of bits of the display. + double GetLuminanceMin() { return m_cStructure->luminance_min; } + + ///@} + +private: + InputstreamMasteringMetadata(const INPUTSTREAM_MASTERING_METADATA* stream) : CStructHdl(stream) {} + InputstreamMasteringMetadata(INPUTSTREAM_MASTERING_METADATA* stream) : CStructHdl(stream) {} +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata class InputstreamContentlightMetadata +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief **Contentlight metadata**\n +/// Describes the metadata for [HDR10](https://en.wikipedia.org/wiki/High-dynamic-range_video). +/// See also @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata "InputstreamMasteringMetadata". +/// +/// Used on @ref kodi::addon::InputstreamInfo::SetContentLightMetadata and @ref kodi::addon::InputstreamInfo::GetContentLightMetadata. +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata_Help +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamContentlightMetadata + : public CStructHdl +{ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + friend class InputstreamInfo; + /*! \endcond */ + +public: + /*! \cond PRIVATE */ + InputstreamContentlightMetadata() = default; + InputstreamContentlightMetadata(const InputstreamContentlightMetadata& stream) + : CStructHdl(stream) + { + } + /*! \endcond */ + + /// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata : + /// | Name | Type | Set call | Get call + /// |------|------|----------|---------- + /// | **Maximum content light level** | `double` | @ref InputstreamContentlightMetadata::SetMaxCll "SetMaxCll" | @ref InputstreamContentlightMetadata::GetMaxCll "GetMaxCll" + /// | **Maximum frame average light level** | `double` | @ref InputstreamContentlightMetadata::SetMaxFall "SetMaxFall" | @ref InputstreamContentlightMetadata::GetMaxFall "GetMaxFall" + + /// @addtogroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata + ///@{ + + /// @brief Metadata class compare. + /// + /// To compare the metadata with another one. + /// + /// @return true if they equal, false otherwise + bool operator==(const kodi::addon::InputstreamContentlightMetadata& right) const + { + if (memcmp(m_cStructure, right.m_cStructure, sizeof(INPUTSTREAM_CONTENTLIGHT_METADATA)) == 0) + return true; + return false; + } + + /// @brief Set the maximum content light level (MaxCLL). + /// + /// This is the bit value corresponding to the brightest pixel used anywhere + /// in the content. + void SetMaxCll(uint64_t value) { m_cStructure->max_cll = value; } + + /// @brief Get the maximum content light level (MaxCLL). + uint64_t GetMaxCll() { return m_cStructure->max_cll; } + + /// @brief Set the maximum frame average light level (MaxFALL). + /// + /// This is the bit value corresponding to the average luminance of the frame + /// which has the brightest average luminance anywhere in the content. + void SetMaxFall(uint64_t value) { m_cStructure->max_fall = value; } + + /// @brief Get the maximum frame average light level (MaxFALL). + uint64_t GetMaxFall() { return m_cStructure->max_fall; } + + ///@} + +private: + InputstreamContentlightMetadata(const INPUTSTREAM_CONTENTLIGHT_METADATA* stream) + : CStructHdl(stream) + { + } + InputstreamContentlightMetadata(INPUTSTREAM_CONTENTLIGHT_METADATA* stream) : CStructHdl(stream) {} +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo class InputstreamInfo +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief **Inputstream add-on stream info**\n +/// This is used to give Kodi the associated and necessary data for an open stream. +/// +/// Used on @ref kodi::addon::CInstanceInputStream::GetStream(). +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo_Help +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamInfo : public CStructHdl +{ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + /*! \endcond */ + +public: + /*! \cond PRIVATE */ + InputstreamInfo() = default; + InputstreamInfo(const InputstreamInfo& stream) : CStructHdl(stream) + { + SetCryptoSession(stream.GetCryptoSession()); + CopyExtraData(); + } + /*! \endcond */ + + /// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo : + /// | Name | Type used | Required | Set call | Get call + /// |------|-----------|----------|----------|--------- + /// | **Stream type** | all | yes | @ref InputstreamInfo::SetStreamType "SetStreamType" | @ref InputstreamInfo::GetStreamType "GetStreamType" + /// | **Feature flags** | all | yes | @ref InputstreamInfo::SetFeatures "SetFeatures" | @ref InputstreamInfo::GetFeatures "GetFeatures" + /// | **Flags** | all | yes | @ref InputstreamInfo::SetFlags "SetFlags" | @ref InputstreamInfo::GetFlags "GetFlags" + /// | **Name** | all | no | @ref InputstreamInfo::SetName "SetName" | @ref InputstreamInfo::GetName "GetName" + /// | **Codec name** | all | yes | @ref InputstreamInfo::SetCodecName "SetCodecName" | @ref InputstreamInfo::GetCodecName "GetCodecName" + /// | **Codec internal name** | all | no | @ref InputstreamInfo::SetCodecInternalName "SetCodecInternalName" | @ref InputstreamInfo::GetCodecInternalName "GetCodecInternalName" + /// | **Codec Profile** | all | no | @ref InputstreamInfo::SetCodecProfile "SetCodecProfile" | @ref InputstreamInfo::GetCodecProfile "GetCodecProfile" + /// | **Physical index** | all | yes | @ref InputstreamInfo::SetPhysicalIndex "SetPhysicalIndex" | @ref InputstreamInfo::GetPhysicalIndex "GetPhysicalIndex" + /// | **Extra data** | Subtitle / all | Type related required | @ref InputstreamInfo::SetExtraData "SetExtraData" | @ref InputstreamInfo::GetExtraData "GetExtraData" + /// | **RFC 5646 language code** | all | no | @ref InputstreamInfo::SetLanguage "SetLanguage" | @ref InputstreamInfo::GetLanguage "GetLanguage" + /// | **FPS scale** | Video | Type related required | @ref InputstreamInfo::SetFpsScale "SetFpsScale" | @ref InputstreamInfo::GetFpsScale "GetFpsScale" + /// | **FPS rate** | Video | Type related required | @ref InputstreamInfo::SetFpsRate "SetFpsRate" | @ref InputstreamInfo::GetFpsRate "GetFpsRate" + /// | **Height** | Video | Type related required | @ref InputstreamInfo::SetHeight "SetHeight" | @ref InputstreamInfo::GetHeight "GetHeight" + /// | **Width** | Video | Type related required | @ref InputstreamInfo::SetWidth "SetWidth" | @ref InputstreamInfo::GetWidth "GetWidth" + /// | **Aspect** | Video | Type related required | @ref InputstreamInfo::SetAspect "SetAspect" | @ref InputstreamInfo::GetAspect "GetAspect" + /// | **Channel quantity** | Audio | Type related required | @ref InputstreamInfo::SetChannels "SetChannels" | @ref InputstreamInfo::GetChannels "GetChannels" + /// | **Sample rate** | Audio | Type related required | @ref InputstreamInfo::SetSampleRate "SetSampleRate" | @ref InputstreamInfo::GetSampleRate "GetSampleRate" + /// | **Bit rate** | Audio | Type related required | @ref InputstreamInfo::SetBitRate "SetBitRate" | @ref InputstreamInfo::GetBitRate "GetBitRate" + /// | **Bits per sample** | Audio | Type related required | @ref InputstreamInfo::SetBitsPerSample "SetBitsPerSample" | @ref InputstreamInfo::GetBitsPerSample "GetBitsPerSample" + /// | **Block align** | | no | @ref InputstreamInfo::SetBlockAlign "SetBlockAlign" | @ref InputstreamInfo::GetBlockAlign "GetBlockAlign" + /// | **Crypto session info** | | no | @ref InputstreamInfo::SetCryptoSession "SetCryptoSession" | @ref InputstreamInfo::GetCryptoSession "GetCryptoSession" + /// | **Four CC code** | | no | @ref InputstreamInfo::SetCodecFourCC "SetCodecFourCC" | @ref InputstreamInfo::GetCodecFourCC "GetCodecFourCC" + /// | **Color space** | | no | @ref InputstreamInfo::SetColorSpace "SetColorSpace" | @ref InputstreamInfo::GetColorSpace "GetColorSpace" + /// | **Color range** | | no | @ref InputstreamInfo::SetColorRange "SetColorRange" | @ref InputstreamInfo::GetColorRange "GetColorRange" + /// | **Color primaries** | | no | @ref InputstreamInfo::SetColorPrimaries "SetColorPrimaries" | @ref InputstreamInfo::GetColorPrimaries "GetColorPrimaries" + /// | **Color transfer characteristic** | | no | @ref InputstreamInfo::SetColorTransferCharacteristic "SetColorTransferCharacteristic" | @ref InputstreamInfo::GetColorTransferCharacteristic "GetColorTransferCharacteristic" + /// | **Mastering metadata** | | no | @ref InputstreamInfo::SetMasteringMetadata "SetMasteringMetadata" | @ref InputstreamInfo::GetMasteringMetadata "GetMasteringMetadata" + /// | **Content light metadata** | | no | @ref InputstreamInfo::SetContentLightMetadata "SetContentLightMetadata" | @ref InputstreamInfo::GetContentLightMetadata "GetContentLightMetadata" + /// + + /// @addtogroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo + ///@{ + + /// @brief Set the wanted stream type. + /// + /// @param[in] streamType By @ref INPUTSTREAM_TYPE defined type + void SetStreamType(INPUTSTREAM_TYPE streamType) { m_cStructure->m_streamType = streamType; } + + /// @brief To get with @ref SetStreamType changed values. + INPUTSTREAM_TYPE GetStreamType() const { return m_cStructure->m_streamType; } + + /// @brief Set special supported feature flags of inputstream. + /// + /// @param[in] features By @ref INPUTSTREAM_CODEC_FEATURES defined type + void SetFeatures(uint32_t features) { m_cStructure->m_features = features; } + + /// @brief To get with @ref SetFeatures changed values. + uint32_t GetFeatures() const { return m_cStructure->m_features; } + + /// @brief Set supported flags of inputstream. + /// + /// @param[in] flags The on @ref INPUTSTREAM_FLAGS defined flags to set + void SetFlags(uint32_t flags) { m_cStructure->m_flags = flags; } + + /// @brief To get with @ref SetFeatures changed values. + uint32_t GetFlags() const { return m_cStructure->m_flags; } + + /// @brief (optional) Name of the stream, leave empty for default handling. + /// + /// @param[in] name Stream name + void SetName(const std::string& name) + { + strncpy(m_cStructure->m_name, name.c_str(), INPUTSTREAM_MAX_STRING_NAME_SIZE); + } + + /// @brief To get with @ref SetName changed values. + std::string GetName() const { return m_cStructure->m_name; } + + /// @brief (required) Name of codec according to ffmpeg. + /// + /// See https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/codec_desc.c about + /// available names. + /// + /// @remark On @ref INPUTSTREAM_TYPE_TELETEXT and @ref INPUTSTREAM_TYPE_RDS + /// this can be ignored and leaved empty. + /// + /// @param[in] codeName Codec name + void SetCodecName(const std::string& codecName) + { + strncpy(m_cStructure->m_codecName, codecName.c_str(), INPUTSTREAM_MAX_STRING_CODEC_SIZE); + } + + /// @brief To get with @ref SetCodecName changed values. + std::string GetCodecName() const { return m_cStructure->m_codecName; } + + /// @brief (optional) Internal name of codec (selectionstream info). + /// + /// @param[in] codecName Internal codec name + void SetCodecInternalName(const std::string& codecName) + { + strncpy(m_cStructure->m_codecInternalName, codecName.c_str(), + INPUTSTREAM_MAX_STRING_CODEC_SIZE); + } + + /// @brief To get with @ref SetCodecInternalName changed values. + std::string GetCodecInternalName() const { return m_cStructure->m_codecInternalName; } + + /// @brief (optional) The profile of the codec. + /// + /// @param[in] codecProfile Values with @ref STREAMCODEC_PROFILE to use + void SetCodecProfile(STREAMCODEC_PROFILE codecProfile) + { + m_cStructure->m_codecProfile = codecProfile; + } + + /// @brief To get with @ref SetCodecProfile changed values. + STREAMCODEC_PROFILE GetCodecProfile() const { return m_cStructure->m_codecProfile; } + + /// @brief (required) Physical index. + /// + /// @param[in] id Index identifier + void SetPhysicalIndex(unsigned int id) { m_cStructure->m_pID = id; } + + /// @brief To get with @ref SetPhysicalIndex changed values. + unsigned int GetPhysicalIndex() const { return m_cStructure->m_pID; } + + /// @brief Additional data where can needed on streams. + /// + /// @param[in] extraData List with memory of extra data + void SetExtraData(const std::vector& extraData) + { + m_extraData = extraData; + m_cStructure->m_ExtraData = m_extraData.data(); + m_cStructure->m_ExtraSize = m_extraData.size(); + } + + /// @brief Additional data where can needed on streams. + /// + /// @param[in] extraData Pointer with memory of extra data + /// @param[in] extraSize Size to store + void SetExtraData(const uint8_t* extraData, size_t extraSize) + { + m_extraData.clear(); + if (extraData && extraSize > 0) { - COLORRANGE_UNKNOWN = 0, - COLORRANGE_LIMITED, - COLORRANGE_FULLRANGE, - COLORRANGE_MAX - }; - - // keep in sync with AVColorTransferCharacteristic - enum COLORTRC : int32_t + for (size_t i = 0; i < extraSize; ++i) + m_extraData.emplace_back(extraData[i]); + } + + m_cStructure->m_ExtraData = m_extraData.data(); + m_cStructure->m_ExtraSize = m_extraData.size(); + } + + /// @brief To get with @ref SetExtraData changed values. + const std::vector& GetExtraData() { return m_extraData; } + + /// @brief To get size with @ref SetExtraData changed values. + size_t GetExtraDataSize() { return m_extraData.size(); } + + /// @brief Compare extra data from outside with class + /// + /// @param[in] extraData Pointer with memory of extra data for compare + /// @param[in] extraSize Size to compare + /// @return true if they equal, false otherwise + bool CompareExtraData(const uint8_t* extraData, size_t extraSize) const + { + if (!extraData || m_extraData.size() != extraSize) + return false; + for (size_t i = 0; i < extraSize; ++i) { - COLORTRC_RESERVED0 = 0, - COLORTRC_BT709 = 1, - COLORTRC_UNSPECIFIED = 2, - COLORTRC_RESERVED = 3, - COLORTRC_GAMMA22 = 4, - COLORTRC_GAMMA28 = 5, - COLORTRC_SMPTE170M = 6, - COLORTRC_SMPTE240M = 7, - COLORTRC_LINEAR = 8, - COLORTRC_LOG = 9, - COLORTRC_LOG_SQRT = 10, - COLORTRC_IEC61966_2_4 = 11, - COLORTRC_BT1361_ECG = 12, - COLORTRC_IEC61966_2_1 = 13, - COLORTRC_BT2020_10 = 14, - COLORTRC_BT2020_12 = 15, - COLORTRC_SMPTE2084 = 16, - COLORTRC_SMPTEST2084 = COLORTRC_SMPTE2084, - COLORTRC_SMPTE428 = 17, - COLORTRC_SMPTEST428_1 = COLORTRC_SMPTE428, - COLORTRC_ARIB_STD_B67 = 18, - COLORTRC_MAX - }; + if (m_extraData[i] != extraData[i]) + return false; + } + return true; + } - uint32_t m_flags; + /// @brief Clear additional data. + void ClearExtraData() + { + m_extraData.clear(); + m_cStructure->m_ExtraData = m_extraData.data(); + m_cStructure->m_ExtraSize = m_extraData.size(); + } - //! @brief (optional) name of the stream, \0 for default handling - char m_name[INPUTSTREAM_MAX_STRING_NAME_SIZE]; + /// @brief RFC 5646 language code (empty string if undefined). + /// + /// @param[in] language The language to set + void SetLanguage(const std::string& language) + { + strncpy(m_cStructure->m_language, language.c_str(), INPUTSTREAM_MAX_STRING_LANGUAGE_SIZE); + } - //! @brief (required) name of codec according to ffmpeg - char m_codecName[INPUTSTREAM_MAX_STRING_CODEC_SIZE]; + /// @brief To get with @ref SetLanguage changed values. + std::string GetLanguage() const { return m_cStructure->m_language; } - //! @brief (optional) internal name of codec (selectionstream info) - char m_codecInternalName[INPUTSTREAM_MAX_STRING_CODEC_SIZE]; + /// @brief Scale of 1000 and a rate of 29970 will result in 29.97 fps. + /// + /// @param[in] fpsScale Scale rate + void SetFpsScale(unsigned int fpsScale) { m_cStructure->m_FpsScale = fpsScale; } - //! @brief (optional) the profile of the codec - STREAMCODEC_PROFILE m_codecProfile; + /// @brief To get with @ref SetFpsScale changed values. + unsigned int GetFpsScale() const { return m_cStructure->m_FpsScale; } - //! @brief (required) physical index - unsigned int m_pID; + /// @brief Rate to use for stream. + /// + /// @param[in] fpsRate Rate to use + void SetFpsRate(unsigned int fpsRate) { m_cStructure->m_FpsRate = fpsRate; } - const uint8_t* m_ExtraData; - unsigned int m_ExtraSize; + /// @brief To get with @ref SetFpsRate changed values. + unsigned int GetFpsRate() const { return m_cStructure->m_FpsRate; } - //! @brief RFC 5646 language code (empty string if undefined) - char m_language[INPUTSTREAM_MAX_STRING_LANGUAGE_SIZE]; + /// @brief Height of the stream reported by the demuxer. + /// + /// @param[in] height Height to use + void SetHeight(unsigned int height) { m_cStructure->m_Height = height; } - //! Video stream related data - //@{ + /// @brief To get with @ref SetHeight changed values. + unsigned int GetHeight() const { return m_cStructure->m_Height; } - //! @brief Scale of 1000 and a rate of 29970 will result in 29.97 fps - unsigned int m_FpsScale; + /// @brief Width of the stream reported by the demuxer. + /// + /// @param[in] width Width to use + void SetWidth(unsigned int width) { m_cStructure->m_Width = width; } - unsigned int m_FpsRate; + /// @brief To get with @ref SetWidth changed values. + unsigned int GetWidth() const { return m_cStructure->m_Width; } - //! @brief height of the stream reported by the demuxer - unsigned int m_Height; + /// @brief Display aspect of stream. + /// + /// @param[in] aspect Aspect ratio to use + void SetAspect(float aspect) { m_cStructure->m_Aspect = aspect; } - //! @brief width of the stream reported by the demuxer - unsigned int m_Width; + /// @brief To get with @ref SetAspect changed values. + float GetAspect() const { return m_cStructure->m_Aspect; } - //! @brief display aspect of stream - float m_Aspect; - - //@} - - //! Audio stream related data - //@{ - - //! @brief (required) amount of channels - unsigned int m_Channels; - - //! @brief (required) sample rate - unsigned int m_SampleRate; - - //! @brief (required) bit rate - unsigned int m_BitRate; - - //! @brief (required) bits per sample - unsigned int m_BitsPerSample; - - unsigned int m_BlockAlign; - - //@} - - CRYPTO_INFO m_cryptoInfo; - - // new in API version 2.0.8 - //@{ - //! @brief Codec If available, the fourcc code codec - unsigned int m_codecFourCC; - - //! @brief definition of colorspace - COLORSPACE m_colorSpace; - - //! @brief color range if available - COLORRANGE m_colorRange; - //@} - - //new in API 2.0.9 / INPUTSTREAM_VERSION_LEVEL 1 - //@{ - COLORPRIMARIES m_colorPrimaries; - COLORTRC m_colorTransferCharacteristic; - //@} - - //! @brief mastering static Metadata - INPUTSTREAM_MASTERING_METADATA* m_masteringMetadata; - - //! @brief content light static Metadata - INPUTSTREAM_CONTENTLIGHT_METADATA* m_contentLightMetadata; - }; + /// @brief (required) Amount of channels. + /// + /// @param[in] sampleRate Channels to use + void SetChannels(unsigned int channels) { m_cStructure->m_Channels = channels; } - struct INPUTSTREAM_TIMES - { - time_t startTime; - double ptsStart; - double ptsBegin; - double ptsEnd; - }; + /// @brief To get with @ref SetChannels changed values. + unsigned int GetChannels() const { return m_cStructure->m_Channels; } - /*! - * @brief "C" ABI Structures to transfer the methods from this to Kodi - */ + /// @brief (required) Sample rate. + /// + /// @param[in] sampleRate Rate to use + void SetSampleRate(unsigned int sampleRate) { m_cStructure->m_SampleRate = sampleRate; } - // this are properties given to the addon on create - // at this time we have no parameters for the addon - typedef struct AddonProps_InputStream /* internal */ + /// @brief To get with @ref SetSampleRate changed values. + unsigned int GetSampleRate() const { return m_cStructure->m_SampleRate; } + + /// @brief Bit rate. + /// + /// @param[in] bitRate Rate to use + void SetBitRate(unsigned int bitRate) { m_cStructure->m_BitRate = bitRate; } + + /// @brief To get with @ref SetBitRate changed values. + unsigned int GetBitRate() const { return m_cStructure->m_BitRate; } + + /// @brief (required) Bits per sample. + /// + /// @param[in] bitsPerSample Bits per sample to use + void SetBitsPerSample(unsigned int bitsPerSample) { - int dummy; - } AddonProps_InputStream; + m_cStructure->m_BitsPerSample = bitsPerSample; + } + + /// @brief To get with @ref SetBitsPerSample changed values. + unsigned int GetBitsPerSample() const { return m_cStructure->m_BitsPerSample; } + + /// @brief To set the necessary stream block alignment size. + /// + /// @param[in] blockAlign Block size in byte + void SetBlockAlign(unsigned int blockAlign) { m_cStructure->m_BlockAlign = blockAlign; } + + /// @brief To get with @ref SetBlockAlign changed values. + unsigned int GetBlockAlign() const { return m_cStructure->m_BlockAlign; } - typedef struct AddonToKodiFuncTable_InputStream /* internal */ + /// @brief To set stream crypto session informations. + /// + /// @param[in] cryptoSession The with @ref cpp_kodi_addon_inputstream_Defs_Interface_StreamCryptoSession setable info + /// + void SetCryptoSession(const kodi::addon::StreamCryptoSession& cryptoSession) { - KODI_HANDLE kodiInstance; - DemuxPacket* (*allocate_demux_packet)(void* kodiInstance, int data_size); - DemuxPacket* (*allocate_encrypted_demux_packet)(void* kodiInstance, - unsigned int data_size, - unsigned int encrypted_subsample_count); - void (*free_demux_packet)(void* kodiInstance, DemuxPacket* packet); - } AddonToKodiFuncTable_InputStream; + m_cryptoSession = cryptoSession; + memcpy(&m_cStructure->m_cryptoSession, m_cryptoSession.GetCStructure(), + sizeof(STREAM_CRYPTO_SESSION)); + } + + /// @brief To get with @ref GetCryptoSession changed values. + const kodi::addon::StreamCryptoSession& GetCryptoSession() const { return m_cryptoSession; } + + /// @brief Codec If available, the fourcc code codec. + /// + /// @param[in] codecFourCC Codec four CC code + void SetCodecFourCC(unsigned int codecFourCC) { m_cStructure->m_codecFourCC = codecFourCC; } + + /// @brief To get with @ref SetCodecFourCC changed values + unsigned int GetCodecFourCC() const { return m_cStructure->m_codecFourCC; } + + /// @brief Definition of colorspace. + /// + /// @param[in] colorSpace The with @ref INPUTSTREAM_COLORSPACE setable color space + void SetColorSpace(INPUTSTREAM_COLORSPACE colorSpace) { m_cStructure->m_colorSpace = colorSpace; } + + /// @brief To get with @ref SetColorSpace changed values. + INPUTSTREAM_COLORSPACE GetColorSpace() const { return m_cStructure->m_colorSpace; } + + /// @brief Color range if available. + /// + /// @param[in] colorRange The with @ref INPUTSTREAM_COLORRANGE setable color space + void SetColorRange(INPUTSTREAM_COLORRANGE colorRange) { m_cStructure->m_colorRange = colorRange; } - struct AddonInstance_InputStream; - typedef struct KodiToAddonFuncTable_InputStream /* internal */ + /// @brief To get with @ref SetColorRange changed values. + INPUTSTREAM_COLORRANGE GetColorRange() const { return m_cStructure->m_colorRange; } + + /// @brief Chromaticity coordinates of the source primaries. These values match the ones defined by ISO/IEC 23001-8_2013 § 7.1. + /// + /// @param[in] colorPrimaries The with @ref INPUTSTREAM_COLORPRIMARIES setable values + void SetColorPrimaries(INPUTSTREAM_COLORPRIMARIES colorPrimaries) { - KODI_HANDLE addonInstance; + m_cStructure->m_colorPrimaries = colorPrimaries; + } - bool(__cdecl* open)(const AddonInstance_InputStream* instance, INPUTSTREAM* props); - void(__cdecl* close)(const AddonInstance_InputStream* instance); - const char*(__cdecl* get_path_list)(const AddonInstance_InputStream* instance); - void(__cdecl* get_capabilities)(const AddonInstance_InputStream* instance, - INPUTSTREAM_CAPABILITIES* capabilities); + /// @brief To get with @ref SetColorPrimaries changed values. + INPUTSTREAM_COLORPRIMARIES GetColorPrimaries() const { return m_cStructure->m_colorPrimaries; } - // IDemux - struct INPUTSTREAM_IDS(__cdecl* get_stream_ids)(const AddonInstance_InputStream* instance); - struct INPUTSTREAM_INFO(__cdecl* get_stream)(const AddonInstance_InputStream* instance, - int streamid); - void(__cdecl* enable_stream)(const AddonInstance_InputStream* instance, - int streamid, - bool enable); - bool(__cdecl* open_stream)(const AddonInstance_InputStream* instance, int streamid); - void(__cdecl* demux_reset)(const AddonInstance_InputStream* instance); - void(__cdecl* demux_abort)(const AddonInstance_InputStream* instance); - void(__cdecl* demux_flush)(const AddonInstance_InputStream* instance); - DemuxPacket*(__cdecl* demux_read)(const AddonInstance_InputStream* instance); - bool(__cdecl* demux_seek_time)(const AddonInstance_InputStream* instance, - double time, - bool backwards, - double* startpts); - void(__cdecl* demux_set_speed)(const AddonInstance_InputStream* instance, int speed); - void(__cdecl* set_video_resolution)(const AddonInstance_InputStream* instance, - int width, - int height); - - // IDisplayTime - int(__cdecl* get_total_time)(const AddonInstance_InputStream* instance); - int(__cdecl* get_time)(const AddonInstance_InputStream* instance); - - // ITime - bool(__cdecl* get_times)(const AddonInstance_InputStream* instance, INPUTSTREAM_TIMES* times); - - // IPosTime - bool(__cdecl* pos_time)(const AddonInstance_InputStream* instance, int ms); - - int(__cdecl* read_stream)(const AddonInstance_InputStream* instance, - uint8_t* buffer, - unsigned int bufferSize); - int64_t(__cdecl* seek_stream)(const AddonInstance_InputStream* instance, - int64_t position, - int whence); - int64_t(__cdecl* position_stream)(const AddonInstance_InputStream* instance); - int64_t(__cdecl* length_stream)(const AddonInstance_InputStream* instance); - bool(__cdecl* is_real_time_stream)(const AddonInstance_InputStream* instance); - - // IChapter - int(__cdecl* get_chapter)(const AddonInstance_InputStream* instance); - int(__cdecl* get_chapter_count)(const AddonInstance_InputStream* instance); - const char*(__cdecl* get_chapter_name)(const AddonInstance_InputStream* instance, int ch); - int64_t(__cdecl* get_chapter_pos)(const AddonInstance_InputStream* instance, int ch); - bool(__cdecl* seek_chapter)(const AddonInstance_InputStream* instance, int ch); - - int(__cdecl* block_size_stream)(const AddonInstance_InputStream* instance); - } KodiToAddonFuncTable_InputStream; - - typedef struct AddonInstance_InputStream /* internal */ - { - AddonProps_InputStream* props; - AddonToKodiFuncTable_InputStream* toKodi; - KodiToAddonFuncTable_InputStream* toAddon; - } AddonInstance_InputStream; + /// @brief Color Transfer Characteristic. These values match the ones defined by ISO/IEC 23001-8_2013 § 7.2. + /// + /// @param[in] colorTransferCharacteristic The with @ref INPUTSTREAM_COLORTRC setable characteristic + void SetColorTransferCharacteristic(INPUTSTREAM_COLORTRC colorTransferCharacteristic) + { + m_cStructure->m_colorTransferCharacteristic = colorTransferCharacteristic; + } -#ifdef __cplusplus -} /* extern "C" */ + /// @brief To get with @ref SetColorTransferCharacteristic changed values. + INPUTSTREAM_COLORTRC GetColorTransferCharacteristic() const + { + return m_cStructure->m_colorTransferCharacteristic; + } -namespace kodi -{ -namespace addon -{ + /// @brief Mastering static Metadata. + /// + /// Describes the metadata for HDR10, used when video is compressed using High + /// Efficiency Video Coding (HEVC). This is used to describe the capabilities + /// of the display used to master the content and the luminance values of the + /// content. + /// + /// @param[in] masteringMetadata The with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamMasteringMetadata setable metadata + void SetMasteringMetadata(const kodi::addon::InputstreamMasteringMetadata& masteringMetadata) + { + m_masteringMetadata = masteringMetadata; + m_cStructure->m_masteringMetadata = m_masteringMetadata; + } -class ATTRIBUTE_HIDDEN CInstanceInputStream : public IAddonInstance -{ -public: - explicit CInstanceInputStream(KODI_HANDLE instance, const std::string& kodiVersion = "") - : IAddonInstance(ADDON_INSTANCE_INPUTSTREAM, - !kodiVersion.empty() ? kodiVersion - : GetKodiTypeVersion(ADDON_INSTANCE_INPUTSTREAM)) + /// @brief To get with @ref SetMasteringMetadata changed values. + const kodi::addon::InputstreamMasteringMetadata& GetMasteringMetadata() const { - if (CAddonBase::m_interface->globalSingleInstance != nullptr) - throw std::logic_error("kodi::addon::CInstanceInputStream: Creation of multiple together " - "with single instance way is not allowed!"); + return m_masteringMetadata; + } - SetAddonStruct(instance, m_kodiVersion); + /// @brief Clear mastering static Metadata. + void ClearMasteringMetadata() { m_cStructure->m_masteringMetadata = nullptr; } + + /// @brief Content light static Metadata. + /// + /// The maximum content light level (MaxCLL) and frame average light level + /// (MaxFALL) for the metadata for HDR10. + /// + /// @param[in] contentLightMetadata The with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamContentlightMetadata setable metadata + void SetContentLightMetadata( + const kodi::addon::InputstreamContentlightMetadata& contentLightMetadata) + { + m_contentLightMetadata = contentLightMetadata; + m_cStructure->m_contentLightMetadata = m_contentLightMetadata; } - ~CInstanceInputStream() override = default; + /// @brief To get with @ref SetContentLightMetadata changed values. + const kodi::addon::InputstreamContentlightMetadata& GetContentLightMetadata() const + { + return m_contentLightMetadata; + } - /*! - * Open a stream. - * @param props - * @return True if the stream has been opened successfully, false otherwise. - * @remarks - */ - virtual bool Open(INPUTSTREAM& props) = 0; - - /*! - * Close an open stream. - * @remarks - */ - virtual void Close() = 0; + /// @brief Clear content light static Metadata. + void ClearContentLightMetadata() { m_cStructure->m_contentLightMetadata = nullptr; } - /*! - * Get Capabilities of this addon. - * @param capabilities The add-on's capabilities. - * @remarks - */ - virtual void GetCapabilities(INPUTSTREAM_CAPABILITIES& capabilities) = 0; - - /*! - * Get IDs of available streams - * @remarks - */ - virtual INPUTSTREAM_IDS GetStreamIds() = 0; - - /*! - * Get stream properties of a stream. - * @param streamid unique id of stream - * @return struc of stream properties - * @remarks - */ - virtual INPUTSTREAM_INFO GetStream(int streamid) = 0; - - /*! - * Enable or disable a stream. - * A disabled stream does not send demux packets - * @param streamid unique id of stream - * @param enable true for enable, false for disable - * @remarks - */ - virtual void EnableStream(int streamid, bool enable) = 0; - - /*! - * Opens a stream for playback. - * @param streamid unique id of stream - * @remarks - */ - virtual bool OpenStream(int streamid) = 0; + ///@} - /*! - * Reset the demultiplexer in the add-on. - * @remarks Required if bHandlesDemuxing is set to true. - */ - virtual void DemuxReset() {} +private: + InputstreamInfo(const INPUTSTREAM_INFO* stream) : CStructHdl(stream) + { + SetCryptoSession(StreamCryptoSession(&stream->m_cryptoSession)); + CopyExtraData(); + } + InputstreamInfo(INPUTSTREAM_INFO* stream) : CStructHdl(stream) + { + SetCryptoSession(StreamCryptoSession(&stream->m_cryptoSession)); + CopyExtraData(); + } - /*! - * Abort the demultiplexer thread in the add-on. - * @remarks Required if bHandlesDemuxing is set to true. - */ - virtual void DemuxAbort() {} + void CopyExtraData() + { + if (m_cStructure->m_ExtraData && m_cStructure->m_ExtraSize > 0) + { + for (unsigned int i = 0; i < m_cStructure->m_ExtraSize; ++i) + m_extraData.emplace_back(m_cStructure->m_ExtraData[i]); + } + if (m_cStructure->m_masteringMetadata) + m_masteringMetadata = m_cStructure->m_masteringMetadata; + if (m_cStructure->m_contentLightMetadata) + m_contentLightMetadata = m_cStructure->m_contentLightMetadata; + } + std::vector m_extraData; + StreamCryptoSession m_cryptoSession; + InputstreamMasteringMetadata m_masteringMetadata; + InputstreamContentlightMetadata m_contentLightMetadata; +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================== +/// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes class InputstreamTimes +/// @ingroup cpp_kodi_addon_inputstream_Defs_Interface +/// @brief **Inputstream add-on times**\n +/// Used on @ref kodi::addon::CInstanceInputStream::GetTimes(). +/// +/// ---------------------------------------------------------------------------- +/// +/// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes_Help +/// +///@{ +class ATTRIBUTE_HIDDEN InputstreamTimes : public CStructHdl +{ + /*! \cond PRIVATE */ + friend class CInstanceInputStream; + /*! \endcond */ - /*! - * Flush all data that's currently in the demultiplexer buffer in the add-on. - * @remarks Required if bHandlesDemuxing is set to true. - */ - virtual void DemuxFlush() {} +public: + /*! \cond PRIVATE */ + InputstreamTimes() = default; + InputstreamTimes(const InputstreamTimes& stream) : CStructHdl(stream) {} + /*! \endcond */ - /*! - * Read the next packet from the demultiplexer, if there is one. - * @return The next packet. - * If there is no next packet, then the add-on should return the - * packet created by calling AllocateDemuxPacket(0) on the callback. - * If the stream changed and Kodi's player needs to be reinitialised, - * then, the add-on should call AllocateDemuxPacket(0) on the - * callback, and set the streamid to DMX_SPECIALID_STREAMCHANGE and - * return the value. - * The add-on should return NULL if an error occurred. - * @remarks Return NULL if this add-on won't provide this function. - */ - virtual DemuxPacket* DemuxRead() { return nullptr; } - - /*! - * Notify the InputStream addon/demuxer that Kodi wishes to seek the stream by time - * Demuxer is required to set stream to an IDR frame - * @param time The absolute time since stream start - * @param backwards True to seek to keyframe BEFORE time, else AFTER - * @param startpts can be updated to point to where display should start - * @return True if the seek operation was possible - * @remarks Optional, and only used if addon has its own demuxer. - */ - virtual bool DemuxSeekTime(double time, bool backwards, double& startpts) { return false; } + /// @defgroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes_Help Value Help + /// @ingroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes + /// + /// The following table contains values that can be set with @ref cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes : + /// | Name | Type | Set call | Get call + /// |------|------|----------|-------------------- + /// | **Start time** | `time_t` | @ref InputstreamTimes::SetStartTime "SetStartTime" | @ref InputstreamTimes::GetStartTime "GetStartTime" + /// | **PTS start** | `double` | @ref InputstreamTimes::SetPtsStart "SetPtsStart" | @ref InputstreamTimes::GetPtsStart "GetPtsStart" + /// | **PTS begin** | `double` | @ref InputstreamTimes::SetPtsBegin "SetPtsBegin" | @ref InputstreamTimes::GetPtsBegin "GetPtsBegin" + /// | **PTS end** | `double` | @ref InputstreamTimes::SetPtsEnd "SetPtsEnd" | @ref InputstreamTimes::GetPtsEnd "GetPtsEnd" + /// - /*! - * Notify the InputStream addon/demuxer that Kodi wishes to change playback speed - * @param speed The requested playback speed - * @remarks Optional, and only used if addon has its own demuxer. - */ - virtual void DemuxSetSpeed(int speed) {} + /// @addtogroup cpp_kodi_addon_inputstream_Defs_Interface_InputstreamTimes + ///@{ - /*! - * Sets desired width / height - * @param width / hight - */ - virtual void SetVideoResolution(int width, int height) {} + /// @brief Start time in milliseconds + void SetStartTime(time_t startTime) const { m_cStructure->startTime = startTime; } - /*! - * Totel time in ms - * @remarks - */ - virtual int GetTotalTime() { return -1; } + /// @brief To get with @ref SetStartTime changed values + time_t GetStartTime() const { return m_cStructure->startTime; } - /*! - * Playing time in ms - * @remarks - */ - virtual int GetTime() { return -1; } + /// @brief Start PTS + void SetPtsStart(double ptsStart) const { m_cStructure->ptsStart = ptsStart; } - /*! - * Get current timing values in PTS scale - * @remarks - */ - virtual bool GetTimes(INPUTSTREAM_TIMES& times) { return false; } + /// @brief To get with @ref SetPtsStart changed values + double GetPtsStart() const { return m_cStructure->ptsStart; } - /*! - * Positions inputstream to playing time given in ms - * @remarks - */ - virtual bool PosTime(int ms) { return false; } + /// @brief Begin PTS + void SetPtsBegin(double ptsBegin) const { m_cStructure->ptsBegin = ptsBegin; } - /*! - * Return currently selected chapter - * @remarks - */ - virtual int GetChapter() { return -1; }; + /// @brief To get with @ref SetPtsBegin changed values + double GetPtsBegin() const { return m_cStructure->ptsBegin; } - /*! - * Return number of available chapters - * @remarks - */ - virtual int GetChapterCount() { return 0; }; + /// @brief End PTS + void SetPtsEnd(double ptsEnd) const { m_cStructure->ptsEnd = ptsEnd; } - /*! - * Return name of chapter # ch - * @remarks - */ - virtual const char* GetChapterName(int ch) { return nullptr; }; + /// @brief To get with @ref SetPtsEnd changed values + double GetPtsEnd() const { return m_cStructure->ptsEnd; } - /*! - * Return position if chapter # ch in milliseconds - * @remarks - */ - virtual int64_t GetChapterPos(int ch) { return 0; }; + ///@} - /*! - * Seek to the beginning of chapter # ch - * @remarks - */ - virtual bool SeekChapter(int ch) { return false; }; +private: + InputstreamTimes(const INPUTSTREAM_TIMES* stream) : CStructHdl(stream) {} + InputstreamTimes(INPUTSTREAM_TIMES* stream) : CStructHdl(stream) {} +}; +///@} +//------------------------------------------------------------------------------ + +//============================================================================ +/// +/// @addtogroup cpp_kodi_addon_inputstream +/// @brief \cpp_class{ kodi::addon::CInstanceInputStream } +/// **Inputstream add-on instance** +/// +/// This instance type is for using input streams to video and audio, to process +/// and then give them to Kodi. +/// +/// This usage can be requested under various conditions, for example explicitly +/// by another addon, by a Mimetype protocol defined in `addon.xml` or supported +/// file extensions. +/// +/// In addition, stream files (* .strm) can be linked to an inputstream addon +/// using `#KODIPROP:inputstream=`. +/// +/// Include the header @ref Inputstream.h "#include " +/// to use this class. +/// +/// ---------------------------------------------------------------------------- +/// +/// Here is an example of what the `addon.xml.in` would look like for an inputstream addon: +/// +/// ~~~~~~~~~~~~~{.xml} +/// +/// +/// @ADDON_DEPENDS@ +/// +/// +/// My InputStream addon +/// My InputStream description +/// @PLATFORM@ +/// +/// +/// ~~~~~~~~~~~~~ +/// +/// +/// At `` the basic instance definition is declared, this is intended to identify the addon as an input stream and to see its supported types: +/// | Name | Description +/// |------|---------------------- +/// | `point` | The identification of the addon instance to inputstream is mandatory `kodi.inputstream`. In addition, the instance declared in the first `` is also +/// | `extension` | A filename extension is an identifier specified as a suffix to the name of a computer file where supported by addon. +/// | `listitemprops` | Values that are available to the addon at @ref InputstreamProperty::GetProperties() and that can be passed to @ref CInstanceInputStream::Open() ith the respective values. +/// | `protocols` | The streaming protocol is a special protocol supported by the addon for the transmission of streaming media data over a network. +/// | `library_@PLATFORM@` | The runtime library used for the addon. This is usually declared by cmake and correctly displayed in the translated `addon.xml`. +/// +/// +/// @remark For more detailed description of the `addon.xml`, see also https://kodi.wiki/view/Addon.xml. +/// +/// +/// -------------------------------------------------------------------------- +/// +/// +/// **Example:** +/// +/// ~~~~~~~~~~~~~{.cpp} +/// #include +/// +/// class CMyInputstream : public kodi::addon::CInstanceInputStream +/// { +/// public: +/// CMyInputstream(KODI_HANDLE instance, const std::string& kodiVersion); +/// +/// void GetCapabilities(kodi::addon::InputstreamCapabilities& capabilities) override; +/// bool Open(const kodi::addon::InputstreamProperty& props) override; +/// void Close() override; +/// ... +/// }; +/// +/// CMyInputstream::CMyInputstream(KODI_HANDLE instance, const std::string& kodiVersion) +/// : kodi::addon::CInstanceInputStream(instance, kodiVersion) +/// { +/// ... +/// } +/// +/// void CMyInputstream::GetCapabilities(kodi::addon::InputstreamCapabilities& capabilities) +/// { +/// capabilities.SetMask(INPUTSTREAM_SUPPORTS_IDEMUX | INPUTSTREAM_SUPPORTS_PAUSE); +/// } +/// +/// void CMyInputstream::Open(const kodi::addon::InputstreamProperty& props) +/// { +/// std::string url = props.GetURL(); +/// ... +/// } +/// +/// void CMyInputstream::Close() +/// { +/// ... +/// } +/// +/// ... +/// +/// //---------------------------------------------------------------------- +/// +/// class CMyAddon : public kodi::addon::CAddonBase +/// { +/// public: +/// CMyAddon() = default; +/// ADDON_STATUS CreateInstance(int instanceType, +/// std::string instanceID, +/// KODI_HANDLE instance, +/// const std::string& version, +/// KODI_HANDLE& addonInstance) override; +/// }; +/// +/// // If you use only one instance in your add-on, can be instanceType and +/// // instanceID ignored +/// ADDON_STATUS CMyAddon::CreateInstance(int instanceType, +/// std::string instanceID, +/// KODI_HANDLE instance, +/// const std::string& version, +/// KODI_HANDLE& addonInstance) +/// { +/// if (instanceType == ADDON_INSTANCE_INPUTSTREAM) +/// { +/// kodi::Log(ADDON_LOG_NOTICE, "Creating my Inputstream"); +/// addonInstance = new CMyInputstream(instance, version); +/// return ADDON_STATUS_OK; +/// } +/// else if (...) +/// { +/// ... +/// } +/// return ADDON_STATUS_UNKNOWN; +/// } +/// +/// ADDONCREATOR(CMyAddon) +/// ~~~~~~~~~~~~~ +/// +/// The destruction of the example class `CMyInputstream` is called from +/// Kodi's header. Manually deleting the add-on instance is not required. +/// +//------------------------------------------------------------------------------ +class ATTRIBUTE_HIDDEN CInstanceInputStream : public IAddonInstance +{ +public: + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Inputstream class constructor used to support multiple instance + /// types + /// + /// @param[in] instance The instance value given to `kodi::addon::CAddonBase::CreateInstance(...)` + /// @param[in] kodiVersion [opt] Version used in Kodi for this instance, to + /// allow compatibility to older Kodi versions. + /// + /// @warning Only use `instance` from the @ref CAddonBase::CreateInstance call. + /// + explicit CInstanceInputStream(KODI_HANDLE instance, const std::string& kodiVersion = "") + : IAddonInstance(ADDON_INSTANCE_INPUTSTREAM, + !kodiVersion.empty() ? kodiVersion + : GetKodiTypeVersion(ADDON_INSTANCE_INPUTSTREAM)) + { + if (CAddonBase::m_interface->globalSingleInstance != nullptr) + throw std::logic_error("kodi::addon::CInstanceInputStream: Creation of multiple together " + "with single instance way is not allowed!"); - /*! - * Read from an open stream. - * @param buffer The buffer to store the data in. - * @param bufferSize The amount of bytes to read. - * @return The amount of bytes that were actually read from the stream. - * @remarks Return -1 if this add-on won't provide this function. - */ - virtual int ReadStream(uint8_t* buffer, unsigned int bufferSize) { return -1; } + SetAddonStruct(instance, m_kodiVersion); + } + //---------------------------------------------------------------------------- - /*! - * Seek in a stream. - * @param position The position to seek to. - * @param whence ? - * @return The new position. - * @remarks Return -1 if this add-on won't provide this function. - */ + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Destructor + /// + ~CInstanceInputStream() override = default; + //---------------------------------------------------------------------------- + + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Get the list of features that this add-on provides. + /// + /// Called by Kodi to query the add-on's capabilities. + /// Used to check which options should be presented in the UI, which methods to call, etc. + /// All capabilities that the add-on supports should be set to true. + /// + /// @param[out] capabilities The with @ref cpp_kodi_addon_inputstream_Defs_Capabilities defined add-on's capabilities. + /// + /// + /// -------------------------------------------------------------------------- + /// + /// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamCapabilities_Help + /// + /// -------------------------------------------------------------------------- + /// @note Valid implementation required. + /// + /// + /// -------------------------------------------------------------------------- + /// + /// **Example:** + /// + /// ~~~~~~~~~~~~~{.cpp} + /// void CMyInputstream::GetCapabilities(kodi::addon::InputstreamCapabilities& capabilities) + /// { + /// capabilities.SetMask(INPUTSTREAM_SUPPORTS_IDEMUX | INPUTSTREAM_SUPPORTS_PAUSE); + /// } + /// ~~~~~~~~~~~~~ + /// + virtual void GetCapabilities(kodi::addon::InputstreamCapabilities& capabilities) = 0; + //---------------------------------------------------------------------------- + + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Open a stream. + /// + /// @param[in] props The used properties about the stream + /// @return True if the stream has been opened successfully, false otherwise. + /// + /// + /// -------------------------------------------------------------------------- + /// + /// @copydetails cpp_kodi_addon_inputstream_Defs_InputstreamProperty_Help + /// + /// -------------------------------------------------------------------------- + /// @note Valid implementation required. + /// + /// + /// -------------------------------------------------------------------------- + /// + /// **Example:** + /// + /// ~~~~~~~~~~~~~{.cpp} + /// void CMyInputstream::Open(const kodi::addon::InputstreamProperty& props) + /// { + /// std::string url = props.GetURL(); + /// std::string license_key = props.GetProperties()["inputstream.myspecialnamefor.license_key"]; + /// ... + /// } + /// ~~~~~~~~~~~~~ + /// + virtual bool Open(const kodi::addon::InputstreamProperty& props) = 0; + //---------------------------------------------------------------------------- + + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Close an open stream. + /// + /// @remarks + /// + /// + /// -------------------------------------------------------------------------- + /// @note Valid implementation required. + /// + virtual void Close() = 0; + //---------------------------------------------------------------------------- + + //============================================================================ + /// @ingroup cpp_kodi_addon_inputstream + /// @brief Check for real-time streaming + /// + /// @return true if current stream is real-time + /// + virtual bool IsRealTimeStream() { return true; } + //---------------------------------------------------------------------------- + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_Read 1. Stream read + /// @brief **Functions required to read streams direct and demux inside Kodi.** + /// + /// This part contains at least the functions necessary for addon that have to + /// be supported. This can only be ignored if you use your own demux. + /// + /// The data loaded by Kodi is then processed in it itself. The source does not + /// matter, only Kodi must be able to process this stream data itself and is + /// therefore limited in some things. + /// + /// For more complex things, the addon must integrate its own demuxer and, + /// if necessary, even its own codec processing (see @ref cpp_kodi_addon_codec "Codec"). + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_IDEMUX + /// is undefined in the capabilities (see @ref GetCapabilities()). + /// Otherwise becomes @ref cpp_kodi_addon_inputstream_Demux "demuxing" used. + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //============================================================================ + /// @brief Read from an open stream. + /// + /// @param[in] buffer The buffer to store the data in. + /// @param[in] bufferSize The amount of bytes to read. + /// @return The amount of bytes that were actually read from the stream. + /// + virtual int ReadStream(uint8_t* buffer, unsigned int bufferSize) { return -1; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Seek in a stream. + /// + /// @param[in] position The position to seek to + /// @param[in] whence offset relative to
+ /// You can set the value of whence to one of three things: + /// | Value | int | Description | + /// |:------------:|:-----:|:----------------------------------------------------| + /// | **SEEK_SET** | `0` | position is relative to the beginning of the file. This is probably what you had in mind anyway, and is the most commonly used value for whence. + /// | **SEEK_CUR** | `1` | position is relative to the current file pointer position. So, in effect, you can say, "Move to my current position plus 30 bytes," or, "move to my current position minus 20 bytes." + /// | **SEEK_END** | `2` | position is relative to the end of the file. Just like SEEK_SET except from the other end of the file. Be sure to use negative values for offset if you want to back up from the end of the file, instead of going past the end into oblivion. + /// + /// @return Returns the resulting offset location as measured in bytes from + /// the beginning of the file. On error, the value -1 is returned. + /// + /// @remarks Optional and can leaved away or return -1 if this add-on won't + /// provide this function. + /// virtual int64_t SeekStream(int64_t position, int whence = SEEK_SET) { return -1; } - - /*! - * @return The position in the stream that's currently being read. - * @remarks Return -1 if this add-on won't provide this function. - */ + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief The position in the stream that's currently being read. + /// + /// @return Stream position + /// + /// @remarks Optional and can leaved away or return -1 if this add-on won't + /// provide this function. + /// virtual int64_t PositionStream() { return -1; } - - /*! - * @return The total length of the stream that's currently being read. - * @remarks Return -1 if this add-on won't provide this function. - */ + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief The Total length of the stream that's currently being read. + /// + /// @return Length of the stream + /// + /// @remarks Optional and can leaved away or return -1 if this add-on won't + /// provide this function. + /// virtual int64_t LengthStream() { return -1; } - - /*! - * @return Obtain the chunk size to use when reading streams. - * @remarks Return 0 if this add-on won't provide this function. - */ + //-------------------------------------------------------------------------- + + //========================================================================== + /// @brief Obtain the chunk size to use when reading streams. + /// + /// @return Block chunk size + /// + /// @remarks Optional and can leaved away or return 0 if this add-on won't + /// provide this function. + /// virtual int GetBlockSize() { return 0; } + //-------------------------------------------------------------------------- + + ///@} + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_Demux 2. Stream demuxing (optional) + /// @brief **Read demux streams.** + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_IDEMUX is set in the capabilities (see @ref GetCapabilities()). + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //============================================================================ + /// @brief Get IDs of available streams + /// + /// @param[in] ids list of used identifications + /// @return true if successfully done, otherwise false + /// + /// @remarks This id's are used to identify wanted data on @ref GetStream call. + /// + /// + /// -------------------------------------------------------------------------- + /// + /// **Example:** + /// + /// ~~~~~~~~~~~~~{.cpp} + /// + /// bool CMyInputstream::GetStreamIds(std::vector& ids) + /// { + /// kodi::Log(ADDON_LOG_DEBUG, "GetStreamIds(...)"); + /// + /// if (m_opened) + /// { + /// // This check not needed to have, the ABI checks also about, but make + /// // sure you not give more as 32 streams. + /// if (m_myStreams.size() > MAX_STREAM_COUNT) + /// { + /// kodi::Log(ADDON_LOG_ERROR, "Too many streams, only %u supported", MAX_STREAM_COUNT); + /// return false; + /// } + /// + /// ids.emplace_back(m_myAudioStreamId); + /// + /// for (const auto& streamPair : m_myOtherStreams) + /// { + /// ids.emplace_back(streamPair.second->uniqueId); + /// } + /// } + /// + /// return !ids.empty(); + /// } + /// ~~~~~~~~~~~~~ + /// + virtual bool GetStreamIds(std::vector& ids) { return false; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Function for giving detailed stream information + /// + /// The associated information is set here for IDs previously given with + /// @ref GetStreamIds. + /// + /// This data is required to identify the associated codec and, if necessary, + /// to refer to your own codec (if available in the addon). + /// + /// @param[in] streamid unique id of stream + /// @param[out] stream Information data of wanted stream + /// @return true if successfully done, otherwise false + /// + /// @remarks Available stream id's previously asked by @ref GetStreamIds + /// + /// + /// -------------------------------------------------------------------------- + /// + /// @copydetails cpp_kodi_addon_inputstream_Defs_Interface_InputstreamInfo_Help + /// + /// -------------------------------------------------------------------------- + /// + /// **Example:** + /// + /// ~~~~~~~~~~~~~{.cpp} + /// bool CMyInputstream::GetStream(int streamid, kodi::addon::InputstreamInfo& stream) + /// { + /// // This is just a small example, this type will be significantly larger + /// // for larger and more complex streams. + /// if (streamid == m_myAudioStreamId) + /// { + /// // This only a minimal exampl + /// stream.SetStreamType(INPUTSTREAM_TYPE_AUDIO); + /// stream.SetFeatures(INPUTSTREAM_FEATURE_NONE); // Only added to example, INPUTSTREAM_FEATURE_NONE is default and no need to call + /// stream.SetFlags(INPUTSTREAM_FLAG_NONE); // Only added to example, INPUTSTREAM_FLAG_NONE is default and no need to call + /// stream.SetCodecName("mp2"); // Codec name, string must by equal with FFmpeg, see https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/codec_desc.c + /// stream.SetPhysicalIndex(1); // Identifier required to set + /// stream.SetLanguage("en"); + /// stream.SetChannels(2); + /// stream.SetSampleRate(48000); + /// stream.SetBitRate(0); + /// stream.SetBitsPerSample(16); + /// } + /// else ... + /// ... + /// return true; + /// } + /// ~~~~~~~~~~~~~ + /// + virtual bool GetStream(int streamid, kodi::addon::InputstreamInfo& stream) { return false; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Enable or disable a stream. + /// + /// A disabled stream does not send demux packets + /// + /// @param[in] streamid unique id of stream + /// @param[in] enable true for enable, false for disable + /// + /// @remarks Available stream id's previously asked by @ref GetStreamIds + /// + /// + /// -------------------------------------------------------------------------- + /// @note Valid implementation required. + /// + virtual void EnableStream(int streamid, bool enable) {} + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Opens a stream for playback. + /// + /// @param[in] streamid unique id of stream + /// + /// @remarks Available stream id's previously asked by @ref GetStreamIds + /// + /// + /// -------------------------------------------------------------------------- + /// @note Valid implementation required. + /// + virtual bool OpenStream(int streamid) { return false; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Reset the demultiplexer in the add-on. + /// + /// @remarks Optional, and only used if addon has its own demuxer. + /// + virtual void DemuxReset() {} + //---------------------------------------------------------------------------- - /*! - * Check for real-time streaming - * @return true if current stream is real-time - */ - virtual bool IsRealTimeStream() { return true; } + //============================================================================ + /// @brief Abort the demultiplexer thread in the add-on. + /// + /// @remarks Optional, and only used if addon has its own demuxer. + /// + virtual void DemuxAbort() {} + //---------------------------------------------------------------------------- - /*! - * @brief Allocate a demux packet. Free with FreeDemuxPacket - * @param dataSize The size of the data that will go into the packet - * @return The allocated packet - */ - DemuxPacket* AllocateDemuxPacket(int dataSize) + //============================================================================ + /// @brief Flush all data that's currently in the demultiplexer buffer in the add-on. + /// + /// @remarks Optional, and only used if addon has its own demuxer. + /// + virtual void DemuxFlush() {} + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Read the next packet from the demultiplexer, if there is one. + /// + /// @return The next packet. + /// If there is no next packet, then the add-on should return the + /// packet created by calling @ref AllocateDemuxPacket "AllocateDemuxPacket(0)" on the callback. + /// If the stream changed and Kodi's player needs to be reinitialised, + /// then, the add-on should call @ref AllocateDemuxPacket "AllocateDemuxPacket(0)" on the + /// callback, and set the streamid to DMX_SPECIALID_STREAMCHANGE and + /// return the value. + /// The add-on should return `nullptr` if an error occured. + /// + /// @remarks Return `nullptr` if this add-on won't provide this function. + /// + virtual DEMUX_PACKET* DemuxRead() { return nullptr; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Notify the InputStream addon/demuxer that Kodi wishes to seek the stream by time + /// + /// Demuxer is required to set stream to an IDR frame + /// + /// @param[in] time The absolute time since stream start + /// @param[in] backwards True to seek to keyframe BEFORE time, else AFTER + /// @param[in] startpts can be updated to point to where display should start + /// @return True if the seek operation was possible + /// + /// @remarks Optional, and only used if addon has its own demuxer. + /// + virtual bool DemuxSeekTime(double time, bool backwards, double& startpts) { return false; } + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Notify the InputStream addon/demuxer that Kodi wishes to change playback speed + /// + /// @param[in] speed The requested playback speed + /// + /// @remarks Optional, and only used if addon has its own demuxer. + /// + virtual void DemuxSetSpeed(int speed) {} + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Sets desired width / height + /// + /// @param[in] width Width to set + /// @param[in] height Height to set + /// + virtual void SetVideoResolution(int width, int height) {} + //---------------------------------------------------------------------------- + + //============================================================================= + /// @brief Allocate a demux packet. Free with @ref FreeDemuxPacket + /// + /// @param[in] dataSize The size of the data that will go into the packet + /// @return The allocated packet + /// + /// @remarks Only called from addon itself + /// + DEMUX_PACKET* AllocateDemuxPacket(int dataSize) { return m_instanceData->toKodi->allocate_demux_packet(m_instanceData->toKodi->kodiInstance, dataSize); } - - /*! - * @brief Allocate a demux packet. Free with FreeDemuxPacket - * @param dataSize The size of the data that will go into the packet - * @return The allocated packet - */ - DemuxPacket* AllocateEncryptedDemuxPacket(int dataSize, unsigned int encryptedSubsampleCount) + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Allocate a encrypted demux packet. Free with @ref FreeDemuxPacket + /// + /// @param[in] dataSize The size of the data that will go into the packet + /// @param[in] encryptedSubsampleCount The encrypted subsample count + /// @return The allocated packet + /// + /// @remarks Only called from addon itself + /// + DEMUX_PACKET* AllocateEncryptedDemuxPacket(int dataSize, unsigned int encryptedSubsampleCount) { return m_instanceData->toKodi->allocate_encrypted_demux_packet( m_instanceData->toKodi->kodiInstance, dataSize, encryptedSubsampleCount); } - - /*! - * @brief Free a packet that was allocated with AllocateDemuxPacket - * @param packet The packet to free - */ - void FreeDemuxPacket(DemuxPacket* packet) + //---------------------------------------------------------------------------- + + //============================================================================ + /// @brief Free a packet that was allocated with AllocateDemuxPacket + /// + /// @param[in] packet The packet to free + /// + /// @remarks Only called from addon itself + /// + void FreeDemuxPacket(DEMUX_PACKET* packet) { return m_instanceData->toKodi->free_demux_packet(m_instanceData->toKodi->kodiInstance, packet); } + //---------------------------------------------------------------------------- + + ///@} + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_Time 3. Time (optional) + /// @brief **To get stream position time.** + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_IDISPLAYTIME is set in the capabilities (see @ref GetCapabilities()). + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //========================================================================== + /// @brief Totel time in ms + /// + /// @return Total time in milliseconds + /// + /// @remarks + /// + virtual int GetTotalTime() { return -1; } + //-------------------------------------------------------------------------- + + //========================================================================== + /// @brief Playing time in ms + /// + /// @return Playing time in milliseconds + /// + /// @remarks + /// + virtual int GetTime() { return -1; } + //-------------------------------------------------------------------------- + + ///@} + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_Times 4. Times (optional) + /// @brief **Another way to get stream position time.** + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_ITIME is set in the capabilities (see @ref GetCapabilities()). + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //============================================================================ + /// @brief Get current timing values in PTS scale + /// + /// @param[out] times The with @ref InputstreamTimes to given times + /// @return true if successfully done, false if not + /// + /// @copydetails cpp_kodi_addon_inputstream_Defs_Times_Help + /// + /// @remarks + /// + virtual bool GetTimes(InputstreamTimes& times) { return false; } + //---------------------------------------------------------------------------- + + ///@} + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_PosTime 5. Position time (optional) + /// @brief **Third way get stream position time.** + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_IPOSTIME is set in the capabilities (see @ref GetCapabilities()). + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //============================================================================ + /// @brief Positions inputstream to playing time given in ms + /// + /// @param[in] ms Position time in milliseconds + /// + /// @remarks + /// + virtual bool PosTime(int ms) { return false; } + //---------------------------------------------------------------------------- + + ///@} + + //############################################################################ + /// @defgroup cpp_kodi_addon_inputstream_Chapter 6. Chapter (optional) + /// @brief **Used to get available chapters.** + /// + /// @note These are used and must be set by the addon if the @ref INPUTSTREAM_SUPPORTS_ICHAPTER is set in the capabilities (see @ref GetCapabilities()). + /// + /// @ingroup cpp_kodi_addon_inputstream + ///@{ + + //========================================================================== + /// + /// @brief Return currently selected chapter + /// + /// @return Chapter number + /// + /// @remarks + /// + virtual int GetChapter() { return -1; }; + //-------------------------------------------------------------------------- + + //========================================================================== + /// + /// @brief Return number of available chapters + /// + /// @return Chapter count + /// + /// @remarks + /// + virtual int GetChapterCount() { return 0; }; + //-------------------------------------------------------------------------- + + //========================================================================== + /// + /// @brief Return name of chapter + /// + /// @param[in] ch Chapter identifier + /// @return Chapter name + /// + /// @remarks + /// + virtual const char* GetChapterName(int ch) { return nullptr; }; + //-------------------------------------------------------------------------- + + //========================================================================== + /// + /// @brief Return position if chapter # ch in milliseconds + /// + /// @param[in] ch Chapter to get position from + /// @return Position in milliseconds + /// + /// @remarks + /// + virtual int64_t GetChapterPos(int ch) { return 0; }; + //-------------------------------------------------------------------------- + + //========================================================================== + /// + /// @brief Seek to the beginning of chapter # ch + /// + /// @param[in] ch Chapter to seek + /// @return True if successfully done, false if not + /// + /// @remarks + /// + virtual bool SeekChapter(int ch) { return false; }; + //-------------------------------------------------------------------------- + + ///@} private: static int compareVersion(const int v1[3], const int v2[3]) @@ -752,9 +1827,10 @@ private: */ } - inline static bool ADDON_Open(const AddonInstance_InputStream* instance, INPUTSTREAM* props) + inline static bool ADDON_Open(const AddonInstance_InputStream* instance, + INPUTSTREAM_PROPERTY* props) { - return static_cast(instance->toAddon->addonInstance)->Open(*props); + return static_cast(instance->toAddon->addonInstance)->Open(props); } inline static void ADDON_Close(const AddonInstance_InputStream* instance) @@ -765,22 +1841,48 @@ private: inline static void ADDON_GetCapabilities(const AddonInstance_InputStream* instance, INPUTSTREAM_CAPABILITIES* capabilities) { - static_cast(instance->toAddon->addonInstance) - ->GetCapabilities(*capabilities); + InputstreamCapabilities caps(capabilities); + static_cast(instance->toAddon->addonInstance)->GetCapabilities(caps); } // IDemux - inline static struct INPUTSTREAM_IDS ADDON_GetStreamIds(const AddonInstance_InputStream* instance) + inline static bool ADDON_GetStreamIds(const AddonInstance_InputStream* instance, + struct INPUTSTREAM_IDS* ids) { - return static_cast(instance->toAddon->addonInstance)->GetStreamIds(); + std::vector idList; + bool ret = + static_cast(instance->toAddon->addonInstance)->GetStreamIds(idList); + if (ret) + { + for (size_t i = 0; i < idList.size() && i < INPUTSTREAM_MAX_STREAM_COUNT; ++i) + { + ids->m_streamCount++; + ids->m_streamIds[i] = idList[i]; + } + } + return ret; } - inline static struct INPUTSTREAM_INFO ADDON_GetStream(const AddonInstance_InputStream* instance, - int streamid) + inline static bool ADDON_GetStream( + const AddonInstance_InputStream* instance, + int streamid, + struct INPUTSTREAM_INFO* info, + KODI_HANDLE* demuxStream, + KODI_HANDLE (*transfer_stream)(KODI_HANDLE handle, + int streamId, + struct INPUTSTREAM_INFO* stream)) { - return static_cast(instance->toAddon->addonInstance) - ->GetStream(streamid); + InputstreamInfo infoData(info); + bool ret = static_cast(instance->toAddon->addonInstance) + ->GetStream(streamid, infoData); + if (ret && transfer_stream) + { + // Do this with given callback to prevent memory problems and leaks. This + // then create on Kodi the needed class where then given back on demuxStream. + *demuxStream = transfer_stream(instance->toKodi->kodiInstance, streamid, info); + } + return ret; } inline static void ADDON_EnableStream(const AddonInstance_InputStream* instance, @@ -812,7 +1914,7 @@ private: static_cast(instance->toAddon->addonInstance)->DemuxFlush(); } - inline static DemuxPacket* ADDON_DemuxRead(const AddonInstance_InputStream* instance) + inline static DEMUX_PACKET* ADDON_DemuxRead(const AddonInstance_InputStream* instance) { return static_cast(instance->toAddon->addonInstance)->DemuxRead(); } @@ -855,7 +1957,8 @@ private: inline static bool ADDON_GetTimes(const AddonInstance_InputStream* instance, INPUTSTREAM_TIMES* times) { - return static_cast(instance->toAddon->addonInstance)->GetTimes(*times); + InputstreamTimes cppTimes(times); + return static_cast(instance->toAddon->addonInstance)->GetTimes(cppTimes); } // IPosTime @@ -927,6 +2030,7 @@ private: AddonInstance_InputStream* m_instanceData; }; +//------------------------------------------------------------------------------ } /* namespace addon */ } /* namespace kodi */ -- cgit v1.2.3