2011-03-29 22:37:42 -07: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 04:12:37 -07: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 11:46:40 -08:00
|
|
|
#if !defined(WaveReader_h_)
|
|
|
|
#define WaveReader_h_
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2012-11-14 11:46:40 -08:00
|
|
|
#include "MediaDecoderReader.h"
|
2013-09-05 13:25:17 -07:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2013-03-02 11:14:44 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class TimeRanges;
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2012-11-14 11:45:33 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-11-14 11:46:40 -08:00
|
|
|
class WaveReader : public MediaDecoderReader
|
2011-03-29 22:37:42 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-08-31 20:50:23 -07:00
|
|
|
explicit WaveReader(AbstractMediaDecoder* aDecoder);
|
2014-07-15 08:37:45 -07:00
|
|
|
|
|
|
|
protected:
|
2012-11-14 11:46:40 -08:00
|
|
|
~WaveReader();
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2014-07-15 08:37:45 -07:00
|
|
|
public:
|
2012-11-14 11:46:40 -08:00
|
|
|
virtual nsresult Init(MediaDecoderReader* aCloneDonor);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool DecodeAudioData();
|
|
|
|
virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aTimeThreshold);
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool HasAudio()
|
2011-03-29 22:37:42 -07:00
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
return true;
|
2011-03-29 22:37:42 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool HasVideo()
|
2011-03-29 22:37:42 -07:00
|
|
|
{
|
2011-09-29 16:34:37 -07:00
|
|
|
return false;
|
2011-03-29 22:37:42 -07:00
|
|
|
}
|
|
|
|
|
2013-09-26 22:22:38 -07:00
|
|
|
virtual nsresult ReadMetadata(MediaInfo* aInfo,
|
2012-11-08 16:40:08 -08:00
|
|
|
MetadataTags** aTags);
|
2014-11-04 16:32:26 -08:00
|
|
|
virtual void Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime);
|
2014-11-11 20:50:21 -08:00
|
|
|
virtual nsresult GetBuffered(dom::TimeRanges* aBuffered);
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2012-05-18 10:35:43 -07:00
|
|
|
// To seek in a buffered range, we just have to seek the stream.
|
|
|
|
virtual bool IsSeekableInBufferedRanges() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-23 03:08:34 -07:00
|
|
|
virtual bool IsMediaSeekable() MOZ_OVERRIDE;
|
|
|
|
|
2011-03-29 22:37:42 -07:00
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
bool ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead = nullptr);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool LoadRIFFChunk();
|
2012-10-06 04:33:11 -07:00
|
|
|
bool GetNextChunk(uint32_t* aChunk, uint32_t* aChunkSize);
|
|
|
|
bool LoadFormatChunk(uint32_t aChunkSize);
|
|
|
|
bool FindDataOffset(uint32_t aChunkSize);
|
2013-03-19 05:23:54 -07:00
|
|
|
bool LoadListChunk(uint32_t aChunkSize, nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
|
|
|
|
bool LoadAllChunks(nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags);
|
2011-03-29 22:37:42 -07: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 15:12:23 -07:00
|
|
|
// stereo 44.1kHz. The time is rounded to the nearest microsecond.
|
2012-08-22 08:56:38 -07:00
|
|
|
double BytesToTime(int64_t aBytes) const;
|
2011-03-29 22:37:42 -07: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 08:56:38 -07:00
|
|
|
int64_t TimeToBytes(double aTime) const;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// Rounds aBytes down to the nearest complete audio frame. Assumes
|
|
|
|
// beginning of byte range is already frame aligned by caller.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t RoundDownToFrame(int64_t aBytes) const;
|
|
|
|
int64_t GetDataLength();
|
|
|
|
int64_t GetPosition();
|
2011-03-29 22:37:42 -07: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 08:56:38 -07:00
|
|
|
uint32_t mSampleRate;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
|
|
|
// Number of channels. Limited to range [1, 2] in LoadFormatChunk.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mChannels;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2011-09-26 20:31:18 -07:00
|
|
|
// Size of a single audio frame, which includes a sample for each channel
|
|
|
|
// (interleaved).
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mFrameSize;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
2012-11-14 11:46:40 -08:00
|
|
|
// The sample format of the PCM data. AudioStream::SampleFormat doesn't
|
2012-10-25 03:09:39 -07:00
|
|
|
// support U8.
|
|
|
|
enum {
|
|
|
|
FORMAT_U8,
|
|
|
|
FORMAT_S16
|
|
|
|
} mSampleFormat;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
|
|
|
// Size of PCM data stored in the WAVE as reported by the data chunk in
|
|
|
|
// the media.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mWaveLength;
|
2011-03-29 22:37:42 -07:00
|
|
|
|
|
|
|
// Start offset of the PCM data in the media stream. Extends mWaveLength
|
|
|
|
// bytes.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mWavePCMOffset;
|
2011-03-29 22:37:42 -07:00
|
|
|
};
|
|
|
|
|
2012-11-14 11:45:33 -08:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-03-29 22:37:42 -07:00
|
|
|
#endif
|