Merge pull request #26073 from sundermann/ffmpeg-new-codec-profiles
[xbmc.git] / xbmc / pvr / addons / PVRClient.h
blob523cb10f6a055c15ec02882074739b934eaeb5a3
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "XBDateTime.h"
12 #include "addons/binary-addons/AddonInstanceHandler.h"
13 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr.h"
14 #include "pvr/addons/PVRClientCapabilities.h"
15 #include "threads/Event.h"
17 #include <atomic>
18 #include <functional>
19 #include <memory>
20 #include <optional>
21 #include <string>
22 #include <utility>
23 #include <vector>
25 struct DemuxPacket;
27 namespace EDL
29 struct Edit;
32 namespace PVR
34 class CPVRChannel;
35 class CPVRChannelGroup;
36 class CPVRChannelGroupMember;
37 class CPVRChannelGroups;
38 class CPVRProvider;
39 class CPVRProvidersContainer;
40 class CPVRClientMenuHook;
41 class CPVRClientMenuHooks;
42 class CPVRDescrambleInfo;
43 class CPVREpg;
44 class CPVREpgInfoTag;
45 class CPVRRecording;
46 class CPVRRecordings;
47 class CPVRSignalStatus;
48 class CPVRStreamProperties;
49 class CPVRTimerInfoTag;
50 class CPVRTimerType;
51 class CPVRTimersContainer;
53 /*!
54 * Interface from Kodi to a PVR add-on.
56 * Also translates Kodi's C++ structures to the add-on's C structures.
58 class CPVRClient : public ADDON::IAddonInstanceHandler
60 public:
61 CPVRClient(const ADDON::AddonInfoPtr& addonInfo, ADDON::AddonInstanceId instanceId, int clientId);
62 ~CPVRClient() override;
64 void OnPreInstall() override;
65 void OnPreUnInstall() override;
67 /** @name PVR add-on methods */
68 //@{
70 /*!
71 * @brief Initialise the instance of this add-on.
73 ADDON_STATUS Create();
75 /*!
76 * @brief Stop this add-on instance. No more client add-on access after this call.
78 void Stop();
80 /*!
81 * @brief Continue this add-on instance. Client add-on access is okay again after this call.
83 void Continue();
85 /*!
86 * @brief Destroy the instance of this add-on.
88 void Destroy();
90 /*!
91 * @brief Destroy and recreate this add-on.
93 void ReCreate();
95 /*!
96 * @return True if this instance is initialised (ADDON_Create returned true), false otherwise.
98 bool ReadyToUse() const;
101 * @brief Gets the backend connection state.
102 * @return the backend connection state.
104 PVR_CONNECTION_STATE GetConnectionState() const;
107 * @brief Sets the backend connection state.
108 * @param state the new backend connection state.
110 void SetConnectionState(PVR_CONNECTION_STATE state);
113 * @brief Gets the backend's previous connection state.
114 * @return the backend's previous connection state.
116 PVR_CONNECTION_STATE GetPreviousConnectionState() const;
119 * @brief Check whether this client should be ignored.
120 * @return True if this client should be ignored, false otherwise.
122 bool IgnoreClient() const;
125 * @brief Check whether this client is enabled, according to its instance/add-on configuration.
126 * @return True if this client is enabled, false otherwise.
128 bool IsEnabled() const;
131 * @return The ID of this instance.
133 int GetID() const;
135 //@}
136 /** @name PVR server methods */
137 //@{
140 * @brief Query this add-on's capabilities.
141 * @return The add-on's capabilities.
143 const CPVRClientCapabilities& GetClientCapabilities() const { return m_clientCapabilities; }
146 * @brief Get the stream properties of the stream that's currently being read.
147 * @param pProperties The properties.
148 * @return PVR_ERROR_NO_ERROR if the properties have been fetched successfully.
150 PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties) const;
153 * @brief A stream was closed or has ended
154 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
156 PVR_ERROR StreamClosed() const;
159 * @return The name reported by the backend.
161 const std::string& GetBackendName() const;
164 * @return The version string reported by the backend.
166 const std::string& GetBackendVersion() const;
169 * @brief the ip address or alias of the pvr backend server
171 const std::string& GetBackendHostname() const;
174 * @return The connection string reported by the backend.
176 const std::string& GetConnectionString() const;
179 * @brief The name of the PVR client, as specified by the addon developer.
180 * @return string that can be used in log messages and the GUI.
182 std::string GetClientName() const;
185 * @brief The name of the PVR client addon instance, as specified by the user in the addon
186 * settings. Empty if addon does not support multiple instances.
187 * @return string that can be used in log messages and the GUI.
189 std::string GetInstanceName() const;
192 * @brief A name used to uniquely identify the client, inclusing addon name and instance
193 * name, if multiple instances are supported by the client implementation.
194 * @return string that can be used in log messages and the GUI.
196 std::string GetFullClientName() const;
199 * @brief Get the disk space reported by the server.
200 * @param iTotal The total disk space.
201 * @param iUsed The used disk space.
202 * @return PVR_ERROR_NO_ERROR if the drive space has been fetched successfully.
204 PVR_ERROR GetDriveSpace(uint64_t& iTotal, uint64_t& iUsed) const;
207 * @brief Start a channel scan on the server.
208 * @return PVR_ERROR_NO_ERROR if the channel scan has been started successfully.
210 PVR_ERROR StartChannelScan();
213 * @brief Request the client to open dialog about given channel to add
214 * @param channel The channel to add
215 * @return PVR_ERROR_NO_ERROR if the add has been fetched successfully.
217 PVR_ERROR OpenDialogChannelAdd(const std::shared_ptr<const CPVRChannel>& channel);
220 * @brief Request the client to open dialog about given channel settings
221 * @param channel The channel to edit
222 * @return PVR_ERROR_NO_ERROR if the edit has been fetched successfully.
224 PVR_ERROR OpenDialogChannelSettings(const std::shared_ptr<const CPVRChannel>& channel);
227 * @brief Request the client to delete given channel
228 * @param channel The channel to delete
229 * @return PVR_ERROR_NO_ERROR if the delete has been fetched successfully.
231 PVR_ERROR DeleteChannel(const std::shared_ptr<const CPVRChannel>& channel);
234 * @brief Request the client to rename given channel
235 * @param channel The channel to rename
236 * @return PVR_ERROR_NO_ERROR if the rename has been fetched successfully.
238 PVR_ERROR RenameChannel(const std::shared_ptr<const CPVRChannel>& channel);
241 * @brief Check if an epg tag can be recorded
242 * @param tag The epg tag
243 * @param bIsRecordable Set to true if the tag can be recorded
244 * @return PVR_ERROR_NO_ERROR if bIsRecordable has been set successfully.
246 PVR_ERROR IsRecordable(const std::shared_ptr<const CPVREpgInfoTag>& tag,
247 bool& bIsRecordable) const;
250 * @brief Check if an epg tag can be played
251 * @param tag The epg tag
252 * @param bIsPlayable Set to true if the tag can be played
253 * @return PVR_ERROR_NO_ERROR if bIsPlayable has been set successfully.
255 PVR_ERROR IsPlayable(const std::shared_ptr<const CPVREpgInfoTag>& tag, bool& bIsPlayable) const;
258 * @brief Fill the given container with the properties required for playback
259 * of the given EPG tag. Values are obtained from the PVR backend.
261 * @param tag The EPG tag.
262 * @param props The container to be filled with the stream properties.
263 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
265 PVR_ERROR GetEpgTagStreamProperties(const std::shared_ptr<const CPVREpgInfoTag>& tag,
266 CPVRStreamProperties& props) const;
268 //@}
269 /** @name PVR EPG methods */
270 //@{
273 * @brief Request an EPG table for a channel from the client.
274 * @param iChannelUid The UID of the channel to get the EPG table for.
275 * @param epg The table to write the data to.
276 * @param start The start time to use.
277 * @param end The end time to use.
278 * @return PVR_ERROR_NO_ERROR if the table has been fetched successfully.
280 PVR_ERROR GetEPGForChannel(int iChannelUid, CPVREpg* epg, time_t start, time_t end) const;
283 * @brief Tell the client the past time frame to use when notifying epg events back
284 * to Kodi.
286 * The client might push epg events asynchronously to Kodi using the callback
287 * function EpgEventStateChange. To be able to only push events that are
288 * actually of interest for Kodi, client needs to know about the past epg time
289 * frame Kodi uses.
291 * @param[in] iPastDays number of days before "now".
292 @ref EPG_TIMEFRAME_UNLIMITED means that Kodi is interested in all epg events,
293 regardless of event times.
294 * @return PVR_ERROR_NO_ERROR if new value was successfully set.
296 PVR_ERROR SetEPGMaxPastDays(int iPastDays);
299 * @brief Tell the client the future time frame to use when notifying epg events back
300 * to Kodi.
302 * The client might push epg events asynchronously to Kodi using the callback
303 * function EpgEventStateChange. To be able to only push events that are
304 * actually of interest for Kodi, client needs to know about the future epg time
305 * frame Kodi uses.
307 * @param[in] iFutureDays number of days after "now".
308 @ref EPG_TIMEFRAME_UNLIMITED means that Kodi is interested in all epg events,
309 regardless of event times.
310 * @return PVR_ERROR_NO_ERROR if new value was successfully set.
312 PVR_ERROR SetEPGMaxFutureDays(int iFutureDays);
314 //@}
315 /** @name PVR channel group methods */
316 //@{
319 * @brief Get the total amount of channel groups from the backend.
320 * @param iGroups The total amount of channel groups on the server or -1 on error.
321 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
323 PVR_ERROR GetChannelGroupsAmount(int& iGroups) const;
326 * @brief Request the list of all channel groups from the backend.
327 * @param groups The groups container to get the groups for.
328 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
330 PVR_ERROR GetChannelGroups(CPVRChannelGroups* groups) const;
333 * @brief Request the list of all group members from the backend.
334 * @param group The group to get the members for.
335 * @param groupMembers The container for the group members.
336 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
338 PVR_ERROR GetChannelGroupMembers(
339 CPVRChannelGroup* group,
340 std::vector<std::shared_ptr<CPVRChannelGroupMember>>& groupMembers) const;
342 //@}
343 /** @name PVR channel methods */
344 //@{
347 * @brief Get the total amount of channels from the backend.
348 * @param iChannels The total amount of channels on the server or -1 on error.
349 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
351 PVR_ERROR GetChannelsAmount(int& iChannels) const;
354 * @brief Request the list of all channels from the backend.
355 * @param bRadio True to get the radio channels, false to get the TV channels.
356 * @param channels The container for the channels.
357 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
359 PVR_ERROR GetChannels(bool bRadio, std::vector<std::shared_ptr<CPVRChannel>>& channels) const;
362 * @brief Get the total amount of providers from the backend.
363 * @param iChannels The total amount of channels on the server or -1 on error.
364 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
366 PVR_ERROR GetProvidersAmount(int& iProviders) const;
369 * @brief Request the list of all providers from the backend.
370 * @param providers The providers list to add the providers to.
371 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
373 PVR_ERROR GetProviders(CPVRProvidersContainer& providers) const;
375 //@}
376 /** @name PVR recording methods */
377 //@{
380 * @brief Get the total amount of recordings from the backend.
381 * @param deleted True to return deleted recordings.
382 * @param iRecordings The total amount of recordings on the server or -1 on error.
383 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
385 PVR_ERROR GetRecordingsAmount(bool deleted, int& iRecordings) const;
388 * @brief Request the list of all recordings from the backend.
389 * @param results The container to add the recordings to.
390 * @param deleted True to return deleted recordings.
391 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
393 PVR_ERROR GetRecordings(CPVRRecordings* results, bool deleted) const;
396 * @brief Delete a recording on the backend.
397 * @param recording The recording to delete.
398 * @return PVR_ERROR_NO_ERROR if the recording has been deleted successfully.
400 PVR_ERROR DeleteRecording(const CPVRRecording& recording);
403 * @brief Undelete a recording on the backend.
404 * @param recording The recording to undelete.
405 * @return PVR_ERROR_NO_ERROR if the recording has been undeleted successfully.
407 PVR_ERROR UndeleteRecording(const CPVRRecording& recording);
410 * @brief Delete all recordings permanent which in the deleted folder on the backend.
411 * @return PVR_ERROR_NO_ERROR if the recordings has been deleted successfully.
413 PVR_ERROR DeleteAllRecordingsFromTrash();
416 * @brief Rename a recording on the backend.
417 * @param recording The recording to rename.
418 * @return PVR_ERROR_NO_ERROR if the recording has been renamed successfully.
420 PVR_ERROR RenameRecording(const CPVRRecording& recording);
423 * @brief Set the lifetime of a recording on the backend.
424 * @param recording The recording to set the lifetime for. recording.m_iLifetime contains the new lifetime value.
425 * @return PVR_ERROR_NO_ERROR if the recording's lifetime has been set successfully.
427 PVR_ERROR SetRecordingLifetime(const CPVRRecording& recording);
430 * @brief Set the play count of a recording on the backend.
431 * @param recording The recording to set the play count.
432 * @param count Play count.
433 * @return PVR_ERROR_NO_ERROR if the recording's play count has been set successfully.
435 PVR_ERROR SetRecordingPlayCount(const CPVRRecording& recording, int count);
438 * @brief Set the last watched position of a recording on the backend.
439 * @param recording The recording.
440 * @param lastplayedposition The last watched position in seconds
441 * @return PVR_ERROR_NO_ERROR if the position has been stored successfully.
443 PVR_ERROR SetRecordingLastPlayedPosition(const CPVRRecording& recording, int lastplayedposition);
446 * @brief Retrieve the last watched position of a recording on the backend.
447 * @param recording The recording.
448 * @param iPosition The last watched position in seconds or -1 on error
449 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
451 PVR_ERROR GetRecordingLastPlayedPosition(const CPVRRecording& recording, int& iPosition) const;
454 * @brief Retrieve the edit decision list (EDL) from the backend.
455 * @param recording The recording.
456 * @param edls The edit decision list (empty on error).
457 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
459 PVR_ERROR GetRecordingEdl(const CPVRRecording& recording, std::vector<EDL::Edit>& edls) const;
462 * @brief Retrieve the size of a recording on the backend.
463 * @param recording The recording.
464 * @param sizeInBytes The size in bytes
465 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
467 PVR_ERROR GetRecordingSize(const CPVRRecording& recording, int64_t& sizeInBytes) const;
470 * @brief Retrieve the edit decision list (EDL) from the backend.
471 * @param epgTag The EPG tag.
472 * @param edls The edit decision list (empty on error).
473 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
475 PVR_ERROR GetEpgTagEdl(const std::shared_ptr<const CPVREpgInfoTag>& epgTag,
476 std::vector<EDL::Edit>& edls) const;
478 //@}
479 /** @name PVR timer methods */
480 //@{
483 * @brief Get the total amount of timers from the backend.
484 * @param iTimers The total amount of timers on the backend or -1 on error.
485 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
487 PVR_ERROR GetTimersAmount(int& iTimers) const;
490 * @brief Request the list of all timers from the backend.
491 * @param results The container to store the result in.
492 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
494 PVR_ERROR GetTimers(CPVRTimersContainer* results) const;
497 * @brief Add a timer on the backend.
498 * @param timer The timer to add.
499 * @return PVR_ERROR_NO_ERROR if the timer has been added successfully.
501 PVR_ERROR AddTimer(const CPVRTimerInfoTag& timer);
504 * @brief Delete a timer on the backend.
505 * @param timer The timer to delete.
506 * @param bForce Set to true to delete a timer that is currently recording a program.
507 * @return PVR_ERROR_NO_ERROR if the timer has been deleted successfully.
509 PVR_ERROR DeleteTimer(const CPVRTimerInfoTag& timer, bool bForce = false);
512 * @brief Update the timer information on the server.
513 * @param timer The timer to update.
514 * @return PVR_ERROR_NO_ERROR if the timer has been updated successfully.
516 PVR_ERROR UpdateTimer(const CPVRTimerInfoTag& timer);
519 * @brief Update all timer types supported by the backend.
520 * @return PVR_ERROR_NO_ERROR if the list has been fetched successfully.
522 PVR_ERROR UpdateTimerTypes();
525 * @brief Get the timer types supported by the backend, without updating them from the backend.
526 * @return the types.
528 const std::vector<std::shared_ptr<CPVRTimerType>>& GetTimerTypes() const;
530 //@}
531 /** @name PVR live stream methods */
532 //@{
535 * @brief Open a live stream on the server.
536 * @param channel The channel to stream.
537 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
539 PVR_ERROR OpenLiveStream(const std::shared_ptr<const CPVRChannel>& channel);
542 * @brief Close an open live stream.
543 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
545 PVR_ERROR CloseLiveStream();
548 * @brief Read from an open live stream.
549 * @param lpBuf The buffer to store the data in.
550 * @param uiBufSize The amount of bytes to read.
551 * @param iRead The amount of bytes that were actually read from the stream.
552 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
554 PVR_ERROR ReadLiveStream(void* lpBuf, int64_t uiBufSize, int& iRead);
557 * @brief Seek in a live stream on a backend.
558 * @param iFilePosition The position to seek to.
559 * @param iWhence ?
560 * @param iPosition The new position or -1 on error.
561 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
563 PVR_ERROR SeekLiveStream(int64_t iFilePosition, int iWhence, int64_t& iPosition);
566 * @brief Get the length of the currently playing live stream, if any.
567 * @param iLength The total length of the stream that's currently being read or -1 on error.
568 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
570 PVR_ERROR GetLiveStreamLength(int64_t& iLength) const;
573 * @brief (Un)Pause a stream.
574 * @param bPaused True to pause the stream, false to unpause.
575 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
577 PVR_ERROR PauseStream(bool bPaused);
580 * @brief Get the signal quality of the stream that's currently open.
581 * @param channelUid Channel unique identifier
582 * @param qualityinfo The signal quality.
583 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
585 PVR_ERROR SignalQuality(int channelUid, CPVRSignalStatus& qualityinfo) const;
588 * @brief Get the descramble information of the stream that's currently open.
589 * @param channelUid Channel unique identifier
590 * @param descrambleinfo The descramble information.
591 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
593 PVR_ERROR GetDescrambleInfo(int channelUid, CPVRDescrambleInfo& descrambleinfo) const;
596 * @brief Fill the given container with the properties required for playback of the given channel. Values are obtained from the PVR backend.
597 * @param channel The channel.
598 * @param source PVR_SOURCE_EPG_AS_LIVE if this call resulted from PVR_STREAM_PROPERTY_EPGPLAYBACKASLIVE being set from GetEPGTagStreamProperties(), DEFAULT otherwise.
599 * @param props The container to be filled with the stream properties.
600 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
602 PVR_ERROR GetChannelStreamProperties(const std::shared_ptr<const CPVRChannel>& channel,
603 PVR_SOURCE source,
604 CPVRStreamProperties& props) const;
607 * @brief Check whether PVR backend supports pausing the currently playing stream
608 * @param bCanPause True if the stream can be paused, false otherwise.
609 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
611 PVR_ERROR CanPauseStream(bool& bCanPause) const;
614 * @brief Check whether PVR backend supports seeking for the currently playing stream
615 * @param bCanSeek True if the stream can be seeked, false otherwise.
616 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
618 PVR_ERROR CanSeekStream(bool& bCanSeek) const;
621 * @brief Notify the pvr addon/demuxer that Kodi wishes to seek the stream by time
622 * @param time The absolute time since stream start
623 * @param backwards True to seek to keyframe BEFORE time, else AFTER
624 * @param startpts can be updated to point to where display should start
625 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
626 * @remarks Optional, and only used if addon has its own demuxer.
628 PVR_ERROR SeekTime(double time, bool backwards, double* startpts);
631 * @brief Notify the pvr addon/demuxer that Kodi wishes to change playback speed
632 * @param speed The requested playback speed
633 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
634 * @remarks Optional, and only used if addon has its own demuxer.
636 PVR_ERROR SetSpeed(int speed);
639 * @brief Notify the pvr addon/demuxer that Kodi wishes to fill demux queue
640 * @param mode for setting on/off
641 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
642 * @remarks Optional, and only used if addon has its own demuxer.
644 PVR_ERROR FillBuffer(bool mode);
646 //@}
647 /** @name PVR recording stream methods */
648 //@{
651 * @brief Open a recording on the server.
652 * @param recording The recording to open.
653 * @param streamId The id of the stream opened.
654 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
656 PVR_ERROR OpenRecordedStream(const std::shared_ptr<const CPVRRecording>& recording,
657 int64_t& streamId);
660 * @brief Close an open recording stream.
661 * @param streamId The id of the stream to close, as returned by OpenRecordedStream.
662 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
664 PVR_ERROR CloseRecordedStream(int64_t streamId);
667 * @brief Read from an open recording stream.
668 * @param streamId The id of the stream to read, as returned by OpenRecordedStream.
669 * @param lpBuf The buffer to store the data in.
670 * @param uiBufSize The amount of bytes to read.
671 * @param iRead The amount of bytes that were actually read from the stream.
672 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
674 PVR_ERROR ReadRecordedStream(int64_t streamId, void* lpBuf, int64_t uiBufSize, int& iRead);
677 * @brief Seek in a recording stream on a backend.
678 * @param streamId The id of the stream to seek, as returned by OpenRecordedStream.
679 * @param iFilePosition The position to seek to.
680 * @param iWhence ?
681 * @param iPosition The new position or -1 on error.
682 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
684 PVR_ERROR SeekRecordedStream(int64_t streamId,
685 int64_t iFilePosition,
686 int iWhence,
687 int64_t& iPosition);
690 * @brief Get the length of the given stream.
691 * @param streamId The id of the stream to get the length for, as returned by OpenRecordedStream.
692 * @param iLength The total length of the stream that's currently being read or -1 on error.
693 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
695 PVR_ERROR GetRecordedStreamLength(int64_t streamId, int64_t& iLength) const;
698 * @brief Check whether the given stream is a real-time stream.
699 * @param streamId The id of the stream to check, as returned by OpenRecordedStream.
700 * @param isRealTime True if real-time, false otherwise.
701 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
703 PVR_ERROR IsRecordedStreamRealTime(int64_t streamId, bool& isRealTime) const;
706 * @brief (Un)Pause a stream.
707 * @param streamId The id of the stream to (un)pause, as returned by OpenRecordedStream.
708 * @param paused True to pause the stream, false to unpause.
709 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
711 PVR_ERROR PauseRecordedStream(int64_t streamId, bool paused);
714 * @brief Get stream times for the given stream.
715 * @param streamId The id of the stream to get times for, as returned by OpenRecordedStream.
716 * @param times The stream times.
717 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
719 PVR_ERROR GetRecordedStreamTimes(int64_t streamId, PVR_STREAM_TIMES* times) const;
722 * @brief Fill the given container with the properties required for playback of the given recording. Values are obtained from the PVR backend.
723 * @param recording The recording.
724 * @param props The container to be filled with the stream properties.
725 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
727 PVR_ERROR GetRecordingStreamProperties(const std::shared_ptr<const CPVRRecording>& recording,
728 CPVRStreamProperties& props) const;
730 //@}
731 /** @name PVR demultiplexer methods */
732 //@{
735 * @brief Reset the demultiplexer in the add-on.
736 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
738 PVR_ERROR DemuxReset();
741 * @brief Abort the demultiplexer thread in the add-on.
742 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
744 PVR_ERROR DemuxAbort();
747 * @brief Flush all data that's currently in the demultiplexer buffer in the add-on.
748 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
750 PVR_ERROR DemuxFlush();
753 * @brief Read a packet from the demultiplexer.
754 * @param packet The packet read.
755 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
757 PVR_ERROR DemuxRead(DemuxPacket*& packet);
759 static const char* ToString(const PVR_ERROR error);
762 * @brief Check whether the currently playing stream, if any, is a real-time stream.
763 * @param bRealTime True if real-time, false otherwise.
764 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
766 PVR_ERROR IsRealTimeStream(bool& bRealTime) const;
769 * @brief Get Stream times for the currently playing stream, if any (will be moved to inputstream).
770 * @param times The stream times.
771 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
773 PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES* times) const;
776 * @brief Get the client's menu hooks.
777 * @return The hooks. Guaranteed never to be nullptr.
779 std::shared_ptr<CPVRClientMenuHooks> GetMenuHooks() const;
782 * @brief Call one of the EPG tag menu hooks of the client.
783 * @param hook The hook to call.
784 * @param tag The EPG tag associated with the hook to be called.
785 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
787 PVR_ERROR CallEpgTagMenuHook(const CPVRClientMenuHook& hook,
788 const std::shared_ptr<const CPVREpgInfoTag>& tag);
791 * @brief Call one of the channel menu hooks of the client.
792 * @param hook The hook to call.
793 * @param tag The channel associated with the hook to be called.
794 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
796 PVR_ERROR CallChannelMenuHook(const CPVRClientMenuHook& hook,
797 const std::shared_ptr<const CPVRChannel>& channel);
800 * @brief Call one of the recording menu hooks of the client.
801 * @param hook The hook to call.
802 * @param tag The recording associated with the hook to be called.
803 * @param bDeleted True, if the recording is deleted (trashed), false otherwise
804 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
806 PVR_ERROR CallRecordingMenuHook(const CPVRClientMenuHook& hook,
807 const std::shared_ptr<const CPVRRecording>& recording,
808 bool bDeleted);
811 * @brief Call one of the timer menu hooks of the client.
812 * @param hook The hook to call.
813 * @param tag The timer associated with the hook to be called.
814 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
816 PVR_ERROR CallTimerMenuHook(const CPVRClientMenuHook& hook,
817 const std::shared_ptr<const CPVRTimerInfoTag>& timer);
820 * @brief Call one of the settings menu hooks of the client.
821 * @param hook The hook to call.
822 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
824 PVR_ERROR CallSettingsMenuHook(const CPVRClientMenuHook& hook);
827 * @brief Propagate power management events to this add-on
828 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
830 PVR_ERROR OnSystemSleep();
831 PVR_ERROR OnSystemWake();
832 PVR_ERROR OnPowerSavingActivated();
833 PVR_ERROR OnPowerSavingDeactivated();
836 * @brief Get the priority of this client. Larger value means higher priority.
837 * @return The priority.
839 int GetPriority() const;
842 * @brief Set a new priority for this client.
843 * @param iPriority The new priority.
845 void SetPriority(int iPriority);
848 * @brief Get the date and time first channels were added for this client.
849 * @return The date and time first channels were added.
851 const CDateTime& GetDateTimeFirstChannelsAdded() const;
854 * @brief Set the date and time first channels were added for this client.
855 * @param dateTime The date and time first channels were added.
857 void SetDateTimeFirstChannelsAdded(const CDateTime& dateTime);
860 * @brief Obtain the chunk size to use when reading streams.
861 * @param iChunkSize the chunk size in bytes.
862 * @return PVR_ERROR_NO_ERROR on success, respective error code otherwise.
864 PVR_ERROR GetStreamReadChunkSize(int& iChunkSize) const;
866 private:
868 * @brief Resets all class members to their defaults, accept the client id.
870 void ResetProperties();
873 * @brief reads the client's properties.
874 * @return True on success, false otherwise.
876 bool GetAddonProperties();
879 * @brief reads the client's name string properties
880 * @return True on success, false otherwise.
882 bool GetAddonNameStringProperties();
885 * @brief Write the given addon properties to the given properties container.
886 * @param properties Pointer to an array of addon properties pointers.
887 * @param iPropertyCount The number of properties contained in the addon properties array.
888 * @param props The container the addon properties shall be written to.
890 static void WriteStreamProperties(PVR_NAMED_VALUE** properties,
891 unsigned int iPropertyCount,
892 CPVRStreamProperties& props);
895 * @brief Whether a channel can be played by this add-on
896 * @param channel The channel to check.
897 * @return True when it can be played, false otherwise.
899 bool CanPlayChannel(const std::shared_ptr<const CPVRChannel>& channel) const;
902 * @brief Stop this instance, if it is currently running.
904 void StopRunningInstance();
907 * @brief Wraps an addon function call in order to do common pre and post function invocation actions.
908 * @param strFunctionName The function name, for logging purposes.
909 * @param function The function to wrap. It has to have return type PVR_ERROR and must take one parameter of type const AddonInstance*.
910 * @param bIsImplemented If false, this method will return PVR_ERROR_NOT_IMPLEMENTED.
911 * @param bCheckReadyToUse If true, this method will check whether this instance is ready for use and return PVR_ERROR_SERVER_ERROR if it is not.
912 * @return PVR_ERROR_NO_ERROR on success, any other PVR_ERROR_* value otherwise.
914 typedef AddonInstance_PVR AddonInstance;
915 PVR_ERROR DoAddonCall(const char* strFunctionName,
916 const std::function<PVR_ERROR(const AddonInstance*)>& function,
917 bool bIsImplemented = true,
918 bool bCheckReadyToUse = true) const;
921 * @brief Wraps an addon callback function call in order to do common pre and post function invocation actions.
922 * @param strFunctionName The function name, for logging purposes.
923 * @param kodiInstance The addon instance pointer.
924 * @param function The function to wrap. It must take one parameter of type CPVRClient*.
925 * @param bForceCall If true, make the call, ignoring client's state.
927 static void HandleAddonCallback(const char* strFunctionName,
928 void* kodiInstance,
929 const std::function<void(CPVRClient* client)>& function,
930 bool bForceCall = false);
933 * @brief Callback functions from addon to kodi
935 //@{
938 * @brief Transfer a channel group from the add-on to Kodi. The group will be created if it doesn't exist.
939 * @param kodiInstance Pointer to Kodi's CPVRClient class
940 * @param handle The handle parameter that Kodi used when requesting the channel groups list
941 * @param entry The entry to transfer to Kodi
943 static void cb_transfer_channel_group(void* kodiInstance,
944 const PVR_HANDLE handle,
945 const PVR_CHANNEL_GROUP* entry);
948 * @brief Transfer a channel group member entry from the add-on to Kodi. The channel will be added to the group if the group can be found.
949 * @param kodiInstance Pointer to Kodi's CPVRClient class
950 * @param handle The handle parameter that Kodi used when requesting the channel group members list
951 * @param entry The entry to transfer to Kodi
953 static void cb_transfer_channel_group_member(void* kodiInstance,
954 const PVR_HANDLE handle,
955 const PVR_CHANNEL_GROUP_MEMBER* entry);
958 * @brief Transfer an EPG tag from the add-on to Kodi
959 * @param kodiInstance Pointer to Kodi's CPVRClient class
960 * @param handle The handle parameter that Kodi used when requesting the EPG data
961 * @param entry The entry to transfer to Kodi
963 static void cb_transfer_epg_entry(void* kodiInstance,
964 const PVR_HANDLE handle,
965 const EPG_TAG* entry);
968 * @brief Transfer a channel entry from the add-on to Kodi
969 * @param kodiInstance Pointer to Kodi's CPVRClient class
970 * @param handle The handle parameter that Kodi used when requesting the channel list
971 * @param entry The entry to transfer to Kodi
973 static void cb_transfer_channel_entry(void* kodiInstance,
974 const PVR_HANDLE handle,
975 const PVR_CHANNEL* entry);
978 * @brief Transfer a provider entry from the add-on to Kodi
979 * @param kodiInstance Pointer to Kodi's CPVRClient class
980 * @param handle The handle parameter that Kodi used when requesting the channel list
981 * @param entry The entry to transfer to Kodi
983 static void cb_transfer_provider_entry(void* kodiInstance,
984 const PVR_HANDLE handle,
985 const PVR_PROVIDER* entry);
988 * @brief Transfer a timer entry from the add-on to Kodi
989 * @param kodiInstance Pointer to Kodi's CPVRClient class
990 * @param handle The handle parameter that Kodi used when requesting the timers list
991 * @param entry The entry to transfer to Kodi
993 static void cb_transfer_timer_entry(void* kodiInstance,
994 const PVR_HANDLE handle,
995 const PVR_TIMER* entry);
998 * @brief Transfer a recording entry from the add-on to Kodi
999 * @param kodiInstance Pointer to Kodi's CPVRClient class
1000 * @param handle The handle parameter that Kodi used when requesting the recordings list
1001 * @param entry The entry to transfer to Kodi
1003 static void cb_transfer_recording_entry(void* kodiInstance,
1004 const PVR_HANDLE handle,
1005 const PVR_RECORDING* entry);
1008 * @brief Add or replace a menu hook for the context menu for this add-on
1009 * @param kodiInstance Pointer to Kodi's CPVRClient class
1010 * @param hook The hook to add.
1012 static void cb_add_menu_hook(void* kodiInstance, const PVR_MENUHOOK* hook);
1015 * @brief Display a notification in Kodi that a recording started or stopped on the server
1016 * @param kodiInstance Pointer to Kodi's CPVRClient class
1017 * @param strName The name of the recording to display
1018 * @param strFileName The filename of the recording
1019 * @param bOnOff True when recording started, false when it stopped
1021 static void cb_recording_notification(void* kodiInstance,
1022 const char* strName,
1023 const char* strFileName,
1024 bool bOnOff);
1027 * @brief Request Kodi to update it's list of channels
1028 * @param kodiInstance Pointer to Kodi's CPVRClient class
1030 static void cb_trigger_channel_update(void* kodiInstance);
1033 * @brief Request Kodi to update it's list of providers
1034 * @param kodiInstance Pointer to Kodi's CPVRClient class
1036 static void cb_trigger_provider_update(void* kodiInstance);
1039 * @brief Request Kodi to update it's list of timers
1040 * @param kodiInstance Pointer to Kodi's CPVRClient class
1042 static void cb_trigger_timer_update(void* kodiInstance);
1045 * @brief Request Kodi to update it's list of recordings
1046 * @param kodiInstance Pointer to Kodi's CPVRClient class
1048 static void cb_trigger_recording_update(void* kodiInstance);
1051 * @brief Request Kodi to update it's list of channel groups
1052 * @param kodiInstance Pointer to Kodi's CPVRClient class
1054 static void cb_trigger_channel_groups_update(void* kodiInstance);
1057 * @brief Schedule an EPG update for the given channel channel
1058 * @param kodiInstance A pointer to the add-on
1059 * @param iChannelUid The unique id of the channel for this add-on
1061 static void cb_trigger_epg_update(void* kodiInstance, unsigned int iChannelUid);
1064 * @brief Free a packet that was allocated with AllocateDemuxPacket
1065 * @param kodiInstance Pointer to Kodi's CPVRClient class
1066 * @param pPacket The packet to free.
1068 static void cb_free_demux_packet(void* kodiInstance, DEMUX_PACKET* pPacket);
1071 * @brief Allocate a demux packet. Free with FreeDemuxPacket
1072 * @param kodiInstance Pointer to Kodi's CPVRClient class.
1073 * @param iDataSize The size of the data that will go into the packet
1074 * @return The allocated packet.
1076 static DEMUX_PACKET* cb_allocate_demux_packet(void* kodiInstance, int iDataSize = 0);
1079 * @brief Notify a state change for a PVR backend connection
1080 * @param kodiInstance Pointer to Kodi's CPVRClient class
1081 * @param strConnectionString The connection string reported by the backend that can be displayed in the UI.
1082 * @param newState The new state.
1083 * @param strMessage A localized addon-defined string representing the new state, that can be displayed
1084 * in the UI or NULL if the Kodi-defined default string for the new state shall be displayed.
1086 static void cb_connection_state_change(void* kodiInstance,
1087 const char* strConnectionString,
1088 PVR_CONNECTION_STATE newState,
1089 const char* strMessage);
1092 * @brief Notify a state change for an EPG event
1093 * @param kodiInstance Pointer to Kodi's CPVRClient class
1094 * @param tag The EPG event.
1095 * @param newState The new state.
1096 * @param newState The new state. For EPG_EVENT_CREATED and EPG_EVENT_UPDATED, tag must be filled with all available
1097 * event data, not just a delta. For EPG_EVENT_DELETED, it is sufficient to fill EPG_TAG.iUniqueBroadcastId
1099 static void cb_epg_event_state_change(void* kodiInstance, EPG_TAG* tag, EPG_EVENT_STATE newState);
1101 /*! @todo remove the use complete from them, or add as generl function?!
1102 * Returns the ffmpeg codec id from given ffmpeg codec string name
1104 static PVR_CODEC cb_get_codec_by_name(const void* kodiInstance, const char* strCodecName);
1105 //@}
1107 const int m_iClientId; /*!< unique ID of the client */
1108 std::atomic<bool>
1109 m_bReadyToUse; /*!< true if this add-on is initialised (ADDON_Create returned true), false otherwise */
1110 std::atomic<bool> m_bBlockAddonCalls; /*!< true if no add-on API calls are allowed */
1111 mutable std::atomic<int> m_iAddonCalls; /*!< number of in-progress addon calls */
1112 mutable CEvent m_allAddonCallsFinished; /*!< fires after last in-progress addon call finished */
1113 PVR_CONNECTION_STATE m_connectionState; /*!< the backend connection state */
1114 PVR_CONNECTION_STATE m_prevConnectionState; /*!< the previous backend connection state */
1115 bool
1116 m_ignoreClient; /*!< signals to PVRManager to ignore this client until it has been connected */
1117 std::vector<std::shared_ptr<CPVRTimerType>>
1118 m_timertypes; /*!< timer types supported by this backend */
1119 mutable std::optional<int> m_priority; /*!< priority of the client */
1120 mutable std::optional<CDateTime>
1121 m_firstChannelsAdded; /*!< date and time the first channels were added for this client */
1123 /* cached data */
1124 std::string m_strBackendName; /*!< the cached backend version */
1125 std::string m_strBackendVersion; /*!< the cached backend version */
1126 std::string m_strConnectionString; /*!< the cached connection string */
1127 std::string m_strBackendHostname; /*!< the cached backend hostname */
1128 CPVRClientCapabilities m_clientCapabilities; /*!< the cached add-on's capabilities */
1129 mutable std::shared_ptr<CPVRClientMenuHooks> m_menuhooks; /*!< the menu hooks for this add-on */
1131 /* stored strings to make sure const char* members in AddonProperties_PVR stay valid */
1132 std::string m_strUserPath; /*!< @brief translated path to the user profile */
1133 std::string m_strClientPath; /*!< @brief translated path to this add-on */
1135 mutable CCriticalSection m_critSection;
1137 } // namespace PVR