Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
VideoCodec.h
1/*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "../AddonBase.h"
12#include "../c-api/addon-instance/video_codec.h"
13#include "inputstream/DemuxPacket.h"
14#include "inputstream/StreamCodec.h"
15#include "inputstream/StreamCrypto.h"
16
17#ifdef __cplusplus
18
19namespace kodi
20{
21namespace addon
22{
23
24class CInstanceVideoCodec;
25
26//==============================================================================
36class ATTR_DLL_LOCAL VideoCodecInitdata : public CStructHdl<VideoCodecInitdata, VIDEOCODEC_INITDATA>
37{
39 friend class CInstanceVideoCodec;
42public:
58
61
65 VIDEOCODEC_TYPE GetCodecType() const { return m_cStructure->codec; }
66
68 STREAMCODEC_PROFILE GetCodecProfile() const { return m_cStructure->codecProfile; }
69
75 std::vector<VIDEOCODEC_FORMAT> GetVideoFormats() const
76 {
77 std::vector<VIDEOCODEC_FORMAT> formats;
78 unsigned int i = 0;
80 m_cStructure->videoFormats[i] != VIDEOCODEC_FORMAT_UNKNOWN)
81 formats.emplace_back(m_cStructure->videoFormats[i++]);
82 if (formats.empty())
83 formats.emplace_back(VIDEOCODEC_FORMAT_UNKNOWN);
84 return formats;
85 }
86
88 uint32_t GetWidth() const { return m_cStructure->width; }
89
91 uint32_t GetHeight() const { return m_cStructure->height; }
92
94 const uint8_t* GetExtraData() const { return m_cStructure->extraData; }
95
97 unsigned int GetExtraDataSize() const { return m_cStructure->extraDataSize; }
98
107 kodi::addon::StreamCryptoSession GetCryptoSession() const { return &m_cStructure->cryptoSession; }
108
110
111private:
112 VideoCodecInitdata() = delete;
113 VideoCodecInitdata(const VideoCodecInitdata& session) : CStructHdl(session) {}
114 VideoCodecInitdata(const VIDEOCODEC_INITDATA* session) : CStructHdl(session) {}
115 VideoCodecInitdata(VIDEOCODEC_INITDATA* session) : CStructHdl(session) {}
116};
118//------------------------------------------------------------------------------
119
120//##############################################################################
128
129//============================================================================
247class ATTR_DLL_LOCAL CInstanceVideoCodec : public IAddonInstance
248{
249public:
250 //============================================================================
260 explicit CInstanceVideoCodec(const IInstanceInfo& instance) : IAddonInstance(instance)
261 {
262 if (CPrivateBase::m_interface->globalSingleInstance != nullptr)
263 throw std::logic_error("kodi::addon::CInstanceVideoCodec: Creation of multiple together with "
264 "single instance way is not allowed!");
265
266 SetAddonStruct(instance);
267 }
268 //----------------------------------------------------------------------------
269
270 //============================================================================
274 ~CInstanceVideoCodec() override = default;
275 //----------------------------------------------------------------------------
276
277 //============================================================================
292 virtual bool Open(const kodi::addon::VideoCodecInitdata& initData) { return false; }
293 //----------------------------------------------------------------------------
294
295 //============================================================================
306 virtual bool Reconfigure(const kodi::addon::VideoCodecInitdata& initData) { return false; }
307 //----------------------------------------------------------------------------
308
309 //============================================================================
316 virtual bool AddData(const DEMUX_PACKET& packet) { return false; }
317 //----------------------------------------------------------------------------
318
319 //============================================================================
331 //----------------------------------------------------------------------------
332
333 //============================================================================
339 virtual const char* GetName() { return nullptr; }
340 //----------------------------------------------------------------------------
341
342 //============================================================================
346 virtual void Reset() {}
347 //----------------------------------------------------------------------------
348
353 //============================================================================
368 {
369 return m_instanceData->toKodi->get_frame_buffer(m_instanceData->toKodi->kodiInstance, &picture);
370 }
371 //----------------------------------------------------------------------------
372
373 //============================================================================
382 void ReleaseFrameBuffer(void* buffer)
383 {
384 return m_instanceData->toKodi->release_frame_buffer(m_instanceData->toKodi->kodiInstance,
385 buffer);
386 }
387 //----------------------------------------------------------------------------
388
389private:
390 void SetAddonStruct(KODI_ADDON_INSTANCE_STRUCT* instance)
391 {
392 instance->hdl = this;
393 instance->videocodec->toAddon->open = ADDON_Open;
394 instance->videocodec->toAddon->reconfigure = ADDON_Reconfigure;
395 instance->videocodec->toAddon->add_data = ADDON_AddData;
396 instance->videocodec->toAddon->get_picture = ADDON_GetPicture;
397 instance->videocodec->toAddon->get_name = ADDON_GetName;
398 instance->videocodec->toAddon->reset = ADDON_Reset;
399
400 m_instanceData = instance->videocodec;
401 m_instanceData->toAddon->addonInstance = this;
402 }
403
404 inline static bool ADDON_Open(const AddonInstance_VideoCodec* instance,
405 VIDEOCODEC_INITDATA* initData)
406 {
407 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Open(initData);
408 }
409
410 inline static bool ADDON_Reconfigure(const AddonInstance_VideoCodec* instance,
411 VIDEOCODEC_INITDATA* initData)
412 {
413 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
414 ->Reconfigure(initData);
415 }
416
417 inline static bool ADDON_AddData(const AddonInstance_VideoCodec* instance,
418 const DEMUX_PACKET* packet)
419 {
420 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->AddData(*packet);
421 }
422
423 inline static VIDEOCODEC_RETVAL ADDON_GetPicture(const AddonInstance_VideoCodec* instance,
424 VIDEOCODEC_PICTURE* picture)
425 {
426 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)
427 ->GetPicture(*picture);
428 }
429
430 inline static const char* ADDON_GetName(const AddonInstance_VideoCodec* instance)
431 {
432 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->GetName();
433 }
434
435 inline static void ADDON_Reset(const AddonInstance_VideoCodec* instance)
436 {
437 return static_cast<CInstanceVideoCodec*>(instance->toAddon->addonInstance)->Reset();
438 }
439
440 AddonInstance_VideoCodec* m_instanceData;
441};
442
443} // namespace addon
444} // namespace kodi
445
446#endif /* __cplusplus */
Definition VideoCodec.h:248
Definition AddonBase.h:206
Definition AddonBase.h:565
Definition AddonBase.h:498
Definition StreamCrypto.h:43
Definition VideoCodec.h:37
Definition demux_packet.h:46
STREAMCODEC_PROFILE
Definition stream_codec.h:25
Definition video_codec.h:165
uint32_t GetWidth() const
Picture width.
Definition VideoCodec.h:88
const uint8_t * GetExtraData() const
Depending on the required decoding, additional data given by the stream.
Definition VideoCodec.h:94
VIDEOCODEC_TYPE GetCodecType() const
The codec type required by Kodi to process the stream.
Definition VideoCodec.h:65
VIDEOCODEC_TYPE
Video codec types that can be requested from Kodi.
Definition video_codec.h:81
STREAMCODEC_PROFILE GetCodecProfile() const
Used profiles for non-scalable 2D video.
Definition VideoCodec.h:68
std::vector< VIDEOCODEC_FORMAT > GetVideoFormats() const
The video stream representations requested by Kodi.
Definition VideoCodec.h:75
uint32_t GetHeight() const
Picture height.
Definition VideoCodec.h:91
kodi::addon::StreamCryptoSession GetCryptoSession() const
Data to manage stream cryptography To get class structure manages any encryption values required in o...
Definition VideoCodec.h:107
unsigned int GetExtraDataSize() const
Size of the data given with extraData.
Definition VideoCodec.h:97
@ VIDEOCODEC_FORMAT_MAXFORMATS
The maximum value to use in a list.
Definition video_codec.h:72
@ VIDEOCODEC_FORMAT_UNKNOWN
Unknown types, this is used to declare the end of a list of requested types.
Definition video_codec.h:52
VIDEOCODEC_RETVAL
Return values used by video decoder interface.
Definition video_codec.h:26
@ VC_ERROR
An error occurred, no other messages will be returned.
Definition video_codec.h:31
~CInstanceVideoCodec() override=default
Destructor.
virtual bool Open(const kodi::addon::VideoCodecInitdata &initData)
Open the decoder, returns true on success.
Definition VideoCodec.h:292
virtual VIDEOCODEC_RETVAL GetPicture(VIDEOCODEC_PICTURE &picture)
GetPicture controls decoding.
Definition VideoCodec.h:330
virtual void Reset()
Reset the decoder.
Definition VideoCodec.h:346
bool GetFrameBuffer(VIDEOCODEC_PICTURE &picture)
AddonToKodi interface.
Definition VideoCodec.h:367
void ReleaseFrameBuffer(void *buffer)
Release the with GetFrameBuffer() given framebuffer.
Definition VideoCodec.h:382
virtual bool Reconfigure(const kodi::addon::VideoCodecInitdata &initData)
Reconfigure the decoder, returns true on success.
Definition VideoCodec.h:306
virtual const char * GetName()
should return codecs name
Definition VideoCodec.h:339
CInstanceVideoCodec(const IInstanceInfo &instance)
Video codec class constructor used to support multiple instance types.
Definition VideoCodec.h:260
virtual bool AddData(const DEMUX_PACKET &packet)
add data, decoder has to consume the entire packet
Definition VideoCodec.h:316
Definition video_codec.h:268
Definition addon_base.h:268
Definition video_codec.h:214