2013-11-20 21:04:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#if !defined(MP4Reader_h_)
|
|
|
|
#define MP4Reader_h_
|
|
|
|
|
|
|
|
#include "MediaDecoderReader.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "PlatformDecoderModule.h"
|
|
|
|
#include "mp4_demuxer/mp4_demuxer.h"
|
2014-02-05 01:29:28 +00:00
|
|
|
#include "MediaTaskQueue.h"
|
2014-07-30 06:53:34 +00:00
|
|
|
#include "mozilla/CDMProxy.h"
|
2013-11-20 21:04:33 +00:00
|
|
|
|
|
|
|
#include <deque>
|
Bug 959440 - Various cleanups in MP4Reader. r=kinetik
Change PlatformDecoderModule::Create*Decoder() to take an
mp4_demuxer::{Audio,Video}DecoderConfig parameter, instead of enumerating all
parameters. This means the platform decoders can have more data if need be,
like the AACAudioConfig.
Change MediaDataDecoder::Input() to take an nsAutoPtr<MP4Sample>&. The sample
will be deleted by the caller (MP4Reader) if Input() returns DECODE_STATUS_OK,
but if the MediaDataDecoder wants to assume responsibility of the
lifecycle of the sample (say to enqueue it), it can forget() on the
nsAutoPtr& passed in and assume responsibility.
Call PlatformDecoderModule::Create() on the decode thread. This is a step
towards making these classes decode-thread only.
Add PlatformDecoderModule::Init(), which caches the pref's we need, since
PlatformDecoderModule::Create() is no longer called on the main thread, we can
no longer access them in there.
Add Init() method to MediaDataDecoder interface. This is so that we can call
MediaDataDecoder::Shutdown() to unblock the initialization of a decoder, if
that init needs to block.
Pass LayersBackend type to WMFVideoDecoder, so it knows whether to init DXVA.
2014-01-15 03:13:54 +00:00
|
|
|
#include "mozilla/Monitor.h"
|
2013-11-20 21:04:33 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::deque<mp4_demuxer::MP4Sample*> MP4SampleQueue;
|
|
|
|
|
|
|
|
class MP4Stream;
|
|
|
|
|
|
|
|
class MP4Reader : public MediaDecoderReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MP4Reader(AbstractMediaDecoder* aDecoder);
|
|
|
|
|
|
|
|
virtual ~MP4Reader();
|
|
|
|
|
|
|
|
virtual nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool DecodeAudioData() MOZ_OVERRIDE;
|
|
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
|
|
|
|
int64_t aTimeThreshold) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool HasAudio() MOZ_OVERRIDE;
|
|
|
|
virtual bool HasVideo() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult ReadMetadata(MediaInfo* aInfo,
|
|
|
|
MetadataTags** aTags) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult Seek(int64_t aTime,
|
|
|
|
int64_t aStartTime,
|
|
|
|
int64_t aEndTime,
|
|
|
|
int64_t aCurrentTime) MOZ_OVERRIDE;
|
2014-06-23 10:08:34 +00:00
|
|
|
|
|
|
|
virtual bool IsMediaSeekable() MOZ_OVERRIDE;
|
|
|
|
|
2014-06-02 15:38:04 +00:00
|
|
|
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered,
|
|
|
|
int64_t aStartTime) MOZ_OVERRIDE;
|
|
|
|
|
2014-07-30 06:53:34 +00:00
|
|
|
virtual bool IsWaitingMediaResources() MOZ_OVERRIDE;
|
|
|
|
|
2014-02-05 01:29:28 +00:00
|
|
|
private:
|
2013-11-20 21:04:33 +00:00
|
|
|
|
2014-07-30 06:53:34 +00:00
|
|
|
void ExtractCryptoInitData(nsTArray<uint8_t>& aInitData);
|
|
|
|
|
2014-02-05 01:29:28 +00:00
|
|
|
// Destroys all decoder resources.
|
|
|
|
void Shutdown();
|
2013-11-20 21:04:33 +00:00
|
|
|
|
2013-11-27 22:12:22 +00:00
|
|
|
// Initializes mLayersBackendType if possible.
|
|
|
|
void InitLayersBackendType();
|
2013-11-20 21:04:33 +00:00
|
|
|
|
|
|
|
// Blocks until the demuxer produces an sample of specified type.
|
|
|
|
// Returns nullptr on error on EOS. Caller must delete sample.
|
|
|
|
mp4_demuxer::MP4Sample* PopSample(mp4_demuxer::TrackType aTrack);
|
|
|
|
|
|
|
|
bool SkipVideoDemuxToNextKeyFrame(int64_t aTimeThreshold, uint32_t& parsed);
|
|
|
|
|
2014-02-05 01:29:28 +00:00
|
|
|
void Output(mp4_demuxer::TrackType aType, MediaData* aSample);
|
|
|
|
void InputExhausted(mp4_demuxer::TrackType aTrack);
|
|
|
|
void Error(mp4_demuxer::TrackType aTrack);
|
|
|
|
bool Decode(mp4_demuxer::TrackType aTrack);
|
|
|
|
void Flush(mp4_demuxer::TrackType aTrack);
|
2014-07-25 02:57:25 +00:00
|
|
|
void DrainComplete(mp4_demuxer::TrackType aTrack);
|
2014-02-05 01:29:28 +00:00
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
nsAutoPtr<mp4_demuxer::MP4Demuxer> mDemuxer;
|
|
|
|
nsAutoPtr<PlatformDecoderModule> mPlatform;
|
|
|
|
|
2014-02-05 01:29:28 +00:00
|
|
|
class DecoderCallback : public MediaDataDecoderCallback {
|
|
|
|
public:
|
|
|
|
DecoderCallback(MP4Reader* aReader,
|
|
|
|
mp4_demuxer::TrackType aType)
|
|
|
|
: mReader(aReader)
|
|
|
|
, mType(aType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual void Output(MediaData* aSample) MOZ_OVERRIDE {
|
|
|
|
mReader->Output(mType, aSample);
|
|
|
|
}
|
|
|
|
virtual void InputExhausted() MOZ_OVERRIDE {
|
|
|
|
mReader->InputExhausted(mType);
|
|
|
|
}
|
|
|
|
virtual void Error() MOZ_OVERRIDE {
|
|
|
|
mReader->Error(mType);
|
|
|
|
}
|
2014-07-25 02:57:25 +00:00
|
|
|
virtual void DrainComplete() MOZ_OVERRIDE {
|
|
|
|
mReader->DrainComplete(mType);
|
|
|
|
}
|
2014-02-05 01:29:28 +00:00
|
|
|
private:
|
|
|
|
MP4Reader* mReader;
|
|
|
|
mp4_demuxer::TrackType mType;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DecoderData {
|
|
|
|
DecoderData(const char* aMonitorName,
|
|
|
|
uint32_t aDecodeAhead)
|
|
|
|
: mMonitor(aMonitorName)
|
|
|
|
, mNumSamplesInput(0)
|
|
|
|
, mNumSamplesOutput(0)
|
|
|
|
, mDecodeAhead(aDecodeAhead)
|
|
|
|
, mActive(false)
|
|
|
|
, mInputExhausted(false)
|
|
|
|
, mError(false)
|
|
|
|
, mIsFlushing(false)
|
2014-07-25 02:57:25 +00:00
|
|
|
, mDrainComplete(false)
|
2014-02-05 01:29:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// The platform decoder.
|
|
|
|
RefPtr<MediaDataDecoder> mDecoder;
|
|
|
|
// TaskQueue on which decoder can choose to decode.
|
|
|
|
// Only non-null up until the decoder is created.
|
|
|
|
RefPtr<MediaTaskQueue> mTaskQueue;
|
|
|
|
// Callback that receives output and error notifications from the decoder.
|
|
|
|
nsAutoPtr<DecoderCallback> mCallback;
|
|
|
|
// Monitor that protects all non-threadsafe state; the primitives
|
|
|
|
// that follow.
|
|
|
|
Monitor mMonitor;
|
|
|
|
uint64_t mNumSamplesInput;
|
|
|
|
uint64_t mNumSamplesOutput;
|
|
|
|
uint32_t mDecodeAhead;
|
|
|
|
// Whether this stream exists in the media.
|
|
|
|
bool mActive;
|
|
|
|
bool mInputExhausted;
|
|
|
|
bool mError;
|
|
|
|
bool mIsFlushing;
|
2014-07-25 02:57:25 +00:00
|
|
|
bool mDrainComplete;
|
2014-02-05 01:29:28 +00:00
|
|
|
};
|
|
|
|
DecoderData mAudio;
|
|
|
|
DecoderData mVideo;
|
2014-07-30 06:53:34 +00:00
|
|
|
// Queued samples extracted by the demuxer, but not yet sent to the platform
|
2014-05-22 02:42:39 +00:00
|
|
|
// decoder.
|
|
|
|
nsAutoPtr<mp4_demuxer::MP4Sample> mQueuedVideoSample;
|
2014-02-05 01:29:28 +00:00
|
|
|
|
|
|
|
// The last number of decoded output frames that we've reported to
|
|
|
|
// MediaDecoder::NotifyDecoded(). We diff the number of output video
|
|
|
|
// frames every time that DecodeVideoData() is called, and report the
|
|
|
|
// delta there.
|
|
|
|
uint64_t mLastReportedNumDecodedFrames;
|
|
|
|
|
|
|
|
DecoderData& GetDecoderData(mp4_demuxer::TrackType aTrack);
|
|
|
|
MediaDataDecoder* Decoder(mp4_demuxer::TrackType aTrack);
|
2013-11-20 21:04:33 +00:00
|
|
|
|
|
|
|
layers::LayersBackend mLayersBackendType;
|
|
|
|
|
2014-07-30 06:53:34 +00:00
|
|
|
nsTArray<nsTArray<uint8_t>> mInitDataEncountered;
|
|
|
|
|
|
|
|
// True if we've read the streams' metadata.
|
|
|
|
bool mDemuxerInitialized;
|
|
|
|
|
|
|
|
// Synchronized by decoder monitor.
|
|
|
|
bool mIsEncrypted;
|
2013-11-20 21:04:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|