Kodi Development  20.0
for Binary and Script based Add-Ons
2. Stream demuxing (optional)

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

◆ GetStreamIds()

virtual bool 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:174
@ ADDON_LOG_ERROR
3 : To report error messages in the log file.
Definition: addon_base.h:183
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749

◆ GetStream()

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

◆ EnableStream()

virtual void 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.

◆ OpenStream()

virtual bool 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.

◆ DemuxReset()

virtual void DemuxReset ( )
inlinevirtual

Reset the demultiplexer in the add-on.

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

◆ DemuxAbort()

virtual void DemuxAbort ( )
inlinevirtual

Abort the demultiplexer thread in the add-on.

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

◆ DemuxFlush()

virtual void 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* 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 occured.
Remarks
Return nullptr if this add-on won't provide this function.

◆ DemuxSeekTime()

virtual bool 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 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.

◆ SetVideoResolution()

virtual void SetVideoResolution ( int  width,
int  height 
)
inlinevirtual

Sets desired width / height.

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

◆ AllocateDemuxPacket()

DEMUX_PACKET* 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* 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

◆ FreeDemuxPacket()

void 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