1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/wave/WaveReader.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,109 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#if !defined(WaveReader_h_) 1.10 +#define WaveReader_h_ 1.11 + 1.12 +#include "MediaDecoderReader.h" 1.13 +#include "mozilla/dom/HTMLMediaElement.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace dom { 1.17 +class TimeRanges; 1.18 +} 1.19 +} 1.20 + 1.21 +namespace mozilla { 1.22 + 1.23 +class WaveReader : public MediaDecoderReader 1.24 +{ 1.25 +public: 1.26 + WaveReader(AbstractMediaDecoder* aDecoder); 1.27 + ~WaveReader(); 1.28 + 1.29 + virtual nsresult Init(MediaDecoderReader* aCloneDonor); 1.30 + virtual bool DecodeAudioData(); 1.31 + virtual bool DecodeVideoFrame(bool &aKeyframeSkip, 1.32 + int64_t aTimeThreshold); 1.33 + 1.34 + virtual bool HasAudio() 1.35 + { 1.36 + return true; 1.37 + } 1.38 + 1.39 + virtual bool HasVideo() 1.40 + { 1.41 + return false; 1.42 + } 1.43 + 1.44 + virtual nsresult ReadMetadata(MediaInfo* aInfo, 1.45 + MetadataTags** aTags); 1.46 + virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime); 1.47 + virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime); 1.48 + 1.49 + // To seek in a buffered range, we just have to seek the stream. 1.50 + virtual bool IsSeekableInBufferedRanges() { 1.51 + return true; 1.52 + } 1.53 + 1.54 +private: 1.55 + bool ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead = nullptr); 1.56 + bool LoadRIFFChunk(); 1.57 + bool GetNextChunk(uint32_t* aChunk, uint32_t* aChunkSize); 1.58 + bool LoadFormatChunk(uint32_t aChunkSize); 1.59 + bool FindDataOffset(uint32_t aChunkSize); 1.60 + bool LoadListChunk(uint32_t aChunkSize, nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags); 1.61 + bool LoadAllChunks(nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags); 1.62 + 1.63 + // Returns the number of seconds that aBytes represents based on the 1.64 + // current audio parameters. e.g. 176400 bytes is 1 second at 16-bit 1.65 + // stereo 44.1kHz. The time is rounded to the nearest microsecond. 1.66 + double BytesToTime(int64_t aBytes) const; 1.67 + 1.68 + // Returns the number of bytes that aTime represents based on the current 1.69 + // audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo 1.70 + // 44.1kHz. 1.71 + int64_t TimeToBytes(double aTime) const; 1.72 + 1.73 + // Rounds aBytes down to the nearest complete audio frame. Assumes 1.74 + // beginning of byte range is already frame aligned by caller. 1.75 + int64_t RoundDownToFrame(int64_t aBytes) const; 1.76 + int64_t GetDataLength(); 1.77 + int64_t GetPosition(); 1.78 + 1.79 + /* 1.80 + Metadata extracted from the WAVE header. Used to initialize the audio 1.81 + stream, and for byte<->time domain conversions. 1.82 + */ 1.83 + 1.84 + // Number of samples per second. Limited to range [100, 96000] in LoadFormatChunk. 1.85 + uint32_t mSampleRate; 1.86 + 1.87 + // Number of channels. Limited to range [1, 2] in LoadFormatChunk. 1.88 + uint32_t mChannels; 1.89 + 1.90 + // Size of a single audio frame, which includes a sample for each channel 1.91 + // (interleaved). 1.92 + uint32_t mFrameSize; 1.93 + 1.94 + // The sample format of the PCM data. AudioStream::SampleFormat doesn't 1.95 + // support U8. 1.96 + enum { 1.97 + FORMAT_U8, 1.98 + FORMAT_S16 1.99 + } mSampleFormat; 1.100 + 1.101 + // Size of PCM data stored in the WAVE as reported by the data chunk in 1.102 + // the media. 1.103 + int64_t mWaveLength; 1.104 + 1.105 + // Start offset of the PCM data in the media stream. Extends mWaveLength 1.106 + // bytes. 1.107 + int64_t mWavePCMOffset; 1.108 +}; 1.109 + 1.110 +} // namespace mozilla 1.111 + 1.112 +#endif