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