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

Side by Side Diff: content/renderer/media/webrtc_audio_device_impl.cc

Issue 37793005: move the APM to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/webrtc_audio_device_impl.h" 5 #include "content/renderer/media/webrtc_audio_device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 int32_t WebRtcAudioDeviceImpl::Release() { 46 int32_t WebRtcAudioDeviceImpl::Release() {
47 DCHECK(thread_checker_.CalledOnValidThread()); 47 DCHECK(thread_checker_.CalledOnValidThread());
48 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1); 48 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1);
49 if (ret == 0) { 49 if (ret == 0) {
50 delete this; 50 delete this;
51 } 51 }
52 return ret; 52 return ret;
53 } 53 }
54 int WebRtcAudioDeviceImpl::CaptureData(const std::vector<int>& channels, 54 void WebRtcAudioDeviceImpl::CaptureData(const std::vector<int>& channels,
55 const int16* audio_data, 55 const int16* audio_data,
56 int sample_rate, 56 int sample_rate,
57 int number_of_channels, 57 int number_of_channels,
58 int number_of_frames, 58 int number_of_frames) {
59 int audio_delay_milliseconds,
60 int current_volume,
61 bool need_audio_processing,
62 bool key_pressed) {
63 int total_delay_ms = 0;
64 { 59 {
65 base::AutoLock auto_lock(lock_); 60 base::AutoLock auto_lock(lock_);
66 // Return immediately when not recording or |channels| is empty. 61 // Return immediately when not recording or |channels| is empty.
67 // See crbug.com/274017: renderer crash dereferencing invalid channels[0]. 62 // See crbug.com/274017: renderer crash dereferencing invalid channels[0].
68 if (!recording_ || channels.empty()) 63 if (!recording_ || channels.empty())
69 return 0; 64 return;
70
71 // Store the reported audio delay locally.
72 input_delay_ms_ = audio_delay_milliseconds;
73 total_delay_ms = input_delay_ms_ + output_delay_ms_;
74 DVLOG(2) << "total delay: " << input_delay_ms_ + output_delay_ms_;
75 } 65 }
76 66
77 // Write audio samples in blocks of 10 milliseconds to the registered 67 // Deliver 10ms of recorded 16-bit linear PCM audio.
78 // webrtc::AudioTransport sink. Keep writing until our internal byte 68 audio_transport_callback_->OnDataAvailable(
79 // buffer is empty. 69 &channels[0], channels.size(), audio_data, sample_rate,
80 const int16* audio_buffer = audio_data; 70 number_of_channels, number_of_frames, 0, 0, false, false);
81 const int samples_per_10_msec = (sample_rate / 100);
82 int accumulated_audio_samples = 0;
83 uint32_t new_volume = 0;
84 while (accumulated_audio_samples < number_of_frames) {
85 // Deliver 10ms of recorded 16-bit linear PCM audio.
86 int new_mic_level = audio_transport_callback_->OnDataAvailable(
87 &channels[0],
88 channels.size(),
89 audio_buffer,
90 sample_rate,
91 number_of_channels,
92 samples_per_10_msec,
93 total_delay_ms,
94 current_volume,
95 key_pressed,
96 need_audio_processing);
97
98 accumulated_audio_samples += samples_per_10_msec;
99 audio_buffer += samples_per_10_msec * number_of_channels;
100
101 // The latest non-zero new microphone level will be returned.
102 if (new_mic_level)
103 new_volume = new_mic_level;
104 }
105
106 return new_volume;
107 } 71 }
108 72
109 void WebRtcAudioDeviceImpl::SetCaptureFormat( 73 void WebRtcAudioDeviceImpl::SetCaptureFormat(
110 const media::AudioParameters& params) { 74 const media::AudioParameters& params) {
111 DVLOG(1) << "WebRtcAudioDeviceImpl::SetCaptureFormat()"; 75 DVLOG(1) << "WebRtcAudioDeviceImpl::SetCaptureFormat()";
112 DCHECK(thread_checker_.CalledOnValidThread()); 76 DCHECK(thread_checker_.CalledOnValidThread());
113 } 77 }
114 78
115 void WebRtcAudioDeviceImpl::RenderData(uint8* audio_data, 79 void WebRtcAudioDeviceImpl::RenderData(uint8* audio_data,
116 int number_of_channels, 80 int number_of_channels,
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 for (CapturerList::const_iterator iter = capturers_.begin(); 439 for (CapturerList::const_iterator iter = capturers_.begin();
476 iter != capturers_.end(); ++iter) { 440 iter != capturers_.end(); ++iter) {
477 if (!(*iter)->device_id().empty()) 441 if (!(*iter)->device_id().empty())
478 return *iter; 442 return *iter;
479 } 443 }
480 444
481 return NULL; 445 return NULL;
482 } 446 }
483 447
484 } // namespace content 448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698