Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2023 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #ifndef FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
21 : #define FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
22 :
23 : #include "GstCapabilities.h"
24 : #include "IGstWrapper.h"
25 : #include "IMediaPipeline.h"
26 : #include <memory>
27 : #include <string>
28 : #include <unordered_map>
29 : #include <unordered_set>
30 : #include <utility>
31 : #include <vector>
32 :
33 : namespace firebolt::rialto::server
34 : {
35 :
36 : /**
37 : * @brief Converts MIME types to simple caps.
38 : *
39 : * @param[in] m_gstWrapper : Member variable that is a shared pointer to an object of type IGstWrapper
40 : * @param[in] m_attachedSource : A const reference to an object of type MediaSource
41 : *
42 : * @retval the pointer to the GstCaps object, which represents the simple caps for the given MIME type. If MIME type is
43 : * not found, an empty GstCaps object is returned
44 : */
45 :
46 21 : inline GstCaps *createSimpleCapsFromMimeType(std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper,
47 : const IMediaPipeline::MediaSource &m_attachedSource)
48 : {
49 : static const std::unordered_map<std::string, std::string> mimeToMediaType =
50 : {{"video/h264", "video/x-h264"}, {"video/h265", "video/x-h265"},
51 : {"video/x-av1", "video/x-av1"}, {"video/x-vp9", "video/x-vp9"},
52 : {"video/mp4", "video/mpeg"}, {"audio/mp4", "audio/mpeg"},
53 : {"audio/mp3", "audio/mpeg"}, {"audio/aac", "audio/mpeg"},
54 : {"audio/x-eac3", "audio/x-eac3"}, {"audio/x-opus", "audio/x-opus"},
55 : {"audio/b-wav", "audio/b-wav"}, {"audio/x-raw", "audio/x-raw"},
56 : {"audio/x-flac", "audio/x-flac"}, {"text/vtt", "application/x-subtitle-vtt"},
57 : {"text/ttml", "application/ttml+xml"}, {"text/cc", "subtitle/x-subtitle-cc"},
58 41 : {"video/x-vp8", "video/x-vp8"}, {"audio/x-vorbis", "audio/x-vorbis"}};
59 21 : auto mimeToMediaTypeIt = mimeToMediaType.find(m_attachedSource.getMimeType());
60 21 : if (mimeToMediaTypeIt != mimeToMediaType.end())
61 : {
62 20 : return m_gstWrapper->gstCapsNewEmptySimple(mimeToMediaTypeIt->second.c_str());
63 : }
64 :
65 1 : return m_gstWrapper->gstCapsNewEmpty();
66 : }
67 :
68 : /**
69 : * @brief Converts simple caps to MIME types.
70 : *
71 : * @param[in] supportedCaps : A const reference to a vector of pointers to GstCaps objects representing the supported caps
72 : * @param[in] m_gstWrapper : Member variable that is a shared pointer to an object of type IGstWrapper
73 : *
74 : * @retval an unordered set of strings representing the supported MIME types
75 : */
76 :
77 : inline std::unordered_set<std::string>
78 10 : convertFromCapsVectorToMimeSet(const std::vector<GstCaps *> &supportedCaps,
79 : std::shared_ptr<firebolt::rialto::wrappers::IGstWrapper> m_gstWrapper)
80 : {
81 : std::vector<std::pair<GstCaps *, std::vector<std::string>>> capsToMimeVec =
82 10 : {{m_gstWrapper->gstCapsFromString("audio/mpeg, mpegversion=(int)4"), {"audio/mp4", "audio/aac", "audio/x-eac3"}},
83 10 : {m_gstWrapper->gstCapsFromString("audio/mpeg, mpegversion=(int)1, layer=(int)3"), {"audio/mp3"}},
84 10 : {m_gstWrapper->gstCapsFromString("audio/x-eac3"), {"audio/x-eac3"}},
85 10 : {m_gstWrapper->gstCapsFromString("audio/b-wav"), {"audio/b-wav"}},
86 10 : {m_gstWrapper->gstCapsFromString("audio/x-raw"), {"audio/x-raw"}},
87 10 : {m_gstWrapper->gstCapsFromString("audio/x-opus"), {"audio/x-opus"}},
88 10 : {m_gstWrapper->gstCapsFromString("audio/x-vorbis"), {"audio/x-vorbis"}},
89 10 : {m_gstWrapper->gstCapsFromString("audio/x-opus, channel-mapping-family=(int)0"), {"audio/x-opus"}},
90 10 : {m_gstWrapper->gstCapsFromString("audio/x-flac"), {"audio/x-flac"}},
91 10 : {m_gstWrapper->gstCapsFromString("video/x-av1"), {"video/x-av1"}},
92 10 : {m_gstWrapper->gstCapsFromString("video/x-h264"), {"video/h264"}},
93 10 : {m_gstWrapper->gstCapsFromString("video/x-h265"), {"video/h265"}},
94 10 : {m_gstWrapper->gstCapsFromString("video/x-vp9"), {"video/x-vp9"}},
95 10 : {m_gstWrapper->gstCapsFromString("video/x-vp8"), {"video/x-vp8"}},
96 10 : {m_gstWrapper->gstCapsFromString("video/mpeg, mpegversion=(int)4"), {"video/mp4"}},
97 10 : {m_gstWrapper->gstCapsFromString("video/x-h264(memory:DMABuf)"), {"video/h264"}},
98 10 : {m_gstWrapper->gstCapsFromString("video/x-h265(memory:DMABuf)"), {"video/h265"}},
99 10 : {m_gstWrapper->gstCapsFromString("video/x-av1(memory:DMABuf)"), {"video/x-av1"}},
100 220 : {m_gstWrapper->gstCapsFromString("video/x-vp9(memory:DMABuf)"), {"video/x-vp9"}}};
101 :
102 10 : std::unordered_set<std::string> supportedMimes;
103 :
104 29 : for (GstCaps *caps : supportedCaps)
105 : {
106 380 : for (const auto &capsToMime : capsToMimeVec)
107 : {
108 361 : if (m_gstWrapper->gstCapsCanIntersect(capsToMime.first, caps))
109 : {
110 18 : supportedMimes.insert(capsToMime.second.begin(), capsToMime.second.end());
111 : }
112 : }
113 : }
114 :
115 200 : for (auto &capsToMime : capsToMimeVec)
116 : {
117 190 : if (capsToMime.first)
118 190 : m_gstWrapper->gstCapsUnref(capsToMime.first);
119 : }
120 :
121 20 : return supportedMimes;
122 240 : }
123 :
124 : }; // namespace firebolt::rialto::server
125 :
126 : #endif // FIREBOLT_RIALTO_SERVER_GST_MIME_MAPPING_H_
|