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_I_GST_GENERIC_PLAYER_H_
21 : #define FIREBOLT_RIALTO_SERVER_I_GST_GENERIC_PLAYER_H_
22 :
23 : #include <MediaCommon.h>
24 : #include <memory>
25 : #include <stdint.h>
26 : #include <string>
27 :
28 : #include "IDataReader.h"
29 : #include "IDecryptionService.h"
30 : #include "IGstGenericPlayerClient.h"
31 : #include "IGstProfiler.h"
32 : #include "IHeartbeatHandler.h"
33 : #include "IMediaPipeline.h"
34 : #include "IRdkGstreamerUtilsWrapper.h"
35 :
36 : namespace firebolt::rialto::server
37 : {
38 : class IRialtoMetrics;
39 : class IGstGenericPlayer;
40 :
41 : /**
42 : * @brief IGstGenericPlayer factory class, returns a concrete implementation of IGstGenericPlayer
43 : */
44 : class IGstGenericPlayerFactory
45 : {
46 : public:
47 182 : IGstGenericPlayerFactory() = default;
48 182 : virtual ~IGstGenericPlayerFactory() = default;
49 :
50 : /**
51 : * @brief Gets the IGstGenericPlayerFactory instance.
52 : *
53 : * @retval the factory instance or null on error.
54 : */
55 : static std::shared_ptr<IGstGenericPlayerFactory> getFactory();
56 :
57 : /**
58 : * @brief Creates an IGstGenericPlayer object.
59 : *
60 : * @param[in] client : The gstreamer player client.
61 : * @param[in] decryptionService : The decryption service.
62 : * @param[in] type : The media type the gstreamer player shall support.
63 : * @param[in] videoRequirements : The video requirements for the playback.
64 : * @param[in] isLive : Indicates if the media is live.
65 : * @param[in] rdkGstreamerUtilsWrapperFactory : The rdk gstreamer utils wrapper factory.
66 : * @param[in] gstProfilerFactory : The gst profiler factory. Defaults to nullptr; when null, the
67 : * concrete factory falls back to IGstProfilerFactory::getFactory().
68 : * This avoids evaluating the real singleton at mocked call sites.
69 : *
70 : * @retval the new player instance or null on error.
71 : */
72 : virtual std::unique_ptr<IGstGenericPlayer> createGstGenericPlayer(
73 : IGstGenericPlayerClient *client, IDecryptionService &decryptionService, MediaType type,
74 : const VideoRequirements &videoRequirements, bool isLive,
75 : const std::shared_ptr<firebolt::rialto::wrappers::IRdkGstreamerUtilsWrapperFactory> &rdkGstreamerUtilsWrapperFactory,
76 : const std::shared_ptr<IGstProfilerFactory> &gstProfilerFactory = nullptr) = 0;
77 : };
78 :
79 : class IGstGenericPlayer
80 : {
81 : public:
82 435 : IGstGenericPlayer() = default;
83 435 : virtual ~IGstGenericPlayer() = default;
84 :
85 : IGstGenericPlayer(const IGstGenericPlayer &) = delete;
86 : IGstGenericPlayer &operator=(const IGstGenericPlayer &) = delete;
87 : IGstGenericPlayer(IGstGenericPlayer &&) = delete;
88 : IGstGenericPlayer &operator=(IGstGenericPlayer &&) = delete;
89 :
90 : virtual std::shared_ptr<IRialtoMetrics> getRialtoMetrics() const = 0;
91 : virtual void setMetricSessionId(int32_t sessionId) = 0;
92 :
93 : /**
94 : * @brief Attaches a source to gstreamer.
95 : *
96 : * @param[in] mediaSource : The media source.
97 : *
98 : */
99 : virtual void attachSource(const std::unique_ptr<IMediaPipeline::MediaSource> &mediaSource) = 0;
100 :
101 : /**
102 : * @brief Removes a source from gstreamer.
103 : *
104 : * @param[in] mediaSourceType : The media source type.
105 : *
106 : */
107 : virtual void removeSource(const MediaSourceType &mediaSourceType) = 0;
108 :
109 : /**
110 : * @brief Handles notification that all sources were attached
111 : *
112 : */
113 : virtual void allSourcesAttached() = 0;
114 :
115 : /**
116 : * @brief Starts playback of the media.
117 : *
118 : * Once the backend is successfully playing it should notify the
119 : * media player client of playback state
120 : * IMediaPipelineClient::PlaybackState::PLAYING.
121 : *
122 : * @param[out] async : True if play method call is asynchronous
123 : *
124 : * @retval true on success.
125 : */
126 : virtual void play(bool &async) = 0;
127 :
128 : /**
129 : * @brief Pauses playback of the media.
130 : *
131 : * This method is considered to be asynchronous and MUST NOT block
132 : * but should request the playback pause and then return.
133 : *
134 : * Once the backend is successfully paused it should notify the
135 : * media player client of playback state PlaybackState::PAUSED.
136 : *
137 : */
138 : virtual void pause() = 0;
139 :
140 : /**
141 : * @brief Stops playback of the media.
142 : *
143 : * This method is considered to be asynchronous and MUST NOT block
144 : * but should request the playback stop and then return.
145 : *
146 : * Once the backend is successfully stopped it should notify the
147 : * media player client of playback state PlaybackState::STOPPED.
148 : *
149 : */
150 : virtual void stop() = 0;
151 :
152 : /**
153 : * @brief Sets video geometry
154 : *
155 : * @param[in] x : X position of rectangle on video
156 : * @param[in] y : Y position of rectangle on video
157 : * @param[in] width : width of rectangle
158 : * @param[in] height : height of rectangle
159 : *
160 : */
161 : virtual void setVideoGeometry(int x, int y, int width, int height) = 0;
162 :
163 : /**
164 : * @brief Queues the end of stream notification at the end of the gstreamer buffers.
165 : *
166 : * @param[in] type : the media source type to set eos
167 : *
168 : */
169 : virtual void setEos(const firebolt::rialto::MediaSourceType &type) = 0;
170 :
171 : /**
172 : * @brief Attaches new samples
173 : *
174 : * This method is considered to be asynchronous and MUST NOT block
175 : * but should request to attach new sample and then return.
176 : */
177 : virtual void attachSamples(const IMediaPipeline::MediaSegmentVector &mediaSegments) = 0;
178 :
179 : /**
180 : * @brief Attaches new samples
181 : *
182 : * This method is considered to be asynchronous and MUST NOT block
183 : * but should request to attach new sample and then return.
184 : */
185 : virtual void attachSamples(const std::shared_ptr<IDataReader> &dataReader) = 0;
186 :
187 : /**
188 : * @brief Set the playback position in nanoseconds.
189 : *
190 : * If playback has not started this method sets the start position
191 : * for playback. If playback has started this method performs a seek.
192 : *
193 : * @param[in] position : The playback position in nanoseconds.
194 : *
195 : */
196 : virtual void setPosition(std::int64_t position) = 0;
197 :
198 : /**
199 : * @brief Get the playback position in nanoseconds.
200 : *
201 : * @param[out] position : The playback position in nanoseconds.
202 : *
203 : * @retval True on success
204 : */
205 : virtual bool getPosition(std::int64_t &position) = 0;
206 :
207 : /**
208 : * @brief Get the playback duration in nanoseconds.
209 : *
210 : * @param[out] duration : The playback duration in nanoseconds.
211 : *
212 : * @retval True on success
213 : */
214 : virtual bool getDuration(std::int64_t &duration) = 0;
215 :
216 : /**
217 : * @brief Sets the "Immediate Output" property for this source.
218 : *
219 : * @param[in] mediaSourceType : The media source type
220 : * @param[in] immediateOutput : Set immediate output mode on the sink
221 : *
222 : * @retval true on success.
223 : */
224 : virtual bool setImmediateOutput(const MediaSourceType &mediaSourceType, bool immediateOutput) = 0;
225 :
226 : /**
227 : * @brief Sets the "Report Decode Error" property for this source.
228 : *
229 : * @param[in] mediaSourceType : The media source type
230 : * @param[in] reportDecodeErrors : Set report decode error
231 : *
232 : * @retval true on success.
233 : */
234 : virtual bool setReportDecodeErrors(const MediaSourceType &mediaSourceType, bool reportDecodeErrors) = 0;
235 :
236 : /**
237 : * @brief Gets the queued frames for this source.
238 : *
239 : * @param[out] queuedFrames : Get queued frames mode on the decoder
240 : *
241 : * @retval true on success.
242 : */
243 : virtual bool getQueuedFrames(uint32_t &queuedFrames) = 0;
244 :
245 : /**
246 : * @brief Gets the "Immediate Output" property for this source.
247 : *
248 : * @param[in] mediaSourceType : The media source type
249 : * @param[out] immediateOutput : Get immediate output mode on the sink
250 : *
251 : * @retval true on success.
252 : */
253 : virtual bool getImmediateOutput(const MediaSourceType &mediaSourceType, bool &immediateOutput) = 0;
254 :
255 : /**
256 : * @brief Get stats for this source.
257 : *
258 : * @param[in] mediaSourceType : The media source type to get stats for
259 : * @param[out] renderedFrames : The number of rendered frames
260 : * @param[out] droppedFrames : The number of dropped frames
261 : *
262 : * @retval true on success.
263 : */
264 : virtual bool getStats(const MediaSourceType &mediaSourceType, uint64_t &renderedFrames, uint64_t &droppedFrames) = 0;
265 :
266 : /**
267 : * @brief Set the playback rate.
268 : *
269 : * @param[in] rate : The playback rate.
270 : *
271 : */
272 : virtual void setPlaybackRate(double rate) = 0;
273 :
274 : /**
275 : * @brief Requests to render a prerolled frame
276 : *
277 : */
278 : virtual void renderFrame() = 0;
279 :
280 : /**
281 : * @brief Set level and transition of audio attenuation.
282 : * Sets the current volume for the pipeline (0.0 silent -> 1.0 full volume)
283 : *
284 : * @param[in] volume : Target volume level (0.0 - 1.0)
285 : */
286 : virtual void setVolume(double targetVolume, uint32_t volumeDuration, firebolt::rialto::EaseType easeType) = 0;
287 :
288 : /**
289 : * @brief Get current audio level. Fetches the current volume level for the pipeline.
290 : *
291 : * @param[out] volume : Current volume level (range 0.0 - 1.0)
292 : *
293 : * @retval True on success
294 : */
295 : virtual bool getVolume(double &volume) = 0;
296 :
297 : /**
298 : * @brief Set mute status of pipeline
299 : *
300 : * Muting does not change the underlying volyme setting so when
301 : * unmuted the user will hear audio at the same volume as previously
302 : * set.
303 : *
304 : * @param[in] mute : Desired mute state, true=muted, false=not muted
305 : */
306 : virtual void setMute(const MediaSourceType &mediaSourceType, bool mute) = 0;
307 :
308 : /**
309 : * @brief Get current mute status of the pipeline
310 : *
311 : * @param[out] mute : Current mute state
312 : *
313 : * @retval True in success, false otherwise
314 : */
315 : virtual bool getMute(const MediaSourceType &mediaSourceType, bool &mute) = 0;
316 :
317 : /**
318 : * @brief Change Text Track Identifier
319 : *
320 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
321 : *
322 : * @retval true on success false otherwise
323 : */
324 : virtual void setTextTrackIdentifier(const std::string &textTrackIdentifier) = 0;
325 :
326 : /**
327 : * @brief Get Text Track Identifier
328 : *
329 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
330 : *
331 : * @retval true on success false otherwise
332 : */
333 : virtual bool getTextTrackIdentifier(std::string &textTrackIdentifier) = 0;
334 :
335 : /**
336 : * @brief Set low latency property on the pipeline. Default false.
337 : *
338 : * @param[in] lowLatency : The low latency value to set.
339 : *
340 : * @retval true on success false otherwise
341 : */
342 : virtual bool setLowLatency(bool lowLatency) = 0;
343 :
344 : /**
345 : * @brief Set sync property on the pipeline. Default false.
346 : *
347 : * @param[in] sync : The sync value to set.
348 : *
349 : * @retval true on success false otherwise
350 : */
351 : virtual bool setSync(bool sync) = 0;
352 :
353 : /**
354 : * @brief Get sync property on the pipeline.
355 : *
356 : * @param[out] sync : Current sync value.
357 : *
358 : * @retval true on success false otherwise
359 : */
360 : virtual bool getSync(bool &sync) = 0;
361 :
362 : /**
363 : * @brief Set sync off property on the pipeline. Default false.
364 : *
365 : * @param[in] syncOff : The sync off value to set.
366 : *
367 : * @retval true on success false otherwise
368 : */
369 : virtual bool setSyncOff(bool syncOff) = 0;
370 :
371 : /**
372 : * @brief Set stream sync mode property on the pipeline. Default 0.
373 : *
374 : * @param[in] mediaSourceType : The media source type to set stream sync mode.
375 : * @param[in] streamSyncMode : The stream sync mode value to set.
376 : *
377 : * @retval true on success false otherwise
378 : */
379 : virtual bool setStreamSyncMode(const MediaSourceType &mediaSourceType, int32_t streamSyncMode) = 0;
380 :
381 : /**
382 : * @brief Get stream sync mode property on the pipeline.
383 : *
384 : * @param[out] streamSyncMode : Current stream sync mode value.
385 : *
386 : * @retval true on success false otherwise
387 : */
388 : virtual bool getStreamSyncMode(int32_t &streamSyncMode) = 0;
389 :
390 : /**
391 : * @brief Checks if worker thread is not deadlocked
392 : *
393 : * @param[out] heartbeatHandler : The heartbeat handler instance
394 : *
395 : */
396 : virtual void ping(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler) = 0;
397 :
398 : /**
399 : * @brief Flushes a source.
400 : *
401 : * @param[in] mediaSourceType : The media source type to flush.
402 : * @param[in] resetTime : True if time should be reset
403 : * @param[out] async : True if flushed source is asynchronous (will preroll after flush)
404 : *
405 : */
406 : virtual void flush(const MediaSourceType &mediaSourceType, bool resetTime, bool &async) = 0;
407 :
408 : /**
409 : * @brief Set the source position in nanoseconds.
410 : *
411 : * This method sets the start position for a source.
412 : *
413 : * @param[in] mediaSourceType : The media source type to flush.
414 : * @param[in] position : The position in nanoseconds.
415 : * @param[in] resetTime : True if time should be reset
416 : * @param[in] appliedRate : The applied rate after seek
417 : * @param[in] stopPosition : The position of last pushed buffer
418 : */
419 : virtual void setSourcePosition(const MediaSourceType &mediaSourceType, int64_t position, bool resetTime,
420 : double appliedRate, uint64_t stopPosition) = 0;
421 :
422 : /**
423 : * @brief Sets the subtitle offset.
424 : *
425 : * This method sets the subtitle offset to synchronize subtitle timing.
426 : *
427 : * @param[in] position : The subtitle offset position in nanoseconds.
428 : */
429 : virtual void setSubtitleOffset(int64_t position) = 0;
430 :
431 : /**
432 : * @brief Process audio gap
433 : *
434 : * This method handles audio gap in order to avoid audio pops during transitions.
435 : *
436 : * @param[in] position : Audio pts fade position value
437 : * @param[in] duration : Audio pts fade duration
438 : * @param[in] discontinuityGap : Audio discontinuity gap
439 : * @param[in] audioAac : True if audio codec is AAC
440 : */
441 : virtual void processAudioGap(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac) = 0;
442 :
443 : /**
444 : * @brief Set buffering limit
445 : *
446 : * This method enables/disables limit buffering and sets millisecond threshold used.
447 : * Use kInvalidLimitBuffering to disable limit buffering
448 : *
449 : * @param[in] limitBufferingMs : buffering limit in ms
450 : *
451 : */
452 : virtual void setBufferingLimit(uint32_t limitBufferingMs) = 0;
453 :
454 : /**
455 : * @brief Get buffering limit
456 : *
457 : * This method returns current value of buffering limit in milliseconds
458 : * Method will return kInvalidLimitBuffering limit buffering is disabled
459 : *
460 : * @param[out] limitBufferingMs : buffering limit in ms
461 : *
462 : * @retval true on success.
463 : */
464 : virtual bool getBufferingLimit(uint32_t &limitBufferingMs) = 0;
465 :
466 : /**
467 : * @brief Enables/disables the buffering option
468 : *
469 : * This method enables the buffering option so that BUFFERING messages are
470 : * emitted based on low-/high-percent thresholds.
471 : *
472 : * @param[in] useBuffering : true if buffering option enabled.
473 : *
474 : */
475 : virtual void setUseBuffering(bool useBuffering) = 0;
476 :
477 : /**
478 : * @brief Checks, if buffering is enabled
479 : *
480 : * This method returns true, if buffering is enabled
481 : *
482 : * @param[out] useBuffering : true if buffering option is enabled.
483 : *
484 : * @retval true on success.
485 : */
486 : virtual bool getUseBuffering(bool &useBuffering) = 0;
487 :
488 : /**
489 : * @brief Switches a source.
490 : *
491 : * @param[in] mediaSource : The media source.
492 : *
493 : */
494 : virtual void switchSource(const std::unique_ptr<IMediaPipeline::MediaSource> &mediaSource) = 0;
495 : };
496 :
497 : }; // namespace firebolt::rialto::server
498 :
499 : #endif // FIREBOLT_RIALTO_SERVER_I_GST_GENERIC_PLAYER_H_
|