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