Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
2. Stream demuxing (optional)

Read demux streams. More...

Functions

virtual bool kodi::addon::CInstanceInputStream::GetStreamIds (std::vector< unsigned int > &ids)
 Get IDs of available streams.
 
virtual bool kodi::addon::CInstanceInputStream::GetStream (int streamid, kodi::addon::InputstreamInfo &stream)
 Function for giving detailed stream information.
 
virtual void kodi::addon::CInstanceInputStream::EnableStream (int streamid, bool enable)
 Enable or disable a stream.
 
virtual bool kodi::addon::CInstanceInputStream::OpenStream (int streamid)
 Opens a stream for playback.
 
virtual void kodi::addon::CInstanceInputStream::DemuxReset ()
 Reset the demultiplexer in the add-on.
 
virtual void kodi::addon::CInstanceInputStream::DemuxAbort ()
 Abort the demultiplexer thread in the add-on.
 
virtual void kodi::addon::CInstanceInputStream::DemuxFlush ()
 Flush all data that's currently in the demultiplexer buffer in the add-on.
 
virtual DEMUX_PACKETkodi::addon::CInstanceInputStream::DemuxRead ()
 Read the next packet from the demultiplexer, if there is one.
 
virtual bool kodi::addon::CInstanceInputStream::DemuxSeekTime (double time, bool backwards, double &startpts)
 Notify the InputStream addon/demuxer that Kodi wishes to seek the stream by time.
 
virtual void kodi::addon::CInstanceInputStream::DemuxSetSpeed (int speed)
 Notify the InputStream addon/demuxer that Kodi wishes to change playback speed.
 
virtual void kodi::addon::CInstanceInputStream::SetVideoResolution (unsigned int width, unsigned int height)
 Notify current screen resolution.
 
virtual void kodi::addon::CInstanceInputStream::SetVideoResolution (unsigned int width, unsigned int height, unsigned int maxWidth, unsigned int maxHeight)
 Notify current screen resolution and max screen resolution allowed.
 
DEMUX_PACKETkodi::addon::CInstanceInputStream::AllocateDemuxPacket (int dataSize)
 Allocate a demux packet. Free with FreeDemuxPacket.
 
DEMUX_PACKETkodi::addon::CInstanceInputStream::AllocateEncryptedDemuxPacket (int dataSize, unsigned int encryptedSubsampleCount)
 Allocate a encrypted demux packet. Free with FreeDemuxPacket.
 
void kodi::addon::CInstanceInputStream::FreeDemuxPacket (DEMUX_PACKET *packet)
 Free a packet that was allocated with AllocateDemuxPacket.
 

Detailed Description

Read demux streams.

Note
These are used and must be set by the addon if the INPUTSTREAM_SUPPORTS_IDEMUX is set in the capabilities (see GetCapabilities()).

Function Documentation

◆ AllocateDemuxPacket()

DEMUX_PACKET * kodi::addon::CInstanceInputStream::AllocateDemuxPacket ( int dataSize)
inline

Allocate a demux packet. Free with FreeDemuxPacket.

Parameters
[in]dataSizeThe size of the data that will go into the packet
Returns
The allocated packet
Remarks
Only called from addon itself

◆ AllocateEncryptedDemuxPacket()

DEMUX_PACKET * kodi::addon::CInstanceInputStream::AllocateEncryptedDemuxPacket ( int dataSize,
unsigned int encryptedSubsampleCount )
inline

Allocate a encrypted demux packet. Free with FreeDemuxPacket.

Parameters
[in]dataSizeThe size of the data that will go into the packet
[in]encryptedSubsampleCountThe encrypted subsample count
Returns
The allocated packet
Remarks
Only called from addon itself

◆ DemuxAbort()

virtual void kodi::addon::CInstanceInputStream::DemuxAbort ( )
inlinevirtual

Abort the demultiplexer thread in the add-on.

Remarks
Optional, and only used if addon has its own demuxer.

◆ DemuxFlush()

virtual void kodi::addon::CInstanceInputStream::DemuxFlush ( )
inlinevirtual

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.

◆ DemuxRead()

virtual DEMUX_PACKET * kodi::addon::CInstanceInputStream::DemuxRead ( )
inlinevirtual

Read the next packet from the demultiplexer, if there is one.

Returns
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 nullptr if an error occurred.
Remarks
Return nullptr if this add-on won't provide this function.

◆ DemuxReset()

virtual void kodi::addon::CInstanceInputStream::DemuxReset ( )
inlinevirtual

Reset the demultiplexer in the add-on.

Remarks
Optional, and only used if addon has its own demuxer.

◆ DemuxSeekTime()

virtual bool kodi::addon::CInstanceInputStream::DemuxSeekTime ( double time,
bool backwards,
double & startpts )
inlinevirtual

Notify the InputStream addon/demuxer that Kodi wishes to seek the stream by time.

Demuxer is required to set stream to an IDR frame

Parameters
[in]timeThe absolute time since stream start
[in]backwardsTrue to seek to keyframe BEFORE time, else AFTER
[in]startptscan be updated to point to where display should start
Returns
True if the seek operation was possible
Remarks
Optional, and only used if addon has its own demuxer.

◆ DemuxSetSpeed()

virtual void kodi::addon::CInstanceInputStream::DemuxSetSpeed ( int speed)
inlinevirtual

Notify the InputStream addon/demuxer that Kodi wishes to change playback speed.

Parameters
[in]speedThe requested playback speed
Remarks
Optional, and only used if addon has its own demuxer.

◆ EnableStream()

virtual void kodi::addon::CInstanceInputStream::EnableStream ( int streamid,
bool enable )
inlinevirtual

Enable or disable a stream.

A disabled stream does not send demux packets

Parameters
[in]streamidunique id of stream
[in]enabletrue for enable, false for disable
Remarks
Available stream id's previously asked by GetStreamIds

Note
Valid implementation required.

◆ FreeDemuxPacket()

void kodi::addon::CInstanceInputStream::FreeDemuxPacket ( DEMUX_PACKET * packet)
inline

Free a packet that was allocated with AllocateDemuxPacket.

Parameters
[in]packetThe packet to free
Remarks
Only called from addon itself

◆ GetStream()

virtual bool kodi::addon::CInstanceInputStream::GetStream ( int streamid,
kodi::addon::InputstreamInfo & stream )
inlinevirtual

Function for giving detailed stream information.

The associated information is set here for IDs previously given with GetStreamIds.

This data is required to identify the associated codec and, if necessary, to refer to your own codec (if available in the addon).

Parameters
[in]streamidunique id of stream
[out]streamInformation data of wanted stream
Returns
true if successfully done, otherwise false
Remarks
Available stream id's previously asked by GetStreamIds

The following table contains values that can be set with class InputstreamInfo :

Name Type used Required Set call Get call
Stream type all yes SetStreamType GetStreamType
Feature flags all yes SetFeatures GetFeatures
Flags all yes SetFlags GetFlags
Name all no SetName GetName
Codec name all yes SetCodecName GetCodecName
Codec internal name all no SetCodecInternalName GetCodecInternalName
Codec Profile all no SetCodecProfile GetCodecProfile
Physical index all yes SetPhysicalIndex GetPhysicalIndex
Extra data Subtitle / all Type related required SetExtraData GetExtraData
RFC 5646 language code all no SetLanguage GetLanguage
FPS scale Video Type related required SetFpsScale GetFpsScale
FPS rate Video Type related required SetFpsRate GetFpsRate
Height Video Type related required SetHeight GetHeight
Width Video Type related required SetWidth GetWidth
Aspect Video Type related required SetAspect GetAspect
Channel quantity Audio Type related required SetChannels GetChannels
Sample rate Audio Type related required SetSampleRate GetSampleRate
Bit rate Audio Type related required SetBitRate GetBitRate
Bits per sample Audio Type related required SetBitsPerSample GetBitsPerSample
Block align no SetBlockAlign GetBlockAlign
Crypto session info no SetCryptoSession GetCryptoSession
Four CC code no SetCodecFourCC GetCodecFourCC
Color space no SetColorSpace GetColorSpace
Color range no SetColorRange GetColorRange
Color primaries no SetColorPrimaries GetColorPrimaries
Color transfer characteristic no SetColorTransferCharacteristic GetColorTransferCharacteristic
Mastering metadata no SetMasteringMetadata GetMasteringMetadata
Content light metadata no SetContentLightMetadata GetContentLightMetadata

Example:

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.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;
}
Definition addon-instance/inputstream.h:508
@ INPUTSTREAM_FEATURE_NONE
0000 0000 0000 0000 : Empty to set if nothing is used
Definition c-api/addon-instance/inputstream.h:203
@ INPUTSTREAM_FLAG_NONE
0000 0000 0000 0000 : Empty to set if nothing is used
Definition c-api/addon-instance/inputstream.h:225
@ INPUTSTREAM_TYPE_AUDIO
2 : To identify cpp_kodi_addon_inputstream_Defs_Info as Audio
Definition c-api/addon-instance/inputstream.h:172
void SetStreamType(INPUTSTREAM_TYPE streamType)
Set the wanted stream type.
Definition addon-instance/inputstream.h:565
void SetFlags(uint32_t flags)
Set supported flags of inputstream.
Definition addon-instance/inputstream.h:581
void SetBitRate(unsigned int bitRate)
Bit rate.
Definition addon-instance/inputstream.h:773
void SetPhysicalIndex(unsigned int id)
(required) Physical index.
Definition addon-instance/inputstream.h:640
void SetFeatures(uint32_t features)
Set special supported feature flags of inputstream.
Definition addon-instance/inputstream.h:573
void SetChannels(unsigned int channels)
(required) Amount of channels.
Definition addon-instance/inputstream.h:757
void SetBitsPerSample(unsigned int bitsPerSample)
(required) Bits per sample.
Definition addon-instance/inputstream.h:781
void SetSampleRate(unsigned int sampleRate)
(required) Sample rate.
Definition addon-instance/inputstream.h:765
void SetLanguage(const std::string &language)
RFC 5646 language code (empty string if undefined).
Definition addon-instance/inputstream.h:706
void SetCodecName(const std::string &codecName)
(required) Name of codec according to ffmpeg.
Definition addon-instance/inputstream.h:606

◆ GetStreamIds()

virtual bool kodi::addon::CInstanceInputStream::GetStreamIds ( std::vector< unsigned int > & ids)
inlinevirtual

Get IDs of available streams.

Parameters
[in]idslist of used identifications
Returns
true if successfully done, otherwise false
Remarks
This id's are used to identify wanted data on GetStream call.

Example:

bool CMyInputstream::GetStreamIds(std::vector<unsigned int>& 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();
}
@ ADDON_LOG_DEBUG
0 : To include debug information in the log file.
Definition addon_base.h:184
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition addon_base.h:193
void ATTR_DLL_LOCAL Log(const ADDON_LOG loglevel, const char *format,...)
Add a message to Kodi's log.
Definition kodi-dev-kit/include/kodi/AddonBase.h:1938

◆ OpenStream()

virtual bool kodi::addon::CInstanceInputStream::OpenStream ( int streamid)
inlinevirtual

Opens a stream for playback.

Parameters
[in]streamidunique id of stream
Remarks
Available stream id's previously asked by GetStreamIds

Note
Valid implementation required.

◆ SetVideoResolution() [1/2]

virtual void kodi::addon::CInstanceInputStream::SetVideoResolution ( unsigned int width,
unsigned int height )
inlinevirtual

Notify current screen resolution.

Parameters
[in]widthWidth to set
[in]heightHeight to set

◆ SetVideoResolution() [2/2]

virtual void kodi::addon::CInstanceInputStream::SetVideoResolution ( unsigned int width,
unsigned int height,
unsigned int maxWidth,
unsigned int maxHeight )
inlinevirtual

Notify current screen resolution and max screen resolution allowed.

Parameters
[in]widthWidth to set
[in]heightHeight to set
[in]maxWidthMax width allowed
[in]maxHeightMax height allowed