1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
/*
* Copyright (C) 2019 Igalia S.L
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* aint with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#if USE(GSTREAMER)
#include "GStreamerCommon.h"
#include "MediaConfiguration.h"
#include "MediaPlayerEnums.h"
#include "RTCRtpCapabilities.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/OptionSet.h>
#include <wtf/text/AtomString.h>
#include <wtf/text/AtomStringHash.h>
#include <wtf/text/StringHash.h>
#if USE(GSTREAMER_WEBRTC)
#include <gst/rtp/rtp.h>
#endif
namespace WebCore {
class ContentType;
void teardownGStreamerRegistryScanner();
class GStreamerRegistryScanner {
WTF_MAKE_NONCOPYABLE(GStreamerRegistryScanner)
public:
static bool singletonWasInitialized();
static GStreamerRegistryScanner& singleton();
static void getSupportedDecodingTypes(HashSet<String>&);
explicit GStreamerRegistryScanner(bool isMediaSource = false);
~GStreamerRegistryScanner() = default;
void refresh();
void teardown();
enum Configuration {
Decoding = 0,
Encoding
};
const HashSet<String>& mimeTypeSet(Configuration) const;
bool isContainerTypeSupported(Configuration, const String& containerType) const;
struct RegistryLookupResult {
bool isSupported { false };
bool isUsingHardware { false };
GRefPtr<GstElementFactory> factory;
operator bool() const { return isSupported; }
static RegistryLookupResult merge(const RegistryLookupResult& a, const RegistryLookupResult& b)
{
return RegistryLookupResult {
a.isSupported && b.isSupported,
a.isSupported && b.isSupported && a.isUsingHardware && b.isUsingHardware,
nullptr
};
}
friend bool operator==(const RegistryLookupResult& lhs, const RegistryLookupResult& rhs)
{
return lhs.isSupported == rhs.isSupported && lhs.isUsingHardware == rhs.isUsingHardware;
}
};
RegistryLookupResult isDecodingSupported(MediaConfiguration& mediaConfiguration) const { return isConfigurationSupported(Configuration::Decoding, mediaConfiguration); };
RegistryLookupResult isEncodingSupported(MediaConfiguration& mediaConfiguration) const { return isConfigurationSupported(Configuration::Encoding, mediaConfiguration); }
struct CodecLookupResult {
CodecLookupResult() = default;
CodecLookupResult(bool isSupported, const GRefPtr<GstElementFactory>& factory)
: isSupported(isSupported)
, factory(factory)
{
}
operator bool() const { return isSupported; }
bool isSupported { false };
GRefPtr<GstElementFactory> factory;
};
enum class CaseSensitiveCodecName : bool { No, Yes };
CodecLookupResult isCodecSupported(Configuration, const String& codec, bool usingHardware = false, CaseSensitiveCodecName = CaseSensitiveCodecName::Yes) const;
MediaPlayerEnums::SupportsType isContentTypeSupported(Configuration, const ContentType&, const Vector<ContentType>& contentTypesRequiringHardwareSupport, CaseSensitiveCodecName = CaseSensitiveCodecName::Yes) const;
bool areAllCodecsSupported(Configuration, const Vector<String>& codecs, bool shouldCheckForHardwareUse = false) const;
CodecLookupResult areCapsSupported(Configuration, const GRefPtr<GstCaps>&, bool shouldCheckForHardwareUse) const;
#if USE(GSTREAMER_WEBRTC)
RTCRtpCapabilities audioRtpCapabilities(Configuration);
RTCRtpCapabilities videoRtpCapabilities(Configuration);
Vector<RTCRtpCapabilities::HeaderExtensionCapability> audioRtpExtensions();
Vector<RTCRtpCapabilities::HeaderExtensionCapability> videoRtpExtensions();
RegistryLookupResult isRtpPacketizerSupported(const String& encoding);
#endif
protected:
struct ElementFactories {
enum class Type {
AudioParser = 1 << 0,
AudioDecoder = 1 << 1,
VideoParser = 1 << 2,
VideoDecoder = 1 << 3,
Demuxer = 1 << 4,
AudioEncoder = 1 << 5,
VideoEncoder = 1 << 6,
Muxer = 1 << 7,
RtpPayloader = 1 << 8,
RtpDepayloader = 1 << 9,
Decryptor = 1 << 10,
All = (1 << 10) - 1
};
explicit ElementFactories(OptionSet<Type>);
~ElementFactories();
static const char* elementFactoryTypeToString(Type);
GList* factory(Type) const;
enum class CheckHardwareClassifier : bool { No, Yes };
RegistryLookupResult hasElementForMediaType(Type, const ASCIILiteral& capsString, CheckHardwareClassifier = CheckHardwareClassifier::No, std::optional<Vector<String>> disallowedList = std::nullopt) const;
RegistryLookupResult hasElementForCaps(Type, const GRefPtr<GstCaps>&, CheckHardwareClassifier = CheckHardwareClassifier::No, std::optional<Vector<String>> disallowedList = std::nullopt) const;
GList* audioDecoderFactories { nullptr };
GList* audioParserFactories { nullptr };
GList* videoDecoderFactories { nullptr };
GList* videoParserFactories { nullptr };
GList* demuxerFactories { nullptr };
GList* audioEncoderFactories { nullptr };
GList* videoEncoderFactories { nullptr };
GList* muxerFactories { nullptr };
GList* rtpPayloaderFactories { nullptr };
GList* rtpDepayloaderFactories { nullptr };
GList* decryptorFactories { nullptr };
};
void initializeDecoders(const ElementFactories&);
void initializeEncoders(const ElementFactories&);
RegistryLookupResult isConfigurationSupported(Configuration, const MediaConfiguration&) const;
struct GstCapsWebKitMapping {
ElementFactories::Type elementType;
ASCIILiteral capsString;
Vector<ASCIILiteral> webkitMIMETypes;
Vector<ASCIILiteral> webkitCodecPatterns;
};
void fillMimeTypeSetFromCapsMapping(const ElementFactories&, const Vector<GstCapsWebKitMapping>&);
private:
CodecLookupResult isAVC1CodecSupported(Configuration, const String& codec, bool shouldCheckForHardwareUse) const;
CodecLookupResult isHEVCCodecSupported(Configuration, const String& codec, bool shouldCheckForHardwareUse) const;
ASCIILiteral configurationNameForLogging(Configuration) const;
bool supportsFeatures(const String& features) const;
#if USE(GSTREAMER_WEBRTC)
void fillAudioRtpCapabilities(Configuration, RTCRtpCapabilities&);
void fillVideoRtpCapabilities(Configuration, RTCRtpCapabilities&);
#define WEBRTC_EXPERIMENTS_HDREXT "http://www.webrtc.org/experiments/rtp-hdrext/"
Vector<ASCIILiteral> m_commonRtpExtensions {
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"_s,
WEBRTC_EXPERIMENTS_HDREXT "abs-send-time"_s,
GST_RTP_HDREXT_BASE "sdes:mid"_s,
GST_RTP_HDREXT_BASE "sdes:repaired-rtp-stream-id"_s,
GST_RTP_HDREXT_BASE "sdes:rtp-stream-id"_s,
GST_RTP_HDREXT_BASE "toffset"_s
};
Vector<ASCIILiteral> m_allAudioRtpExtensions {
GST_RTP_HDREXT_BASE "ssrc-audio-level"_s
};
Vector<ASCIILiteral> m_allVideoRtpExtensions {
WEBRTC_EXPERIMENTS_HDREXT "color-space"_s,
WEBRTC_EXPERIMENTS_HDREXT "playout-delay"_s,
WEBRTC_EXPERIMENTS_HDREXT "video-content-type"_s,
WEBRTC_EXPERIMENTS_HDREXT "video-timing"_s,
"urn:3gpp:video-orientation"_s
};
#undef WEBRTC_EXPERIMENTS_HDREXT
std::optional<Vector<RTCRtpCapabilities::HeaderExtensionCapability>> m_audioRtpExtensions;
std::optional<Vector<RTCRtpCapabilities::HeaderExtensionCapability>> m_videoRtpExtensions;
#endif
bool m_isMediaSource { false };
HashSet<String> m_decoderMimeTypeSet;
UncheckedKeyHashMap<String, RegistryLookupResult> m_decoderCodecMap;
HashSet<String> m_encoderMimeTypeSet;
UncheckedKeyHashMap<String, RegistryLookupResult> m_encoderCodecMap;
};
} // namespace WebCore
#endif // USE(GSTREAMER)
|