2016-03-31 11:32:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-07-27 09:49:57 +03:00
|
|
|
#ifndef ReaderProxy_h_
|
|
|
|
#define ReaderProxy_h_
|
2016-03-31 11:32:03 +03:00
|
|
|
|
|
|
|
#include "mozilla/AbstractThread.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2016-07-07 09:44:53 +03:00
|
|
|
#include "mozilla/Variant.h"
|
2016-03-31 11:32:03 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
|
2016-06-14 06:22:45 +03:00
|
|
|
#include "MediaEventSource.h"
|
2017-07-19 12:34:05 +03:00
|
|
|
#include "MediaFormatReader.h"
|
2016-03-31 11:32:03 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
2017-07-19 12:01:32 +03:00
|
|
|
* A wrapper around MediaFormatReader to offset the timestamps of Audio/Video
|
2016-03-31 11:32:03 +03:00
|
|
|
* samples by the start time to ensure MDSM can always assume zero start time.
|
|
|
|
* It also adjusts the seek target passed to Seek() to ensure correct seek time
|
|
|
|
* is passed to the underlying reader.
|
|
|
|
*/
|
2017-07-27 09:49:57 +03:00
|
|
|
class ReaderProxy
|
|
|
|
{
|
2017-07-19 12:34:05 +03:00
|
|
|
using MetadataPromise = MediaFormatReader::MetadataPromise;
|
|
|
|
using AudioDataPromise = MediaFormatReader::AudioDataPromise;
|
|
|
|
using VideoDataPromise = MediaFormatReader::VideoDataPromise;
|
|
|
|
using SeekPromise = MediaFormatReader::SeekPromise;
|
|
|
|
using WaitForDataPromise = MediaFormatReader::WaitForDataPromise;
|
|
|
|
using TrackSet = MediaFormatReader::TrackSet;
|
2017-07-27 09:49:57 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ReaderProxy);
|
2016-03-31 11:32:03 +03:00
|
|
|
|
|
|
|
public:
|
2017-07-27 09:49:57 +03:00
|
|
|
ReaderProxy(AbstractThread* aOwnerThread, MediaFormatReader* aReader);
|
2016-03-31 11:32:03 +03:00
|
|
|
|
|
|
|
media::TimeUnit StartTime() const;
|
|
|
|
RefPtr<MetadataPromise> ReadMetadata();
|
2016-04-27 09:50:23 +03:00
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<AudioDataPromise> RequestAudioData();
|
2016-12-20 08:17:05 +03:00
|
|
|
|
2017-03-22 06:28:33 +03:00
|
|
|
RefPtr<VideoDataPromise>
|
2017-06-19 05:45:55 +03:00
|
|
|
RequestVideoData(const media::TimeUnit& aTimeThreshold);
|
2016-04-27 09:50:23 +03:00
|
|
|
|
2016-12-20 09:31:29 +03:00
|
|
|
RefPtr<WaitForDataPromise> WaitForData(MediaData::Type aType);
|
2016-04-27 09:50:23 +03:00
|
|
|
|
2016-11-29 17:42:50 +03:00
|
|
|
RefPtr<SeekPromise> Seek(const SeekTarget& aTarget);
|
2016-04-19 11:14:30 +03:00
|
|
|
RefPtr<ShutdownPromise> Shutdown();
|
|
|
|
|
2016-08-17 10:03:30 +03:00
|
|
|
void ReleaseResources();
|
2016-05-31 07:32:37 +03:00
|
|
|
void ResetDecode(TrackSet aTracks);
|
2016-04-19 11:14:30 +03:00
|
|
|
|
|
|
|
nsresult Init() { return mReader->Init(); }
|
2016-04-19 11:14:33 +03:00
|
|
|
bool UseBufferingHeuristics() const { return mReader->UseBufferingHeuristics(); }
|
2016-04-19 11:14:30 +03:00
|
|
|
|
|
|
|
bool VideoIsHardwareAccelerated() const {
|
|
|
|
return mReader->VideoIsHardwareAccelerated();
|
|
|
|
}
|
|
|
|
TimedMetadataEventSource& TimedMetadataEvent() {
|
|
|
|
return mReader->TimedMetadataEvent();
|
|
|
|
}
|
2016-04-20 09:45:40 +03:00
|
|
|
MediaEventSource<void>& OnMediaNotSeekable() {
|
|
|
|
return mReader->OnMediaNotSeekable();
|
|
|
|
}
|
2016-04-19 11:14:30 +03:00
|
|
|
size_t SizeOfAudioQueueInFrames() const {
|
|
|
|
return mReader->SizeOfAudioQueueInFrames();
|
|
|
|
}
|
|
|
|
size_t SizeOfVideoQueueInFrames() const {
|
|
|
|
return mReader->SizeOfVideoQueueInFrames();
|
|
|
|
}
|
|
|
|
void ReadUpdatedMetadata(MediaInfo* aInfo) {
|
|
|
|
mReader->ReadUpdatedMetadata(aInfo);
|
|
|
|
}
|
|
|
|
AbstractCanonical<media::TimeIntervals>* CanonicalBuffered() {
|
|
|
|
return mReader->CanonicalBuffered();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCDMProxy(CDMProxy* aProxy) { mReader->SetCDMProxy(aProxy); }
|
2016-03-31 11:32:03 +03:00
|
|
|
|
2016-07-29 09:51:18 +03:00
|
|
|
void SetVideoBlankDecode(bool aIsBlankDecode);
|
|
|
|
|
2017-07-06 06:45:02 +03:00
|
|
|
void SetCanonicalDuration(
|
|
|
|
AbstractCanonical<media::NullableTimeUnit>* aCanonical);
|
|
|
|
|
2017-11-10 07:06:12 +03:00
|
|
|
void SetSeamlessLoopingEnabled(bool aEnabled);
|
|
|
|
|
2017-11-24 05:28:42 +03:00
|
|
|
void AdjustByLooping(media::TimeUnit& aTime);
|
|
|
|
|
2016-03-31 11:32:03 +03:00
|
|
|
private:
|
2017-07-27 09:49:57 +03:00
|
|
|
~ReaderProxy();
|
2017-05-18 05:20:44 +03:00
|
|
|
RefPtr<MetadataPromise> OnMetadataRead(MetadataHolder&& aMetadata);
|
2017-05-09 18:31:32 +03:00
|
|
|
RefPtr<MetadataPromise> OnMetadataNotRead(const MediaResult& aError);
|
2017-07-06 06:45:02 +03:00
|
|
|
void UpdateDuration();
|
2017-11-10 08:50:38 +03:00
|
|
|
RefPtr<SeekPromise> SeekInternal(const SeekTarget& aTarget);
|
2016-05-19 14:02:20 +03:00
|
|
|
|
2017-11-10 06:19:04 +03:00
|
|
|
RefPtr<ReaderProxy::AudioDataPromise> OnAudioDataRequestCompleted(
|
|
|
|
RefPtr<AudioData> aAudio);
|
|
|
|
RefPtr<ReaderProxy::AudioDataPromise> OnAudioDataRequestFailed(
|
|
|
|
const MediaResult& aError);
|
|
|
|
|
2016-03-31 11:32:03 +03:00
|
|
|
const RefPtr<AbstractThread> mOwnerThread;
|
2017-07-19 12:01:32 +03:00
|
|
|
const RefPtr<MediaFormatReader> mReader;
|
2016-03-31 11:32:03 +03:00
|
|
|
|
|
|
|
bool mShutdown = false;
|
2016-10-14 14:10:24 +03:00
|
|
|
Maybe<media::TimeUnit> mStartTime;
|
2017-07-06 06:45:02 +03:00
|
|
|
|
|
|
|
// State-watching manager.
|
2017-07-27 09:49:57 +03:00
|
|
|
WatchManager<ReaderProxy> mWatchManager;
|
2017-07-06 06:45:02 +03:00
|
|
|
|
|
|
|
// Duration, mirrored from the state machine task queue.
|
|
|
|
Mirror<media::NullableTimeUnit> mDuration;
|
2017-11-10 07:06:12 +03:00
|
|
|
|
2017-11-10 08:50:38 +03:00
|
|
|
// The total duration of audio looping in previous rounds.
|
|
|
|
media::TimeUnit mLoopingOffset = media::TimeUnit::Zero();
|
|
|
|
// To keep tracking the latest time of decoded audio data.
|
|
|
|
media::TimeUnit mLastAudioEndTime = media::TimeUnit::Zero();
|
2017-11-24 05:28:42 +03:00
|
|
|
// The duration of the audio track.
|
|
|
|
media::TimeUnit mAudioDuration = media::TimeUnit::Invalid();
|
2017-11-10 08:50:38 +03:00
|
|
|
|
2017-11-22 06:17:09 +03:00
|
|
|
// To prevent seamless looping while seeking.
|
|
|
|
bool mSeamlessLoopingBlocked;
|
2017-11-10 07:06:12 +03:00
|
|
|
// Indicates whether we should loop the media.
|
|
|
|
bool mSeamlessLoopingEnabled;
|
2016-03-31 11:32:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-07-27 09:49:57 +03:00
|
|
|
#endif // ReaderProxy_h_
|