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