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_I_MEDIA_PIPELINE_H_
21 : #define FIREBOLT_RIALTO_I_MEDIA_PIPELINE_H_
22 :
23 : /**
24 : * @file IMediaPipeline.h
25 : *
26 : * The definition of the IMediaPipeline interface.
27 : *
28 : * This interface defines the public API of Rialto for playback of AV content.
29 : */
30 :
31 : #include <stdint.h>
32 :
33 : #include <algorithm>
34 : #include <memory>
35 : #include <string>
36 : #include <vector>
37 :
38 : #include "IMediaPipelineClient.h"
39 : #include "MediaCommon.h"
40 :
41 : namespace firebolt::rialto
42 : {
43 : class IMediaPipeline;
44 :
45 : /**
46 : * @brief IMediaPipeline factory class, returns a concrete implementation of IMediaPipeline
47 : */
48 : class IMediaPipelineFactory
49 : {
50 : public:
51 132 : IMediaPipelineFactory() = default;
52 132 : virtual ~IMediaPipelineFactory() = default;
53 :
54 : /**
55 : * @brief Create a IMediaPipelineFactory instance.
56 : *
57 : * @retval the factory instance or null on error.
58 : */
59 : static std::shared_ptr<IMediaPipelineFactory> createFactory();
60 :
61 : /**
62 : * @brief IMediaPipeline factory method, returns a concrete implementation of IMediaPipeline
63 : *
64 : * @param[in] client : The Rialto media player client.
65 : * @param[in] videoRequirements : The video decoder requirements for the MediaPipeline session
66 : *
67 : * @retval the new backend instance or null on error.
68 : */
69 : virtual std::unique_ptr<IMediaPipeline> createMediaPipeline(std::weak_ptr<IMediaPipelineClient> client,
70 : const VideoRequirements &videoRequirements) const = 0;
71 : };
72 :
73 : /**
74 : * @brief The definition of the IMediaPipeline interface.
75 : *
76 : * This interface defines the public API of Rialto for playback of AV content which
77 : * should be implemented by both Rialto Client & Rialto Server.
78 : */
79 : class IMediaPipeline
80 : {
81 : public:
82 387 : IMediaPipeline() = default;
83 387 : virtual ~IMediaPipeline() = default;
84 :
85 : IMediaPipeline(const IMediaPipeline &) = delete;
86 : IMediaPipeline &operator=(const IMediaPipeline &) = delete;
87 : IMediaPipeline(IMediaPipeline &&) = delete;
88 : IMediaPipeline &operator=(IMediaPipeline &&) = delete;
89 :
90 : /**
91 : * @brief A class that represents a source of media data.
92 : */
93 : class MediaSource
94 : {
95 : public:
96 : /**
97 : * @brief Virtual destructor.
98 : */
99 : virtual ~MediaSource() {}
100 :
101 : /**
102 : * @brief Create a copy
103 : */
104 : virtual std::unique_ptr<MediaSource> copy() const = 0;
105 :
106 : /**
107 : * @brief Return the source type.
108 : */
109 0 : virtual MediaSourceType getType() const { return MediaSourceType::UNKNOWN; }
110 :
111 : /**
112 : * @brief Return the MIME type.
113 : */
114 76 : std::string getMimeType() const { return m_mimeType; }
115 :
116 : /**
117 : * @brief Return if source has drm
118 : */
119 46 : bool getHasDrm() const { return m_hasDrm; }
120 :
121 : /**
122 : * @brief Return the source config type.
123 : */
124 77 : SourceConfigType getConfigType() const { return m_configType; }
125 :
126 : /**
127 : * @brief Return the source id.
128 : */
129 112 : int32_t getId() const { return m_id; }
130 :
131 : /**
132 : * @brief Set the source id.
133 : */
134 109 : void setId(int32_t id) { m_id = id; }
135 :
136 : protected:
137 : /**
138 : * @brief Default constructor.
139 : *
140 : * @param[in] configType : The source config type.
141 : * @param[in] mimeType : The mime type string.
142 : * @param[in] hasDrm : Information if source will use drm
143 : */
144 151 : explicit MediaSource(SourceConfigType configType = SourceConfigType::UNKNOWN,
145 : const std::string &mimeType = std::string(), bool hasDrm = true)
146 151 : : m_id(0), m_configType(configType), m_mimeType(mimeType), m_hasDrm(hasDrm)
147 : {
148 : }
149 : /**
150 : * @brief The source id. Parameter will be set by a successful call to attachSource()
151 : */
152 : int32_t m_id;
153 :
154 : /**
155 : * @brief The source config type.
156 : */
157 : SourceConfigType m_configType;
158 :
159 : /**
160 : * @brief The MIME type.
161 : */
162 : std::string m_mimeType;
163 :
164 : /**
165 : * @brief Parameter to check if encrypted frames will be used for this source.
166 : */
167 : bool m_hasDrm;
168 : };
169 :
170 : /**
171 : * @brief A class that represents media source audio and video derived from MediaSource class, which represents the
172 : * source of media data
173 : */
174 : class MediaSourceAV : public MediaSource
175 : {
176 : public:
177 : ~MediaSourceAV() {}
178 0 : std::unique_ptr<MediaSource> copy() const { return std::make_unique<MediaSourceAV>(*this); }
179 :
180 : /**
181 : * @brief Gets the segment alignment
182 : */
183 43 : SegmentAlignment getSegmentAlignment() const { return m_alignment; }
184 :
185 : /**
186 : * @brief Gets the codec data
187 : */
188 62 : const std::shared_ptr<CodecData> &getCodecData() const { return m_codecData; }
189 :
190 : /**
191 : * @brief Gets the stream format
192 : */
193 53 : StreamFormat getStreamFormat() const { return m_streamFormat; }
194 :
195 : protected:
196 : /**
197 : * @brief Default constructor.
198 : *
199 : * @param[in] configType : The source config type.
200 : * @param[in] mimeType : The mime type string.
201 : * @param[in] hasDrm : Information if source will use drm
202 : * @param[in] alignment : The alignment of media segment.
203 : * @param[in] streamFormat : The stream format
204 : * @param[in] codecData : The additional data for decoder
205 : */
206 142 : explicit MediaSourceAV(SourceConfigType configType = SourceConfigType::UNKNOWN,
207 : const std::string &mimeType = std::string(), bool hasDrm = true,
208 : SegmentAlignment alignment = SegmentAlignment::UNDEFINED,
209 : StreamFormat streamFormat = StreamFormat::UNDEFINED,
210 : const std::shared_ptr<CodecData> &codecData = nullptr)
211 284 : : MediaSource(configType, mimeType, hasDrm), m_alignment(alignment), m_streamFormat(streamFormat),
212 142 : m_codecData(codecData)
213 : {
214 : }
215 : /**
216 : * @brief The alignment of media segment
217 : */
218 : SegmentAlignment m_alignment;
219 :
220 : /**
221 : * @brief The stream format
222 : */
223 : StreamFormat m_streamFormat;
224 :
225 : /**
226 : * @brief Additional data for decoder
227 : */
228 : std::shared_ptr<CodecData> m_codecData;
229 : };
230 :
231 : /**
232 : * @brief A class that represents media source audio derived from MediaSource class, which represents the source of
233 : * media data
234 : */
235 :
236 : class MediaSourceAudio : public MediaSourceAV
237 : {
238 : public:
239 : /**
240 : * @brief Constructor for audio specific configuration.
241 : *
242 : * @param[in] mimeType : The mime type string.
243 : * @param[in] hasDrm : Information if source will use drm
244 : * @param[in] audioConfig : The audio specific configuration.
245 : * @param[in] alignment : The alignment of media segment.
246 : * @param[in] streamFormat : The stream format
247 : * @param[in] codecData : The additional data for decoder
248 : */
249 90 : MediaSourceAudio(const std::string &mimeType, bool hasDrm = true, const AudioConfig &audioConfig = AudioConfig(),
250 : SegmentAlignment alignment = SegmentAlignment::UNDEFINED,
251 : StreamFormat streamFormat = StreamFormat::UNDEFINED,
252 : const std::shared_ptr<CodecData> &codecData = nullptr)
253 90 : : MediaSourceAV(SourceConfigType::AUDIO, mimeType, hasDrm, alignment, streamFormat, codecData),
254 90 : m_audioConfig(audioConfig)
255 : {
256 : }
257 :
258 : ~MediaSourceAudio() {}
259 :
260 137 : MediaSourceType getType() const override { return MediaSourceType::AUDIO; }
261 10 : std::unique_ptr<MediaSource> copy() const override { return std::make_unique<MediaSourceAudio>(*this); }
262 :
263 : /**
264 : * @brief Gets the audio specific configuration
265 : *
266 : * @retval audio specific configuration
267 : */
268 64 : const AudioConfig &getAudioConfig() const { return m_audioConfig; }
269 :
270 : protected:
271 : /**
272 : * @brief Variable that stores the audio specific configuration
273 : */
274 : AudioConfig m_audioConfig;
275 : };
276 :
277 : /**
278 : * @brief A class that represents media source video derived from MediaSource class, which represents the source of
279 : * media data
280 : */
281 :
282 : class MediaSourceVideo : public MediaSourceAV
283 : {
284 : public:
285 : /**
286 : * @brief Constructor for video specific configuration.
287 : *
288 : * @param[in] mimeType : The mime type string.
289 : * @param[in] hasDrm : Information if source will use drm
290 : * @param[in] width : The width of the video
291 : * @param[in] height : The height of the video
292 : * @param[in] alignment : The alignment of media segment.
293 : * @param[in] streamFormat : The stream format
294 : * @param[in] codecData : The additional data for decoder
295 : */
296 43 : MediaSourceVideo(const std::string &mimeType, bool hasDrm = true,
297 : int32_t width = firebolt::rialto::kUndefinedSize,
298 : int32_t height = firebolt::rialto::kUndefinedSize,
299 : SegmentAlignment alignment = SegmentAlignment::UNDEFINED,
300 : StreamFormat streamFormat = StreamFormat::UNDEFINED,
301 : const std::shared_ptr<CodecData> &codecData = nullptr)
302 43 : : MediaSourceAV(SourceConfigType::VIDEO, mimeType, hasDrm, alignment, streamFormat, codecData),
303 43 : m_width(width), m_height(height)
304 : {
305 : }
306 : ~MediaSourceVideo() {}
307 :
308 131 : MediaSourceType getType() const override { return MediaSourceType::VIDEO; }
309 8 : std::unique_ptr<MediaSource> copy() const { return std::make_unique<MediaSourceVideo>(*this); }
310 :
311 : /**
312 : * @brief Gets the width of the video
313 : *
314 : * @retval width of the video
315 : */
316 20 : int32_t getWidth() const { return m_width; }
317 :
318 : /**
319 : * @brief Gets the height of the video
320 : *
321 : * @retval height of the video
322 : */
323 20 : int32_t getHeight() const { return m_height; }
324 :
325 : protected:
326 : /**
327 : * @brief Constructor for video specific configuration.
328 : *
329 : * @param[in] sourceConfigType : The source config type
330 : * @param[in] mimeType : The mime type string.
331 : * @param[in] hasDrm : Information if source will use drm
332 : * @param[in] width : The width of the video
333 : * @param[in] height : The height of the video
334 : * @param[in] alignment : The alignment of media segment.
335 : * @param[in] streamFormat : The stream format
336 : * @param[in] codecData : The additional data for decoder
337 : */
338 5 : MediaSourceVideo(SourceConfigType sourceConfigType, const std::string &mimeType, bool hasDrm = true,
339 : int32_t width = firebolt::rialto::kUndefinedSize,
340 : int32_t height = firebolt::rialto::kUndefinedSize,
341 : SegmentAlignment alignment = SegmentAlignment::UNDEFINED,
342 : StreamFormat streamFormat = StreamFormat::UNDEFINED,
343 : const std::shared_ptr<CodecData> &codecData = nullptr)
344 10 : : MediaSourceAV(sourceConfigType, mimeType, hasDrm, alignment, streamFormat, codecData), m_width(width),
345 5 : m_height(height)
346 : {
347 : }
348 :
349 : private:
350 : /**
351 : * @brief The video width
352 : */
353 : int m_width;
354 :
355 : /**
356 : * @brief The video height
357 : */
358 : int m_height;
359 : };
360 :
361 : /**
362 : * @brief A class that represents media source video dolby vision derived from media source video data
363 : */
364 :
365 : class MediaSourceVideoDolbyVision : public MediaSourceVideo
366 : {
367 : public:
368 : /**
369 : * @brief Constructor for dolby vision specific configuration.
370 : *
371 : * @param[in] mimeType : The mime type string.
372 : * @param[in] dolbyVisionProfile : The dolby vision profile
373 : * @param[in] hasDrm : Information if source will use drm
374 : * @param[in] width : The width of the video
375 : * @param[in] height : The height of the video
376 : * @param[in] alignment : The alignment of media segment.
377 : * @param[in] streamFormat : The stream format
378 : * @param[in] codecData : The additional data for decoder
379 : */
380 4 : MediaSourceVideoDolbyVision(const std::string &mimeType, int32_t dolbyVisionProfile, bool hasDrm = true,
381 : int32_t width = firebolt::rialto::kUndefinedSize,
382 : int32_t height = firebolt::rialto::kUndefinedSize,
383 : SegmentAlignment alignment = SegmentAlignment::UNDEFINED,
384 : StreamFormat streamFormat = StreamFormat::UNDEFINED,
385 : const std::shared_ptr<CodecData> &codecData = nullptr)
386 4 : : MediaSourceVideo(SourceConfigType::VIDEO_DOLBY_VISION, mimeType, hasDrm, width, height, alignment,
387 : streamFormat, codecData),
388 4 : m_dolbyVisionProfile(dolbyVisionProfile)
389 : {
390 : }
391 : ~MediaSourceVideoDolbyVision() {}
392 1 : std::unique_ptr<MediaSource> copy() const { return std::make_unique<MediaSourceVideoDolbyVision>(*this); }
393 :
394 : /**
395 : * @brief Gets the dolby vision profile
396 : *
397 : * @retval dolby vision profile
398 : */
399 4 : uint32_t getDolbyVisionProfile() const { return m_dolbyVisionProfile; }
400 :
401 : protected:
402 : /**
403 : * @brief Variable that stores the Dolby Vision Profile
404 : */
405 : uint32_t m_dolbyVisionProfile;
406 : };
407 :
408 : /**
409 : * @brief A class that represents media source subtitle derived from media source video data
410 : */
411 : class MediaSourceSubtitle : public MediaSource
412 : {
413 : public:
414 : /**
415 : * @brief Construct a new Media Source Subtitle object
416 : *
417 : * @param mimeType : The mime type string
418 : * @param textTrackIdentifier : The text track identifier string
419 : */
420 4 : MediaSourceSubtitle(const std::string &mimeType, const std::string &textTrackIdentifier)
421 4 : : MediaSource(SourceConfigType::SUBTITLE, mimeType, false), m_textTrackIdentifier(textTrackIdentifier)
422 : {
423 : }
424 :
425 : ~MediaSourceSubtitle() {}
426 :
427 7 : MediaSourceType getType() const override { return MediaSourceType::SUBTITLE; }
428 1 : std::unique_ptr<MediaSource> copy() const override { return std::make_unique<MediaSourceSubtitle>(*this); }
429 :
430 : /**
431 : * @brief Get the Text Track Identifier object
432 : *
433 : * @return the text track identifier
434 : */
435 3 : const std::string &getTextTrackIdentifier() const { return m_textTrackIdentifier; }
436 :
437 : protected:
438 : /**
439 : * @brief Variable that stores the text track identifier
440 : */
441 : std::string m_textTrackIdentifier;
442 : };
443 :
444 : /**
445 : * @brief A class that represents a media segment
446 : */
447 : class MediaSegment
448 : {
449 : public:
450 : /**
451 : * @brief Default constructor.
452 : *
453 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
454 : * @param[in] type : The source type.
455 : * @param[in] timeStamp : The timestamp in nanoseconds.
456 : * @param[in] duration : The duration in nanoseconds.
457 : */
458 130 : MediaSegment(int32_t sourceId = 0, MediaSourceType type = MediaSourceType::UNKNOWN, int64_t timeStamp = 0,
459 : int64_t duration = 0)
460 130 : : m_sourceId(sourceId), m_type(type), m_data(nullptr), m_dataLength(0u), m_timeStamp(timeStamp),
461 390 : m_duration(duration), m_encrypted(false), m_mediaKeySessionId(0), m_initWithLast15(0),
462 130 : m_alignment(SegmentAlignment::UNDEFINED), m_cipherMode(CipherMode::UNKNOWN), m_crypt(0), m_skip(0),
463 130 : m_encryptionPatternSet(false)
464 : {
465 : }
466 :
467 : /**
468 : * @brief Virtual destructor.
469 : */
470 : virtual ~MediaSegment() {}
471 :
472 : /**
473 : * @brief Makes a shallow copy of the segment
474 : *
475 : * @retval Shallow copy of the segment
476 : */
477 2 : virtual std::unique_ptr<MediaSegment> copy() const { return std::make_unique<MediaSegment>(*this); }
478 :
479 : /**
480 : * @brief Return the source id.
481 : *
482 : * @retval the source id.
483 : */
484 41 : int32_t getId() const { return m_sourceId; }
485 :
486 : /**
487 : * @brief The source type for the data.
488 : *
489 : * @retval the source type.
490 : */
491 135 : MediaSourceType getType() const { return m_type; }
492 :
493 : /**
494 : * @brief Returns a pointer to the data.
495 : *
496 : * @retval the data.
497 : */
498 142 : const uint8_t *getData() const { return m_data; }
499 :
500 : /**
501 : * @brief Returns a the data length.
502 : *
503 : * @retval the data.
504 : */
505 204 : uint32_t getDataLength() const { return m_dataLength; }
506 :
507 : /**
508 : * @brief Returns the time stamp.
509 : *
510 : * @retval the timestamp in nanoseconds.
511 : */
512 56 : int64_t getTimeStamp() const { return m_timeStamp; }
513 :
514 : /**
515 : * @brief Sets the time stamp (value in nanoseconds).
516 : */
517 : void setTimeStamp(int64_t timeStamp) { m_timeStamp = timeStamp; }
518 :
519 : /**
520 : * @brief Returns the duration.
521 : *
522 : * @retval the duration in nanoseconds.
523 : */
524 56 : int64_t getDuration() const { return m_duration; }
525 :
526 : /**
527 : * @brief Returns a pointer to the extra data.
528 : *
529 : * @retval the data.
530 : */
531 140 : const std::vector<uint8_t> &getExtraData() const { return m_extraData; }
532 :
533 : /**
534 : * @brief Indicates that the data is encrypted.
535 : *
536 : * @retval true if the data is encrypted.
537 : */
538 82 : bool isEncrypted() const { return m_encrypted; }
539 :
540 : /**
541 : * @brief Returns the media key session id. Empty if unencrypted.
542 : *
543 : * @retval the media key session id.
544 : */
545 22 : const int32_t getMediaKeySessionId() const { return m_mediaKeySessionId; }
546 :
547 : /**
548 : * @brief Returns the key id. Empty if unencrypted.
549 : *
550 : * @retval the key id.
551 : */
552 38 : const std::vector<uint8_t> &getKeyId() const { return m_keyId; }
553 :
554 : /**
555 : * @brief Returns the initialisation vector. Empty if unencrypted.
556 : *
557 : * @retval the initialisation vector.
558 : */
559 35 : const std::vector<uint8_t> &getInitVector() const { return m_initVector; }
560 :
561 : /**
562 : * @brief Returns the sub samples. Empty if unencrypted.
563 : *
564 : * @retval the sub samples.
565 : */
566 37 : const std::vector<SubSamplePair> &getSubSamples() const { return m_subSamples; }
567 :
568 : /**
569 : * @brief Returns the initWithLast15 value
570 : *
571 : * @retval the initWithLast15 value.
572 : */
573 20 : const uint32_t getInitWithLast15() const { return m_initWithLast15; }
574 :
575 : /**
576 : * @brief Returns the segment alignment
577 : *
578 : * @retval the segment alignment
579 : */
580 31 : const SegmentAlignment getSegmentAlignment() const { return m_alignment; }
581 :
582 : /**
583 : * @brief Gets the codec data
584 : *
585 : * @retval the codec data
586 : */
587 51 : const std::shared_ptr<CodecData> &getCodecData() const { return m_codecData; }
588 :
589 : /**
590 : * @brief Gets the cipher mode for common encryption
591 : *
592 : * @retval cipher mode uses for this sample
593 : */
594 17 : const CipherMode &getCipherMode() const { return m_cipherMode; }
595 :
596 : /**
597 : * @brief Gets the crypt & skip byte block for pattern encryption
598 : *
599 : * @param[out] crypt : Crypt byte block value
600 : * @param[out] skip : Skip byte block value
601 : *
602 : * @retval if the encryption pattern has been set
603 : */
604 17 : const bool getEncryptionPattern(uint32_t &crypt, uint32_t &skip) const
605 : {
606 17 : crypt = m_crypt;
607 17 : skip = m_skip;
608 17 : return m_encryptionPatternSet;
609 : }
610 :
611 : protected:
612 : /**
613 : * @brief The source id.
614 : */
615 : int32_t m_sourceId;
616 :
617 : /**
618 : * @brief The source type.
619 : */
620 : MediaSourceType m_type;
621 :
622 : /**
623 : * @brief The data
624 : */
625 : const uint8_t *m_data;
626 :
627 : /**
628 : * @brief The data length
629 : */
630 : uint32_t m_dataLength;
631 :
632 : /**
633 : * @brief The time stamp.
634 : */
635 : int64_t m_timeStamp;
636 :
637 : /**
638 : * @brief The duration.
639 : */
640 : int64_t m_duration;
641 :
642 : /**
643 : * @brief Additional data for decoder
644 : */
645 : std::shared_ptr<CodecData> m_codecData;
646 :
647 : /**
648 : * @brief The data
649 : */
650 : std::vector<uint8_t> m_extraData;
651 :
652 : /**
653 : * @brief Indicates the data is encrypted.
654 : */
655 : bool m_encrypted;
656 :
657 : /**
658 : * @brief Key session ID to use for decryption - only required for Netflix.
659 : */
660 : int32_t m_mediaKeySessionId;
661 :
662 : /**
663 : * @brief The encryption key id.
664 : */
665 : std::vector<uint8_t> m_keyId;
666 :
667 : /**
668 : * @brief The encryption key initialisation vector.
669 : */
670 : std::vector<uint8_t> m_initVector;
671 :
672 : /**
673 : * @brief The sub-sample pairs.
674 : */
675 : std::vector<SubSamplePair> m_subSamples;
676 :
677 : /**
678 : * @brief Whether decryption context needs to be initialized with
679 : * last 15 bytes. Currently this only applies to PlayReady DRM.
680 : */
681 : uint32_t m_initWithLast15;
682 :
683 : /**
684 : * @brief The alignment of media segment
685 : */
686 : SegmentAlignment m_alignment;
687 :
688 : /**
689 : * @brief Cipher mode of the sample.
690 : */
691 : CipherMode m_cipherMode;
692 :
693 : /**
694 : * @brief Crypt byte block value.
695 : */
696 : uint32_t m_crypt;
697 :
698 : /**
699 : * @brief Skip byte block value.
700 : */
701 : uint32_t m_skip;
702 :
703 : /**
704 : * @brief Whether the encryption pattern has been set.
705 : */
706 : bool m_encryptionPatternSet;
707 :
708 : public:
709 : /**
710 : * @brief Sets the segment data.
711 : *
712 : * @warning Note that the caller must guarantee that the buffer referenced by 'data' must remain
713 : * valid until the corresponding call to haveData() has completed (at which point the data will
714 : * have been copied out).
715 : *
716 : * @note This is for performance reasons to avoid multiple copies of AV data. A raw pointer is
717 : * used for the same reason since most runtimes will expose a raw pointer to the data.
718 : *
719 : * @retval true on success.
720 : */
721 104 : bool setData(uint32_t dataLength, const uint8_t *data)
722 : {
723 104 : m_dataLength = dataLength;
724 104 : m_data = data;
725 104 : return true;
726 : }
727 :
728 : /**
729 : * @brief Sets the extra data.
730 : *
731 : * @retval true on success.
732 : */
733 18 : bool setExtraData(const std::vector<uint8_t> &extraData)
734 : {
735 18 : m_extraData = extraData;
736 18 : return true;
737 : }
738 :
739 : /**
740 : * @brief Sets the segment alignment
741 : *
742 : * @param[in] alignment : The new segment alignment
743 : */
744 6 : void setSegmentAlignment(const SegmentAlignment &alignment) { m_alignment = alignment; }
745 :
746 : /**
747 : * @brief Sets new codec_data for the segment.
748 : *
749 : * @note Should only be called if the codec data changes
750 : *
751 : * @param[in] codecData The updated codec data for the source
752 : */
753 10 : void setCodecData(const std::shared_ptr<CodecData> &codecData) { m_codecData = codecData; }
754 :
755 : /**
756 : * @brief Sets the encrypted flag.
757 : *
758 : * @param[in] encrypted : Set true to indicated encrypted data.
759 : */
760 22 : void setEncrypted(bool encrypted) { m_encrypted = encrypted; }
761 :
762 : /**
763 : * @brief Sets the media key session id.
764 : *
765 : * @param[in] mksId : the media key session id.
766 : */
767 15 : void setMediaKeySessionId(int32_t mksId) { m_mediaKeySessionId = mksId; }
768 :
769 : /**
770 : * @brief Sets the key id.
771 : *
772 : * @param[in] keyId : The key id.
773 : */
774 14 : void setKeyId(const std::vector<uint8_t> &keyId) { m_keyId = keyId; }
775 :
776 : /**
777 : * @brief Sets the encryption initialisation vector.
778 : *
779 : * @param[in] initVector : The initialisation vector.
780 : */
781 13 : void setInitVector(const std::vector<uint8_t> &initVector) { m_initVector = initVector; }
782 :
783 : /**
784 : * @brief Adds a sub-sample pair to the sub samples.
785 : *
786 : * @param[in] numClearBytes : The number of clear bytes.
787 : * @param[in] numEncryptedBytes : The number of encrypted bytes.
788 : */
789 13 : void addSubSample(size_t numClearBytes, size_t numEncryptedBytes)
790 : {
791 13 : m_subSamples.emplace_back(SubSamplePair{numClearBytes, numEncryptedBytes});
792 : }
793 :
794 : /**
795 : * @brief Sets initWithLast15 value
796 : *
797 : * @param[in] initWithLast15 : initWithLast15 value
798 : */
799 13 : void setInitWithLast15(uint32_t initWithLast15) { m_initWithLast15 = initWithLast15; }
800 :
801 : /**
802 : * @brief Sets the cipher mode for common encryption.
803 : *
804 : * @param[in] cipherMode : Specifies cipher mode uses for this sample.
805 : */
806 11 : void setCipherMode(CipherMode cipherMode) { m_cipherMode = cipherMode; }
807 :
808 : /**
809 : * @brief Sets the crypt & skip byte block for pattern encryption
810 : *
811 : * @param[in] crypt : Crypt byte block value
812 : * @param[in] skip : Skip byte block value
813 : */
814 6 : void setEncryptionPattern(uint32_t crypt, uint32_t skip)
815 : {
816 6 : m_crypt = crypt;
817 6 : m_skip = skip;
818 6 : m_encryptionPatternSet = true;
819 : }
820 :
821 : /**
822 : * @brief Copies the data from other to this.
823 : */
824 : void copy(const MediaSegment &other);
825 : };
826 :
827 : /**
828 : * @brief A class that represents media source audio data
829 : */
830 : class MediaSegmentAudio : public MediaSegment
831 : {
832 : public:
833 : /**
834 : * @brief Default constructor.
835 : *
836 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
837 : * @param[in] timeStamp : The timestamp in nanoseconds.
838 : * @param[in] duration : The duration in nanoseconds.
839 : * @param[in] sampleRate : The sample rate in samples per second.
840 : * @param[in] numberOfChannels : The number of audio channels.
841 : * @param[in] clippingStart : The amount of audio to clip from start of buffer
842 : * @param[in] clippingEnd : The amount of audio to clip from end of buffer
843 : */
844 67 : MediaSegmentAudio(int32_t sourceId = 0, int64_t timeStamp = 0, int64_t duration = 0, int32_t sampleRate = 0,
845 : int32_t numberOfChannels = 0, uint64_t clippingStart = 0, uint64_t clippingEnd = 0)
846 134 : : MediaSegment(sourceId, MediaSourceType::AUDIO, timeStamp, duration), m_sampleRate(sampleRate),
847 67 : m_numberOfChannels(numberOfChannels), m_clippingStart(clippingStart), m_clippingEnd(clippingEnd)
848 : {
849 : }
850 :
851 : /**
852 : * @brief Copy constructor.
853 : */
854 1 : MediaSegmentAudio(const MediaSegmentAudio &other) : MediaSegment(other)
855 : {
856 1 : m_sampleRate = other.m_sampleRate;
857 1 : m_numberOfChannels = other.m_numberOfChannels;
858 : }
859 :
860 : /**
861 : * @brief Makes a shallow copy of the segment
862 : *
863 : * @retval Shallow copy of the segment
864 : */
865 1 : std::unique_ptr<MediaSegment> copy() const override { return std::make_unique<MediaSegmentAudio>(*this); }
866 :
867 : /**
868 : * @brief Return the audio sample rate.
869 : *
870 : * @retval the sample rate in samples per second.
871 : */
872 27 : int32_t getSampleRate() const { return m_sampleRate; }
873 :
874 : /**
875 : * @brief Return the number of audio channels.
876 : *
877 : * @retval the number of channels.
878 : */
879 27 : int32_t getNumberOfChannels() const { return m_numberOfChannels; }
880 :
881 : /**
882 : * @brief Return the amount of audio to clip from start of buffer
883 : *
884 : * @retval the amount of audio to clip from start of buffer
885 : */
886 17 : uint64_t getClippingStart() const { return m_clippingStart; }
887 :
888 : /**
889 : * @brief Return the amount of audio to clip from end of buffer
890 : *
891 : * @retval the amount of audio to clip from end of buffer
892 : */
893 17 : uint64_t getClippingEnd() const { return m_clippingEnd; }
894 :
895 : /**
896 : * @brief Copy assignment operator.
897 : *
898 : * @retval the copy.
899 : */
900 : MediaSegmentAudio &operator=(const MediaSegmentAudio &other)
901 : {
902 : copy(other);
903 : return *this;
904 : }
905 :
906 : protected:
907 : /**
908 : * @brief Copies the data from other to this.
909 : */
910 : void copy(const MediaSegmentAudio &other);
911 :
912 : /**
913 : * @brief The audio sample rate.
914 : */
915 : int32_t m_sampleRate;
916 :
917 : /**
918 : * @brief The number of audio channels.
919 : */
920 : int32_t m_numberOfChannels;
921 :
922 : /**
923 : * @brief The amount of audio to clip from start of buffer
924 : */
925 : uint64_t m_clippingStart;
926 :
927 : /**
928 : * @brief The amount of audio to clip from end of buffer
929 : */
930 : uint64_t m_clippingEnd;
931 : };
932 :
933 : /**
934 : * @brief A class that represents media source video data
935 : */
936 : class MediaSegmentVideo : public MediaSegment
937 : {
938 : public:
939 : /**
940 : * @brief Default constructor.
941 : *
942 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
943 : * @param[in] timeStamp : The timestamp in nanoseconds.
944 : * @param[in] duration : The duration in nanoseconds.
945 : * @param[in] width : The video width in pixels.
946 : * @param[in] height : The video height in pixels.
947 : * @param[in] frameRate : The fractional framerate of the sample.
948 : */
949 36 : MediaSegmentVideo(int32_t sourceId = 0, int64_t timeStamp = 0, int64_t duration = 0,
950 : int32_t width = firebolt::rialto::kUndefinedSize,
951 : int32_t height = firebolt::rialto::kUndefinedSize,
952 : firebolt::rialto::Fraction frameRate = {firebolt::rialto::kUndefinedSize,
953 : firebolt::rialto::kUndefinedSize})
954 72 : : MediaSegment(sourceId, MediaSourceType::VIDEO, timeStamp, duration), m_width(width), m_height(height),
955 36 : m_frameRate(frameRate)
956 : {
957 : }
958 :
959 : /**
960 : * @brief Copy constructor.
961 : */
962 0 : MediaSegmentVideo(const MediaSegmentVideo &other) : MediaSegment(other)
963 : {
964 0 : m_width = other.m_width;
965 0 : m_height = other.m_height;
966 0 : m_frameRate = other.m_frameRate;
967 : }
968 :
969 : /**
970 : * @brief Makes a shallow copy of the segment
971 : *
972 : * @retval Shallow copy of the segment
973 : */
974 0 : std::unique_ptr<MediaSegment> copy() const override { return std::make_unique<MediaSegmentVideo>(*this); }
975 :
976 : /**
977 : * @brief Return the video width.
978 : *
979 : * @retval the video width in pixels.
980 : */
981 27 : int32_t getWidth() const { return m_width; }
982 :
983 : /**
984 : * @brief Return the video height.
985 : *
986 : * @retval the video height in pixels.
987 : */
988 27 : int32_t getHeight() const { return m_height; }
989 :
990 : /**
991 : * @brief Return the video frameRate.
992 : *
993 : * @retval the fractional framerate of the sample.
994 : */
995 26 : firebolt::rialto::Fraction getFrameRate() const { return m_frameRate; }
996 :
997 : /**
998 : * @brief Copy assignment operator.
999 : *
1000 : * @retval the copy.
1001 : */
1002 : MediaSegmentVideo &operator=(const MediaSegmentVideo &other)
1003 : {
1004 : copy(other);
1005 : return *this;
1006 : }
1007 :
1008 : protected:
1009 : /**
1010 : * @brief Copies the data from other to this.
1011 : */
1012 : void copy(const MediaSegmentVideo &other);
1013 :
1014 : /**
1015 : * @brief The video width in pixels.
1016 : */
1017 : int32_t m_width;
1018 :
1019 : /**
1020 : * @brief The video height in pixels.
1021 : */
1022 : int32_t m_height;
1023 :
1024 : /**
1025 : * @brief The fractional framerate of the sample.
1026 : */
1027 : firebolt::rialto::Fraction m_frameRate;
1028 : };
1029 :
1030 : /**
1031 : * @brief A vector that contains one or more media segments.
1032 : */
1033 : typedef std::vector<std::unique_ptr<MediaSegment>> MediaSegmentVector;
1034 :
1035 : /**
1036 : * @brief Returns the media player client.
1037 : *
1038 : * @retval The media player client.
1039 : */
1040 : virtual std::weak_ptr<IMediaPipelineClient> getClient() = 0;
1041 :
1042 : /**
1043 : * @brief Loads the media and backend delegate.
1044 : *
1045 : * This method loads the media and backend appropriate for the media.
1046 : * The media type determines the backend delegate to use to play back
1047 : * the media. The MIME type confirms the type and CODECs for the media.
1048 : * The URL will comprise the media URL for types MediaType::URL and
1049 : * MediaType::HLS. For MediaType::MSE the URL will comprise a blob URL
1050 : * as the data is loaded by the browser.
1051 : *
1052 : * @param[in] type : The media type.
1053 : * @param[in] mimeType : The MIME type.
1054 : * @param[in] url : The URL.
1055 : */
1056 : virtual bool load(MediaType type, const std::string &mimeType, const std::string &url) = 0;
1057 :
1058 : /**
1059 : * @brief Attaches a source stream to the backend.
1060 : *
1061 : * This method is called by Rialto Client to attach a media source stream to
1062 : * the backend. It is only called when Media Source Extensions are
1063 : * being used. I.e. if the MediaType value in load() is
1064 : * MediaType::MSE.
1065 : *
1066 : * @param[in] source : The source.
1067 : *
1068 : * @retval true on success.
1069 : */
1070 : virtual bool attachSource(const std::unique_ptr<MediaSource> &source) = 0;
1071 :
1072 : /**
1073 : * @brief Unattaches a source.
1074 : *
1075 : * This method is called by Rialto Client to detach a media source stream from
1076 : * the backend. It is only called when Media Source Extensions are
1077 : * being used. I.e. if the MediaType value in load() is
1078 : * MediaType::MSE.
1079 : *
1080 : * @param[in] id : The source id. Value should be set to the MediaSource.id returned after attachSource()
1081 : *
1082 : * @retval true on success.
1083 : */
1084 : virtual bool removeSource(int32_t id) = 0;
1085 :
1086 : /**
1087 : * @brief Notifies Rialto Server that all sources were attached
1088 : *
1089 : * This method is called by Rialto Client to notify the RialtoServer
1090 : * that all sources were attached.
1091 : *
1092 : * Must be called, otherwise streaming cannot commence.
1093 : * Can be called only once.
1094 : *
1095 : * @retval true on success.
1096 : */
1097 : virtual bool allSourcesAttached() = 0;
1098 :
1099 : /**
1100 : * @brief Starts playback of the media.
1101 : *
1102 : * This method is considered to be asynchronous and MUST NOT block
1103 : * but should request playback and then return.
1104 : *
1105 : * Once the backend is successfully playing it should notify the
1106 : * media player client of playback state
1107 : * IMediaPipelineClient::PlaybackState::PLAYING.
1108 : *
1109 : * @retval true on success.
1110 : */
1111 : virtual bool play() = 0;
1112 :
1113 : /**
1114 : * @brief Pauses playback of the media.
1115 : *
1116 : * This method is considered to be asynchronous and MUST NOT block
1117 : * but should request the playback pause and then return.
1118 : *
1119 : * Once the backend is successfully playing it should notify the
1120 : * media player client of playback state
1121 : *IMediaPipelineClient::PlaybackState::PAUSED.
1122 : *
1123 : * @retval true on success.
1124 : */
1125 : virtual bool pause() = 0;
1126 :
1127 : /**
1128 : * @brief Stops playback of the media.
1129 : *
1130 : * This method is considered to be asynchronous and MUST NOT block
1131 : * but should request the playback stop and then return.
1132 : *
1133 : * Once the backend is successfully stopped it should notify the
1134 : * media player client of playback state
1135 : * IMediaPipelineClient::PlaybackState::STOPPED.
1136 : *
1137 : * @retval true on success.
1138 : */
1139 : virtual bool stop() = 0;
1140 :
1141 : /**
1142 : * @brief Set the playback rate
1143 : *
1144 : * This method sets the playback rate. The supported playback rates
1145 : * are dependent upon the backend playback method.
1146 : *
1147 : * @param[in] rate : The playback rate.
1148 : *
1149 : * @retval true on success.
1150 : */
1151 : virtual bool setPlaybackRate(double rate) = 0;
1152 :
1153 : /**
1154 : * @brief Set the playback position in nanoseconds.
1155 : *
1156 : * If playback has not started this method sets the start position
1157 : * for playback. If playback has started this method performs a seek.
1158 : *
1159 : * This method is considered to be asynchronous and MUST NOT block
1160 : * but should request the new playback position and then return.
1161 : *
1162 : * Once the backend is seeking it should notify the media player
1163 : * client of playback state
1164 : * IMediaPipelineClient::PlaybackState::SEEKING. When seeking has
1165 : * completed the state IMediaPipelineClient::PlaybackState::SEEK_DONE
1166 : * should be notified followed by
1167 : * IMediaPipelineClient::PlaybackState::PLAYING.
1168 : *
1169 : * @param[in] position : The playback position in nanoseconds.
1170 : *
1171 : * @retval true on success.
1172 : */
1173 : virtual bool setPosition(int64_t position) = 0;
1174 :
1175 : /**
1176 : * @brief Get the playback position in nanoseconds.
1177 : *
1178 : * This method is sychronous, it returns current playback position
1179 : *
1180 : * @param[out] position : The playback position in nanoseconds
1181 : *
1182 : * @retval true on success.
1183 : */
1184 : virtual bool getPosition(int64_t &position) = 0;
1185 :
1186 : /**
1187 : * @brief Get stats for this source.
1188 : *
1189 : * This method is sychronous, it returns dropped frames and rendered frames
1190 : *
1191 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
1192 : * @param[out] renderedFrames : The number of rendered frames
1193 : * @param[out] droppedFrames : The number of dropped frames
1194 : *
1195 : * @retval true on success.
1196 : */
1197 : virtual bool getStats(int32_t sourceId, uint64_t &renderedFrames, uint64_t &droppedFrames) = 0;
1198 :
1199 : /**
1200 : * @brief Sets the "Immediate Output" property for this source.
1201 : *
1202 : * This method is asynchronous, it will set the "Immediate Output" property
1203 : *
1204 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
1205 : * @param[in] immediateOutput : Set immediate output mode on the sink
1206 : *
1207 : * @retval true on success.
1208 : */
1209 : virtual bool setImmediateOutput(int32_t sourceId, bool immediateOutput) = 0;
1210 :
1211 : /**
1212 : * @brief Gets the "Immediate Output" property for this source.
1213 : *
1214 : * This method is sychronous, it gets the "Immediate Output" property
1215 : *
1216 : * @param[in] sourceId : The source id. Value should be get to the MediaSource.id returned after attachSource()
1217 : * @param[out] immediateOutput : Get immediate output mode on the sink
1218 : *
1219 : * @retval true on success.
1220 : */
1221 : virtual bool getImmediateOutput(int32_t sourceId, bool &immediateOutput) = 0;
1222 :
1223 : /**
1224 : * @brief Sets the coordinates of where the video should be displayed.
1225 : *
1226 : * @param[in] x : The x position in pixels.
1227 : * @param[in] y : The y position in pixels.
1228 : * @param[in] width : The width in pixels.
1229 : * @param[in] height : The height in pixels.
1230 : *
1231 : * @retval true on success.
1232 : */
1233 : virtual bool setVideoWindow(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
1234 :
1235 : /**
1236 : * @brief Returns data requested using notifyNeedMediaData().
1237 : *
1238 : * This method is called as a result of calling notifyNeedMediaData() on
1239 : * the media client. The status value indicates the success or
1240 : * otherwise of the request. The client must first call addSegment() for
1241 : * for each media segment to be sent.
1242 : * A status of MediaSourceStatus::OK indicates success and there will
1243 : * be data within the data vector. A status of MediaSourceStatus::EOS
1244 : * indicates success but the end of the stream was reached. Again
1245 : * there will be data in the vector. A status of
1246 : * MediaSourceStatus::ERROR indicates an error occurred and no data
1247 : * was returned.
1248 : *
1249 : *
1250 : * @param[in] status : The status
1251 : * @param[in] needDataRequestId : Need data request id
1252 : */
1253 : virtual bool haveData(MediaSourceStatus status, uint32_t needDataRequestId) = 0;
1254 :
1255 : /**
1256 : * @brief Adds a single segment to Rialto in response to notifyNeedData()
1257 : *
1258 : * This method is should be called by the client as a result of a notifyNeedData()
1259 : * notification. The client should call this API for each segment to be sent in
1260 : * response to the notification and then call haveData() when all segments
1261 : * have been 'added'.
1262 : *
1263 : * If the return code is NO_SPACE the segment has not been accepted but this is
1264 : * not an error. The client should retain the segment until the next notifyNeedData()
1265 : * is received for the source and immediately call haveData() to trigger Rialto
1266 : * to start processing the segments already added.
1267 : *
1268 : * @param[in] needDataRequestId : The status
1269 : * @param[in] mediaSegment : The data returned.
1270 : *
1271 : * @retval status of adding segment
1272 : */
1273 : virtual AddSegmentStatus addSegment(uint32_t needDataRequestId, const std::unique_ptr<MediaSegment> &mediaSegment) = 0;
1274 :
1275 : /**
1276 : * @brief Requests to render a prerolled frame
1277 : */
1278 : virtual bool renderFrame() = 0;
1279 :
1280 : /**
1281 : * @brief Set the target volume level and transition duration with easing type.
1282 : * By default volume is set immediately if duration and type are not set.
1283 : *
1284 : * @param[in] targetVolume : Target volume level (0.0 - 1.0)
1285 : * @param[in] volumeDuration : (Optional) Duration of the volume transition in milliseconds
1286 : * @param[in] easeType : (Optional) Easing type for the volume transition
1287 : *
1288 : * @retval true on success, false otherwise.
1289 : */
1290 : virtual bool setVolume(double targetVolume, uint32_t volumeDuration = 0,
1291 : EaseType easeType = EaseType::EASE_LINEAR) = 0;
1292 :
1293 : /**
1294 : * @brief Get current audio level. Fetches the current volume level for the pipeline.
1295 : *
1296 : * @param[out] currentVolume : Current volume level (range 0.0 - 1.0)
1297 : *
1298 : * @retval true on success, false otherwise.
1299 : */
1300 : virtual bool getVolume(double ¤tVolume) = 0;
1301 :
1302 : /**
1303 : * @brief Set mute status of pipeline.
1304 : *
1305 : * Change mute status of media source
1306 : *
1307 : * @param[in] sourceId Source, which mute status should be changed
1308 : * @param[in] mute Desired mute state, true=muted, false=not muted
1309 : *
1310 : * @retval true on success false otherwise
1311 : */
1312 : virtual bool setMute(int32_t sourceId, bool mute) = 0;
1313 :
1314 : /**
1315 : * @brief Get current mute status of the media source
1316 : *
1317 : * @param[in] sourceId Source, which mute status should be fetched
1318 : * @param[out] mute Current mute state
1319 : *
1320 : * @retval true on success false otherwise
1321 : */
1322 : virtual bool getMute(int32_t sourceId, bool &mute) = 0;
1323 :
1324 : /**
1325 : * @brief Change Text Track Identifier
1326 : *
1327 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
1328 : *
1329 : * @retval true on success false otherwise
1330 : */
1331 : virtual bool setTextTrackIdentifier(const std::string &textTrackIdentifier) = 0;
1332 :
1333 : /**
1334 : * @brief Get Text Track Identifier
1335 : *
1336 : * @param[in] textTrackIdentifier Text track identifier of subtitle stream
1337 : *
1338 : * @retval true on success false otherwise
1339 : */
1340 : virtual bool getTextTrackIdentifier(std::string &textTrackIdentifier) = 0;
1341 :
1342 : /**
1343 : * @brief Set low latency property on the audio sink. Default false.
1344 : *
1345 : * For use with gaming (no audio decoding, no a/v sync).
1346 : *
1347 : * @param[in] lowLatency : The low latency value to set.
1348 : *
1349 : * @retval true on success false otherwise
1350 : */
1351 : virtual bool setLowLatency(bool lowLatency) = 0;
1352 :
1353 : /**
1354 : * @brief Set sync property on the audio sink. Default false.
1355 : *
1356 : * Syncs the stream on the clock.
1357 : *
1358 : * @param[in] sync : The sync value to set.
1359 : *
1360 : * @retval true on success false otherwise
1361 : */
1362 : virtual bool setSync(bool sync) = 0;
1363 :
1364 : /**
1365 : * @brief Get sync property on the audio sink.
1366 : *
1367 : * @param[out] sync : Current sync value.
1368 : *
1369 : * @retval true on success false otherwise
1370 : */
1371 : virtual bool getSync(bool &sync) = 0;
1372 :
1373 : /**
1374 : * @brief Set sync off property on the audio decoder. Default false.
1375 : *
1376 : * Turn on free running audio. Must be set before pipeline is PLAYING state.
1377 : *
1378 : * @param[in] syncOff : The sync off value to set.
1379 : *
1380 : * @retval true on success false otherwise
1381 : */
1382 : virtual bool setSyncOff(bool syncOff) = 0;
1383 :
1384 : /**
1385 : * @brief Set stream sync mode property on the audio decoder or video filter. Default 0.
1386 : *
1387 : * 1 - Frame to decode frame will immediately proceed next frame sync.
1388 : * 0 - Frame decoded with no frame sync.
1389 : *
1390 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
1391 : * @param[in] streamSyncMode : The stream sync mode value to set.
1392 : *
1393 : * @retval true on success false otherwise
1394 : */
1395 : virtual bool setStreamSyncMode(int32_t sourceId, int32_t streamSyncMode) = 0;
1396 :
1397 : /**
1398 : * @brief Get stream sync mode property on the audio decoder.
1399 : *
1400 : * @param[out] streamSyncMode : Current stream sync mode value.
1401 : *
1402 : * @retval true on success false otherwise
1403 : */
1404 : virtual bool getStreamSyncMode(int32_t &streamSyncMode) = 0;
1405 :
1406 : /**
1407 : * @brief Flushes a source.
1408 : *
1409 : * This method is called by Rialto Client to flush out all queued data for a media source stream.
1410 : *
1411 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
1412 : * @param[in] resetTime : True if time should be reset
1413 : *
1414 : * @retval true on success.
1415 : */
1416 : virtual bool flush(int32_t sourceId, bool resetTime) = 0;
1417 :
1418 : /**
1419 : * @brief Set the source position in nanoseconds.
1420 : *
1421 : * This method sets the start position for a source.
1422 : *
1423 : * @param[in] sourceId : The source id. Value should be set to the MediaSource.id returned after attachSource()
1424 : * @param[in] position : The position in nanoseconds.
1425 : * @param[in] resetTime : True if time should be reset
1426 : * @param[in] appliedRate : The applied rate after seek. Default value is 1.0.
1427 : * @param[in] stopPosition : The position of last pushed buffer
1428 : *
1429 : * @retval true on success.
1430 : */
1431 : virtual bool setSourcePosition(int32_t sourceId, int64_t position, bool resetTime = false, double appliedRate = 1.0,
1432 : uint64_t stopPosition = kUndefinedPosition) = 0;
1433 :
1434 : /**
1435 : * @brief Process audio gap
1436 : *
1437 : * This method handles audio gap in order to avoid audio pops during transitions.
1438 : *
1439 : * @param[in] position : Audio pts fade position
1440 : * @param[in] duration : Audio pts fade duration
1441 : * @param[in] discontinuityGap : Audio discontinuity gap
1442 : * @param[in] audioAac : True if audio codec is AAC
1443 : *
1444 : * @retval true on success.
1445 : */
1446 : virtual bool processAudioGap(int64_t position, uint32_t duration, int64_t discontinuityGap, bool audioAac) = 0;
1447 :
1448 : /**
1449 : * @brief Set buffering limit
1450 : *
1451 : * This method enables/disables limit buffering and sets millisecond threshold used.
1452 : * Use kInvalidLimitBuffering to disable limit buffering
1453 : *
1454 : * @param[in] limitBufferingMs : buffering limit in ms
1455 : *
1456 : * @retval true on success.
1457 : */
1458 : virtual bool setBufferingLimit(uint32_t limitBufferingMs) = 0;
1459 :
1460 : /**
1461 : * @brief Get buffering limit
1462 : *
1463 : * This method returns current value of buffering limit in milliseconds
1464 : * Method will return kInvalidLimitBuffering limit buffering is disabled
1465 : *
1466 : * @param[out] limitBufferingMs : buffering limit in ms
1467 : *
1468 : * @retval true on success.
1469 : */
1470 : virtual bool getBufferingLimit(uint32_t &limitBufferingMs) = 0;
1471 :
1472 : /**
1473 : * @brief Enables/disables the buffering option
1474 : *
1475 : * This method enables the buffering option so that BUFFERING messages are
1476 : * emitted based on low-/high-percent thresholds.
1477 : *
1478 : * @param[in] useBuffering : true if buffering option enabled.
1479 : *
1480 : * @retval true on success.
1481 : */
1482 : virtual bool setUseBuffering(bool useBuffering) = 0;
1483 :
1484 : /**
1485 : * @brief Checks, if buffering is enabled
1486 : *
1487 : * This method returns true, if buffering is enabled
1488 : *
1489 : * @param[out] useBuffering : true if buffering option is enabled.
1490 : *
1491 : * @retval true on success.
1492 : */
1493 : virtual bool getUseBuffering(bool &useBuffering) = 0;
1494 :
1495 : /**
1496 : * @brief Switches a source stream.
1497 : *
1498 : * This method is called to switch a media source stream.
1499 : *
1500 : * @param[in] source : The source.
1501 : *
1502 : * @retval true on success.
1503 : */
1504 : virtual bool switchSource(const std::unique_ptr<MediaSource> &source) = 0;
1505 : };
1506 :
1507 : }; // namespace firebolt::rialto
1508 :
1509 : #endif // FIREBOLT_RIALTO_I_MEDIA_PIPELINE_H_
|