// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/Array.h" #include "Math/Range.h" #include "Misc/Timespan.h" #include "Misc/Optional.h" #include "Templates/SharedPointer.h" #include "IMediaTimeSource.h" class IMediaAudioSample; class IMediaBinarySample; class IMediaOverlaySample; class IMediaTextureSample; /** * Interface for access to a media player's sample queue. * * @see IMediaCache, IMediaControls, IMediaPlayer, IMediaTracks, IMediaView */ class IMediaSamples { public: //~ The following methods are optional /** * Fetch the next audio sample. * * @param TimeRange The range of present times that the sample is allowed to have. * @param OutSample Will contain the sample if the queue is not empty. * @return true if the returned sample is valid, false otherwise. * @see FetchCaption, FetchMetadata, FetchSubtitle, FetchVideo */ virtual bool FetchAudio(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } virtual bool FetchAudio(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } /** * Fetch the next caption sample. * * @param TimeRange The range of present times that the sample is allowed to have. * @param OutSample Will contain the sample if the queue is not empty. * @return true if the returned sample is valid, false otherwise. * @see FetchAudio, FetchMetadata, FetchSubtitle, FetchVideo */ virtual bool FetchCaption(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } virtual bool FetchCaption(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } /** * Fetch the next metadata sample. * * @param TimeRange The range of present times that the sample is allowed to have. * @param OutSample Will contain the sample if the queue is not empty. * @return true if the returned sample is valid, false otherwise. * @see FetchAudio, FetchCaption, FetchSubtitle, FetchVideo */ virtual bool FetchMetadata(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } virtual bool FetchMetadata(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } /** * Fetch the next subtitle sample. * * @param TimeRange The range of present times that the sample is allowed to have. * @param OutSample Will contain the sample if the queue is not empty. * @return true if the returned sample is valid, false otherwise. * @see FetchAudio, FetchCaption, FetchMetadata, FetchVideo */ virtual bool FetchSubtitle(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } virtual bool FetchSubtitle(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } /** * Fetch the next video sample. * * @param TimeRange The range of present times that the sample is allowed to have. * @param OutSample Will contain the sample if the queue is not empty. * @return true if the returned sample is valid, false otherwise. * @see FetchAudio, FetchCaption, FetchMetadata, FetchSubtitle */ virtual bool FetchVideo(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } virtual bool FetchVideo(TRange TimeRange, TSharedPtr& OutSample) { return false; // override in child classes, if supported } /** Discard any outstanding media samples. */ virtual void FlushSamples() { // override in child classes, if supported } /** Sets the number of samples to be stored in sample container. */ virtual void SetSampleBufferSize(int32 BufferSize) {}; enum class EFetchBestSampleResult { Ok = 0, NoSample, PurgedToEmpty, NotSupported, }; virtual EFetchBestSampleResult FetchBestVideoSampleForTimeRange(const TRange& TimeRange, TSharedPtr& OutSample, bool bReverse, bool bConsistentResult) { return EFetchBestSampleResult::NotSupported; } virtual void SetMinExpectedNextSequenceIndex(TOptional InNextSequenceIndex) { } virtual bool PeekVideoSampleTime(FMediaTimeStamp& TimeStamp) = 0; virtual bool PeekVideoSampleTimeRanges(TArray>& TimeRange) { return false; } virtual bool PeekAudioSampleTimeRanges(TArray>& TimeRange) { return false; } virtual bool DiscardVideoSamples(const TRange& TimeRange, bool bReverse) { return false; } virtual bool DiscardAudioSamples(const TRange& TimeRange, bool bReverse) { return false; } virtual bool DiscardCaptionSamples(const TRange& TimeRange, bool bReverse) { return false; } virtual bool DiscardSubtitleSamples(const TRange& TimeRange, bool bReverse) { return false; } virtual bool DiscardMetadataSamples(const TRange& TimeRange, bool bReverse) { return false; } virtual uint32 PurgeOutdatedVideoSamples(const FMediaTimeStamp& ReferenceTime, bool bReversed, FTimespan MaxAge) { return 0; }; virtual uint32 PurgeOutdatedCaptionSamples(const FMediaTimeStamp& ReferenceTime, bool bReversed, FTimespan MaxAge) { return 0; }; virtual uint32 PurgeOutdatedSubtitleSamples(const FMediaTimeStamp& ReferenceTime, bool bReversed, FTimespan MaxAge) { return 0; }; virtual uint32 PurgeOutdatedMetadataSamples(const FMediaTimeStamp& ReferenceTime, bool bReversed, FTimespan MaxAge) { return 0; }; virtual bool CanReceiveVideoSamples(uint32 Num) const { return true; } virtual bool CanReceiveAudioSamples(uint32 Num) const { return true; } virtual bool CanReceiveSubtitleSamples(uint32 Num) const { return true; } virtual bool CanReceiveCaptionSamples(uint32 Num) const { return true; } virtual bool CanReceiveMetadataSamples(uint32 Num) const { return true; } virtual int32 NumAudioSamples() const { return -1; } virtual int32 NumCaptionSamples() const { return -1; } virtual int32 NumMetadataSamples() const { return -1; } virtual int32 NumSubtitleSamples() const { return -1; } virtual int32 NumVideoSamples() const { return -1; } public: /** Virtual destructor. */ virtual ~IMediaSamples() { } };