2011-03-30 05:37:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2012-11-14 19:46:40 +00:00
|
|
|
#if !defined(WaveReader_h_)
|
|
|
|
#define WaveReader_h_
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2012-11-14 19:46:40 +00:00
|
|
|
#include "MediaDecoderReader.h"
|
2013-09-05 20:25:17 +00:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2013-03-02 19:14:44 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
}
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2012-11-14 19:45:33 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-11-14 19:46:40 +00:00
|
|
|
class WaveReader : public MediaDecoderReader
|
2011-03-30 05:37:42 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-11-19 15:11:21 +00:00
|
|
|
WaveReader(AbstractMediaDecoder* aDecoder);
|
2012-11-14 19:46:40 +00:00
|
|
|
~WaveReader();
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2012-11-14 19:46:40 +00:00
|
|
|
virtual nsresult Init(MediaDecoderReader* aCloneDonor);
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool DecodeAudioData();
|
|
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t aTimeThreshold);
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool HasAudio()
|
2011-03-30 05:37:42 +00:00
|
|
|
{
|
2011-09-29 23:34:37 +00:00
|
|
|
return true;
|
2011-03-30 05:37:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool HasVideo()
|
2011-03-30 05:37:42 +00:00
|
|
|
{
|
2011-09-29 23:34:37 +00:00
|
|
|
return false;
|
2011-03-30 05:37:42 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 05:22:38 +00:00
|
|
|
virtual nsresult ReadMetadata(MediaInfo* aInfo,
|
2012-11-09 00:40:08 +00:00
|
|
|
MetadataTags** aTags);
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
|
2013-03-02 19:14:44 +00:00
|
|
|
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime);
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2012-05-18 17:35:43 +00:00
|
|
|
// To seek in a buffered range, we just have to seek the stream.
|
|
|
|
virtual bool IsSeekableInBufferedRanges() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 05:37:42 +00:00
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
bool ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead = nullptr);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool LoadRIFFChunk();
|
2012-10-06 11:33:11 +00:00
|
|
|
bool GetNextChunk(uint32_t* aChunk, uint32_t* aChunkSize);
|
|
|
|
bool LoadFormatChunk(uint32_t aChunkSize);
|
|
|
|
bool FindDataOffset(uint32_t aChunkSize);
|
2013-03-19 12:23:54 +00:00
|
|
|
bool LoadListChunk(uint32_t aChunkSize, nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
|
|
|
|
bool LoadAllChunks(nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
// Returns the number of seconds that aBytes represents based on the
|
|
|
|
// current audio parameters. e.g. 176400 bytes is 1 second at 16-bit
|
2011-04-13 22:12:23 +00:00
|
|
|
// stereo 44.1kHz. The time is rounded to the nearest microsecond.
|
2012-08-22 15:56:38 +00:00
|
|
|
double BytesToTime(int64_t aBytes) const;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
// Returns the number of bytes that aTime represents based on the current
|
|
|
|
// audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo
|
|
|
|
// 44.1kHz.
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t TimeToBytes(double aTime) const;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2011-09-27 03:31:18 +00:00
|
|
|
// Rounds aBytes down to the nearest complete audio frame. Assumes
|
|
|
|
// beginning of byte range is already frame aligned by caller.
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t RoundDownToFrame(int64_t aBytes) const;
|
|
|
|
int64_t GetDataLength();
|
|
|
|
int64_t GetPosition();
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Metadata extracted from the WAVE header. Used to initialize the audio
|
|
|
|
stream, and for byte<->time domain conversions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Number of samples per second. Limited to range [100, 96000] in LoadFormatChunk.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mSampleRate;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
// Number of channels. Limited to range [1, 2] in LoadFormatChunk.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mChannels;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2011-09-27 03:31:18 +00:00
|
|
|
// Size of a single audio frame, which includes a sample for each channel
|
|
|
|
// (interleaved).
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mFrameSize;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
2012-11-14 19:46:40 +00:00
|
|
|
// The sample format of the PCM data. AudioStream::SampleFormat doesn't
|
2012-10-25 10:09:39 +00:00
|
|
|
// support U8.
|
|
|
|
enum {
|
|
|
|
FORMAT_U8,
|
|
|
|
FORMAT_S16
|
|
|
|
} mSampleFormat;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
// Size of PCM data stored in the WAVE as reported by the data chunk in
|
|
|
|
// the media.
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t mWaveLength;
|
2011-03-30 05:37:42 +00:00
|
|
|
|
|
|
|
// Start offset of the PCM data in the media stream. Extends mWaveLength
|
|
|
|
// bytes.
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t mWavePCMOffset;
|
2011-03-30 05:37:42 +00:00
|
|
|
};
|
|
|
|
|
2012-11-14 19:45:33 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-03-30 05:37:42 +00:00
|
|
|
#endif
|