Line data Source code
1 : /*
2 : * Copyright (C) 2022 Sky UK
3 : *
4 : * This library is free software; you can redistribute it and/or
5 : * modify it under the terms of the GNU Lesser General Public
6 : * License as published by the Free Software Foundation;
7 : * version 2.1 of the License.
8 : *
9 : * This library is distributed in the hope that it will be useful,
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : * Lesser General Public License for more details.
13 : *
14 : * You should have received a copy of the GNU Lesser General Public
15 : * License along with this library; if not, write to the Free Software
16 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 : */
18 :
19 : #include "GStreamerMSEUtils.h"
20 : #include "GstreamerCatLog.h"
21 :
22 : #include <unordered_map>
23 : #include <unordered_set>
24 :
25 : #define GST_CAT_DEFAULT rialtoGStreamerCat
26 :
27 3 : void rialto_mse_sink_setup_supported_caps(GstElementClass *elementClass,
28 : const std::vector<std::string> &supportedMimeTypes)
29 : {
30 : static const std::unordered_map<std::string, std::vector<std::string>> kMimeToCaps =
31 : {{"audio/mp4", {"audio/mpeg, mpegversion=1", "audio/mpeg, mpegversion=2", "audio/mpeg, mpegversion=4"}},
32 : {"audio/aac", {"audio/mpeg, mpegversion=2", "audio/mpeg, mpegversion=4"}},
33 : {"audio/x-eac3", {"audio/x-ac3", "audio/x-eac3"}},
34 : {"audio/x-opus", {"audio/x-opus"}},
35 : {"audio/b-wav", {"audio/b-wav"}},
36 : {"audio/x-flac", {"audio/x-flac"}},
37 : #ifdef RIALTO_ENABLE_X_RAW
38 : {"audio/x-raw", {"audio/x-raw"}},
39 : #endif
40 : {"video/h264", {"video/x-h264"}},
41 : {"video/h265", {"video/x-h265"}},
42 : {"video/x-av1", {"video/x-av1"}},
43 : {"video/x-vp9", {"video/x-vp9"}},
44 : {"text/vtt", {"text/vtt", "application/x-subtitle-vtt"}},
45 18 : {"text/ttml", {"application/ttml+xml"}}};
46 :
47 3 : std::unordered_set<std::string> addedCaps; // keep track what caps were added to avoid duplicates
48 3 : GstCaps *caps = gst_caps_new_empty();
49 17 : for (const std::string &mime : supportedMimeTypes)
50 : {
51 14 : auto mimeToCapsIt = kMimeToCaps.find(mime);
52 14 : if (mimeToCapsIt != kMimeToCaps.end())
53 : {
54 31 : for (const std::string &capsStr : mimeToCapsIt->second)
55 : {
56 18 : if (addedCaps.find(capsStr) == addedCaps.end())
57 : {
58 16 : GST_INFO("Caps '%s' is supported", capsStr.c_str());
59 16 : GstCaps *newCaps = gst_caps_from_string(capsStr.c_str());
60 16 : gst_caps_append(caps, newCaps);
61 16 : addedCaps.insert(capsStr);
62 : }
63 : }
64 : }
65 : else
66 : {
67 1 : GST_WARNING("Mime '%s' is not supported", mime.c_str());
68 : }
69 : }
70 :
71 3 : GstPadTemplate *sinktempl = gst_pad_template_new("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
72 3 : gst_element_class_add_pad_template(elementClass, sinktempl);
73 3 : gst_caps_unref(caps);
74 7 : }
75 :
76 5 : std::optional<firebolt::rialto::Layout> rialto_mse_sink_convert_layout(const gchar *layoutStr)
77 : {
78 5 : if (g_strcmp0(layoutStr, "interleaved") == 0)
79 : {
80 2 : return firebolt::rialto::Layout::INTERLEAVED;
81 : }
82 3 : if (g_strcmp0(layoutStr, "non-interleaved") == 0)
83 : {
84 2 : return firebolt::rialto::Layout::NON_INTERLEAVED;
85 : }
86 1 : return std::nullopt;
87 : }
88 :
89 33 : std::optional<firebolt::rialto::Format> rialto_mse_sink_convert_format(const gchar *formatStr)
90 : {
91 : static const std::unordered_map<std::string, firebolt::rialto::Format>
92 0 : kStringToFormat{{"S8", firebolt::rialto::Format::S8},
93 0 : {"U8", firebolt::rialto::Format::U8},
94 0 : {"S16LE", firebolt::rialto::Format::S16LE},
95 0 : {"S16BE", firebolt::rialto::Format::S16BE},
96 0 : {"U16LE", firebolt::rialto::Format::U16LE},
97 0 : {"U16BE", firebolt::rialto::Format::U16BE},
98 0 : {"S24_32LE", firebolt::rialto::Format::S24_32LE},
99 0 : {"S24_32BE", firebolt::rialto::Format::S24_32BE},
100 0 : {"U24_32LE", firebolt::rialto::Format::U24_32LE},
101 0 : {"U24_32BE", firebolt::rialto::Format::U24_32BE},
102 0 : {"S32LE", firebolt::rialto::Format::S32LE},
103 0 : {"S32BE", firebolt::rialto::Format::S32BE},
104 0 : {"U32LE", firebolt::rialto::Format::U32LE},
105 0 : {"U32BE", firebolt::rialto::Format::U32BE},
106 0 : {"S24LE", firebolt::rialto::Format::S24LE},
107 0 : {"S24BE", firebolt::rialto::Format::S24BE},
108 0 : {"U24LE", firebolt::rialto::Format::U24LE},
109 0 : {"U24BE", firebolt::rialto::Format::U24BE},
110 0 : {"S20LE", firebolt::rialto::Format::S20LE},
111 0 : {"S20BE", firebolt::rialto::Format::S20BE},
112 0 : {"U20LE", firebolt::rialto::Format::U20LE},
113 0 : {"U20BE", firebolt::rialto::Format::U20BE},
114 0 : {"S18LE", firebolt::rialto::Format::S18LE},
115 0 : {"S18BE", firebolt::rialto::Format::S18BE},
116 0 : {"U18LE", firebolt::rialto::Format::U18LE},
117 0 : {"U18BE", firebolt::rialto::Format::U18BE},
118 0 : {"F32LE", firebolt::rialto::Format::F32LE},
119 0 : {"F32BE", firebolt::rialto::Format::F32BE},
120 0 : {"F64LE", firebolt::rialto::Format::F64LE},
121 65 : {"F64BE", firebolt::rialto::Format::F64BE}};
122 33 : const auto it = kStringToFormat.find(formatStr);
123 33 : if (it != kStringToFormat.end())
124 : {
125 32 : return it->second;
126 : }
127 1 : return std::nullopt;
128 : }
|