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