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 119 : IMediaPipelineIpcFactory() = default;
44 119 : 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 293 : IMediaPipelineIpc() = default;
75 293 : 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 Gets the "Immediate Output" property for this source.
193 : *
194 : * This method is sychronous
195 : *
196 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
197 : * @param[out] immediateOutput : Returns the immediate output mode of the sink
198 : *
199 : * @retval true on success.
200 : */
201 : virtual bool getImmediateOutput(int32_t sourceId, bool &immediateOutput) = 0;
202 :
203 : /**
204 : * @brief Get stats for this source.
205 : *
206 : * This method is sychronous, it returns dropped frames and rendered frames
207 : *
208 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
209 : * @param[out] droppedFrames : The number of dropped frames
210 : * @param[out] renderedFrames : The number of rendered frames
211 : *
212 : * @retval true on success.
213 : */
214 : virtual bool getStats(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames) = 0;
215 :
216 : /**
217 : * @brief Request new playback rate.
218 : *
219 : * @param[in] rate : The playback rate.
220 : *
221 : * @retval true on success.
222 : */
223 : virtual bool setPlaybackRate(double rate) = 0;
224 :
225 : /**
226 : * @brief Requests to render a prerolled frame
227 : */
228 : virtual bool renderFrame() = 0;
229 :
230 : /**
231 : * @brief Set level and transition of audio attenuation.
232 : * Sets the current volume for the pipeline (0.0 silent -> 1.0 full volume)
233 : *
234 : * @param[in] targetVolume : Target volume level (0.0 - 1.0)
235 : * @param[in] volumeDuration : Duration of the volume transition in milliseconds
236 : * @param[in] ease_type : Easing type for the volume transition
237 : *
238 : * @retval true on success false otherwise
239 : */
240 : virtual bool setVolume(double targetVolume, uint32_t volumeDuration, EaseType easeType) = 0;
241 :
242 : /**
243 : * @brief Get current audio level. Fetches the current volume level for the pipeline.
244 : *
245 : * @param[out] volume Current volume level (range 0.0 - 1.0)
246 : *
247 : * @retval true on success false otherwise
248 : */
249 : virtual bool getVolume(double &volume) = 0;
250 :
251 : /**
252 : * @brief Set mute status of pipeline.
253 : *
254 : * Change mute status of media source
255 : *
256 : * @param[in] sourceId Source, which mute status should be changed
257 : * @param[in] mute Desired mute state, true=muted, false=not muted
258 : *
259 : * @retval true on success false otherwise
260 : */
261 : virtual bool setMute(int32_t sourceId, bool mute) = 0;
262 :
263 : /**
264 : * @brief Get current mute status of the media source
265 : *
266 : * @param[in] sourceId Source, which mute status should be fetched
267 : * @param[out] mute Current mute state
268 : *
269 : * @retval true on success false otherwise
270 : */
271 : virtual bool getMute(int32_t sourceId, bool &mute) = 0;
272 :
273 : /**
274 : * @brief Change Text Track Identifier
275 : *
276 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
277 : *
278 : * @retval true on success false otherwise
279 : */
280 : virtual bool setTextTrackIdentifier(const std::string &textTrackIdentifier) = 0;
281 :
282 : /**
283 : * @brief Get Text Track Identifier
284 : *
285 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
286 : *
287 : * @retval true on success false otherwise
288 : */
289 : virtual bool getTextTrackIdentifier(std::string &textTrackIdentifier) = 0;
290 :
291 : /**
292 : * @brief Set low latency property on the pipeline. Default false.
293 : *
294 : * @param[in] lowLatency : The low latency value to set.
295 : *
296 : * @retval true on success false otherwise
297 : */
298 : virtual bool setLowLatency(bool lowLatency) = 0;
299 :
300 : /**
301 : * @brief Set sync property on the pipeline. Default false.
302 : *
303 : * @param[in] sync : The sync value to set.
304 : *
305 : * @retval true on success false otherwise
306 : */
307 : virtual bool setSync(bool sync) = 0;
308 :
309 : /**
310 : * @brief Get sync property on the pipeline.
311 : *
312 : * @param[out] sync : Current sync value.
313 : *
314 : * @retval true on success false otherwise
315 : */
316 : virtual bool getSync(bool &sync) = 0;
317 :
318 : /**
319 : * @brief Set sync off property on the pipeline. Default false.
320 : *
321 : * @param[in] syncOff : The sync off value to set.
322 : *
323 : * @retval true on success false otherwise
324 : */
325 : virtual bool setSyncOff(bool syncOff) = 0;
326 :
327 : /**
328 : * @brief Set stream sync mode property on the pipeline. Default 0.
329 : *
330 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
331 : * @param[in] streamSyncMode : The stream sync mode value to set.
332 : *
333 : * @retval true on success false otherwise
334 : */
335 : virtual bool setStreamSyncMode(int32_t sourceId, int32_t streamSyncMode) = 0;
336 :
337 : /**
338 : * @brief Get stream sync mode property on the pipeline.
339 : *
340 : * @param[out] streamSyncMode : Current stream sync mode value.
341 : *
342 : * @retval true on success false otherwise
343 : */
344 : virtual bool getStreamSyncMode(int32_t &streamSyncMode) = 0;
345 :
346 : /**
347 : * @brief Flushes a source.
348 : *
349 : * This method is called by Rialto Client to flush out all queued data for a media source stream.
350 : *
351 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
352 : * @param[in] resetTime : True if time should be reset
353 : * @param[out] async : True if flushed source is asynchronous (will preroll after flush)
354 : *
355 : * @retval true on success.
356 : */
357 : virtual bool flush(int32_t sourceId, bool resetTime, bool &async) = 0;
358 :
359 : /**
360 : * @brief Set the source position in nanoseconds.
361 : *
362 : * This method sets the start position for a source.
363 : *
364 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
365 : * @param[in] position : The position in nanoseconds.
366 : * @param[in] resetTime : True if time should be reset
367 : * @param[in] appliedRate : The applied rate after seek
368 : * @param[in] stopPosition : The position of last pushed buffer
369 : *
370 : * @retval true on success.
371 : */
372 : virtual bool setSourcePosition(int32_t sourceId, int64_t position, bool resetTime, double appliedRate,
373 : uint64_t stopPosition) = 0;
374 :
375 : /**
376 : * @brief Set the subtitle offset in nanoseconds.
377 : *
378 : * This method sets the subtitle offset for a subtitle source.
379 : *
380 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
381 : * @param[in] position : The offset position in nanoseconds.
382 : *
383 : * @retval true on success.
384 : */
385 : virtual bool setSubtitleOffset(int32_t sourceId, int64_t position) = 0;
386 :
387 : /**
388 : * @brief Process audio gap
389 : *
390 : * This method handles audio gap in order to avoid audio pops during transitions.
391 : *
392 : * @param[in] position : Audio pts fade pts value
393 : * @param[in] duration : Audio pts fade duration
394 : * @param[in] discontinuityGap : Audio discontinuity gap
395 : * @param[in] audioAac : True if audio codec is AAC
396 : *
397 : * @retval true on success.
398 : */
399 : virtual bool processAudioGap(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac) = 0;
400 :
401 : /**
402 : * @brief Set buffering limit
403 : *
404 : * This method enables/disables limit buffering and sets millisecond threshold used.
405 : * Use kInvalidLimitBuffering to disable limit buffering
406 : *
407 : * @param[in] limitBufferingMs : buffering limit in ms
408 : *
409 : * @retval true on success.
410 : */
411 : virtual bool setBufferingLimit(uint32_t limitBufferingMs) = 0;
412 :
413 : /**
414 : * @brief Get buffering limit
415 : *
416 : * This method returns current value of buffering limit in milliseconds
417 : * Method will return kInvalidLimitBuffering limit buffering is disabled
418 : *
419 : * @param[out] limitBufferingMs : buffering limit in ms
420 : *
421 : * @retval true on success.
422 : */
423 : virtual bool getBufferingLimit(uint32_t &limitBufferingMs) = 0;
424 :
425 : /**
426 : * @brief Enables/disables the buffering option
427 : *
428 : * This method enables the buffering option so that BUFFERING messages are
429 : * emitted based on low-/high-percent thresholds.
430 : *
431 : * @param[in] useBuffering : true if buffering option enabled.
432 : *
433 : * @retval true on success.
434 : */
435 : virtual bool setUseBuffering(bool useBuffering) = 0;
436 :
437 : /**
438 : * @brief Check, if buffering is enabled
439 : *
440 : * This method returns true, if buffering is enabled
441 : *
442 : * @param[out] useBuffering : true if buffering option is enabled.
443 : *
444 : * @retval true on success.
445 : */
446 : virtual bool getUseBuffering(bool &useBuffering) = 0;
447 :
448 : /**
449 : * @brief Request to switch the source to the server backend.
450 : *
451 : * @param[in] source : The source.
452 : *
453 : * @retval true on success.
454 : */
455 : virtual bool switchSource(const std::unique_ptr<IMediaPipeline::MediaSource> &source) = 0;
456 : };
457 :
458 : }; // namespace firebolt::rialto::client
459 :
460 : #endif // FIREBOLT_RIALTO_CLIENT_I_MEDIA_PIPELINE_IPC_H_
|