Skip to content

Commit

Permalink
Revert 217768 "Adding key press detection in the browser process."
Browse files Browse the repository at this point in the history
> Adding key press detection in the browser process.
> It works like this on the browser side: 
> A new object KeyPressMonitor is created on BrowserMainLoop and passed to AudioInputRendererHost to pass to AudioInputController.
> AudioInputController::DoRecord calls KeyPressMonitor::AddKeyPressListener --> KeyPressMonitor listens to system key events through UserInputMonitor(only implemented on Linux) --> AudioInputController::OnKeyPressed is called and sets key_pressed_ --> When AudioInputController::OnData called, it writes key_pressed_ to shared memory along with the audio data buffer.
> On the renderer side a new param "key_pressed" is added through the code path of passing the flag to the webrtc voice engine.
> This CL includes all these changes except the implementation of UserInputMonitor for Windows and Mac. The impl of UserInputMonitor is mostly copied from remoting/host/local_input_monitor_linux.cc
> 
> 
> BUG=
> 
> Review URL: https://chromiumcodereview.appspot.com/21183002

TBR=jiayl@chromium.org

Review URL: https://codereview.chromium.org/22871007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217774 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
phoglund@chromium.org committed Aug 15, 2013
1 parent 8c2614c commit 1a8d01d
Show file tree
Hide file tree
Showing 37 changed files with 159 additions and 931 deletions.
9 changes: 0 additions & 9 deletions content/browser/browser_main_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#include "crypto/nss_util.h"
#include "media/audio/audio_manager.h"
#include "media/base/media.h"
#include "media/base/user_input_monitor.h"
#include "media/midi/midi_manager.h"
#include "net/base/network_change_notifier.h"
#include "net/socket/client_socket_factory.h"
Expand Down Expand Up @@ -873,14 +872,6 @@ int BrowserMainLoop::BrowserThreadsStarted() {
audio_manager_.get(), media_stream_manager_.get()));
}

{
TRACE_EVENT0(
"startup",
"BrowserMainLoop::BrowserThreadsStarted::InitUserInputMonitor");
user_input_monitor_ = media::UserInputMonitor::Create(
io_thread_->message_loop_proxy(), main_thread_->message_loop_proxy());
}

// Alert the clipboard class to which threads are allowed to access the
// clipboard:
std::vector<base::PlatformThreadId> allowed_clipboard_threads;
Expand Down
6 changes: 0 additions & 6 deletions content/browser/browser_main_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class TraceMemoryController;
namespace media {
class AudioManager;
class MIDIManager;
class UserInputMonitor;
} // namespace media

namespace net {
Expand Down Expand Up @@ -87,9 +86,6 @@ class CONTENT_EXPORT BrowserMainLoop {
MediaStreamManager* media_stream_manager() const {
return media_stream_manager_.get();
}
media::UserInputMonitor* user_input_monitor() const {
return user_input_monitor_.get();
}
media::MIDIManager* midi_manager() const { return midi_manager_.get(); }
base::Thread* indexed_db_thread() const { return indexed_db_thread_.get(); }

Expand Down Expand Up @@ -126,8 +122,6 @@ class CONTENT_EXPORT BrowserMainLoop {
scoped_ptr<base::PowerMonitor> power_monitor_;
scoped_ptr<base::HighResolutionTimerManager> hi_res_timer_manager_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
// user_input_monitor_ has to outlive audio_manager_, so declared first.
scoped_ptr<media::UserInputMonitor> user_input_monitor_;
scoped_ptr<media::AudioManager> audio_manager_;
scoped_ptr<media::MIDIManager> midi_manager_;
scoped_ptr<AudioMirroringManager> audio_mirroring_manager_;
Expand Down
30 changes: 13 additions & 17 deletions content/browser/renderer_host/media/audio_input_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ AudioInputRendererHost::AudioEntry::~AudioEntry() {}
AudioInputRendererHost::AudioInputRendererHost(
media::AudioManager* audio_manager,
MediaStreamManager* media_stream_manager,
AudioMirroringManager* audio_mirroring_manager,
media::UserInputMonitor* user_input_monitor)
AudioMirroringManager* audio_mirroring_manager)
: audio_manager_(audio_manager),
media_stream_manager_(media_stream_manager),
audio_mirroring_manager_(audio_mirroring_manager),
user_input_monitor_(user_input_monitor) {}
audio_mirroring_manager_(audio_mirroring_manager) {
}

AudioInputRendererHost::~AudioInputRendererHost() {
DCHECK(audio_entries_.empty());
Expand Down Expand Up @@ -273,23 +272,20 @@ void AudioInputRendererHost::OnCreateStream(
entry->controller = media::AudioInputController::CreateForStream(
audio_manager_->GetMessageLoop(),
this,
WebContentsAudioInputStream::Create(device_id,
audio_params,
audio_manager_->GetWorkerLoop(),
audio_mirroring_manager_),
entry->writer.get(),
user_input_monitor_);
WebContentsAudioInputStream::Create(
device_id, audio_params, audio_manager_->GetWorkerLoop(),
audio_mirroring_manager_),
entry->writer.get());
} else {
// TODO(henrika): replace CreateLowLatency() with Create() as soon
// as satish has ensured that Speech Input also uses the default low-
// latency path. See crbug.com/112472 for details.
entry->controller =
media::AudioInputController::CreateLowLatency(audio_manager_,
this,
audio_params,
device_id,
entry->writer.get(),
user_input_monitor_);
entry->controller = media::AudioInputController::CreateLowLatency(
audio_manager_,
this,
audio_params,
device_id,
entry->writer.get());
}

if (!entry->controller.get()) {
Expand Down
13 changes: 4 additions & 9 deletions content/browser/renderer_host/media/audio_input_renderer_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
namespace media {
class AudioManager;
class AudioParameters;
class UserInputMonitor;
}

namespace content {
Expand All @@ -56,11 +55,10 @@ class CONTENT_EXPORT AudioInputRendererHost
public media::AudioInputController::EventHandler {
public:
// Called from UI thread from the owner of this object.
// |user_input_monitor| is used for typing detection and can be NULL.
AudioInputRendererHost(media::AudioManager* audio_manager,
MediaStreamManager* media_stream_manager,
AudioMirroringManager* audio_mirroring_manager,
media::UserInputMonitor* user_input_monitor);
AudioInputRendererHost(
media::AudioManager* audio_manager,
MediaStreamManager* media_stream_manager,
AudioMirroringManager* audio_mirroring_manager);

// BrowserMessageFilter implementation.
virtual void OnChannelClosing() OVERRIDE;
Expand Down Expand Up @@ -156,9 +154,6 @@ class CONTENT_EXPORT AudioInputRendererHost
// A map of stream IDs to audio sources.
AudioEntryMap audio_entries_;

// Raw pointer of the UserInputMonitor.
media::UserInputMonitor* user_input_monitor_;

DISALLOW_COPY_AND_ASSIGN(AudioInputRendererHost);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) {
socket_->Send(&bytes, sizeof(bytes));
}

uint32 AudioInputSyncWriter::Write(const void* data,
uint32 size,
double volume,
bool key_pressed) {
uint32 AudioInputSyncWriter::Write(
const void* data, uint32 size, double volume) {
uint8* ptr = static_cast<uint8*>(shared_memory_->memory());
ptr += current_segment_id_ * shared_memory_segment_size_;
media::AudioInputBuffer* buffer =
reinterpret_cast<media::AudioInputBuffer*>(ptr);
buffer->params.volume = volume;
buffer->params.size = size;
buffer->params.key_pressed = key_pressed;
memcpy(buffer->audio, data, size);

if (++current_segment_id_ >= shared_memory_segment_count_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ class AudioInputSyncWriter : public media::AudioInputController::SyncWriter {

// media::AudioOutputController::SyncWriter implementation.
virtual void UpdateRecordedBytes(uint32 bytes) OVERRIDE;
virtual uint32 Write(const void* data,
uint32 size,
double volume,
bool key_pressed) OVERRIDE;
virtual uint32 Write(const void* data, uint32 size, double volume) OVERRIDE;
virtual void Close() OVERRIDE;

bool Init();
Expand Down
9 changes: 3 additions & 6 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,11 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new AudioInputRendererHost(
audio_manager,
media_stream_manager,
BrowserMainLoop::GetInstance()->audio_mirroring_manager(),
BrowserMainLoop::GetInstance()->user_input_monitor()));
BrowserMainLoop::GetInstance()->audio_mirroring_manager()));
channel_->AddFilter(new AudioRendererHost(
GetID(),
audio_manager,
GetID(), audio_manager,
BrowserMainLoop::GetInstance()->audio_mirroring_manager(),
media_internals,
media_stream_manager));
media_internals, media_stream_manager));
channel_->AddFilter(
new MIDIHost(BrowserMainLoop::GetInstance()->midi_manager()));
channel_->AddFilter(new MIDIDispatcherHost(GetID(), browser_context));
Expand Down
2 changes: 1 addition & 1 deletion content/browser/speech/speech_recognizer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ SpeechRecognizerImpl::StartRecording(const FSMEventArgs&) {
new OnDataConverter(input_parameters, output_parameters));

audio_controller_ = AudioInputController::Create(
audio_manager, this, input_parameters, device_id_, NULL);
audio_manager, this, input_parameters, device_id_);

if (!audio_controller_.get()) {
return Abort(SpeechRecognitionError(SPEECH_RECOGNITION_ERROR_AUDIO));
Expand Down
2 changes: 1 addition & 1 deletion content/renderer/media/webaudio_capturer_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void WebAudioCapturerSource::consumeAudio(
int capture_frames = params_.frames_per_buffer();
while (fifo_->frames() >= capture_frames) {
fifo_->Consume(capture_bus_.get(), 0, capture_frames);
callback_->Capture(capture_bus_.get(), 0, 1.0, false);
callback_->Capture(capture_bus_.get(), 0, 1.0);
}
}

Expand Down
22 changes: 8 additions & 14 deletions content/renderer/media/webrtc_audio_capturer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,14 @@ class WebRtcAudioCapturer::TrackOwner
int number_of_channels,
int number_of_frames,
int audio_delay_milliseconds,
int volume,
bool key_pressed) {
int volume) {
base::AutoLock lock(lock_);
if (delegate_) {
delegate_->CaptureData(audio_data,
number_of_channels,
number_of_frames,
audio_delay_milliseconds,
volume,
key_pressed);
volume);
}
}

Expand Down Expand Up @@ -426,11 +424,10 @@ void WebRtcAudioCapturer::SetAutomaticGainControl(bool enable) {

void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source,
int audio_delay_milliseconds,
double volume,
bool key_pressed) {
// This callback is driven by AudioInputDevice::AudioThreadCallback if
// |source_| is AudioInputDevice, otherwise it is driven by client's
// CaptureCallback.
double volume) {
// This callback is driven by AudioInputDevice::AudioThreadCallback if
// |source_| is AudioInputDevice, otherwise it is driven by client's
// CaptureCallback.
#if defined(OS_WIN) || defined(OS_MACOSX)
DCHECK_LE(volume, 1.0);
#elif defined(OS_LINUX) || defined(OS_OPENBSD)
Expand Down Expand Up @@ -474,11 +471,8 @@ void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source,
it != tracks.end();
++it) {
(*it)->CaptureData(buffer_ref_while_calling->buffer(),
audio_source->channels(),
audio_source->frames(),
audio_delay_milliseconds,
volume,
key_pressed);
audio_source->channels(), audio_source->frames(),
audio_delay_milliseconds, volume_);
}
}

Expand Down
3 changes: 1 addition & 2 deletions content/renderer/media/webrtc_audio_capturer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ class CONTENT_EXPORT WebRtcAudioCapturer
// Called on the AudioInputDevice audio thread.
virtual void Capture(media::AudioBus* audio_source,
int audio_delay_milliseconds,
double volume,
bool key_pressed) OVERRIDE;
double volume) OVERRIDE;
virtual void OnCaptureError() OVERRIDE;

// Reconfigures the capturer with a new buffer size and capture parameters.
Expand Down
16 changes: 5 additions & 11 deletions content/renderer/media/webrtc_audio_capturer_sink_owner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ int WebRtcAudioCapturerSinkOwner::CaptureData(const std::vector<int>& channels,
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) {
bool need_audio_processing) {
base::AutoLock lock(lock_);
if (delegate_) {
delegate_->CaptureData(channels,
audio_data,
sample_rate,
number_of_channels,
number_of_frames,
audio_delay_milliseconds,
current_volume,
need_audio_processing,
key_pressed);
return delegate_->CaptureData(channels, audio_data, sample_rate,
number_of_channels, number_of_frames,
audio_delay_milliseconds, current_volume,
need_audio_processing);
}

return 0;
Expand Down
3 changes: 1 addition & 2 deletions content/renderer/media/webrtc_audio_capturer_sink_owner.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class WebRtcAudioCapturerSinkOwner
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) OVERRIDE;
bool need_audio_processing) OVERRIDE;

virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE;

Expand Down
5 changes: 3 additions & 2 deletions content/renderer/media/webrtc_audio_device_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ int WebRtcAudioDeviceImpl::CaptureData(const std::vector<int>& channels,
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) {
bool need_audio_processing) {
int total_delay_ms = 0;
{
base::AutoLock auto_lock(lock_);
Expand All @@ -76,9 +75,11 @@ int WebRtcAudioDeviceImpl::CaptureData(const std::vector<int>& channels,
// Write audio samples in blocks of 10 milliseconds to the registered
// webrtc::AudioTransport sink. Keep writing until our internal byte
// buffer is empty.
// TODO(niklase): Wire up the key press detection.
const int16* audio_buffer = audio_data;
const int samples_per_10_msec = (sample_rate / 100);
int accumulated_audio_samples = 0;
bool key_pressed = false;
uint32_t new_volume = 0;
while (accumulated_audio_samples < number_of_frames) {
// Deliver 10ms of recorded 16-bit linear PCM audio.
Expand Down
6 changes: 2 additions & 4 deletions content/renderer/media/webrtc_audio_device_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ class WebRtcAudioCapturerSink {
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) = 0;
bool need_audio_processing) = 0;

// Set the format for the capture audio parameters.
virtual void SetCaptureFormat(const media::AudioParameters& params) = 0;
Expand Down Expand Up @@ -340,8 +339,7 @@ class CONTENT_EXPORT WebRtcAudioDeviceImpl
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) OVERRIDE;
bool need_audio_processing) OVERRIDE;

// Called on the main render thread.
virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE;
Expand Down
12 changes: 3 additions & 9 deletions content/renderer/media/webrtc_audio_device_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ class MockWebRtcAudioCapturerSink : public WebRtcAudioCapturerSink {
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) OVERRIDE {
bool need_audio_processing) OVERRIDE {
// Signal that a callback has been received.
event_->Signal();
return 0;
Expand Down Expand Up @@ -382,13 +381,8 @@ int RunWebRtcLoopbackTimeTest(media::AudioManager* manager,
capturer_sink->CaptureData(
voe_channels,
reinterpret_cast<int16*>(capture_data.get() + input_packet_size * j),
params.sample_rate(),
params.channels(),
params.frames_per_buffer(),
kHardwareLatencyInMs,
1.0,
enable_apm,
false);
params.sample_rate(), params.channels(), params.frames_per_buffer(),
kHardwareLatencyInMs, 1.0, enable_apm);

// Receiving data from WebRtc.
renderer_source->RenderData(
Expand Down
15 changes: 7 additions & 8 deletions content/renderer/media/webrtc_local_audio_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ void WebRtcLocalAudioRenderer::OnRenderError() {

// content::WebRtcAudioCapturerSink implementation
int WebRtcLocalAudioRenderer::CaptureData(const std::vector<int>& channels,
const int16* audio_data,
int sample_rate,
int number_of_channels,
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) {
const int16* audio_data,
int sample_rate,
int number_of_channels,
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing) {
TRACE_EVENT0("audio", "WebRtcLocalAudioRenderer::CaptureData");
base::AutoLock auto_lock(thread_lock_);

Expand Down
3 changes: 1 addition & 2 deletions content/renderer/media/webrtc_local_audio_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ class CONTENT_EXPORT WebRtcLocalAudioRenderer
int number_of_frames,
int audio_delay_milliseconds,
int current_volume,
bool need_audio_processing,
bool key_pressed) OVERRIDE;
bool need_audio_processing) OVERRIDE;

// Can be called on different user thread.
virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE;
Expand Down
Loading

0 comments on commit 1a8d01d

Please sign in to comment.