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