summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/audio/audio_manager.h3
-rw-r--r--media/audio/audio_manager_base.cc19
-rw-r--r--media/audio/audio_manager_base.h32
-rw-r--r--media/audio/audio_output_proxy_unittest.cc1
-rw-r--r--media/audio/linux/alsa_input.cc10
-rw-r--r--media/audio/linux/alsa_input.h9
-rw-r--r--media/audio/linux/audio_manager_linux.h25
-rw-r--r--media/audio/mac/audio_input_mac.cc6
-rw-r--r--media/audio/mac/audio_input_mac.h11
-rw-r--r--media/audio/mac/audio_manager_mac.h18
-rw-r--r--media/audio/openbsd/audio_manager_openbsd.cc5
-rw-r--r--media/audio/openbsd/audio_manager_openbsd.h16
-rw-r--r--media/audio/win/audio_manager_win.h24
-rw-r--r--media/audio/win/wavein_input_win.cc6
-rw-r--r--media/audio/win/wavein_input_win.h9
15 files changed, 135 insertions, 59 deletions
diff --git a/media/audio/audio_manager.h b/media/audio/audio_manager.h
index d80026d..628eee9 100644
--- a/media/audio/audio_manager.h
+++ b/media/audio/audio_manager.h
@@ -100,6 +100,9 @@ class MEDIA_EXPORT AudioManager {
virtual void MuteAll() = 0;
virtual void UnMuteAll() = 0;
+ // Used to determine if something else is currently making use of audio input.
+ virtual bool IsRecordingInProcess() = 0;
+
// Returns message loop used for audio IO.
virtual MessageLoop* GetMessageLoop() = 0;
diff --git a/media/audio/audio_manager_base.cc b/media/audio/audio_manager_base.cc
index d0614f4..5053e87 100644
--- a/media/audio/audio_manager_base.cc
+++ b/media/audio/audio_manager_base.cc
@@ -12,7 +12,8 @@ const char AudioManagerBase::kDefaultDeviceName[] = "Default";
AudioManagerBase::AudioManagerBase()
: audio_thread_("AudioThread"),
- initialized_(false) {
+ initialized_(false),
+ num_active_input_streams_(0) {
}
AudioManagerBase::~AudioManagerBase() {
@@ -62,3 +63,19 @@ void AudioManagerBase::ShowAudioInputSettings() {
void AudioManagerBase::GetAudioInputDeviceNames(
media::AudioDeviceNames* device_names) {
}
+
+void AudioManagerBase::IncreaseActiveInputStreamCount() {
+ base::AutoLock auto_lock(active_input_streams_lock_);
+ ++num_active_input_streams_;
+}
+
+void AudioManagerBase::DecreaseActiveInputStreamCount() {
+ base::AutoLock auto_lock(active_input_streams_lock_);
+ DCHECK_GT(num_active_input_streams_, 0);
+ --num_active_input_streams_;
+}
+
+bool AudioManagerBase::IsRecordingInProcess() {
+ base::AutoLock auto_lock(active_input_streams_lock_);
+ return num_active_input_streams_ > 0;
+}
diff --git a/media/audio/audio_manager_base.h b/media/audio/audio_manager_base.h
index fb4c51e..f24a299 100644
--- a/media/audio/audio_manager_base.h
+++ b/media/audio/audio_manager_base.h
@@ -7,6 +7,7 @@
#include <map>
+#include "base/compiler_specific.h"
#include "base/threading/thread.h"
#include "media/audio/audio_manager.h"
@@ -20,20 +21,26 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
AudioManagerBase();
- virtual void Init();
- virtual void Cleanup();
+ virtual void Init() OVERRIDE;
+ virtual void Cleanup() OVERRIDE;
- virtual MessageLoop* GetMessageLoop();
+ virtual MessageLoop* GetMessageLoop() OVERRIDE;
- virtual string16 GetAudioInputDeviceModel();
+ virtual string16 GetAudioInputDeviceModel() OVERRIDE;
- virtual bool CanShowAudioInputSettings();
- virtual void ShowAudioInputSettings();
+ virtual bool CanShowAudioInputSettings() OVERRIDE;
+ virtual void ShowAudioInputSettings() OVERRIDE;
- virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names);
+ virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names)
+ OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStreamProxy(
- const AudioParameters& params);
+ const AudioParameters& params) OVERRIDE;
+
+ virtual bool IsRecordingInProcess() OVERRIDE;
+
+ void IncreaseActiveInputStreamCount();
+ void DecreaseActiveInputStreamCount();
protected:
virtual ~AudioManagerBase();
@@ -52,6 +59,15 @@ class MEDIA_EXPORT AudioManagerBase : public AudioManager {
AudioOutputDispatchersMap output_dispatchers_;
+ // Counts the number of active input streams to find out if something else
+ // is currently recording in Chrome.
+ int num_active_input_streams_;
+
+ // Lock used to synchronize the access to num_active_input_streams_.
+ // Do not use for anything else and try to avoid using other locks
+ // in this code whenever possible.
+ base::Lock active_input_streams_lock_;
+
DISALLOW_COPY_AND_ASSIGN(AudioManagerBase);
};
diff --git a/media/audio/audio_output_proxy_unittest.cc b/media/audio/audio_output_proxy_unittest.cc
index 895cb1b..50a5020 100644
--- a/media/audio/audio_output_proxy_unittest.cc
+++ b/media/audio/audio_output_proxy_unittest.cc
@@ -53,6 +53,7 @@ class MockAudioManager : public AudioManager {
MOCK_METHOD0(GetMessageLoop, MessageLoop*());
MOCK_METHOD1(GetAudioInputDeviceNames, void(
media::AudioDeviceNames* device_name));
+ MOCK_METHOD0(IsRecordingInProcess, bool());
};
class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback {
diff --git a/media/audio/linux/alsa_input.cc b/media/audio/linux/alsa_input.cc
index 8aad65a..725ecb4 100644
--- a/media/audio/linux/alsa_input.cc
+++ b/media/audio/linux/alsa_input.cc
@@ -9,8 +9,10 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/time.h"
+#include "media/audio/audio_manager.h"
#include "media/audio/linux/alsa_util.h"
#include "media/audio/linux/alsa_wrapper.h"
+#include "media/audio/linux/audio_manager_linux.h"
static const int kNumPacketsInRingBuffer = 3;
@@ -105,6 +107,9 @@ void AlsaPcmInputStream::Start(AudioInputCallback* callback) {
FROM_HERE,
base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
delay_ms);
+
+ static_cast<AudioManagerLinux*>(AudioManager::GetAudioManager())->
+ IncreaseActiveInputStreamCount();
}
}
@@ -213,6 +218,11 @@ void AlsaPcmInputStream::Stop() {
if (!device_handle_ || !callback_)
return;
+ // Stop is always called before Close. In case of error, this will be
+ // also called when closing the input controller.
+ static_cast<AudioManagerLinux*>(AudioManager::GetAudioManager())->
+ DecreaseActiveInputStreamCount();
+
weak_factory_.InvalidateWeakPtrs(); // Cancel the next scheduled read.
int error = wrapper_->PcmDrop(device_handle_);
if (error < 0)
diff --git a/media/audio/linux/alsa_input.h b/media/audio/linux/alsa_input.h
index 3e5209a..6aa1b87 100644
--- a/media/audio/linux/alsa_input.h
+++ b/media/audio/linux/alsa_input.h
@@ -9,6 +9,7 @@
#include <string>
+#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "media/audio/audio_io.h"
@@ -34,10 +35,10 @@ class AlsaPcmInputStream : public AudioInputStream {
virtual ~AlsaPcmInputStream();
// Implementation of AudioOutputStream.
- virtual bool Open();
- virtual void Start(AudioInputCallback* callback);
- virtual void Stop();
- virtual void Close();
+ virtual bool Open() OVERRIDE;
+ virtual void Start(AudioInputCallback* callback) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void Close() OVERRIDE;
private:
// Logs the error and invokes any registered callbacks.
diff --git a/media/audio/linux/audio_manager_linux.h b/media/audio/linux/audio_manager_linux.h
index 5ec6221..77ea481 100644
--- a/media/audio/linux/audio_manager_linux.h
+++ b/media/audio/linux/audio_manager_linux.h
@@ -7,6 +7,7 @@
#include <set>
+#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread.h"
#include "media/audio/audio_manager_base.h"
@@ -18,20 +19,22 @@ class MEDIA_EXPORT AudioManagerLinux : public AudioManagerBase {
AudioManagerLinux();
// Call before using a newly created AudioManagerLinux instance.
- virtual void Init();
+ virtual void Init() OVERRIDE;
// Implementation of AudioManager.
- virtual bool HasAudioOutputDevices();
- virtual bool HasAudioInputDevices();
+ virtual bool HasAudioOutputDevices() OVERRIDE;
+ virtual bool HasAudioInputDevices() OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStream(
- const AudioParameters& params);
- virtual AudioInputStream* MakeAudioInputStream(const AudioParameters& params);
- virtual bool CanShowAudioInputSettings();
- virtual void ShowAudioInputSettings();
- virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names);
-
- virtual void MuteAll();
- virtual void UnMuteAll();
+ const AudioParameters& params) OVERRIDE;
+ virtual AudioInputStream* MakeAudioInputStream(const AudioParameters& params)
+ OVERRIDE;
+ virtual bool CanShowAudioInputSettings() OVERRIDE;
+ virtual void ShowAudioInputSettings() OVERRIDE;
+ virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names)
+ OVERRIDE;
+
+ virtual void MuteAll() OVERRIDE;
+ virtual void UnMuteAll() OVERRIDE;
virtual void ReleaseOutputStream(AudioOutputStream* stream);
diff --git a/media/audio/mac/audio_input_mac.cc b/media/audio/mac/audio_input_mac.cc
index e96277f..c59eb61 100644
--- a/media/audio/mac/audio_input_mac.cc
+++ b/media/audio/mac/audio_input_mac.cc
@@ -70,11 +70,17 @@ void PCMQueueInAudioInputStream::Start(AudioInputCallback* callback) {
OSStatus err = AudioQueueStart(audio_queue_, NULL);
if (err != noErr)
HandleError(err);
+ else
+ manager_->IncreaseActiveInputStreamCount();
}
void PCMQueueInAudioInputStream::Stop() {
if (!audio_queue_)
return;
+ // Stop is always called before Close. In case of error, this will be
+ // also called when closing the input controller.
+ manager_->DecreaseActiveInputStreamCount();
+
// We request a synchronous stop, so the next call can take some time. In
// the windows implementation we block here as well.
OSStatus err = AudioQueueStop(audio_queue_, true);
diff --git a/media/audio/mac/audio_input_mac.h b/media/audio/mac/audio_input_mac.h
index 1796d82..7569c36 100644
--- a/media/audio/mac/audio_input_mac.h
+++ b/media/audio/mac/audio_input_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include <AudioToolbox/AudioQueue.h>
#include <AudioToolbox/AudioFormat.h>
+#include "base/compiler_specific.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_parameters.h"
@@ -23,10 +24,10 @@ class PCMQueueInAudioInputStream : public AudioInputStream {
virtual ~PCMQueueInAudioInputStream();
// Implementation of AudioInputStream.
- virtual bool Open();
- virtual void Start(AudioInputCallback* callback);
- virtual void Stop();
- virtual void Close();
+ virtual bool Open() OVERRIDE;
+ virtual void Start(AudioInputCallback* callback) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void Close() OVERRIDE;
private:
// Issue the OnError to |callback_|;
diff --git a/media/audio/mac/audio_manager_mac.h b/media/audio/mac/audio_manager_mac.h
index a8ffced..b7c29bc 100644
--- a/media/audio/mac/audio_manager_mac.h
+++ b/media/audio/mac/audio_manager_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#define MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "media/audio/audio_manager_base.h"
class PCMQueueInAudioInputStream;
@@ -19,15 +20,16 @@ class AudioManagerMac : public AudioManagerBase {
AudioManagerMac();
// Implementation of AudioManager.
- virtual bool HasAudioOutputDevices();
- virtual bool HasAudioInputDevices();
- virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names);
+ virtual bool HasAudioOutputDevices() OVERRIDE;
+ virtual bool HasAudioInputDevices() OVERRIDE;
+ virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names)
+ OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStream(
- const AudioParameters& params);
+ const AudioParameters& params) OVERRIDE;
virtual AudioInputStream* MakeAudioInputStream(
- const AudioParameters& params);
- virtual void MuteAll();
- virtual void UnMuteAll();
+ const AudioParameters& params) OVERRIDE;
+ virtual void MuteAll() OVERRIDE;
+ virtual void UnMuteAll() OVERRIDE;
// Mac-only method to free the streams created by above facoty methods.
// They are called internally by the respective audio stream when it has
diff --git a/media/audio/openbsd/audio_manager_openbsd.cc b/media/audio/openbsd/audio_manager_openbsd.cc
index c9fc9e8..cb94324 100644
--- a/media/audio/openbsd/audio_manager_openbsd.cc
+++ b/media/audio/openbsd/audio_manager_openbsd.cc
@@ -49,6 +49,11 @@ void AudioManagerOpenBSD::UnMuteAll() {
NOTIMPLEMENTED();
}
+bool AudioManagerOpenBSD::IsRecordingInProgress() {
+ NOTIMPLEMENTED();
+ return false;
+}
+
// static
AudioManager* AudioManager::CreateAudioManager() {
return new AudioManagerOpenBSD();
diff --git a/media/audio/openbsd/audio_manager_openbsd.h b/media/audio/openbsd/audio_manager_openbsd.h
index 455c38e..8f7c412 100644
--- a/media/audio/openbsd/audio_manager_openbsd.h
+++ b/media/audio/openbsd/audio_manager_openbsd.h
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
#define MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
+#include "base/compiler_specific.h"
#include "media/audio/audio_io.h"
class AudioManagerOpenBSD : public AudioManagerBase {
@@ -15,14 +16,15 @@ class AudioManagerOpenBSD : public AudioManagerBase {
virtual void Init();
// Implementation of AudioManager.
- virtual bool HasAudioOutputDevices();
- virtual bool HasAudioInputDevices();
+ virtual bool HasAudioOutputDevices() OVERRIDE;
+ virtual bool HasAudioInputDevices() OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStream(
- const AudioParameters& params);
+ const AudioParameters& params) OVERRIDE;
virtual AudioInputStream* MakeAudioInputStream(
- const AudioParameters& params);
- virtual void MuteAll();
- virtual void UnMuteAll();
+ const AudioParameters& params) OVERRIDE;
+ virtual bool IsRecordingInProgress() OVERRIDE;
+ virtual void MuteAll() OVERRIDE;
+ virtual void UnMuteAll() OVERRIDE;
protected:
virtual ~AudioManagerOpenBSD();
diff --git a/media/audio/win/audio_manager_win.h b/media/audio/win/audio_manager_win.h
index 198e5e9..6db13c9 100644
--- a/media/audio/win/audio_manager_win.h
+++ b/media/audio/win/audio_manager_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include <windows.h>
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "media/audio/audio_manager_base.h"
class PCMWaveInAudioInputStream;
@@ -20,18 +21,19 @@ class AudioManagerWin : public AudioManagerBase {
public:
AudioManagerWin();
// Implementation of AudioManager.
- virtual bool HasAudioOutputDevices();
- virtual bool HasAudioInputDevices();
+ virtual bool HasAudioOutputDevices() OVERRIDE;
+ virtual bool HasAudioInputDevices() OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStream(
- const AudioParameters& params);
+ const AudioParameters& params) OVERRIDE;
virtual AudioInputStream* MakeAudioInputStream(
- const AudioParameters& params);
- virtual void MuteAll();
- virtual void UnMuteAll();
- virtual string16 GetAudioInputDeviceModel();
- virtual bool CanShowAudioInputSettings();
- virtual void ShowAudioInputSettings();
- virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names);
+ const AudioParameters& params) OVERRIDE;
+ virtual void MuteAll() OVERRIDE;
+ virtual void UnMuteAll() OVERRIDE;
+ virtual string16 GetAudioInputDeviceModel() OVERRIDE;
+ virtual bool CanShowAudioInputSettings() OVERRIDE;
+ virtual void ShowAudioInputSettings() OVERRIDE;
+ virtual void GetAudioInputDeviceNames(media::AudioDeviceNames* device_names)
+ OVERRIDE;
// Windows-only methods to free a stream created in MakeAudioStream. These
// are called internally by the audio stream when it has been closed.
diff --git a/media/audio/win/wavein_input_win.cc b/media/audio/win/wavein_input_win.cc
index b994a29..d9f600b 100644
--- a/media/audio/win/wavein_input_win.cc
+++ b/media/audio/win/wavein_input_win.cc
@@ -121,6 +121,8 @@ void PCMWaveInAudioInputStream::Start(AudioInputCallback* callback) {
if (result != MMSYSERR_NOERROR) {
HandleError(result);
state_ = kStateReady;
+ } else {
+ manager_->IncreaseActiveInputStreamCount();
}
}
@@ -138,6 +140,10 @@ void PCMWaveInAudioInputStream::Stop() {
HandleError(::GetLastError());
return;
}
+ // Stop is always called before Close. In case of error, this will be
+ // also called when closing the input controller.
+ manager_->DecreaseActiveInputStreamCount();
+
state_ = kStateStopped;
MMRESULT res = ::waveInReset(wavein_);
if (res != MMSYSERR_NOERROR) {
diff --git a/media/audio/win/wavein_input_win.h b/media/audio/win/wavein_input_win.h
index f549f34..c16a4a7 100644
--- a/media/audio/win/wavein_input_win.h
+++ b/media/audio/win/wavein_input_win.h
@@ -9,6 +9,7 @@
#include <mmsystem.h>
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/win/scoped_handle.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_parameters.h"
@@ -27,10 +28,10 @@ class PCMWaveInAudioInputStream : public AudioInputStream {
virtual ~PCMWaveInAudioInputStream();
// Implementation of AudioInputStream.
- virtual bool Open();
- virtual void Start(AudioInputCallback* callback);
- virtual void Stop();
- virtual void Close();
+ virtual bool Open() OVERRIDE;
+ virtual void Start(AudioInputCallback* callback) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+ virtual void Close() OVERRIDE;
private:
enum State {