2013-08-13 08:49:25 +04: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(DirectShowReader_h_)
|
|
|
|
#define DirectShowReader_h_
|
|
|
|
|
2013-09-24 12:41:00 +04:00
|
|
|
#include "windows.h" // HRESULT, DWORD
|
2013-08-13 08:49:25 +04:00
|
|
|
#include "MediaDecoderReader.h"
|
2015-11-25 12:30:09 +03:00
|
|
|
#include "MediaResource.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-09-10 04:45:33 +04:00
|
|
|
#include "MP3FrameParser.h"
|
2013-08-13 08:49:25 +04:00
|
|
|
|
2014-06-19 04:57:51 +04:00
|
|
|
struct IGraphBuilder;
|
|
|
|
struct IMediaControl;
|
|
|
|
struct IMediaSeeking;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class AudioSinkFilter;
|
|
|
|
class SourceFilter;
|
|
|
|
|
|
|
|
// Decoder backend for decoding MP3 using DirectShow. DirectShow operates as
|
|
|
|
// a filter graph. The basic design of the DirectShowReader is that we have
|
|
|
|
// a SourceFilter that wraps the MediaResource that connects to the
|
|
|
|
// MP3 decoder filter. The MP3 decoder filter "pulls" data as it requires it
|
|
|
|
// downstream on its own thread. When the MP3 decoder has produced a block of
|
|
|
|
// decoded samples, its thread calls downstream into our AudioSinkFilter,
|
|
|
|
// passing the decoded buffer in. The AudioSinkFilter inserts the samples into
|
|
|
|
// a SampleSink object. The SampleSink blocks the MP3 decoder's thread until
|
|
|
|
// the decode thread calls DecodeAudioData(), whereupon the SampleSink
|
|
|
|
// releases the decoded samples to the decode thread, and unblocks the MP3
|
|
|
|
// decoder's thread. The MP3 decoder can then request more data from the
|
|
|
|
// SourceFilter, and decode more data. If the decode thread calls
|
|
|
|
// DecodeAudioData() and there's no decoded samples waiting to be extracted
|
|
|
|
// in the SampleSink, the SampleSink blocks the decode thread until the MP3
|
|
|
|
// decoder produces a decoded sample.
|
|
|
|
class DirectShowReader : public MediaDecoderReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DirectShowReader(AbstractMediaDecoder* aDecoder);
|
|
|
|
|
|
|
|
virtual ~DirectShowReader();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool DecodeAudioData() override;
|
2013-08-13 08:49:25 +04:00
|
|
|
bool DecodeVideoFrame(bool &aKeyframeSkip,
|
2015-03-21 19:28:04 +03:00
|
|
|
int64_t aTimeThreshold) override;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
2015-10-21 05:59:56 +03:00
|
|
|
nsresult ReadMetadata(MediaInfo* aInfo,
|
|
|
|
MetadataTags** aTags) override;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SeekPromise>
|
2015-03-21 19:28:04 +03:00
|
|
|
Seek(int64_t aTime, int64_t aEndTime) override;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
2015-06-17 01:37:48 +03:00
|
|
|
protected:
|
2015-11-02 16:28:57 +03:00
|
|
|
void NotifyDataArrivedInternal() override;
|
2014-06-23 14:08:34 +04:00
|
|
|
|
2013-08-13 08:49:25 +04:00
|
|
|
private:
|
2013-09-13 06:33:54 +04:00
|
|
|
// Notifies the filter graph that playback is complete. aStatus is
|
|
|
|
// the code to send to the filter graph. Always returns false, so
|
|
|
|
// that we can just "return Finish()" from DecodeAudioData().
|
2013-08-13 08:49:25 +04:00
|
|
|
bool Finish(HRESULT aStatus);
|
|
|
|
|
2014-11-05 03:32:26 +03:00
|
|
|
nsresult SeekInternal(int64_t aTime);
|
|
|
|
|
2013-08-13 08:49:25 +04:00
|
|
|
// DirectShow filter graph, and associated playback and seeking
|
|
|
|
// control interfaces.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IGraphBuilder> mGraph;
|
|
|
|
RefPtr<IMediaControl> mControl;
|
|
|
|
RefPtr<IMediaSeeking> mMediaSeeking;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
|
|
|
// Wraps the MediaResource, and feeds undecoded data into the filter graph.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceFilter> mSourceFilter;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
|
|
|
// Sits at the end of the graph, removing decoded samples from the graph.
|
|
|
|
// The graph will block while this is blocked, i.e. it will pause decoding.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioSinkFilter> mAudioSinkFilter;
|
2013-08-13 08:49:25 +04:00
|
|
|
|
2013-09-10 04:45:33 +04:00
|
|
|
// Some MP3s are variable bitrate, so DirectShow's duration estimation
|
|
|
|
// can make its duration estimation based on the wrong bitrate. So we parse
|
|
|
|
// the MP3 frames to get a more accuate estimate of the duration.
|
|
|
|
MP3FrameParser mMP3FrameParser;
|
|
|
|
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Used to add/remove the filter graph to the Running Object Table. You can
|
|
|
|
// connect GraphEdit/GraphStudio to the graph to observe and/or debug its
|
|
|
|
// topology and state.
|
|
|
|
DWORD mRotRegister;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Number of channels in the audio stream.
|
|
|
|
uint32_t mNumChannels;
|
|
|
|
|
|
|
|
// Samples per second in the audio stream.
|
|
|
|
uint32_t mAudioRate;
|
|
|
|
|
|
|
|
// Number of bytes per sample. Can be either 1 or 2.
|
|
|
|
uint32_t mBytesPerSample;
|
2013-09-10 04:45:33 +04:00
|
|
|
|
|
|
|
// Duration of the stream, in microseconds.
|
|
|
|
int64_t mDuration;
|
2015-09-29 10:29:44 +03:00
|
|
|
|
2015-11-25 12:30:09 +03:00
|
|
|
MediaByteRangeSet mLastCachedRanges;
|
2013-08-13 08:49:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|