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

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

Issue 2437863004: 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
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(uint32_t pending_data) override; 44 void Process(int64_t pending_data, base::TimeTicks data_timestamp) 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(uint32_t pending_data) { 310 void AudioInputDevice::AudioThreadCallback::Process(
311 int64_t pending_data,
312 base::TimeTicks data_timestamp) {
311 // The shared memory represents parameters, size of the data buffer and the 313 // The shared memory represents parameters, size of the data buffer and the
312 // actual data buffer containing audio data. Map the memory into this 314 // actual data buffer containing audio data. Map the memory into this
313 // structure and parse out parameters and the data area. 315 // structure and parse out parameters and the data area.
314 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory()); 316 uint8_t* ptr = static_cast<uint8_t*>(shared_memory_.memory());
315 ptr += current_segment_id_ * segment_length_; 317 ptr += current_segment_id_ * segment_length_;
316 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); 318 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr);
317 319
318 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz, 320 // Usually this will be equal but in the case of low sample rate (e.g. 8kHz,
319 // the buffer may be bigger (on mac at least)). 321 // the buffer may be bigger (on mac at least)).
320 DCHECK_GE(buffer->params.size, 322 DCHECK_GE(buffer->params.size,
321 segment_length_ - sizeof(AudioInputBufferParameters)); 323 segment_length_ - sizeof(AudioInputBufferParameters));
322 324
323 // Verify correct sequence. 325 // Verify correct sequence.
324 if (buffer->params.id != last_buffer_id_ + 1) { 326 if (buffer->params.id != last_buffer_id_ + 1) {
325 std::string message = base::StringPrintf( 327 std::string message = base::StringPrintf(
326 "Incorrect buffer sequence. Expected = %u. Actual = %u.", 328 "Incorrect buffer sequence. Expected = %u. Actual = %u.",
327 last_buffer_id_ + 1, buffer->params.id); 329 last_buffer_id_ + 1, buffer->params.id);
328 LOG(ERROR) << message; 330 LOG(ERROR) << message;
329 capture_callback_->OnCaptureError(message); 331 capture_callback_->OnCaptureError(message);
330 } 332 }
331 if (current_segment_id_ != static_cast<int>(pending_data)) { 333 if (current_segment_id_ != static_cast<int>(pending_data)) {
332 std::string message = base::StringPrintf( 334 std::string message =
333 "Segment id not matching. Remote = %u. Local = %d.", 335 base::StringPrintf("Segment id not matching. Remote = %ld. Local = %d.",
334 pending_data, current_segment_id_); 336 pending_data, current_segment_id_);
335 LOG(ERROR) << message; 337 LOG(ERROR) << message;
336 capture_callback_->OnCaptureError(message); 338 capture_callback_->OnCaptureError(message);
337 } 339 }
338 last_buffer_id_ = buffer->params.id; 340 last_buffer_id_ = buffer->params.id;
339 341
340 // Use pre-allocated audio bus wrapping existing block of shared memory. 342 // Use pre-allocated audio bus wrapping existing block of shared memory.
341 media::AudioBus* audio_bus = audio_buses_[current_segment_id_]; 343 media::AudioBus* audio_bus = audio_buses_[current_segment_id_];
342 344
343 // Deliver captured data to the client in floating point format and update 345 // Deliver captured data to the client in floating point format and update
344 // the audio delay measurement. 346 // the audio delay measurement.
345 capture_callback_->Capture( 347 capture_callback_->Capture(
346 audio_bus, 348 audio_bus,
347 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms 349 buffer->params.hardware_delay_bytes / bytes_per_ms_, // Delay in ms
348 buffer->params.volume, buffer->params.key_pressed); 350 buffer->params.volume, buffer->params.key_pressed);
349 351
350 if (++current_segment_id_ >= total_segments_) 352 if (++current_segment_id_ >= total_segments_)
351 current_segment_id_ = 0; 353 current_segment_id_ = 0;
352 } 354 }
353 355
354 } // namespace media 356 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698