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_CLIENT_I_MEDIA_PIPELINE_IPC_H_
21 : #define FIREBOLT_RIALTO_CLIENT_I_MEDIA_PIPELINE_IPC_H_
22 :
23 : #include <stdint.h>
24 :
25 : #include <memory>
26 : #include <string>
27 :
28 : #include "IMediaPipeline.h"
29 : #include "IMediaPipelineIpcClient.h"
30 : #include "MediaCommon.h"
31 :
32 : namespace firebolt::rialto::client
33 : {
34 : class IMediaPipelineIpc;
35 : class IIpcClient;
36 :
37 : /**
38 : * @brief IMediaPipelineIpc factory class, returns a concrete implementation of IMediaPipelineIpc
39 : */
40 : class IMediaPipelineIpcFactory
41 : {
42 : public:
43 123 : IMediaPipelineIpcFactory() = default;
44 123 : virtual ~IMediaPipelineIpcFactory() = default;
45 :
46 : /**
47 : * @brief Gets the IMediaPipelineIpcFactory instance.
48 : *
49 : * @retval the factory instance or null on error.
50 : */
51 : static std::shared_ptr<IMediaPipelineIpcFactory> getFactory();
52 :
53 : /**
54 : * @brief Creates a IMediaPipelineIpc object.
55 : *
56 : * @param[in] client : The Rialto ipc media player client.
57 : * @param[in] videoRequirements : The video decoder requirements for the MediaPipeline session.
58 : *
59 : * @retval the new media player ipc instance or null on error.
60 : */
61 : virtual std::unique_ptr<IMediaPipelineIpc> createMediaPipelineIpc(IMediaPipelineIpcClient *client,
62 : const VideoRequirements &videoRequirements,
63 : std::weak_ptr<IIpcClient> ipcClient = {}) = 0;
64 : };
65 :
66 : /**
67 : * @brief The definition of the IMediaPipelineIpc interface.
68 : *
69 : * This interface defines the media player ipc APIs that are used to communicate with the Rialto server.
70 : */
71 : class IMediaPipelineIpc
72 : {
73 : public:
74 305 : IMediaPipelineIpc() = default;
75 305 : virtual ~IMediaPipelineIpc() = default;
76 :
77 : IMediaPipelineIpc(const IMediaPipelineIpc &) = delete;
78 : IMediaPipelineIpc &operator=(const IMediaPipelineIpc &) = delete;
79 : IMediaPipelineIpc(IMediaPipelineIpc &&) = delete;
80 : IMediaPipelineIpc &operator=(IMediaPipelineIpc &&) = delete;
81 :
82 : /**
83 : * @brief Request to attach the source to the server backend.
84 : *
85 : * @param[in] source : The source.
86 : * @param[out] sourceId : The unique id of the media source.
87 : *
88 : * @retval true on success.
89 : */
90 : virtual bool attachSource(const std::unique_ptr<IMediaPipeline::MediaSource> &source, int32_t &sourceId) = 0;
91 :
92 : /**
93 : * @brief Request to remove the source to the server backend.
94 : *
95 : * @param[in] sourceId : The unique id of the media source.
96 : *
97 : * @retval true on success.
98 : */
99 : virtual bool removeSource(int32_t sourceId) = 0;
100 :
101 : virtual bool allSourcesAttached() = 0;
102 :
103 : /**
104 : * @brief Request to load the media pipeline.
105 : *
106 : * @param[in] type : The media type.
107 : * @param[in] mimeType : The MIME type.
108 : * @param[in] url : The URL.
109 : *
110 : * @retval true on success.
111 : */
112 : virtual bool load(MediaType type, const std::string &mimeType, const std::string &url) = 0;
113 :
114 : /**
115 : * @brief Request to set the coordinates of the video window.
116 : *
117 : * @param[in] x : The x position in pixels.
118 : * @param[in] y : The y position in pixels.
119 : * @param[in] width : The width in pixels.
120 : * @param[in] height : The height in pixels.
121 : *
122 : * @retval true on success.
123 : */
124 : virtual bool setVideoWindow(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
125 :
126 : /**
127 : * @brief Request play on the playback session.
128 : *
129 : * @param[out] async : True if play method call is asynchronous
130 : *
131 : * @retval true on success.
132 : */
133 : virtual bool play(bool &async) = 0;
134 :
135 : /**
136 : * @brief Request pause on the playback session.
137 : *
138 : * @retval true on success.
139 : */
140 : virtual bool pause() = 0;
141 :
142 : /**
143 : * @brief Request stop on the playback session.
144 : *
145 : * @retval true on success.
146 : */
147 : virtual bool stop() = 0;
148 :
149 : /**
150 : * @brief Notify server that the data has been written to the shared memory.
151 : *
152 : * @param[in] status : The status.
153 : * @param[in] requestId : The Need data request id.
154 : *
155 : * @retval true on success.
156 : */
157 : virtual bool haveData(MediaSourceStatus status, uint32_t numFrames, uint32_t requestId) = 0;
158 :
159 : /**
160 : * @brief Request new playback position.
161 : *
162 : * @param[in] position : The playback position in nanoseconds.
163 : *
164 : * @retval true on success.
165 : */
166 : virtual bool setPosition(int64_t position) = 0;
167 :
168 : /**
169 : * @brief Get the playback position in nanoseconds.
170 : *
171 : * This method is sychronous, it returns current playback position
172 : *
173 : * @param[out] position : The playback position in nanoseconds
174 : *
175 : * @retval true on success.
176 : */
177 : virtual bool getPosition(int64_t &position) = 0;
178 :
179 : /**
180 : * @brief Sets the "Immediate Output" property for this source.
181 : *
182 : * This method is asynchronous
183 : *
184 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
185 : * @param[in] immediateOutput : The desired immediate output mode on the sink
186 : *
187 : * @retval true on success.
188 : */
189 : virtual bool setImmediateOutput(int32_t sourceId, bool immediateOutput) = 0;
190 :
191 : /**
192 : * @brief Sets the "Report Decode Errors" property for this source.
193 : *
194 : * This method is asynchronous, it will set the "Report Decode Errors" property
195 : *
196 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
197 : * @param[in] reportDecodeErrors : Set Report Decode Errors mode on the sink
198 : *
199 : * @retval true on success.
200 : */
201 : virtual bool setReportDecodeErrors(int32_t sourceId, bool reportDecodeErrors) = 0;
202 :
203 : /**
204 : * @brief Gets the queued frames for this source.
205 : *
206 : * This method is synchronous, it gets the queued frames property
207 : *
208 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
209 : * @param[out] queuedFrames : Get queued frames on the decoder
210 : *
211 : * @retval true on success.
212 : */
213 : virtual bool getQueuedFrames(int32_t sourceId, uint32_t &queuedFrames) = 0;
214 :
215 : /**
216 : * @brief Gets the "Immediate Output" property for this source.
217 : *
218 : * This method is sychronous
219 : *
220 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
221 : * @param[out] immediateOutput : Returns the immediate output mode of the sink
222 : *
223 : * @retval true on success.
224 : */
225 : virtual bool getImmediateOutput(int32_t sourceId, bool &immediateOutput) = 0;
226 :
227 : /**
228 : * @brief Get stats for this source.
229 : *
230 : * This method is sychronous, it returns dropped frames and rendered frames
231 : *
232 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
233 : * @param[out] droppedFrames : The number of dropped frames
234 : * @param[out] renderedFrames : The number of rendered frames
235 : *
236 : * @retval true on success.
237 : */
238 : virtual bool getStats(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames) = 0;
239 :
240 : /**
241 : * @brief Request new playback rate.
242 : *
243 : * @param[in] rate : The playback rate.
244 : *
245 : * @retval true on success.
246 : */
247 : virtual bool setPlaybackRate(double rate) = 0;
248 :
249 : /**
250 : * @brief Requests to render a prerolled frame
251 : */
252 : virtual bool renderFrame() = 0;
253 :
254 : /**
255 : * @brief Set level and transition of audio attenuation.
256 : * Sets the current volume for the pipeline (0.0 silent -> 1.0 full volume)
257 : *
258 : * @param[in] targetVolume : Target volume level (0.0 - 1.0)
259 : * @param[in] volumeDuration : Duration of the volume transition in milliseconds
260 : * @param[in] ease_type : Easing type for the volume transition
261 : *
262 : * @retval true on success false otherwise
263 : */
264 : virtual bool setVolume(double targetVolume, uint32_t volumeDuration, EaseType easeType) = 0;
265 :
266 : /**
267 : * @brief Get current audio level. Fetches the current volume level for the pipeline.
268 : *
269 : * @param[out] volume Current volume level (range 0.0 - 1.0)
270 : *
271 : * @retval true on success false otherwise
272 : */
273 : virtual bool getVolume(double &volume) = 0;
274 :
275 : /**
276 : * @brief Set mute status of pipeline.
277 : *
278 : * Change mute status of media source
279 : *
280 : * @param[in] sourceId Source, which mute status should be changed
281 : * @param[in] mute Desired mute state, true=muted, false=not muted
282 : *
283 : * @retval true on success false otherwise
284 : */
285 : virtual bool setMute(int32_t sourceId, bool mute) = 0;
286 :
287 : /**
288 : * @brief Get current mute status of the media source
289 : *
290 : * @param[in] sourceId Source, which mute status should be fetched
291 : * @param[out] mute Current mute state
292 : *
293 : * @retval true on success false otherwise
294 : */
295 : virtual bool getMute(int32_t sourceId, bool &mute) = 0;
296 :
297 : /**
298 : * @brief Change Text Track Identifier
299 : *
300 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
301 : *
302 : * @retval true on success false otherwise
303 : */
304 : virtual bool setTextTrackIdentifier(const std::string &textTrackIdentifier) = 0;
305 :
306 : /**
307 : * @brief Get Text Track Identifier
308 : *
309 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
310 : *
311 : * @retval true on success false otherwise
312 : */
313 : virtual bool getTextTrackIdentifier(std::string &textTrackIdentifier) = 0;
314 :
315 : /**
316 : * @brief Set low latency property on the pipeline. Default false.
317 : *
318 : * @param[in] lowLatency : The low latency value to set.
319 : *
320 : * @retval true on success false otherwise
321 : */
322 : virtual bool setLowLatency(bool lowLatency) = 0;
323 :
324 : /**
325 : * @brief Set sync property on the pipeline. Default false.
326 : *
327 : * @param[in] sync : The sync value to set.
328 : *
329 : * @retval true on success false otherwise
330 : */
331 : virtual bool setSync(bool sync) = 0;
332 :
333 : /**
334 : * @brief Get sync property on the pipeline.
335 : *
336 : * @param[out] sync : Current sync value.
337 : *
338 : * @retval true on success false otherwise
339 : */
340 : virtual bool getSync(bool &sync) = 0;
341 :
342 : /**
343 : * @brief Set sync off property on the pipeline. Default false.
344 : *
345 : * @param[in] syncOff : The sync off value to set.
346 : *
347 : * @retval true on success false otherwise
348 : */
349 : virtual bool setSyncOff(bool syncOff) = 0;
350 :
351 : /**
352 : * @brief Set stream sync mode property on the pipeline. Default 0.
353 : *
354 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
355 : * @param[in] streamSyncMode : The stream sync mode value to set.
356 : *
357 : * @retval true on success false otherwise
358 : */
359 : virtual bool setStreamSyncMode(int32_t sourceId, int32_t streamSyncMode) = 0;
360 :
361 : /**
362 : * @brief Get stream sync mode property on the pipeline.
363 : *
364 : * @param[out] streamSyncMode : Current stream sync mode value.
365 : *
366 : * @retval true on success false otherwise
367 : */
368 : virtual bool getStreamSyncMode(int32_t &streamSyncMode) = 0;
369 :
370 : /**
371 : * @brief Flushes a source.
372 : *
373 : * This method is called by Rialto Client to flush out all queued data for a media source stream.
374 : *
375 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
376 : * @param[in] resetTime : True if time should be reset
377 : * @param[out] async : True if flushed source is asynchronous (will preroll after flush)
378 : *
379 : * @retval true on success.
380 : */
381 : virtual bool flush(int32_t sourceId, bool resetTime, bool &async) = 0;
382 :
383 : /**
384 : * @brief Set the source position in nanoseconds.
385 : *
386 : * This method sets the start position for a source.
387 : *
388 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
389 : * @param[in] position : The position in nanoseconds.
390 : * @param[in] resetTime : True if time should be reset
391 : * @param[in] appliedRate : The applied rate after seek
392 : * @param[in] stopPosition : The position of last pushed buffer
393 : *
394 : * @retval true on success.
395 : */
396 : virtual bool setSourcePosition(int32_t sourceId, int64_t position, bool resetTime, double appliedRate,
397 : uint64_t stopPosition) = 0;
398 :
399 : /**
400 : * @brief Set the subtitle offset in nanoseconds.
401 : *
402 : * This method sets the subtitle offset for a subtitle source.
403 : *
404 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
405 : * @param[in] position : The offset position in nanoseconds.
406 : *
407 : * @retval true on success.
408 : */
409 : virtual bool setSubtitleOffset(int32_t sourceId, int64_t position) = 0;
410 :
411 : /**
412 : * @brief Process audio gap
413 : *
414 : * This method handles audio gap in order to avoid audio pops during transitions.
415 : *
416 : * @param[in] position : Audio pts fade pts value
417 : * @param[in] duration : Audio pts fade duration
418 : * @param[in] discontinuityGap : Audio discontinuity gap
419 : * @param[in] audioAac : True if audio codec is AAC
420 : *
421 : * @retval true on success.
422 : */
423 : virtual bool processAudioGap(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac) = 0;
424 :
425 : /**
426 : * @brief Set buffering limit
427 : *
428 : * This method enables/disables limit buffering and sets millisecond threshold used.
429 : * Use kInvalidLimitBuffering to disable limit buffering
430 : *
431 : * @param[in] limitBufferingMs : buffering limit in ms
432 : *
433 : * @retval true on success.
434 : */
435 : virtual bool setBufferingLimit(uint32_t limitBufferingMs) = 0;
436 :
437 : /**
438 : * @brief Get buffering limit
439 : *
440 : * This method returns current value of buffering limit in milliseconds
441 : * Method will return kInvalidLimitBuffering limit buffering is disabled
442 : *
443 : * @param[out] limitBufferingMs : buffering limit in ms
444 : *
445 : * @retval true on success.
446 : */
447 : virtual bool getBufferingLimit(uint32_t &limitBufferingMs) = 0;
448 :
449 : /**
450 : * @brief Enables/disables the buffering option
451 : *
452 : * This method enables the buffering option so that BUFFERING messages are
453 : * emitted based on low-/high-percent thresholds.
454 : *
455 : * @param[in] useBuffering : true if buffering option enabled.
456 : *
457 : * @retval true on success.
458 : */
459 : virtual bool setUseBuffering(bool useBuffering) = 0;
460 :
461 : /**
462 : * @brief Check, if buffering is enabled
463 : *
464 : * This method returns true, if buffering is enabled
465 : *
466 : * @param[out] useBuffering : true if buffering option is enabled.
467 : *
468 : * @retval true on success.
469 : */
470 : virtual bool getUseBuffering(bool &useBuffering) = 0;
471 :
472 : /**
473 : * @brief Request to switch the source to the server backend.
474 : *
475 : * @param[in] source : The source.
476 : *
477 : * @retval true on success.
478 : */
479 : virtual bool switchSource(const std::unique_ptr<IMediaPipeline::MediaSource> &source) = 0;
480 : };
481 :
482 : }; // namespace firebolt::rialto::client
483 :
484 : #endif // FIREBOLT_RIALTO_CLIENT_I_MEDIA_PIPELINE_IPC_H_
|