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

Side by Side Diff: media/base/audio_bus.h

Issue 1906423005: Replace scoped_ptr with std::unique_ptr in //media/base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scopedptr-media-base: android Created 4 years, 8 months 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
« no previous file with comments | « media/base/audio_buffer_unittest.cc ('k') | media/base/audio_bus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_BASE_AUDIO_BUS_H_ 5 #ifndef MEDIA_BASE_AUDIO_BUS_H_
6 #define MEDIA_BASE_AUDIO_BUS_H_ 6 #define MEDIA_BASE_AUDIO_BUS_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/aligned_memory.h" 14 #include "base/memory/aligned_memory.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "media/base/media_export.h" 16 #include "media/base/media_export.h"
17 17
18 namespace media { 18 namespace media {
19 class AudioParameters; 19 class AudioParameters;
20 20
21 // Scoped container for "busing" audio channel data around. Each channel is 21 // Scoped container for "busing" audio channel data around. Each channel is
22 // stored in planar format and guaranteed to be aligned by kChannelAlignment. 22 // stored in planar format and guaranteed to be aligned by kChannelAlignment.
23 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus 23 // AudioBus objects can be created normally or via wrapping. Normally, AudioBus
24 // will dice up a contiguous memory block for channel data. When wrapped, 24 // will dice up a contiguous memory block for channel data. When wrapped,
25 // AudioBus instead routes requests for channel data to the wrapped object. 25 // AudioBus instead routes requests for channel data to the wrapped object.
26 class MEDIA_EXPORT AudioBus { 26 class MEDIA_EXPORT AudioBus {
27 public: 27 public:
28 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy 28 // Guaranteed alignment of each channel's data; use 16-byte alignment for easy
29 // SSE optimizations. 29 // SSE optimizations.
30 enum { kChannelAlignment = 16 }; 30 enum { kChannelAlignment = 16 };
31 31
32 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses 32 // Creates a new AudioBus and allocates |channels| of length |frames|. Uses
33 // channels() and frames_per_buffer() from AudioParameters if given. 33 // channels() and frames_per_buffer() from AudioParameters if given.
34 static scoped_ptr<AudioBus> Create(int channels, int frames); 34 static std::unique_ptr<AudioBus> Create(int channels, int frames);
35 static scoped_ptr<AudioBus> Create(const AudioParameters& params); 35 static std::unique_ptr<AudioBus> Create(const AudioParameters& params);
36 36
37 // Creates a new AudioBus with the given number of channels, but zero length. 37 // Creates a new AudioBus with the given number of channels, but zero length.
38 // It's expected to be used with SetChannelData() and set_frames() to 38 // It's expected to be used with SetChannelData() and set_frames() to
39 // wrap externally allocated memory. 39 // wrap externally allocated memory.
40 static scoped_ptr<AudioBus> CreateWrapper(int channels); 40 static std::unique_ptr<AudioBus> CreateWrapper(int channels);
41 41
42 // Creates a new AudioBus from an existing channel vector. Does not transfer 42 // Creates a new AudioBus from an existing channel vector. Does not transfer
43 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive 43 // ownership of |channel_data| to AudioBus; i.e., |channel_data| must outlive
44 // the returned AudioBus. Each channel must be aligned by kChannelAlignment. 44 // the returned AudioBus. Each channel must be aligned by kChannelAlignment.
45 static scoped_ptr<AudioBus> WrapVector( 45 static std::unique_ptr<AudioBus> WrapVector(
46 int frames, const std::vector<float*>& channel_data); 46 int frames,
47 const std::vector<float*>& channel_data);
47 48
48 // Creates a new AudioBus by wrapping an existing block of memory. Block must 49 // Creates a new AudioBus by wrapping an existing block of memory. Block must
49 // be at least CalculateMemorySize() bytes in size. |data| must outlive the 50 // be at least CalculateMemorySize() bytes in size. |data| must outlive the
50 // returned AudioBus. |data| must be aligned by kChannelAlignment. 51 // returned AudioBus. |data| must be aligned by kChannelAlignment.
51 static scoped_ptr<AudioBus> WrapMemory(int channels, int frames, void* data); 52 static std::unique_ptr<AudioBus> WrapMemory(int channels,
52 static scoped_ptr<AudioBus> WrapMemory(const AudioParameters& params, 53 int frames,
53 void* data); 54 void* data);
55 static std::unique_ptr<AudioBus> WrapMemory(const AudioParameters& params,
56 void* data);
54 static int CalculateMemorySize(const AudioParameters& params); 57 static int CalculateMemorySize(const AudioParameters& params);
55 58
56 // Calculates the required size for an AudioBus given the number of channels 59 // Calculates the required size for an AudioBus given the number of channels
57 // and frames. 60 // and frames.
58 static int CalculateMemorySize(int channels, int frames); 61 static int CalculateMemorySize(int channels, int frames);
59 62
60 // Helper methods for converting an AudioBus from and to interleaved integer 63 // Helper methods for converting an AudioBus from and to interleaved integer
61 // data. Expects interleaving to be [ch0, ch1, ..., chN, ch0, ch1, ...] with 64 // data. Expects interleaving to be [ch0, ch1, ..., chN, ch0, ch1, ...] with
62 // |bytes_per_sample| per value. Values are scaled and bias corrected during 65 // |bytes_per_sample| per value. Values are scaled and bias corrected during
63 // conversion. ToInterleaved() will also clip values to format range. 66 // conversion. ToInterleaved() will also clip values to format range.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 AudioBus(int channels, int frames, float* data); 126 AudioBus(int channels, int frames, float* data);
124 AudioBus(int frames, const std::vector<float*>& channel_data); 127 AudioBus(int frames, const std::vector<float*>& channel_data);
125 explicit AudioBus(int channels); 128 explicit AudioBus(int channels);
126 129
127 private: 130 private:
128 // Helper method for building |channel_data_| from a block of memory. |data| 131 // Helper method for building |channel_data_| from a block of memory. |data|
129 // must be at least BlockSize() bytes in size. 132 // must be at least BlockSize() bytes in size.
130 void BuildChannelData(int channels, int aligned_frame, float* data); 133 void BuildChannelData(int channels, int aligned_frame, float* data);
131 134
132 // Contiguous block of channel memory. 135 // Contiguous block of channel memory.
133 scoped_ptr<float, base::AlignedFreeDeleter> data_; 136 std::unique_ptr<float, base::AlignedFreeDeleter> data_;
134 137
135 std::vector<float*> channel_data_; 138 std::vector<float*> channel_data_;
136 int frames_; 139 int frames_;
137 140
138 // Protect SetChannelData() and set_frames() for use by CreateWrapper(). 141 // Protect SetChannelData() and set_frames() for use by CreateWrapper().
139 bool can_set_channel_data_; 142 bool can_set_channel_data_;
140 143
141 DISALLOW_COPY_AND_ASSIGN(AudioBus); 144 DISALLOW_COPY_AND_ASSIGN(AudioBus);
142 }; 145 };
143 146
(...skipping 11 matching lines...) Expand all
155 158
156 AudioBusRefCounted(int channels, int frames); 159 AudioBusRefCounted(int channels, int frames);
157 ~AudioBusRefCounted() override; 160 ~AudioBusRefCounted() override;
158 161
159 DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted); 162 DISALLOW_COPY_AND_ASSIGN(AudioBusRefCounted);
160 }; 163 };
161 164
162 } // namespace media 165 } // namespace media
163 166
164 #endif // MEDIA_BASE_AUDIO_BUS_H_ 167 #endif // MEDIA_BASE_AUDIO_BUS_H_
OLDNEW
« no previous file with comments | « media/base/audio_buffer_unittest.cc ('k') | media/base/audio_bus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698