Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_BASE_AUDIO_BUS_H_ | |
| 6 #define MEDIA_BASE_AUDIO_BUS_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/logging.h" | |
| 11 #include "base/memory/aligned_memory.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "media/audio/audio_parameters.h" | |
| 14 #include "media/base/channel_layout.h" | |
| 15 | |
| 16 namespace media { | |
| 17 | |
| 18 // Scoped container for "busing" audio channel data around. | |
| 19 class MEDIA_EXPORT AudioBus { | |
| 20 public: | |
| 21 ~AudioBus(); | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
if you only return scoped_ptr<> this can be privat
DaleCurtis
2012/08/07 01:36:32
Nice!
| |
| 22 | |
| 23 // Creates a new AudioBus and allocates |channels| of length |frames|. | |
| 24 static scoped_ptr<AudioBus> Create(int channels, int frames); | |
| 25 | |
| 26 // Same thing as above, except extracts |channels| and |frames| from the given | |
| 27 // AudioParameters structure. Additionally sets |channel_layout_|. | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
nit: I'd just move this up by the other Create() a
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 28 static scoped_ptr<AudioBus> Create(const AudioParameters& params); | |
| 29 | |
| 30 // Creates a new AudioBus and from an existing channel vector. | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
s/and//
I'd doc that this isn't ownership transfe
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 31 static scoped_ptr<AudioBus> WrapVector( | |
| 32 int frames, | |
| 33 const std::vector<float*>& audio_data_vector); | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
s/audio_data_vector/channel_data?
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 34 | |
| 35 // Returns a raw pointer to internal data for reconstruction of an AudioBus | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
I'd drop reference to shared memory -- that's some
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 36 // object across shared memory. Can not be used with an AudioBus constructed | |
| 37 // via wrapping. | |
| 38 void* audio_data() { | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
s/audio_// here + below (no need to prefix methods
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 39 DCHECK(audio_data_.get()); | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
I see what you mean about the DCHECK() -- I would
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 40 return audio_data_.get(); | |
| 41 } | |
| 42 | |
| 43 // Size in bytes of internal data. Should only be used for transferring an | |
| 44 // AudioBus object across shared memory. | |
| 45 int audio_data_size() const { | |
| 46 DCHECK(audio_data_.get()); | |
| 47 return audio_data_size_; | |
| 48 } | |
| 49 | |
| 50 // Returns a raw pointer to the requested channel. Pointer is guaranteed to | |
| 51 // have a 16-byte alignment. | |
| 52 float* channel(int channel) { return audio_data_vector_[channel]; } | |
| 53 const float* channel(int channel) const { | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
what's up with the overloaded const version? where
DaleCurtis
2012/08/07 01:36:32
In AudioUtil::InterleaveFloatToInt, see:
http://co
| |
| 54 return audio_data_vector_[channel]; | |
| 55 } | |
| 56 | |
| 57 int channels() const { return audio_data_vector_.size(); } | |
| 58 int frames() const { return frames_; } | |
| 59 | |
| 60 // Track channel layout information in case of channel remixing. Defaults to | |
| 61 // CHANNEL_LAYOUT_NONE if no layout is provided. | |
| 62 ChannelLayout channel_layout() const { return channel_layout_; } | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
I don't see channel layout used in 10823175 -- can
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 63 void set_channel_layout(ChannelLayout layout) { | |
| 64 DCHECK_EQ(static_cast<size_t>(ChannelLayoutToChannelCount(layout)), | |
| 65 audio_data_vector_.size()); | |
| 66 channel_layout_ = layout; | |
| 67 } | |
| 68 | |
| 69 // Helper method for zeroing out all channels of audio data. | |
| 70 void Zero(int frames); | |
| 71 void Zero() { Zero(frames_); } | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
instead of overload (generally avoided), how about
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 72 | |
| 73 private: | |
| 74 AudioBus(int channels, int frames, ChannelLayout channel_layout); | |
| 75 AudioBus(int frames, const std::vector<float*>& audio_data_vector); | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
ditto
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 76 | |
| 77 // Contiguous block of channel memory. | |
| 78 scoped_ptr_malloc<float, base::ScopedPtrAlignedFree> audio_data_; | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
similar to above this can be data_ if you want
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 79 int audio_data_size_; | |
| 80 | |
| 81 // Vector of pointers to each channel's audio data. | |
| 82 std::vector<float*> audio_data_vector_; | |
|
scherkus (not reviewing)
2012/08/06 18:55:34
similar to above this can be channel_data_
DaleCurtis
2012/08/07 01:36:32
Done.
| |
| 83 int frames_; | |
| 84 | |
| 85 ChannelLayout channel_layout_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(AudioBus); | |
| 88 }; | |
| 89 | |
| 90 } // namespace media | |
| 91 | |
| 92 #endif // MEDIA_BASE_AUDIO_BUS_H_ | |
| OLD | NEW |