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

Side by Side Diff: media/audio/audio_input_device.cc

Issue 2867443002: Remove ScopedVector from media/audio/ (Closed)
Patch Set: Addressed review comments Created 3 years, 7 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 | « no previous file | media/audio/audio_manager_base.h » ('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 #include "media/audio/audio_input_device.h" 5 #include "media/audio/audio_input_device.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
14 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "build/build_config.h" 15 #include "build/build_config.h"
17 #include "media/audio/audio_manager_base.h" 16 #include "media/audio/audio_manager_base.h"
18 #include "media/base/audio_bus.h" 17 #include "media/base/audio_bus.h"
19 18
20 namespace media { 19 namespace media {
21 20
22 // The number of shared memory buffer segments indicated to browser process 21 // The number of shared memory buffer segments indicated to browser process
(...skipping 17 matching lines...) Expand all
40 39
41 void MapSharedMemory() override; 40 void MapSharedMemory() override;
42 41
43 // Called whenever we receive notifications about pending data. 42 // Called whenever we receive notifications about pending data.
44 void Process(uint32_t pending_data) override; 43 void Process(uint32_t pending_data) override;
45 44
46 private: 45 private:
47 const double bytes_per_ms_; 46 const double bytes_per_ms_;
48 int current_segment_id_; 47 int current_segment_id_;
49 uint32_t last_buffer_id_; 48 uint32_t last_buffer_id_;
50 ScopedVector<media::AudioBus> audio_buses_; 49 std::vector<std::unique_ptr<media::AudioBus>> audio_buses_;
51 CaptureCallback* capture_callback_; 50 CaptureCallback* capture_callback_;
52 51
53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 52 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
54 }; 53 };
55 54
56 AudioInputDevice::AudioInputDevice( 55 AudioInputDevice::AudioInputDevice(
57 std::unique_ptr<AudioInputIPC> ipc, 56 std::unique_ptr<AudioInputIPC> ipc,
58 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 57 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
59 : ScopedTaskRunnerObserver(io_task_runner), 58 : ScopedTaskRunnerObserver(io_task_runner),
60 callback_(NULL), 59 callback_(NULL),
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 289 }
291 290
292 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() { 291 void AudioInputDevice::AudioThreadCallback::MapSharedMemory() {
293 shared_memory_.Map(memory_length_); 292 shared_memory_.Map(memory_length_);
294 293
295 // Create vector of audio buses by wrapping existing blocks of memory. 294 // Create vector of audio buses by wrapping existing blocks of memory.
296 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); 295 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory());
297 for (int i = 0; i < total_segments_; ++i) { 296 for (int i = 0; i < total_segments_; ++i) {
298 media::AudioInputBuffer* buffer = 297 media::AudioInputBuffer* buffer =
299 reinterpret_cast<media::AudioInputBuffer*>(ptr); 298 reinterpret_cast<media::AudioInputBuffer*>(ptr);
300 std::unique_ptr<media::AudioBus> audio_bus = 299 audio_buses_.push_back(
301 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); 300 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio));
302 audio_buses_.push_back(std::move(audio_bus));
303 ptr += segment_length_; 301 ptr += segment_length_;
304 } 302 }
305 303
306 // Indicate that browser side capture initialization has succeeded and IPC 304 // Indicate that browser side capture initialization has succeeded and IPC
307 // channel initialized. This effectively completes the 305 // channel initialized. This effectively completes the
308 // AudioCapturerSource::Start()' phase as far as the caller of that function 306 // AudioCapturerSource::Start()' phase as far as the caller of that function
309 // is concerned. 307 // is concerned.
310 capture_callback_->OnCaptureStarted(); 308 capture_callback_->OnCaptureStarted();
311 } 309 }
312 310
(...skipping 21 matching lines...) Expand all
334 if (current_segment_id_ != static_cast<int>(pending_data)) { 332 if (current_segment_id_ != static_cast<int>(pending_data)) {
335 std::string message = base::StringPrintf( 333 std::string message = base::StringPrintf(
336 "Segment id not matching. Remote = %u. Local = %d.", 334 "Segment id not matching. Remote = %u. Local = %d.",
337 pending_data, current_segment_id_); 335 pending_data, current_segment_id_);
338 LOG(ERROR) << message; 336 LOG(ERROR) << message;
339 capture_callback_->OnCaptureError(message); 337 capture_callback_->OnCaptureError(message);
340 } 338 }
341 last_buffer_id_ = buffer->params.id; 339 last_buffer_id_ = buffer->params.id;
342 340
343 // Use pre-allocated audio bus wrapping existing block of shared memory. 341 // Use pre-allocated audio bus wrapping existing block of shared memory.
344 media::AudioBus* audio_bus = audio_buses_[current_segment_id_]; 342 media::AudioBus* audio_bus = audio_buses_[current_segment_id_].get();
345 343
346 // Deliver captured data to the client in floating point format and update 344 // Deliver captured data to the client in floating point format and update
347 // the audio delay measurement. 345 // the audio delay measurement.
348 capture_callback_->Capture( 346 capture_callback_->Capture(
349 audio_bus, 347 audio_bus,
350 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms 348 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms
351 buffer->params.volume, buffer->params.key_pressed); 349 buffer->params.volume, buffer->params.key_pressed);
352 350
353 if (++current_segment_id_ >= total_segments_) 351 if (++current_segment_id_ >= total_segments_)
354 current_segment_id_ = 0; 352 current_segment_id_ = 0;
355 } 353 }
356 354
357 } // namespace media 355 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698