| 1 |
/* |
| 2 |
* Copyright (C) 2013-2019 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 |
/** |
| 12 |
* \file platform\DecoderFilter.h |
| 13 |
* \brief Declares CDecoderFilterManager which gives control about how / when to use platform decoder. |
| 14 |
* |
| 15 |
*/ |
| 16 |
#include "threads/CriticalSection.h" |
| 17 |
|
| 18 |
#include <cinttypes> |
| 19 |
#include <set> |
| 20 |
#include <string> |
| 21 |
|
| 22 |
class CDVDStreamInfo; |
| 23 |
|
| 24 |
namespace tinyxml2 |
| 25 |
{ |
| 26 |
class XMLNode; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* @class CDecoderFilter |
| 31 |
* |
| 32 |
* @brief Declaration of CDecoderFilter. |
| 33 |
* |
| 34 |
*/ |
| 35 |
class CDecoderFilter |
| 36 |
{ |
| 37 |
public: |
| 38 |
/** |
| 39 |
* @brief Flags to control decoder validity. |
| 40 |
*/ |
| 41 |
enum : uint32_t |
| 42 |
{ |
| 43 |
FLAG_GENERAL_ALLOWED = 1, ///< early false exit if set |
| 44 |
FLAG_STILLS_ALLOWED = 2, ///< early false exit if set and stream is marked as "has stillframes" |
| 45 |
FLAG_DVD_ALLOWED = 4 ///< early false exit if set and stream is marked as dvd |
| 46 |
}; |
| 47 |
|
| 48 |
/** |
| 49 |
* \fn CDecoderFilter::CDecoderFilter(const std::string& name); |
| 50 |
* \brief constructs a CDecoderFilter |
| 51 |
* \param name decodername |
| 52 |
* \return nothing. |
| 53 |
*/ |
| 54 |
CDecoderFilter(const std::string& name) : m_name(name) {} |
| 55 |
|
| 56 |
/** |
| 57 |
* \fn CDecoderFilter::CDecoderFilter(const std::string& name, uint32_t flags, uint32_t maxWidth, uint32_t maxHeight); |
| 58 |
* \brief constructs a CDecoderFilter |
| 59 |
* \param name decodername |
| 60 |
* \param flags collection of FLAG_ values, bitwise OR |
| 61 |
* \param minHeight minimum height of stream allowed by this decoder |
| 62 |
* \return nothing. |
| 63 |
*/ |
| 64 |
CDecoderFilter(const std::string& name, uint32_t flags, int minHeight); |
| 65 |
|
| 66 |
virtual ~CDecoderFilter() = default; |
| 67 |
|
| 68 |
/** |
| 69 |
* \fn CDecoderFilter::operator < (const CDecoderFilter& other); |
| 70 |
* \brief used for sorting / replacing / find |
| 71 |
*/ |
| 72 |
bool operator<(const CDecoderFilter& other) const { return m_name < other.m_name; } |
| 73 |
|
| 74 |
/** |
| 75 |
* \fn CDecoderFilter::isValid(const CDVDStreamInfo& streamInfo); |
| 76 |
* \brief test if stream is allowed by filter. |
| 77 |
* \return true if valid, false otherwise |
| 78 |
*/ |
| 79 |
virtual bool isValid(const CDVDStreamInfo& streamInfo) const; |
| 80 |
|
| 81 |
/** |
| 82 |
* \fn CDecoderFilter::Load(const XMLNode* settings); |
| 83 |
* \brief load all members from XML node |
| 84 |
* \param node filter node from where to get the values |
| 85 |
* \return true if operation was successful, false on error |
| 86 |
*/ |
| 87 |
virtual bool Load(const tinyxml2::XMLNode* node); |
| 88 |
|
| 89 |
/** |
| 90 |
* \fn CDecoderFilter::Save(XMLNode* settings); |
| 91 |
* \brief store all members in XML node |
| 92 |
* \param node a ready to use filter setting node |
| 93 |
* \return true if operation was successful, false on error |
| 94 |
*/ |
| 95 |
virtual bool Save(tinyxml2::XMLNode* node) const; |
| 96 |
|
| 97 |
private: |
| 98 |
std::string m_name; |
| 99 |
|
| 100 |
uint32_t m_flags = 0; |
| 101 |
int m_minHeight = 0; |
| 102 |
}; |
| 103 |
|
| 104 |
|
| 105 |
/** |
| 106 |
* @class CDecoderFilterManager |
| 107 |
* |
| 108 |
* @brief Class which handles multiple CDecoderFilter elements. |
| 109 |
* |
| 110 |
*/ |
| 111 |
|
| 112 |
class CDecoderFilterManager |
| 113 |
{ |
| 114 |
public: |
| 115 |
CDecoderFilterManager() { Load(); } |
| 116 |
virtual ~CDecoderFilterManager() { Save(); } |
| 117 |
|
| 118 |
/** |
| 119 |
* \fn bool CDecoderFilterManager::add(const CDecoderFilter& filter); |
| 120 |
* \brief adds an CDecoderFilter if key [filter.name] is not yet existing. |
| 121 |
* \param filter the decoder filter to add / replace. |
| 122 |
* \return nothing. |
| 123 |
*/ |
| 124 |
void add(const CDecoderFilter& filter); |
| 125 |
|
| 126 |
|
| 127 |
/** |
| 128 |
* \fn bool CDecoderFilterManager::validate(const std::string& name, const CDVDStreamInfo& streamInfo); |
| 129 |
* \brief Validates if decoder with name [name] is allowed to be used. |
| 130 |
* \param streamInfo Stream information used to validate(). |
| 131 |
* \return true if HardwarDecoder could be used, false otherwise. |
| 132 |
*/ |
| 133 |
bool isValid(const std::string& name, const CDVDStreamInfo& streamInfo); |
| 134 |
|
| 135 |
protected: |
| 136 |
bool Load(); |
| 137 |
bool Save() const; |
| 138 |
|
| 139 |
private: |
| 140 |
bool m_dirty = false; |
| 141 |
std::set<CDecoderFilter> m_filters; |
| 142 |
mutable CCriticalSection m_critical; |
| 143 |
}; |