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_MEDIA_PIPELINE_SERVER_INTERNAL_H_
21 : #define FIREBOLT_RIALTO_SERVER_MEDIA_PIPELINE_SERVER_INTERNAL_H_
22 :
23 : #include "DataReaderFactory.h"
24 : #include "IActiveRequests.h"
25 : #include "IGstGenericPlayer.h"
26 : #include "IMainThread.h"
27 : #include "IMediaPipelineServerInternal.h"
28 : #include "IRialtoMetrics.h"
29 : #include "ITimer.h"
30 : #include "NeedDataDelayCalculator.h"
31 : #include <map>
32 : #include <memory>
33 : #include <mutex>
34 : #include <set>
35 : #include <shared_mutex>
36 : #include <string>
37 : #include <unordered_map>
38 : #include <vector>
39 :
40 : namespace firebolt::rialto::server
41 : {
42 : /**
43 : * @brief IMediaPipelineServerInternal factory class definition.
44 : */
45 : class MediaPipelineServerInternalFactory : public server::IMediaPipelineServerInternalFactory
46 : {
47 : public:
48 2 : MediaPipelineServerInternalFactory() = default;
49 2 : ~MediaPipelineServerInternalFactory() override = default;
50 :
51 : std::unique_ptr<IMediaPipeline> createMediaPipeline(std::weak_ptr<IMediaPipelineClient> client,
52 : const VideoRequirements &videoRequirements) const override;
53 :
54 : std::unique_ptr<server::IMediaPipelineServerInternal> createMediaPipelineServerInternal(
55 : std::weak_ptr<IMediaPipelineClient> client, const VideoRequirements &videoRequirements, int sessionId,
56 : const std::shared_ptr<ISharedMemoryBuffer> &shmBuffer, IDecryptionService &decryptionService) const override;
57 :
58 : /**
59 : * @brief Create the generic media player factory object.
60 : *
61 : * @retval the generic media player factory instance or null on error.
62 : */
63 : static std::shared_ptr<MediaPipelineServerInternalFactory> createFactory();
64 : };
65 :
66 : /**
67 : * @brief The definition of the MediaPipelineServerInternal.
68 : */
69 : class MediaPipelineServerInternal : public IMediaPipelineServerInternal, public IGstGenericPlayerClient
70 : {
71 : public:
72 : /**
73 : * @brief The constructor.
74 : *
75 : * @param[in] client : The Rialto media player client.
76 : * @param[in] videoRequirements : The video decoder requirements for the MediaPipeline session.
77 : * @param[in] gstPlayerFactory : The gstreamer player factory.
78 : * @param[in] sessionId : The session id
79 : * @param[in] shmBuffer : The shared memory buffer
80 : * @param[in] mainThreadFactory : The main thread factory.
81 : * @param[in] dataReaderFactory : The data reader factory
82 : * @param[in] activeRequests : The active requests
83 : * @param[in] decryptionService : The decryption service
84 : */
85 : MediaPipelineServerInternal(const std::shared_ptr<IMediaPipelineClient> &client,
86 : const VideoRequirements &videoRequirements,
87 : const std::shared_ptr<IGstGenericPlayerFactory> &gstPlayerFactory, int sessionId,
88 : const std::shared_ptr<ISharedMemoryBuffer> &shmBuffer,
89 : const std::shared_ptr<IMainThreadFactory> &mainThreadFactory,
90 : const std::shared_ptr<common::ITimerFactory> &timerFactory,
91 : std::unique_ptr<IDataReaderFactory> &&dataReaderFactory,
92 : std::unique_ptr<IActiveRequests> &&activeRequests, IDecryptionService &decryptionService);
93 :
94 : /**
95 : * @brief Virtual destructor.
96 : */
97 : virtual ~MediaPipelineServerInternal();
98 :
99 : bool load(MediaType type, const std::string &mimeType, const std::string &url, bool isLive) override;
100 :
101 : bool attachSource(const std::unique_ptr<MediaSource> &source) override;
102 :
103 : bool removeSource(int32_t id) override;
104 :
105 : bool allSourcesAttached() override;
106 :
107 : bool play(bool &async) override;
108 :
109 : bool pause() override;
110 :
111 : bool stop() override;
112 :
113 : bool setPlaybackRate(double rate) override;
114 :
115 : bool setPosition(int64_t position) override;
116 :
117 : bool getPosition(int64_t &position) override;
118 :
119 : bool setImmediateOutput(int32_t sourceId, bool immediateOutput) override;
120 :
121 : bool setReportDecodeErrors(int32_t sourceId, bool reportDecodeErrors) override;
122 :
123 : bool setMetricSubscription(const std::vector<MetricType> &types) override;
124 :
125 : bool getQueuedFrames(int32_t sourceId, uint32_t &queuedFrames) override;
126 :
127 : bool getImmediateOutput(int32_t sourceId, bool &immediateOutput) override;
128 :
129 : bool getStats(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames) override;
130 :
131 : bool getFrameCounters(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames,
132 : uint64_t &corruptedFrames, uint64_t ×tamp) override;
133 : bool getFrameCounters(int32_t sessionId, int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames,
134 : uint64_t &corruptedFrames, uint64_t ×tamp) override;
135 :
136 : bool setVideoWindow(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
137 :
138 : bool haveData(MediaSourceStatus status, uint32_t needDataRequestId) override;
139 :
140 : bool haveData(MediaSourceStatus status, uint32_t numFrames, uint32_t needDataRequestId) override;
141 :
142 : void ping(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler) override;
143 :
144 : bool renderFrame() override;
145 :
146 : bool setVolume(double targetVolume, uint32_t volumeDuration, EaseType easeType) override;
147 :
148 : bool getVolume(double ¤tVolume) override;
149 :
150 : bool setMute(std::int32_t sourceId, bool mute) override;
151 :
152 : bool getMute(std::int32_t sourceId, bool &mute) override;
153 :
154 : bool setTextTrackIdentifier(const std::string &textTrackIdentifier) override;
155 :
156 : bool getTextTrackIdentifier(std::string &textTrackIdentifier) override;
157 :
158 : bool setLowLatency(bool lowLatency) override;
159 :
160 : bool setSync(bool sync) override;
161 :
162 : bool getSync(bool &sync) override;
163 :
164 : bool setSyncOff(bool syncOff) override;
165 :
166 : bool setStreamSyncMode(int32_t sourceId, int32_t streamSyncMode) override;
167 :
168 : bool getStreamSyncMode(int32_t &streamSyncMode) override;
169 :
170 : bool flush(int32_t sourceId, bool resetTime, bool &async) override;
171 :
172 : bool setSourcePosition(int32_t sourceId, int64_t position, bool resetTime, double appliedRate,
173 : uint64_t stopPosition) override;
174 :
175 : bool setSubtitleOffset(int32_t sourceId, int64_t position) override;
176 :
177 : bool processAudioGap(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac) override;
178 :
179 : bool setBufferingLimit(uint32_t limitBufferingMs) override;
180 :
181 : bool getBufferingLimit(uint32_t &limitBufferingMs) override;
182 :
183 : bool setUseBuffering(bool useBuffering) override;
184 :
185 : bool getUseBuffering(bool &useBuffering) override;
186 :
187 : bool switchSource(const std::unique_ptr<MediaSource> &source) override;
188 :
189 : bool getDuration(int64_t &duration) override;
190 :
191 : AddSegmentStatus addSegment(uint32_t needDataRequestId, const std::unique_ptr<MediaSegment> &mediaSegment) override;
192 :
193 : std::weak_ptr<IMediaPipelineClient> getClient() override;
194 :
195 : void notifyPlaybackState(PlaybackState state) override;
196 :
197 : bool notifyNeedMediaData(MediaSourceType mediaSourceType) override;
198 :
199 : bool notifyNeedMediaDataWithDelay(MediaSourceType mediaSourceType) override;
200 :
201 : void notifyPosition(std::int64_t position) override;
202 :
203 : void notifyNetworkState(NetworkState state) override;
204 :
205 : void clearActiveRequestsCache() override;
206 :
207 : void invalidateActiveRequests(const MediaSourceType &type) override;
208 :
209 : void notifyQos(MediaSourceType mediaSourceType, const QosInfo &qosInfo) override;
210 :
211 : void notifyMetric(const MetricEvent &metric) override;
212 :
213 : void notifyBufferUnderflow(MediaSourceType mediaSourceType) override;
214 :
215 : void notifyFirstFrameReceived(MediaSourceType mediaSourceType) override;
216 :
217 : void notifyPlaybackError(MediaSourceType mediaSourceType, PlaybackError error) override;
218 :
219 : void notifyOutputRestrictionCleared(MediaSourceType mediaSourceType) override;
220 :
221 : void notifySourceFlushed(MediaSourceType mediaSourceType) override;
222 :
223 : void notifyPlaybackInfo(const PlaybackInfo &playbackInfo) override;
224 :
225 : protected:
226 : /**
227 : * @brief The media player client.
228 : */
229 : std::shared_ptr<IMediaPipelineClient> m_mediaPipelineClient;
230 :
231 : /**
232 : * @brief The mainThread object.
233 : */
234 : std::shared_ptr<IMainThread> m_mainThread;
235 :
236 : /**
237 : * @brief The gstreamer player factory object.
238 : */
239 : const std::shared_ptr<IGstGenericPlayerFactory> m_kGstPlayerFactory;
240 :
241 : /**
242 : * @brief The gstreamer player.
243 : */
244 : std::unique_ptr<IGstGenericPlayer> m_gstPlayer;
245 :
246 : /**
247 : * @brief The video decoder requirements for the MediaPipeline session.
248 : */
249 : const VideoRequirements m_kVideoRequirements;
250 :
251 : /**
252 : * @brief ID of a session represented by this MediaPipeline
253 : */
254 : int m_sessionId;
255 :
256 : /**
257 : * @brief Shared memory buffer
258 : */
259 : std::shared_ptr<ISharedMemoryBuffer> m_shmBuffer;
260 :
261 : /**
262 : * @brief DataReader factory
263 : */
264 : std::unique_ptr<IDataReaderFactory> m_dataReaderFactory;
265 :
266 : /**
267 : * @brief Factory creating timers
268 : */
269 : std::shared_ptr<common::ITimerFactory> m_timerFactory;
270 :
271 : /**
272 : * @brief Object containing all active NeedDataRequests
273 : */
274 : std::unique_ptr<IActiveRequests> m_activeRequests;
275 :
276 : /**
277 : * @brief This objects id registered on the main thread
278 : */
279 : uint32_t m_mainThreadClientId;
280 :
281 : /**
282 : * @brief Decryption service
283 : */
284 : IDecryptionService &m_decryptionService;
285 :
286 : /**
287 : * @brief Current playback state
288 : */
289 : PlaybackState m_currentPlaybackState;
290 :
291 : /**
292 : * @brief Map containing scheduled need media data requests.
293 : */
294 : std::unordered_map<MediaSourceType, std::unique_ptr<firebolt::rialto::common::ITimer>> m_needMediaDataTimers;
295 :
296 : /**
297 : * @brief Currently attached sources
298 : */
299 : std::map<MediaSourceType, std::int32_t> m_attachedSources;
300 :
301 : /**
302 : * @brief Map to keep track of the count of MediaSourceStatus with the value NO_AVAILABLE_SAMPLES for each MediaSource
303 : */
304 : std::map<MediaSourceType, unsigned int> m_noAvailableSamplesCounter;
305 :
306 : /**
307 : * @brief Flag used to check if allSourcesAttached was already called
308 : */
309 : bool m_wasAllSourcesAttachedCalled;
310 :
311 : /**
312 : * @brief Flag used to check if low latency is set for video source
313 : */
314 : bool m_IsLowLatencyVideoPlayer{false};
315 :
316 : /**
317 : * @brief Flag used to check if low latency is set for audio source
318 : */
319 : bool m_IsLowLatencyAudioPlayer{false};
320 :
321 : /**
322 : * @brief Map of flags used to check if Eos has been set on the media type for this playback
323 : */
324 : std::map<MediaSourceType, bool> m_isMediaTypeEosMap;
325 :
326 : /**
327 : * @brief Mutex to protect gstPlayer access in getPosition method
328 : */
329 : std::shared_mutex m_getPropertyMutex;
330 :
331 : /**
332 : * @brief Object to calculate the delay for scheduling NeedMediaData when no segments were received in haveData() call
333 : */
334 : NeedDataDelayCalculator m_needDataDelayCalculator;
335 :
336 : /**
337 : * @brief The metric types the client is notified about. Empty until set via setMetricSubscription().
338 : */
339 : std::set<MetricType> m_metricSubscription;
340 :
341 : /**
342 : * @brief Guards m_metricSubscription, which is read on the caller thread of notifyMetric().
343 : */
344 : std::mutex m_metricSubscriptionMutex;
345 :
346 : /**
347 : * @brief Load internally, only to be called on the main thread.
348 : *
349 : * @param[in] type : The media type.
350 : * @param[in] mimeType : The MIME type.
351 : * @param[in] url : The URL.
352 : * @param[in] isLive : Indicates if the media is live.
353 : *
354 : * @retval true on success.
355 : */
356 : bool loadInternal(MediaType type, const std::string &mimeType, const std::string &url, bool isLive);
357 :
358 : /**
359 : * @brief Attach source internally, only to be called on the main thread.
360 : *
361 : * @param[in] source : The source.
362 : *
363 : * @retval true on success.
364 : */
365 : bool attachSourceInternal(const std::unique_ptr<MediaSource> &source);
366 :
367 : /**
368 : * @brief Remove source internally, only to be called on the main thread.
369 : *
370 : * @param[in] id : The source id.
371 : *
372 : * @retval true on success.
373 : */
374 : bool removeSourceInternal(int32_t id);
375 :
376 : /**
377 : * @brief Notify all sources attached internally, only to be called on the main thread.
378 : *
379 : * @retval true on success.
380 : */
381 : bool allSourcesAttachedInternal();
382 :
383 : /**
384 : * @brief Play internally, only to be called on the main thread.
385 : *
386 : * @param[out] async : True if play method call is asynchronous
387 : *
388 : * @retval true on success.
389 : */
390 : bool playInternal(bool &async);
391 :
392 : /**
393 : * @brief Pause internally, only to be called on the main thread.
394 : *
395 : * @retval true on success.
396 : */
397 : bool pauseInternal();
398 :
399 : /**
400 : * @brief Stop internally, only to be called on the main thread.
401 : *
402 : * @retval true on success.
403 : */
404 : bool stopInternal();
405 :
406 : /**
407 : * @brief Set the playback rate internally, only to be called on the main thread.
408 : *
409 : * @param[in] rate : The playback rate.
410 : *
411 : * @retval true on success.
412 : */
413 : bool setPlaybackRateInternal(double rate);
414 :
415 : /**
416 : * @brief Set the position internally, only to be called on the main thread.
417 : *
418 : * @param[in] position : The playback position in nanoseconds.
419 : *
420 : * @retval true on success.
421 : */
422 : bool setPositionInternal(int64_t position);
423 :
424 : /**
425 : * @brief Sets the "Immediate Output" property for this source.
426 : *
427 : * This method is asynchronous
428 : *
429 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
430 : * @param[in] immediateOutput : The desired immediate output mode on the sink
431 : *
432 : * @retval true on success.
433 : */
434 : bool setImmediateOutputInternal(int32_t sourceId, bool immediateOutput);
435 :
436 : /**
437 : * @brief Sets the "Report Decode Errors" property for this source.
438 : *
439 : * This method is asynchronous
440 : *
441 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
442 : * @param[in] reportDecodeErrors : The desired Set Report Decode Errors mode on the sink
443 : *
444 : * @retval true on success.
445 : */
446 : bool setReportDecodeErrorsInternal(int32_t sourceId, bool reportDecodeErrors);
447 :
448 : /**
449 : * @brief Replaces the set of metric types the client is notified about, only to be called on the main thread.
450 : *
451 : * @param[in] types : The metric types to subscribe to. An empty vector disables metric notifications.
452 : *
453 : * @retval true on success.
454 : */
455 : bool setMetricSubscriptionInternal(const std::vector<MetricType> &types);
456 :
457 : /**
458 : * @brief Gets the queued frames for this source.
459 : *
460 : * This method is asynchronous
461 : *
462 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
463 : * @param[in] queuedFrames : Number of queued frames
464 : *
465 : * @retval true on success.
466 : */
467 : bool getQueuedFramesInternal(int32_t sourceId, uint32_t &queuedFrames);
468 :
469 : /**
470 : * @brief Gets the "Immediate Output" property for this source.
471 : *
472 : * This method is sychronous
473 : *
474 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
475 : * @param[out] immediateOutput : Returns the immediate output mode on the sink
476 : *
477 : * @retval true on success.
478 : */
479 : bool getImmediateOutputInternal(int32_t sourceId, bool &immediateOutput);
480 :
481 : /**
482 : * @brief Get stats for this source.
483 : *
484 : * This method is sychronous, it returns dropped frames and rendered frames
485 : *
486 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
487 : * @param[out] renderedFrames : The number of rendered frames
488 : * @param[out] droppedFrames : The number of dropped frames
489 : *
490 : * @retval true on success.
491 : */
492 : bool getStatsInternal(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames);
493 :
494 : bool getFrameCountersInternal(int32_t sessionId, int32_t sourceId, uint64_t &renderedFrames,
495 : uint64_t &droppedFrames, uint64_t &corruptedFrames, uint64_t ×tamp);
496 :
497 : /**
498 : * @brief Set video window internally, only to be called on the main thread.
499 : *
500 : * @param[in] x : The x position in pixels.
501 : * @param[in] y : The y position in pixels.
502 : * @param[in] width : The width in pixels.
503 : * @param[in] height : The height in pixels.
504 : *
505 : * @retval true on success.
506 : */
507 : bool setVideoWindowInternal(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
508 :
509 : /**
510 : * @brief Have data internally, only to be called on the main thread.
511 : *
512 : * @param[in] status : The status
513 : * @param[in] needDataRequestId : Need data request id
514 : *
515 : * @retval true on success.
516 : */
517 : bool haveDataInternal(MediaSourceStatus status, uint32_t needDataRequestId);
518 :
519 : /**
520 : * @brief Render frame internally, only to be called on the main thread.
521 : *
522 : * @retval true on success.
523 : */
524 : bool renderFrameInternal();
525 :
526 : /**
527 : * @brief Have data internally, only to be called on the main thread.
528 : *
529 : * @param[in] status : The status
530 : * @param[in] numFrames : The number of frames written.
531 : * @param[in] needDataRequestId : Need data request id
532 : *
533 : * @retval true on success.
534 : */
535 : bool haveDataInternal(MediaSourceStatus status, uint32_t numFrames, uint32_t needDataRequestId);
536 :
537 : /**
538 : * @brief Add segment internally, only to be called on the main thread.
539 : *
540 : * @param[in] needDataRequestId : The status
541 : * @param[in] mediaSegment : The data returned.
542 : *
543 : * @retval status of adding segment
544 : */
545 : AddSegmentStatus addSegmentInternal(uint32_t needDataRequestId, const std::unique_ptr<MediaSegment> &mediaSegment);
546 :
547 : /**
548 : * @brief Notify need media data internally, only to be called on the main thread.
549 : *
550 : * @param[in] mediaSourceType : The media source type.
551 : */
552 : bool notifyNeedMediaDataInternal(MediaSourceType mediaSourceType);
553 :
554 : /**
555 : * @brief Notify need media data with delay internally, only to be called on the main thread.
556 : *
557 : * @param[in] mediaSourceType : The media source type.
558 : */
559 : bool notifyNeedMediaDataWithDelayInternal(MediaSourceType mediaSourceType);
560 :
561 : /**
562 : * @brief Schedules resending of NeedMediaData after a short delay. Used when no segments were received in the
563 : * haveData() call to prevent a storm of needData()/haveData() calls, only to be called on the main thread.
564 : *
565 : * @param[in] mediaSourceType : The media source type.
566 : */
567 : void scheduleNotifyNeedMediaData(MediaSourceType mediaSourceType);
568 :
569 : /**
570 : * @brief Set the target volume level with a transition internally, only to be called on the main thread.
571 : *
572 : * @param[in] targetVolume : Target volume level (0.0 - 1.0)
573 : * @param[in] volumeDuration : Duration of the volume transition in milliseconds
574 : * @param[in] ease_type : Easing type for the volume transition
575 : *
576 : * @retval true on success, false otherwise
577 : */
578 : bool setVolumeInternal(double targetVolume, uint32_t volumeDuration, EaseType easeType);
579 :
580 : /**
581 : * @brief Get the current volume level internally, only to be called on the main thread.
582 : * Fetches the current volume level for the pipeline.
583 : *
584 : * @param[out] currentVolume : Current volume level (range 0.0 - 1.0)
585 : *
586 : * @retval true on success, false otherwise
587 : */
588 : bool getVolumeInternal(double ¤tVolume);
589 :
590 : /**
591 : * @brief Set mute internally, only to be called on the main thread.
592 : *
593 : * @param[in] mute Desired mute state, true=muted, false=not muted
594 : *
595 : * @retval true on success false otherwise
596 : */
597 : bool setMuteInternal(std::int32_t sourceId, bool mute);
598 :
599 : /**
600 : * @brief Get mute internally, only to be called on the main thread.
601 : *
602 : * @param[out] mute Current mute state
603 : *
604 : * @retval true on success false otherwise
605 : */
606 : bool getMuteInternal(std::int32_t sourceId, bool &mute);
607 :
608 : /**
609 : * @brief Change Text Track Identifier
610 : *
611 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
612 : *
613 : * @retval true on success false otherwise
614 : */
615 : bool setTextTrackIdentifierInternal(const std::string &textTrackIdentifier);
616 :
617 : /**
618 : * @brief Get Text Track Identifier
619 : *
620 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
621 : *
622 : * @retval true on success false otherwise
623 : */
624 : bool getTextTrackIdentifierInternal(std::string &textTrackIdentifier);
625 :
626 : /**
627 : * @brief Set low latency internally, only to be called on the main thread.
628 : *
629 : * @param[in] lowLatency : The low latency value to set.
630 : *
631 : * @retval true on success false otherwise
632 : */
633 : bool setLowLatencyInternal(bool lowLatency);
634 :
635 : /**
636 : * @brief Set sync internally, only to be called on the main thread.
637 : *
638 : * @param[in] sync : The sync value to set.
639 : *
640 : * @retval true on success false otherwise
641 : */
642 : bool setSyncInternal(bool sync);
643 :
644 : /**
645 : * @brief Get sync internally, only to be called on the main thread.
646 : *
647 : * @param[out] sync : Current sync value.
648 : *
649 : * @retval true on success false otherwise
650 : */
651 : bool getSyncInternal(bool &sync);
652 :
653 : /**
654 : * @brief Set sync off internally, only to be called on the main thread.
655 : *
656 : * @param[in] syncOff : The sync off value to set.
657 : *
658 : * @retval true on success false otherwise
659 : */
660 : bool setSyncOffInternal(bool syncOff);
661 :
662 : /**
663 : * @brief Set stream sync mode internally, only to be called on the main thread.
664 : *
665 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
666 : * @param[in] streamSyncMode : The stream sync mode value to set.
667 : *
668 : * @retval true on success false otherwise
669 : */
670 : bool setStreamSyncModeInternal(int32_t sourceId, int32_t streamSyncMode);
671 :
672 : /**
673 : * @brief Get stream sync mode internally, only to be called on the main thread.
674 : *
675 : * @param[out] streamSyncMode : Current stream sync mode value.
676 : *
677 : * @retval true on success false otherwise
678 : */
679 : bool getStreamSyncModeInternal(int32_t &streamSyncMode);
680 :
681 : /**
682 : * @brief Checks if MediaPipeline threads are not deadlocked internally
683 : *
684 : * @param[out] heartbeatHandler : The heartbeat handler instance
685 : */
686 : void pingInternal(std::unique_ptr<IHeartbeatHandler> &&heartbeatHandler);
687 :
688 : /**
689 : * @brief Flushes a source.
690 : *
691 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
692 : * @param[in] resetTime : True if time should be reset
693 : * @param[out] async : True if flushed source is asynchronous (will preroll after flush)
694 : *
695 : * @retval true on success.
696 : */
697 : bool flushInternal(int32_t sourceId, bool resetTime, bool &async);
698 :
699 : /**
700 : * @brief Set the source position in nanoseconds.
701 : *
702 : * This method sets the start position for a source.
703 : *
704 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
705 : * @param[in] position : The position in nanoseconds.
706 : * @param[in] resetTime : True if time should be reset
707 : * @param[in] appliedRate : The applied rate after seek
708 : * @param[in] stopPosition : The position of last pushed buffer
709 : *
710 : * @retval true on success.
711 : */
712 : bool setSourcePositionInternal(int32_t sourceId, int64_t position, bool resetTime, double appliedRate,
713 : uint64_t stopPosition);
714 :
715 : /**
716 : * @brief Set subtitle offset for a subtitle source.
717 : *
718 : * This method is used to set the subtitle offset for a subtitle source.
719 : *
720 : * @param[in] sourceId : The id of the subtitle source
721 : * @param[in] position : The subtitle offset position in nanoseconds
722 : *
723 : * @retval true on success.
724 : */
725 : bool setSubtitleOffsetInternal(int32_t sourceId, int64_t position);
726 :
727 : /**
728 : * @brief Process audio gap
729 : *
730 : * This method handles audio gap in order to avoid audio pops during transitions.
731 : *
732 : * @param[in] position : Audio pts fade position
733 : * @param[in] duration : Audio pts fade duration
734 : * @param[in] discontinuityGap : Audio discontinuity gap
735 : * @param[in] audioAac : True if audio codec is AAC
736 : *
737 : * @retval true on success.
738 : */
739 : bool processAudioGapInternal(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac);
740 :
741 : /**
742 : * @brief Set buffering limit
743 : *
744 : * This method enables/disables limit buffering and sets millisecond threshold used.
745 : * Use kInvalidLimitBuffering to disable limit buffering
746 : *
747 : * @param[in] limitBufferingMs : buffering limit in ms
748 : *
749 : * @retval true on success.
750 : */
751 : bool setBufferingLimitInternal(uint32_t limitBufferingMs);
752 :
753 : /**
754 : * @brief Get buffering limit
755 : *
756 : * This method returns current value of buffering limit in milliseconds
757 : * Method will return kInvalidLimitBuffering limit buffering is disabled
758 : *
759 : * @param[out] limitBufferingMs : buffering limit in ms
760 : *
761 : * @retval true on success.
762 : */
763 : bool getBufferingLimitInternal(uint32_t &limitBufferingMs);
764 :
765 : /**
766 : * @brief Enables/disables the buffering option
767 : *
768 : * This method enables the buffering option so that BUFFERING messages are
769 : * emitted based on low-/high-percent thresholds.
770 : *
771 : * @param[in] useBuffering : true if buffering option enabled.
772 : *
773 : * @retval true on success.
774 : */
775 : bool setUseBufferingInternal(bool useBuffering);
776 :
777 : /**
778 : * @brief Checks, if buffering is enabled
779 : *
780 : * This method returns true, if buffering is enabled
781 : *
782 : * @param[out] useBuffering : true if buffering option is enabled.
783 : *
784 : * @retval true on success.
785 : */
786 : bool getUseBufferingInternal(bool &useBuffering);
787 :
788 : /**
789 : * @brief Switches a source.
790 : *
791 : * @param[in] mediaSource : The media source.
792 : *
793 : */
794 : bool switchSourceInternal(const std::unique_ptr<MediaSource> &source);
795 :
796 : /**
797 : * @brief Returns how long should we wait to send next NeedMediaData
798 : * if rialto client returns NO_AVAILABLE_SAMPLES
799 : *
800 : * @param[in] mediaSourceType : The media source type.
801 : *
802 : * @retval NeedMediaData timeout
803 : */
804 : std::chrono::milliseconds getNeedMediaDataTimeout(MediaSourceType mediaSourceType);
805 : };
806 :
807 : }; // namespace firebolt::rialto::server
808 :
809 : #endif // FIREBOLT_RIALTO_SERVER_MEDIA_PIPELINE_SERVER_INTERNAL_H_
|