Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: media/audio/sounds/wav_audio_handler.h

Issue 1453233002: Improve input handling for WaveAudioHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Remove VLOG()s Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_ 5 #ifndef MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_
6 #define MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_ 6 #define MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_
7 7
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
11 13
12 namespace media { 14 namespace media {
13 15
14 class AudioBus; 16 class AudioBus;
15 17
16 // This class provides the input from wav file format. See 18 // This class provides the input from wav file format. See
17 // https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ 19 // https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
18 class MEDIA_EXPORT WavAudioHandler { 20 class MEDIA_EXPORT WavAudioHandler {
19 public: 21 public:
20 explicit WavAudioHandler(const base::StringPiece& wav_data); 22 static scoped_ptr<WavAudioHandler> Create(const base::StringPiece& wav_data);
wzhong 2015/11/18 22:21:35 static methods should be after dtor.
slan 2015/11/19 00:19:44 Done.
21 virtual ~WavAudioHandler(); 23 virtual ~WavAudioHandler();
22 24
23 // Returns true when cursor points to the end of the track. 25 // Returns true when cursor points to the end of the track.
24 bool AtEnd(size_t cursor) const; 26 bool AtEnd(size_t cursor) const;
25 27
26 // Copies the audio data to |bus| starting from the |cursor| and in 28 // Copies the audio data to |bus| starting from the |cursor| and in
27 // the case of success stores the number of written bytes in 29 // the case of success stores the number of written bytes in
28 // |bytes_written|. |bytes_written| should not be NULL. 30 // |bytes_written|. |bytes_written| should not be NULL. Returns false if the
31 // operation was unsuccessful. Returns true otherwise.
29 bool CopyTo(AudioBus* bus, size_t cursor, size_t* bytes_written) const; 32 bool CopyTo(AudioBus* bus, size_t cursor, size_t* bytes_written) const;
30 33
31 // Accessors. 34 // Accessors.
32 const base::StringPiece& data() const { return data_; } 35 const base::StringPiece& data() const { return data_; }
33 uint16_t num_channels() const { return num_channels_; } 36 uint16_t num_channels() const { return num_channels_; }
34 uint32_t sample_rate() const { return sample_rate_; } 37 uint32_t sample_rate() const { return sample_rate_; }
35 uint16_t bits_per_sample() const { return bits_per_sample_; } 38 uint16_t bits_per_sample() const { return bits_per_sample_; }
36 uint32_t total_frames() const { return total_frames_; } 39 uint32_t total_frames() const { return total_frames_; }
37 40
38 // Returns the duration of the entire audio chunk. 41 // Returns the duration of the entire audio chunk.
39 base::TimeDelta GetDuration() const; 42 base::TimeDelta GetDuration() const;
40 43
41 private: 44 private:
42 // Parses a chunk of wav format data. Returns the length of the chunk. 45 explicit WavAudioHandler(const base::StringPiece& audio_data,
wzhong 2015/11/18 22:21:35 explicit not needed.
slan 2015/11/19 00:19:44 Whoops, leftover. Done.
43 int ParseSubChunk(const base::StringPiece& data); 46 uint16_t num_channels,
44 47 uint32_t sample_rate,
45 // Parses the 'fmt' section chunk and stores |params_|. 48 uint16_t bits_per_sample);
46 bool ParseFmtChunk(const base::StringPiece& data);
47
48 // Parses the 'data' section chunk and stores |data_|.
49 bool ParseDataChunk(const base::StringPiece& data);
50 49
51 // Data part of the |wav_data_|. 50 // Data part of the |wav_data_|.
52 base::StringPiece data_; 51 const base::StringPiece data_;
52 const uint16_t num_channels_;
53 const uint32_t sample_rate_;
54 const uint16_t bits_per_sample_;
55 uint32_t total_frames_;
53 56
54 uint16_t num_channels_; 57 DISALLOW_COPY_AND_ASSIGN(WavAudioHandler);
55 uint32_t sample_rate_;
56 uint16_t bits_per_sample_;
57 uint32_t total_frames_;
58 }; 58 };
59 59
60 } // namespace media 60 } // namespace media
61 61
62 #endif // MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_ 62 #endif // MEDIA_AUDIO_SOUNDS_WAV_AUDIO_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698