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 2022 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_GENERIC_PLAYER_CONTEXT_H_
21 : #define FIREBOLT_RIALTO_SERVER_GENERIC_PLAYER_CONTEXT_H_
22 :
23 : #include "FlushOnPrerollController.h"
24 : #include "IGstSrc.h"
25 : #include "IRdkGstreamerUtilsWrapper.h"
26 : #include "ITimer.h"
27 : #include "MediaCommon.h"
28 : #include <gst/gst.h>
29 : #include <list>
30 : #include <map>
31 : #include <memory>
32 : #include <mutex>
33 : #include <unordered_map>
34 : #include <vector>
35 :
36 : namespace firebolt::rialto::server
37 : {
38 : constexpr double kNoPendingPlaybackRate{0.0};
39 :
40 : enum class EosState
41 : {
42 : PENDING,
43 : SET
44 : };
45 :
46 : /**
47 : * @brief Structure used for video geometry
48 : */
49 : struct Rectangle
50 : {
51 : int x, y, width, height;
52 507 : constexpr Rectangle() : x(0), y(0), width(0), height(0) {}
53 1 : constexpr Rectangle(int x_, int y_, int w_, int h_) : x(x_), y(y_), width(w_), height(h_) {}
54 : Rectangle(const Rectangle &rhs) = default;
55 10 : inline constexpr bool empty() { return (width == 0) || (height == 0); }
56 2 : inline void clear() { x = y = width = height = 0; }
57 : };
58 :
59 : /**
60 : * @brief Structure used for set source position
61 : */
62 : struct SegmentData
63 : {
64 : int64_t position;
65 : bool resetTime;
66 : double appliedRate;
67 : uint64_t stopPosition;
68 : };
69 :
70 : struct GenericPlayerContext
71 : {
72 : /**
73 : * @brief The rialto src object.
74 : */
75 : std::shared_ptr<IGstSrc> gstSrc{nullptr};
76 :
77 : /**
78 : * @brief The gstreamer pipeline.
79 : */
80 : GstElement *pipeline{nullptr};
81 :
82 : /**
83 : * @brief The gstreamer source.
84 : */
85 : GstElement *source{nullptr};
86 :
87 : /**
88 : * @brief A map of streams attached to the source.
89 : */
90 : StreamInfoMap streamInfo{};
91 :
92 : /**
93 : * @brief Child sink of the autovideosink.
94 : */
95 : GstElement *autoVideoChildSink{nullptr};
96 :
97 : /**
98 : * @brief Child sink of the autoaudiosink.
99 : */
100 : GstElement *autoAudioChildSink{nullptr};
101 :
102 : /**
103 : * @brief The subtitle sink
104 : */
105 : GstElement *subtitleSink{nullptr};
106 :
107 : /**
108 : * @brief The video sink
109 : */
110 : GstElement *videoSink{nullptr};
111 :
112 : /**
113 : * @brief Flag used to check, if video decoder handle has been set.
114 : */
115 : bool isVideoHandleSet{false};
116 :
117 : /**
118 : * @brief Flag used to check, if BUFFERED notification has been sent.
119 : *
120 : * Flag can be used only in worker thread
121 : */
122 : bool bufferedNotificationSent{false};
123 :
124 : /**
125 : * @brief Flag used to check, if the playback is in the playing state
126 : *
127 : * Flag can be used only in worker thread
128 : */
129 : bool isPlaying{false};
130 :
131 : /**
132 : * @brief Flag used to check, if EOS has been notified to the client
133 : *
134 : * Flag can be used only in worker thread
135 : */
136 : bool eosNotified{false};
137 :
138 : /**
139 : * @brief Pending video geometry
140 : */
141 : Rectangle pendingGeometry;
142 :
143 : /**
144 : * @brief Current playback rate
145 : */
146 : double playbackRate{1.0};
147 :
148 : /**
149 : * @brief Pending playback rate
150 : */
151 : double pendingPlaybackRate{kNoPendingPlaybackRate};
152 :
153 : /**
154 : * @brief Pending immediate output for MediaSourceType::VIDEO
155 : */
156 : std::optional<bool> pendingImmediateOutputForVideo{};
157 :
158 : /**
159 : * @brief Pending report decode errors for MediaSourceType::VIDEO
160 : */
161 : std::optional<bool> pendingReportDecodeErrorsForVideo{};
162 :
163 : /**
164 : * @brief Pending low latency
165 : */
166 : std::optional<bool> pendingLowLatency{};
167 :
168 : /**
169 : * @brief Pending sync
170 : */
171 : std::optional<bool> pendingSync{};
172 :
173 : /**
174 : * @brief Pending sync off
175 : */
176 : std::optional<bool> pendingSyncOff{};
177 :
178 : /**
179 : * @brief Pending buffering limit
180 : */
181 : std::optional<uint32_t> pendingBufferingLimit{};
182 :
183 : /**
184 : * @brief Pending use buffering
185 : */
186 : std::optional<bool> pendingUseBuffering{};
187 :
188 : /**
189 : * @brief Pending stream sync mode
190 : */
191 : std::map<MediaSourceType, int32_t> pendingStreamSyncMode{};
192 :
193 : /**
194 : * @brief Pending render frame
195 : */
196 : bool pendingRenderFrame{false};
197 :
198 : /**
199 : * @brief Pending show video window
200 : */
201 : std::optional<bool> pendingShowVideoWindow{};
202 :
203 : /**
204 : * @brief Last audio sample timestamps
205 : * TODO(LLDEV-31012) Needed to detect audio stream underflow
206 : */
207 : int64_t lastAudioSampleTimestamps{0};
208 :
209 : /**
210 : * @brief The decryption service.
211 : */
212 : IDecryptionService *decryptionService{nullptr};
213 :
214 : /**
215 : * @brief Audio elements of gst pipeline.
216 : *
217 : * Attribute can be used only in worker thread
218 : */
219 : firebolt::rialto::wrappers::PlaybackGroupPrivate playbackGroup;
220 :
221 : /**
222 : * @brief A map of streams that have ended.
223 : */
224 : std::unordered_map<MediaSourceType, EosState> endOfStreamInfo{};
225 :
226 : /**
227 : * @brief Flag used to check if client already notified server that all sources were attached
228 : *
229 : * Attribute can be used only in worker thread
230 : */
231 : bool wereAllSourcesAttached{false};
232 :
233 : /**
234 : * @brief Flag used to check if FinishSetupSource is finished. It is needed to avoid need data overwriting.
235 : *
236 : * Attribute can be used only in worker thread
237 : */
238 : bool setupSourceFinished{false};
239 :
240 : /**
241 : * @brief Queued source positions. Used by SetSourcePosition task to request pushing new sample.
242 : *
243 : * Attribute can be used only in worker thread
244 : */
245 : std::map<GstElement *, std::vector<SegmentData>> initialPositions;
246 :
247 : /**
248 : * @brief Currently set position of a source. Used to check, if additional segment should be pushed.
249 : *
250 : * Attribute can be used only in worker thread
251 : */
252 : std::map<GstElement *, SegmentData> currentPosition;
253 :
254 : /**
255 : * @brief The mutex, which protects properties, which are read/written by main/worker thread.
256 : * This mutex should be removed in future, when we find out better solution for
257 : * property read-write.
258 : */
259 : std::mutex propertyMutex;
260 :
261 : /**
262 : * @brief Flag used to check if audio fade is enabled
263 : *
264 : * Attribute can be used only in worker thread
265 : */
266 : std::atomic_bool audioFadeEnabled{false};
267 :
268 : /**
269 : * @brief Workaround for the gstreamer flush issue
270 : */
271 : std::shared_ptr<IFlushOnPrerollController> flushOnPrerollController{std::make_shared<FlushOnPrerollController>()};
272 : };
273 : } // namespace firebolt::rialto::server
274 :
275 : #endif // FIREBOLT_RIALTO_SERVER_GENERIC_PLAYER_CONTEXT_H_
|