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