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

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

Issue 22801007: Adds the UserInputMonitor implementation for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 no_data_timer_->Start( 332 no_data_timer_->Start(
328 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds), 333 FROM_HERE, base::TimeDelta::FromSeconds(kTimerResetIntervalSeconds),
329 base::Bind(&AudioInputController::DoCheckForNoData, 334 base::Bind(&AudioInputController::DoCheckForNoData,
330 base::Unretained(this))); 335 base::Unretained(this)));
331 } 336 }
332 337
333 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, 338 void AudioInputController::OnData(AudioInputStream* stream, const uint8* data,
334 uint32 size, uint32 hardware_delay_bytes, 339 uint32 size, uint32 hardware_delay_bytes,
335 double volume) { 340 double volume) {
336 bool key_pressed = false; 341 bool key_pressed = false;
342 #if defined(OS_MACOSX)
343 uint32_t current_count = CGEventSourceCounterForEventType(
Mark Mentovai 2013/08/22 18:27:52 I don’t know much about when this thing is called.
jiayl 2013/08/22 18:51:16 Done initialization in DoRecord. I don't think it
344 kCGEventSourceStateHIDSystemState, kCGEventKeyDown);
345 if (current_count > prev_key_down_count_ && prev_key_down_count_ != 0) {
Mark Mentovai 2013/08/22 18:27:52 If you change > to !=, then this handles rollover
jiayl 2013/08/22 18:51:16 Done.
346 key_pressed = true;
347 }
348 prev_key_down_count_ = current_count;
349 #else
337 { 350 {
338 base::AutoLock auto_lock(lock_); 351 base::AutoLock auto_lock(lock_);
339 if (state_ != kRecording) 352 if (state_ != kRecording)
340 return; 353 return;
341 354
342 std::swap(key_pressed, key_pressed_); 355 std::swap(key_pressed, key_pressed_);
343 } 356 }
357 #endif // defined(OS_MACOSX)
344 358
345 // Mark data as active to ensure that the periodic calls to 359 // Mark data as active to ensure that the periodic calls to
346 // DoCheckForNoData() does not report an error to the event handler. 360 // DoCheckForNoData() does not report an error to the event handler.
347 SetDataIsActive(true); 361 SetDataIsActive(true);
348 362
349 // Use SyncSocket if we are in a low-latency mode. 363 // Use SyncSocket if we are in a low-latency mode.
350 if (LowLatencyMode()) { 364 if (LowLatencyMode()) {
351 sync_writer_->Write(data, size, volume, key_pressed); 365 sync_writer_->Write(data, size, volume, key_pressed);
352 sync_writer_->UpdateRecordedBytes(hardware_delay_bytes); 366 sync_writer_->UpdateRecordedBytes(hardware_delay_bytes);
353 return; 367 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 406
393 void AudioInputController::SetDataIsActive(bool enabled) { 407 void AudioInputController::SetDataIsActive(bool enabled) {
394 base::subtle::Release_Store(&data_is_active_, enabled); 408 base::subtle::Release_Store(&data_is_active_, enabled);
395 } 409 }
396 410
397 bool AudioInputController::GetDataIsActive() { 411 bool AudioInputController::GetDataIsActive() {
398 return (base::subtle::Acquire_Load(&data_is_active_) != false); 412 return (base::subtle::Acquire_Load(&data_is_active_) != false);
399 } 413 }
400 414
401 } // namespace media 415 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698