1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla code.
17 : *
18 : * The Initial Developer of the Original Code is the Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Matthew Gregan <kinetik@flim.org>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 : #if !defined(nsWaveReader_h_)
39 : #define nsWaveReader_h_
40 :
41 : #include "nsBuiltinDecoderReader.h"
42 :
43 : class nsBuiltinDecoder;
44 : class nsTimeRanges;
45 :
46 : class nsWaveReader : public nsBuiltinDecoderReader
47 : {
48 : public:
49 : nsWaveReader(nsBuiltinDecoder* aDecoder);
50 : ~nsWaveReader();
51 :
52 : virtual nsresult Init(nsBuiltinDecoderReader* aCloneDonor);
53 : virtual bool DecodeAudioData();
54 : virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
55 : PRInt64 aTimeThreshold);
56 :
57 0 : virtual bool HasAudio()
58 : {
59 0 : return true;
60 : }
61 :
62 0 : virtual bool HasVideo()
63 : {
64 0 : return false;
65 : }
66 :
67 : virtual nsresult ReadMetadata(nsVideoInfo* aInfo);
68 : virtual nsresult Seek(PRInt64 aTime, PRInt64 aStartTime, PRInt64 aEndTime, PRInt64 aCurrentTime);
69 : virtual nsresult GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime);
70 :
71 : private:
72 : bool ReadAll(char* aBuf, PRInt64 aSize, PRInt64* aBytesRead = nsnull);
73 : bool LoadRIFFChunk();
74 : bool ScanForwardUntil(PRUint32 aWantedChunk, PRUint32* aChunkSize);
75 : bool LoadFormatChunk();
76 : bool FindDataOffset();
77 :
78 : // Returns the number of seconds that aBytes represents based on the
79 : // current audio parameters. e.g. 176400 bytes is 1 second at 16-bit
80 : // stereo 44.1kHz. The time is rounded to the nearest microsecond.
81 : double BytesToTime(PRInt64 aBytes) const;
82 :
83 : // Returns the number of bytes that aTime represents based on the current
84 : // audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo
85 : // 44.1kHz.
86 : PRInt64 TimeToBytes(double aTime) const;
87 :
88 : // Rounds aBytes down to the nearest complete audio frame. Assumes
89 : // beginning of byte range is already frame aligned by caller.
90 : PRInt64 RoundDownToFrame(PRInt64 aBytes) const;
91 : PRInt64 GetDataLength();
92 : PRInt64 GetPosition();
93 :
94 : /*
95 : Metadata extracted from the WAVE header. Used to initialize the audio
96 : stream, and for byte<->time domain conversions.
97 : */
98 :
99 : // Number of samples per second. Limited to range [100, 96000] in LoadFormatChunk.
100 : PRUint32 mSampleRate;
101 :
102 : // Number of channels. Limited to range [1, 2] in LoadFormatChunk.
103 : PRUint32 mChannels;
104 :
105 : // Size of a single audio frame, which includes a sample for each channel
106 : // (interleaved).
107 : PRUint32 mFrameSize;
108 :
109 : // The sample format of the PCM data.
110 : nsAudioStream::SampleFormat mSampleFormat;
111 :
112 : // Size of PCM data stored in the WAVE as reported by the data chunk in
113 : // the media.
114 : PRInt64 mWaveLength;
115 :
116 : // Start offset of the PCM data in the media stream. Extends mWaveLength
117 : // bytes.
118 : PRInt64 mWavePCMOffset;
119 : };
120 :
121 : #endif
|