content/media/wave/WaveReader.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 #if !defined(WaveReader_h_)
michael@0 7 #define WaveReader_h_
michael@0 8
michael@0 9 #include "MediaDecoderReader.h"
michael@0 10 #include "mozilla/dom/HTMLMediaElement.h"
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace dom {
michael@0 14 class TimeRanges;
michael@0 15 }
michael@0 16 }
michael@0 17
michael@0 18 namespace mozilla {
michael@0 19
michael@0 20 class WaveReader : public MediaDecoderReader
michael@0 21 {
michael@0 22 public:
michael@0 23 WaveReader(AbstractMediaDecoder* aDecoder);
michael@0 24 ~WaveReader();
michael@0 25
michael@0 26 virtual nsresult Init(MediaDecoderReader* aCloneDonor);
michael@0 27 virtual bool DecodeAudioData();
michael@0 28 virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
michael@0 29 int64_t aTimeThreshold);
michael@0 30
michael@0 31 virtual bool HasAudio()
michael@0 32 {
michael@0 33 return true;
michael@0 34 }
michael@0 35
michael@0 36 virtual bool HasVideo()
michael@0 37 {
michael@0 38 return false;
michael@0 39 }
michael@0 40
michael@0 41 virtual nsresult ReadMetadata(MediaInfo* aInfo,
michael@0 42 MetadataTags** aTags);
michael@0 43 virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
michael@0 44 virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime);
michael@0 45
michael@0 46 // To seek in a buffered range, we just have to seek the stream.
michael@0 47 virtual bool IsSeekableInBufferedRanges() {
michael@0 48 return true;
michael@0 49 }
michael@0 50
michael@0 51 private:
michael@0 52 bool ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead = nullptr);
michael@0 53 bool LoadRIFFChunk();
michael@0 54 bool GetNextChunk(uint32_t* aChunk, uint32_t* aChunkSize);
michael@0 55 bool LoadFormatChunk(uint32_t aChunkSize);
michael@0 56 bool FindDataOffset(uint32_t aChunkSize);
michael@0 57 bool LoadListChunk(uint32_t aChunkSize, nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
michael@0 58 bool LoadAllChunks(nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
michael@0 59
michael@0 60 // Returns the number of seconds that aBytes represents based on the
michael@0 61 // current audio parameters. e.g. 176400 bytes is 1 second at 16-bit
michael@0 62 // stereo 44.1kHz. The time is rounded to the nearest microsecond.
michael@0 63 double BytesToTime(int64_t aBytes) const;
michael@0 64
michael@0 65 // Returns the number of bytes that aTime represents based on the current
michael@0 66 // audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo
michael@0 67 // 44.1kHz.
michael@0 68 int64_t TimeToBytes(double aTime) const;
michael@0 69
michael@0 70 // Rounds aBytes down to the nearest complete audio frame. Assumes
michael@0 71 // beginning of byte range is already frame aligned by caller.
michael@0 72 int64_t RoundDownToFrame(int64_t aBytes) const;
michael@0 73 int64_t GetDataLength();
michael@0 74 int64_t GetPosition();
michael@0 75
michael@0 76 /*
michael@0 77 Metadata extracted from the WAVE header. Used to initialize the audio
michael@0 78 stream, and for byte<->time domain conversions.
michael@0 79 */
michael@0 80
michael@0 81 // Number of samples per second. Limited to range [100, 96000] in LoadFormatChunk.
michael@0 82 uint32_t mSampleRate;
michael@0 83
michael@0 84 // Number of channels. Limited to range [1, 2] in LoadFormatChunk.
michael@0 85 uint32_t mChannels;
michael@0 86
michael@0 87 // Size of a single audio frame, which includes a sample for each channel
michael@0 88 // (interleaved).
michael@0 89 uint32_t mFrameSize;
michael@0 90
michael@0 91 // The sample format of the PCM data. AudioStream::SampleFormat doesn't
michael@0 92 // support U8.
michael@0 93 enum {
michael@0 94 FORMAT_U8,
michael@0 95 FORMAT_S16
michael@0 96 } mSampleFormat;
michael@0 97
michael@0 98 // Size of PCM data stored in the WAVE as reported by the data chunk in
michael@0 99 // the media.
michael@0 100 int64_t mWaveLength;
michael@0 101
michael@0 102 // Start offset of the PCM data in the media stream. Extends mWaveLength
michael@0 103 // bytes.
michael@0 104 int64_t mWavePCMOffset;
michael@0 105 };
michael@0 106
michael@0 107 } // namespace mozilla
michael@0 108
michael@0 109 #endif

mercurial