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

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

Issue 90743004: Add generic interfaces for the sinks of the media stream audio track (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added a DCHECK(other) and rebased Created 7 years 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 (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 "content/renderer/media/webrtc_local_audio_renderer.h" 5 #include "content/renderer/media/webrtc_local_audio_renderer.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 DVLOG(2) << "loopback FIFO is empty"; 49 DVLOG(2) << "loopback FIFO is empty";
50 } 50 }
51 51
52 return audio_bus->frames(); 52 return audio_bus->frames();
53 } 53 }
54 54
55 void WebRtcLocalAudioRenderer::OnRenderError() { 55 void WebRtcLocalAudioRenderer::OnRenderError() {
56 NOTIMPLEMENTED(); 56 NOTIMPLEMENTED();
57 } 57 }
58 58
59 // content::WebRtcAudioCapturerSink implementation 59 // content::MediaStreamAudioSink implementation
60 int WebRtcLocalAudioRenderer::CaptureData(const std::vector<int>& channels, 60 void WebRtcLocalAudioRenderer::OnData(const int16* audio_data,
61 const int16* audio_data, 61 int sample_rate,
62 int sample_rate, 62 int number_of_channels,
63 int number_of_channels, 63 int number_of_frames) {
64 int number_of_frames,
65 int audio_delay_milliseconds,
66 int current_volume,
67 bool need_audio_processing,
68 bool key_pressed) {
69 DCHECK(capture_thread_checker_.CalledOnValidThread()); 64 DCHECK(capture_thread_checker_.CalledOnValidThread());
70 TRACE_EVENT0("audio", "WebRtcLocalAudioRenderer::CaptureData"); 65 TRACE_EVENT0("audio", "WebRtcLocalAudioRenderer::CaptureData");
71 base::AutoLock auto_lock(thread_lock_); 66 base::AutoLock auto_lock(thread_lock_);
72 if (!playing_ || !volume_ || !loopback_fifo_) 67 if (!playing_ || !volume_ || !loopback_fifo_)
73 return 0; 68 return;
74 69
75 // Push captured audio to FIFO so it can be read by a local sink. 70 // Push captured audio to FIFO so it can be read by a local sink.
76 if (loopback_fifo_->frames() + number_of_frames <= 71 if (loopback_fifo_->frames() + number_of_frames <=
77 loopback_fifo_->max_frames()) { 72 loopback_fifo_->max_frames()) {
78 scoped_ptr<media::AudioBus> audio_source = media::AudioBus::Create( 73 scoped_ptr<media::AudioBus> audio_source = media::AudioBus::Create(
79 number_of_channels, number_of_frames); 74 number_of_channels, number_of_frames);
80 audio_source->FromInterleaved(audio_data, 75 audio_source->FromInterleaved(audio_data,
81 audio_source->frames(), 76 audio_source->frames(),
82 sizeof(audio_data[0])); 77 sizeof(audio_data[0]));
83 loopback_fifo_->Push(audio_source.get()); 78 loopback_fifo_->Push(audio_source.get());
84 79
85 const base::TimeTicks now = base::TimeTicks::Now(); 80 const base::TimeTicks now = base::TimeTicks::Now();
86 total_render_time_ += now - last_render_time_; 81 total_render_time_ += now - last_render_time_;
87 last_render_time_ = now; 82 last_render_time_ = now;
88 } else { 83 } else {
89 DVLOG(1) << "FIFO is full"; 84 DVLOG(1) << "FIFO is full";
90 } 85 }
91
92 return 0;
93 } 86 }
94 87
95 void WebRtcLocalAudioRenderer::SetCaptureFormat( 88 void WebRtcLocalAudioRenderer::OnSetFormat(
96 const media::AudioParameters& params) { 89 const media::AudioParameters& params) {
97 DVLOG(1) << "WebRtcLocalAudioRenderer::SetCaptureFormat()"; 90 DVLOG(1) << "WebRtcLocalAudioRenderer::OnSetFormat()";
98 // If the source is restarted, we might have changed to another capture 91 // If the source is restarted, we might have changed to another capture
99 // thread. 92 // thread.
100 capture_thread_checker_.DetachFromThread(); 93 capture_thread_checker_.DetachFromThread();
101 DCHECK(capture_thread_checker_.CalledOnValidThread()); 94 DCHECK(capture_thread_checker_.CalledOnValidThread());
102 95
103 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match 96 // Reset the |source_params_|, |sink_params_| and |loopback_fifo_| to match
104 // the new format. 97 // the new format.
105 { 98 {
106 base::AutoLock auto_lock(thread_lock_); 99 base::AutoLock auto_lock(thread_lock_);
107 if (source_params_ == params) 100 if (source_params_ == params)
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // parameters. Then, invoke MaybeStartSink() to restart everything again. 313 // parameters. Then, invoke MaybeStartSink() to restart everything again.
321 if (sink_started_) { 314 if (sink_started_) {
322 sink_->Stop(); 315 sink_->Stop();
323 sink_started_ = false; 316 sink_started_ = false;
324 } 317 }
325 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_); 318 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_);
326 MaybeStartSink(); 319 MaybeStartSink();
327 } 320 }
328 321
329 } // namespace content 322 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698