content/media/directshow/DirectShowReader.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #if !defined(DirectShowReader_h_)
michael@0 8 #define DirectShowReader_h_
michael@0 9
michael@0 10 #include "windows.h" // HRESULT, DWORD
michael@0 11 #include "MediaDecoderReader.h"
michael@0 12 #include "mozilla/RefPtr.h"
michael@0 13 #include "MP3FrameParser.h"
michael@0 14
michael@0 15 class IGraphBuilder;
michael@0 16 class IMediaControl;
michael@0 17 class IMediaSeeking;
michael@0 18 class IMediaEventEx;
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21
michael@0 22 class AudioSinkFilter;
michael@0 23 class SourceFilter;
michael@0 24
michael@0 25 namespace dom {
michael@0 26 class TimeRanges;
michael@0 27 }
michael@0 28
michael@0 29 // Decoder backend for decoding MP3 using DirectShow. DirectShow operates as
michael@0 30 // a filter graph. The basic design of the DirectShowReader is that we have
michael@0 31 // a SourceFilter that wraps the MediaResource that connects to the
michael@0 32 // MP3 decoder filter. The MP3 decoder filter "pulls" data as it requires it
michael@0 33 // downstream on its own thread. When the MP3 decoder has produced a block of
michael@0 34 // decoded samples, its thread calls downstream into our AudioSinkFilter,
michael@0 35 // passing the decoded buffer in. The AudioSinkFilter inserts the samples into
michael@0 36 // a SampleSink object. The SampleSink blocks the MP3 decoder's thread until
michael@0 37 // the decode thread calls DecodeAudioData(), whereupon the SampleSink
michael@0 38 // releases the decoded samples to the decode thread, and unblocks the MP3
michael@0 39 // decoder's thread. The MP3 decoder can then request more data from the
michael@0 40 // SourceFilter, and decode more data. If the decode thread calls
michael@0 41 // DecodeAudioData() and there's no decoded samples waiting to be extracted
michael@0 42 // in the SampleSink, the SampleSink blocks the decode thread until the MP3
michael@0 43 // decoder produces a decoded sample.
michael@0 44 class DirectShowReader : public MediaDecoderReader
michael@0 45 {
michael@0 46 public:
michael@0 47 DirectShowReader(AbstractMediaDecoder* aDecoder);
michael@0 48
michael@0 49 virtual ~DirectShowReader();
michael@0 50
michael@0 51 nsresult Init(MediaDecoderReader* aCloneDonor) MOZ_OVERRIDE;
michael@0 52
michael@0 53 bool DecodeAudioData() MOZ_OVERRIDE;
michael@0 54 bool DecodeVideoFrame(bool &aKeyframeSkip,
michael@0 55 int64_t aTimeThreshold) MOZ_OVERRIDE;
michael@0 56
michael@0 57 bool HasAudio() MOZ_OVERRIDE;
michael@0 58 bool HasVideo() MOZ_OVERRIDE;
michael@0 59
michael@0 60 nsresult ReadMetadata(MediaInfo* aInfo,
michael@0 61 MetadataTags** aTags) MOZ_OVERRIDE;
michael@0 62
michael@0 63 nsresult Seek(int64_t aTime,
michael@0 64 int64_t aStartTime,
michael@0 65 int64_t aEndTime,
michael@0 66 int64_t aCurrentTime) MOZ_OVERRIDE;
michael@0 67
michael@0 68 void NotifyDataArrived(const char* aBuffer,
michael@0 69 uint32_t aLength,
michael@0 70 int64_t aOffset) MOZ_OVERRIDE;
michael@0 71
michael@0 72 private:
michael@0 73
michael@0 74 // Notifies the filter graph that playback is complete. aStatus is
michael@0 75 // the code to send to the filter graph. Always returns false, so
michael@0 76 // that we can just "return Finish()" from DecodeAudioData().
michael@0 77 bool Finish(HRESULT aStatus);
michael@0 78
michael@0 79 // DirectShow filter graph, and associated playback and seeking
michael@0 80 // control interfaces.
michael@0 81 RefPtr<IGraphBuilder> mGraph;
michael@0 82 RefPtr<IMediaControl> mControl;
michael@0 83 RefPtr<IMediaSeeking> mMediaSeeking;
michael@0 84
michael@0 85 // Wraps the MediaResource, and feeds undecoded data into the filter graph.
michael@0 86 RefPtr<SourceFilter> mSourceFilter;
michael@0 87
michael@0 88 // Sits at the end of the graph, removing decoded samples from the graph.
michael@0 89 // The graph will block while this is blocked, i.e. it will pause decoding.
michael@0 90 RefPtr<AudioSinkFilter> mAudioSinkFilter;
michael@0 91
michael@0 92 // Some MP3s are variable bitrate, so DirectShow's duration estimation
michael@0 93 // can make its duration estimation based on the wrong bitrate. So we parse
michael@0 94 // the MP3 frames to get a more accuate estimate of the duration.
michael@0 95 MP3FrameParser mMP3FrameParser;
michael@0 96
michael@0 97 #ifdef DEBUG
michael@0 98 // Used to add/remove the filter graph to the Running Object Table. You can
michael@0 99 // connect GraphEdit/GraphStudio to the graph to observe and/or debug its
michael@0 100 // topology and state.
michael@0 101 DWORD mRotRegister;
michael@0 102 #endif
michael@0 103
michael@0 104 // Number of channels in the audio stream.
michael@0 105 uint32_t mNumChannels;
michael@0 106
michael@0 107 // Samples per second in the audio stream.
michael@0 108 uint32_t mAudioRate;
michael@0 109
michael@0 110 // Number of bytes per sample. Can be either 1 or 2.
michael@0 111 uint32_t mBytesPerSample;
michael@0 112
michael@0 113 // Duration of the stream, in microseconds.
michael@0 114 int64_t mDuration;
michael@0 115 };
michael@0 116
michael@0 117 } // namespace mozilla
michael@0 118
michael@0 119 #endif

mercurial