2012-12-18 00:49:58 -08: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(WMFReader_h_)
|
|
|
|
#define WMFReader_h_
|
|
|
|
|
|
|
|
#include "WMF.h"
|
|
|
|
#include "MediaDecoderReader.h"
|
2013-05-04 03:12:41 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-05 13:25:17 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "nsRect.h"
|
2012-12-18 00:49:58 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class WMFByteStream;
|
2013-02-15 00:35:48 -08:00
|
|
|
class WMFSourceReaderCallback;
|
2013-05-04 03:12:41 -07:00
|
|
|
class DXVA2Manager;
|
2012-12-18 00:49:58 -08:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
|
2013-08-12 21:49:25 -07:00
|
|
|
// Decoder backend for reading H.264/AAC in MP4/M4A, and MP3 files using
|
|
|
|
// Windows Media Foundation.
|
2012-12-18 00:49:58 -08:00
|
|
|
class WMFReader : public MediaDecoderReader
|
|
|
|
{
|
|
|
|
public:
|
2013-02-01 14:13:23 -08:00
|
|
|
WMFReader(AbstractMediaDecoder* aDecoder);
|
2012-12-18 00:49:58 -08:00
|
|
|
|
|
|
|
virtual ~WMFReader();
|
|
|
|
|
|
|
|
nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
bool DecodeAudioData() MOZ_OVERRIDE;
|
|
|
|
bool DecodeVideoFrame(bool &aKeyframeSkip,
|
|
|
|
int64_t aTimeThreshold) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
bool HasAudio() MOZ_OVERRIDE;
|
|
|
|
bool HasVideo() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
nsresult ReadMetadata(VideoInfo* aInfo,
|
|
|
|
MetadataTags** aTags) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
nsresult Seek(int64_t aTime,
|
|
|
|
int64_t aStartTime,
|
|
|
|
int64_t aEndTime,
|
|
|
|
int64_t aCurrentTime) MOZ_OVERRIDE;
|
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
nsresult GetBuffered(mozilla::dom::TimeRanges* aBuffered,
|
2012-12-18 00:49:58 -08:00
|
|
|
int64_t aStartTime) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
void OnDecodeThreadStart() MOZ_OVERRIDE;
|
|
|
|
void OnDecodeThreadFinish() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2013-02-14 15:54:27 -08:00
|
|
|
HRESULT ConfigureAudioDecoder();
|
|
|
|
HRESULT ConfigureVideoDecoder();
|
2013-01-20 17:38:47 -08:00
|
|
|
HRESULT ConfigureVideoFrameGeometry(IMFMediaType* aMediaType);
|
2013-04-30 03:14:18 -07:00
|
|
|
void GetSupportedAudioCodecs(const GUID** aCodecs, uint32_t* aNumCodecs);
|
2012-12-18 00:49:58 -08:00
|
|
|
|
2013-05-04 03:12:41 -07:00
|
|
|
HRESULT CreateBasicVideoFrame(IMFSample* aSample,
|
|
|
|
int64_t aTimestampUsecs,
|
|
|
|
int64_t aDurationUsecs,
|
|
|
|
int64_t aOffsetBytes,
|
|
|
|
VideoData** aOutVideoData);
|
|
|
|
|
|
|
|
HRESULT CreateD3DVideoFrame(IMFSample* aSample,
|
|
|
|
int64_t aTimestampUsecs,
|
|
|
|
int64_t aDurationUsecs,
|
|
|
|
int64_t aOffsetBytes,
|
|
|
|
VideoData** aOutVideoData);
|
|
|
|
|
2013-08-09 14:56:15 -07:00
|
|
|
// Attempt to initialize DXVA. Returns true on success.
|
|
|
|
bool InitializeDXVA();
|
2013-05-04 03:12:41 -07:00
|
|
|
|
2013-06-10 17:53:26 -07:00
|
|
|
// Notifies the MediaDecoder of the number of bytes we have consumed
|
|
|
|
// since last time we called this. We call this once per call to
|
|
|
|
// DecodeVideoFrame() and/or DecodeAudioData().
|
|
|
|
void NotifyBytesConsumed();
|
|
|
|
|
2012-12-27 06:02:37 -08:00
|
|
|
RefPtr<IMFSourceReader> mSourceReader;
|
2012-12-18 00:49:58 -08:00
|
|
|
RefPtr<WMFByteStream> mByteStream;
|
2013-02-15 00:35:48 -08:00
|
|
|
RefPtr<WMFSourceReaderCallback> mSourceReaderCallback;
|
2013-05-04 03:12:41 -07:00
|
|
|
nsAutoPtr<DXVA2Manager> mDXVA2Manager;
|
2012-12-18 00:49:58 -08:00
|
|
|
|
2013-01-20 17:38:47 -08:00
|
|
|
// Region inside the video frame that makes up the picture. Pixels outside
|
|
|
|
// of this region should not be rendered.
|
|
|
|
nsIntRect mPictureRegion;
|
|
|
|
|
2012-12-18 00:49:58 -08:00
|
|
|
uint32_t mAudioChannels;
|
|
|
|
uint32_t mAudioBytesPerSample;
|
|
|
|
uint32_t mAudioRate;
|
|
|
|
|
2013-05-04 03:12:41 -07:00
|
|
|
uint32_t mVideoWidth;
|
2012-12-18 00:49:58 -08:00
|
|
|
uint32_t mVideoHeight;
|
|
|
|
uint32_t mVideoStride;
|
|
|
|
|
2013-05-30 16:34:52 -07:00
|
|
|
// The offset, in audio frames, at which playback started since the
|
|
|
|
// last discontinuity.
|
|
|
|
int64_t mAudioFrameOffset;
|
|
|
|
// The number of audio frames that we've played since the last
|
|
|
|
// discontinuity.
|
|
|
|
int64_t mAudioFrameSum;
|
|
|
|
// True if we need to re-initialize mAudioFrameOffset and mAudioFrameSum
|
|
|
|
// from the next audio packet we decode. This happens after a seek, since
|
|
|
|
// WMF doesn't mark a stream as having a discontinuity after a seek(0).
|
|
|
|
bool mMustRecaptureAudioPosition;
|
|
|
|
|
2012-12-18 00:49:58 -08:00
|
|
|
bool mHasAudio;
|
|
|
|
bool mHasVideo;
|
2013-08-09 14:56:15 -07:00
|
|
|
bool mUseHwAccel;
|
2013-04-30 03:14:18 -07:00
|
|
|
|
|
|
|
// We can't call WMFDecoder::IsMP3Supported() on non-main threads, since it
|
|
|
|
// checks a pref, so we cache its value in mIsMP3Enabled and use that on
|
|
|
|
// the decode thread.
|
|
|
|
const bool mIsMP3Enabled;
|
2013-06-20 05:57:46 -07:00
|
|
|
|
|
|
|
bool mCOMInitialized;
|
2012-12-18 00:49:58 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|