OLD | NEW |
---|---|
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_controller.h" | 5 #include "media/audio/audio_input_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
9 #include "media/base/limits.h" | 9 #include "media/base/limits.h" |
10 #include "media/base/scoped_histogram_timer.h" | 10 #include "media/base/scoped_histogram_timer.h" |
11 | 11 |
12 #if defined(OS_MACOSX) | |
13 #include <ApplicationServices/ApplicationServices.h> | |
14 #endif | |
15 | |
12 namespace { | 16 namespace { |
13 const int kMaxInputChannels = 2; | 17 const int kMaxInputChannels = 2; |
14 | 18 |
15 // TODO(henrika): remove usage of timers and add support for proper | 19 // TODO(henrika): remove usage of timers and add support for proper |
16 // notification of when the input device is removed. This was originally added | 20 // notification of when the input device is removed. This was originally added |
17 // to resolve http://crbug.com/79936 for Windows platforms. This then caused | 21 // to resolve http://crbug.com/79936 for Windows platforms. This then caused |
18 // breakage (very hard to repro bugs!) on other platforms: See | 22 // breakage (very hard to repro bugs!) on other platforms: See |
19 // http://crbug.com/226327 and http://crbug.com/230972. | 23 // http://crbug.com/226327 and http://crbug.com/230972. |
20 const int kTimerResetIntervalSeconds = 1; | 24 const int kTimerResetIntervalSeconds = 1; |
21 #if defined(OS_IOS) | 25 #if defined(OS_IOS) |
(...skipping 17 matching lines...) Expand all Loading... | |
39 SyncWriter* sync_writer, | 43 SyncWriter* sync_writer, |
40 UserInputMonitor* user_input_monitor) | 44 UserInputMonitor* user_input_monitor) |
41 : creator_loop_(base::MessageLoopProxy::current()), | 45 : creator_loop_(base::MessageLoopProxy::current()), |
42 handler_(handler), | 46 handler_(handler), |
43 stream_(NULL), | 47 stream_(NULL), |
44 data_is_active_(false), | 48 data_is_active_(false), |
45 state_(kEmpty), | 49 state_(kEmpty), |
46 sync_writer_(sync_writer), | 50 sync_writer_(sync_writer), |
47 max_volume_(0.0), | 51 max_volume_(0.0), |
48 user_input_monitor_(user_input_monitor), | 52 user_input_monitor_(user_input_monitor), |
53 prev_key_down_count_(0), | |
49 key_pressed_(false) { | 54 key_pressed_(false) { |
50 DCHECK(creator_loop_.get()); | 55 DCHECK(creator_loop_.get()); |
51 } | 56 } |
52 | 57 |
53 AudioInputController::~AudioInputController() { | 58 AudioInputController::~AudioInputController() { |
54 DCHECK(kClosed == state_ || kCreated == state_ || kEmpty == state_); | 59 DCHECK(kClosed == state_ || kCreated == state_ || kEmpty == state_); |
55 } | 60 } |
56 | 61 |
57 // static | 62 // static |
58 scoped_refptr<AudioInputController> AudioInputController::Create( | 63 scoped_refptr<AudioInputController> AudioInputController::Create( |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 | 239 |
235 if (no_data_timer_) { | 240 if (no_data_timer_) { |
236 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, | 241 // Start the data timer. Once |kTimerResetIntervalSeconds| have passed, |
237 // a callback to DoCheckForNoData() is made. | 242 // a callback to DoCheckForNoData() is made. |
238 no_data_timer_->Reset(); | 243 no_data_timer_->Reset(); |
239 } | 244 } |
240 | 245 |
241 stream_->Start(this); | 246 stream_->Start(this); |
242 handler_->OnRecording(this); | 247 handler_->OnRecording(this); |
243 | 248 |
249 #if defined(OS_MACOSX) | |
250 prev_key_down_count_ = CGEventSourceCounterForEventType( | |
251 kCGEventSourceStateHIDSystemState, kCGEventKeyDown); | |
252 #endif // defined(OS_MACOSX) | |
253 | |
244 if (user_input_monitor_) | 254 if (user_input_monitor_) |
245 user_input_monitor_->AddKeyStrokeListener(this); | 255 user_input_monitor_->AddKeyStrokeListener(this); |
246 } | 256 } |
247 | 257 |
248 void AudioInputController::DoClose() { | 258 void AudioInputController::DoClose() { |
249 DCHECK(message_loop_->BelongsToCurrentThread()); | 259 DCHECK(message_loop_->BelongsToCurrentThread()); |
250 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CloseTime"); | 260 SCOPED_UMA_HISTOGRAM_TIMER("Media.AudioInputController.CloseTime"); |
251 | 261 |
252 // Delete the timer on the same thread that created it. | 262 // Delete the timer on the same thread that created it. |
253 no_data_timer_.reset(); | 263 no_data_timer_.reset(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 double volume) { | 345 double volume) { |
336 bool key_pressed = false; | 346 bool key_pressed = false; |
337 { | 347 { |
338 base::AutoLock auto_lock(lock_); | 348 base::AutoLock auto_lock(lock_); |
339 if (state_ != kRecording) | 349 if (state_ != kRecording) |
340 return; | 350 return; |
341 | 351 |
342 std::swap(key_pressed, key_pressed_); | 352 std::swap(key_pressed, key_pressed_); |
343 } | 353 } |
344 | 354 |
355 #if defined(OS_MACOSX) | |
Robert Sesek
2013/08/22 20:45:16
nit: #if should not be indented
| |
356 uint32_t current_count = CGEventSourceCounterForEventType( | |
357 kCGEventSourceStateHIDSystemState, kCGEventKeyDown); | |
358 if (current_count != prev_key_down_count_) { | |
359 key_pressed = true; | |
360 } | |
361 prev_key_down_count_ = current_count; | |
362 #endif // defined(OS_MACOSX) | |
363 | |
345 // Mark data as active to ensure that the periodic calls to | 364 // Mark data as active to ensure that the periodic calls to |
346 // DoCheckForNoData() does not report an error to the event handler. | 365 // DoCheckForNoData() does not report an error to the event handler. |
347 SetDataIsActive(true); | 366 SetDataIsActive(true); |
348 | 367 |
349 // Use SyncSocket if we are in a low-latency mode. | 368 // Use SyncSocket if we are in a low-latency mode. |
350 if (LowLatencyMode()) { | 369 if (LowLatencyMode()) { |
351 sync_writer_->Write(data, size, volume, key_pressed); | 370 sync_writer_->Write(data, size, volume, key_pressed); |
352 sync_writer_->UpdateRecordedBytes(hardware_delay_bytes); | 371 sync_writer_->UpdateRecordedBytes(hardware_delay_bytes); |
353 return; | 372 return; |
354 } | 373 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 411 |
393 void AudioInputController::SetDataIsActive(bool enabled) { | 412 void AudioInputController::SetDataIsActive(bool enabled) { |
394 base::subtle::Release_Store(&data_is_active_, enabled); | 413 base::subtle::Release_Store(&data_is_active_, enabled); |
395 } | 414 } |
396 | 415 |
397 bool AudioInputController::GetDataIsActive() { | 416 bool AudioInputController::GetDataIsActive() { |
398 return (base::subtle::Acquire_Load(&data_is_active_) != false); | 417 return (base::subtle::Acquire_Load(&data_is_active_) != false); |
399 } | 418 } |
400 | 419 |
401 } // namespace media | 420 } // namespace media |
OLD | NEW |