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

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

Issue 2452183003: Revert of Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: Created 4 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
« no previous file with comments | « media/audio/audio_device_thread.cc ('k') | media/audio/audio_output_controller.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"
(...skipping 23 matching lines...) Expand all
34 AudioThreadCallback(const AudioParameters& audio_parameters, 34 AudioThreadCallback(const AudioParameters& audio_parameters,
35 base::SharedMemoryHandle memory, 35 base::SharedMemoryHandle memory,
36 int memory_length, 36 int memory_length,
37 int total_segments, 37 int total_segments,
38 CaptureCallback* capture_callback); 38 CaptureCallback* capture_callback);
39 ~AudioThreadCallback() override; 39 ~AudioThreadCallback() override;
40 40
41 void MapSharedMemory() override; 41 void MapSharedMemory() override;
42 42
43 // Called whenever we receive notifications about pending data. 43 // Called whenever we receive notifications about pending data.
44 void Process(int64_t pending_data, base::TimeTicks data_timestamp) override; 44 void Process(uint32_t pending_data) override;
45 45
46 private: 46 private:
47 const double bytes_per_ms_; 47 const double bytes_per_ms_;
48 int current_segment_id_; 48 int current_segment_id_;
49 uint32_t last_buffer_id_; 49 uint32_t last_buffer_id_;
50 ScopedVector<media::AudioBus> audio_buses_; 50 ScopedVector<media::AudioBus> audio_buses_;
51 CaptureCallback* capture_callback_; 51 CaptureCallback* capture_callback_;
52 52
53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback); 53 DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
54 }; 54 };
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 for (int i = 0; i < total_segments_; ++i) { 300 for (int i = 0; i < total_segments_; ++i) {
301 media::AudioInputBuffer* buffer = 301 media::AudioInputBuffer* buffer =
302 reinterpret_cast<media::AudioInputBuffer*>(ptr); 302 reinterpret_cast<media::AudioInputBuffer*>(ptr);
303 std::unique_ptr<media::AudioBus> audio_bus = 303 std::unique_ptr<media::AudioBus> audio_bus =
304 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio); 304 media::AudioBus::WrapMemory(audio_parameters_, buffer->audio);
305 audio_buses_.push_back(std::move(audio_bus)); 305 audio_buses_.push_back(std::move(audio_bus));
306 ptr += segment_length_; 306 ptr += segment_length_;
307 } 307 }
308 } 308 }
309 309
310 void AudioInputDevice::AudioThreadCallback::Process( 310 void AudioInputDevice::AudioThreadCallback::Process(uint32_t pending_data) {
311 int64_t pending_data,
312 base::TimeTicks data_timestamp) {
313 // The shared memory represents parameters, size of the data buffer and the 311 // The shared memory represents parameters, size of the data buffer and the
314 // actual data buffer containing audio data. Map the memory into this 312 // actual data buffer containing audio data. Map the memory into this
315 // structure and parse out parameters and the data area. 313 // structure and parse out parameters and the data area.
316 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); 314 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory());
317 ptr += current_segment_id_ * segment_length_; 315 ptr += current_segment_id_ * segment_length_;
318 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); 316 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr);
319 317
320 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, 318 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz,
321 // the buffer may be bigger (on mac at least)). 319 // the buffer may be bigger (on mac at least)).
322 DCHECK_GE(buffer->params.size, 320 DCHECK_GE(buffer->params.size,
323 segment_length_ - sizeof(AudioInputBufferParameters)); 321 segment_length_ - sizeof(AudioInputBufferParameters));
324 322
325 // Verify correct sequence. 323 // Verify correct sequence.
326 if (buffer->params.id != last_buffer_id_ + 1) { 324 if (buffer->params.id != last_buffer_id_ + 1) {
327 std::string message = base::StringPrintf( 325 std::string message = base::StringPrintf(
328 "Incorrect buffer sequence. Expected = %u. Actual = %u.", 326 "Incorrect buffer sequence. Expected = %u. Actual = %u.",
329 last_buffer_id_ + 1, buffer->params.id); 327 last_buffer_id_ + 1, buffer->params.id);
330 LOG(ERROR) << message; 328 LOG(ERROR) << message;
331 capture_callback_->OnCaptureError(message); 329 capture_callback_->OnCaptureError(message);
332 } 330 }
333 if (current_segment_id_ != static_cast<int>(pending_data)) { 331 if (current_segment_id_ != static_cast<int>(pending_data)) {
334 std::string message = 332 std::string message = base::StringPrintf(
335 base::StringPrintf("Segment id not matching. Remote = %d. Local = %d.", 333 "Segment id not matching. Remote = %u. Local = %d.",
336 static_cast<int>(pending_data), current_segment_id_); 334 pending_data, current_segment_id_);
337 LOG(ERROR) << message; 335 LOG(ERROR) << message;
338 capture_callback_->OnCaptureError(message); 336 capture_callback_->OnCaptureError(message);
339 } 337 }
340 last_buffer_id_ = buffer->params.id; 338 last_buffer_id_ = buffer->params.id;
341 339
342 // Use pre-allocated audio bus wrapping existing block of shared memory. 340 // Use pre-allocated audio bus wrapping existing block of shared memory.
343 media::AudioBus* audio_bus = audio_buses_[current_segment_id_]; 341 media::AudioBus* audio_bus = audio_buses_[current_segment_id_];
344 342
345 // Deliver captured data to the client in floating point format and update 343 // Deliver captured data to the client in floating point format and update
346 // the audio delay measurement. 344 // the audio delay measurement.
347 capture_callback_->Capture( 345 capture_callback_->Capture(
348 audio_bus, 346 audio_bus,
349 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms 347 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms
350 buffer->params.volume, buffer->params.key_pressed); 348 buffer->params.volume, buffer->params.key_pressed);
351 349
352 if (++current_segment_id_ >= total_segments_) 350 if (++current_segment_id_ >= total_segments_)
353 current_segment_id_ = 0; 351 current_segment_id_ = 0;
354 } 352 }
355 353
356 } // namespace media 354 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.cc ('k') | media/audio/audio_output_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698