michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #if !defined(WaveReader_h_) michael@0: #define WaveReader_h_ michael@0: michael@0: #include "MediaDecoderReader.h" michael@0: #include "mozilla/dom/HTMLMediaElement.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class TimeRanges; michael@0: } michael@0: } michael@0: michael@0: namespace mozilla { michael@0: michael@0: class WaveReader : public MediaDecoderReader michael@0: { michael@0: public: michael@0: WaveReader(AbstractMediaDecoder* aDecoder); michael@0: ~WaveReader(); michael@0: michael@0: virtual nsresult Init(MediaDecoderReader* aCloneDonor); michael@0: virtual bool DecodeAudioData(); michael@0: virtual bool DecodeVideoFrame(bool &aKeyframeSkip, michael@0: int64_t aTimeThreshold); michael@0: michael@0: virtual bool HasAudio() michael@0: { michael@0: return true; michael@0: } michael@0: michael@0: virtual bool HasVideo() michael@0: { michael@0: return false; michael@0: } michael@0: michael@0: virtual nsresult ReadMetadata(MediaInfo* aInfo, michael@0: MetadataTags** aTags); michael@0: virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime); michael@0: virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime); michael@0: michael@0: // To seek in a buffered range, we just have to seek the stream. michael@0: virtual bool IsSeekableInBufferedRanges() { michael@0: return true; michael@0: } michael@0: michael@0: private: michael@0: bool ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead = nullptr); michael@0: bool LoadRIFFChunk(); michael@0: bool GetNextChunk(uint32_t* aChunk, uint32_t* aChunkSize); michael@0: bool LoadFormatChunk(uint32_t aChunkSize); michael@0: bool FindDataOffset(uint32_t aChunkSize); michael@0: bool LoadListChunk(uint32_t aChunkSize, nsAutoPtr &aTags); michael@0: bool LoadAllChunks(nsAutoPtr &aTags); michael@0: michael@0: // Returns the number of seconds that aBytes represents based on the michael@0: // current audio parameters. e.g. 176400 bytes is 1 second at 16-bit michael@0: // stereo 44.1kHz. The time is rounded to the nearest microsecond. michael@0: double BytesToTime(int64_t aBytes) const; michael@0: michael@0: // Returns the number of bytes that aTime represents based on the current michael@0: // audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo michael@0: // 44.1kHz. michael@0: int64_t TimeToBytes(double aTime) const; michael@0: michael@0: // Rounds aBytes down to the nearest complete audio frame. Assumes michael@0: // beginning of byte range is already frame aligned by caller. michael@0: int64_t RoundDownToFrame(int64_t aBytes) const; michael@0: int64_t GetDataLength(); michael@0: int64_t GetPosition(); michael@0: michael@0: /* michael@0: Metadata extracted from the WAVE header. Used to initialize the audio michael@0: stream, and for byte<->time domain conversions. michael@0: */ michael@0: michael@0: // Number of samples per second. Limited to range [100, 96000] in LoadFormatChunk. michael@0: uint32_t mSampleRate; michael@0: michael@0: // Number of channels. Limited to range [1, 2] in LoadFormatChunk. michael@0: uint32_t mChannels; michael@0: michael@0: // Size of a single audio frame, which includes a sample for each channel michael@0: // (interleaved). michael@0: uint32_t mFrameSize; michael@0: michael@0: // The sample format of the PCM data. AudioStream::SampleFormat doesn't michael@0: // support U8. michael@0: enum { michael@0: FORMAT_U8, michael@0: FORMAT_S16 michael@0: } mSampleFormat; michael@0: michael@0: // Size of PCM data stored in the WAVE as reported by the data chunk in michael@0: // the media. michael@0: int64_t mWaveLength; michael@0: michael@0: // Start offset of the PCM data in the media stream. Extends mWaveLength michael@0: // bytes. michael@0: int64_t mWavePCMOffset; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif