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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 4661001: Simplified AudioOutputStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month 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
« no previous file with comments | « media/audio/linux/audio_manager_linux.h ('k') | media/audio/mac/audio_input_mac.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/linux/audio_manager_linux.h" 5 #include "media/audio/linux/audio_manager_linux.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/audio/fake_audio_input_stream.h" 9 #include "media/audio/fake_audio_input_stream.h"
10 #include "media/audio/fake_audio_output_stream.h" 10 #include "media/audio/fake_audio_output_stream.h"
11 #include "media/audio/linux/alsa_input.h" 11 #include "media/audio/linux/alsa_input.h"
12 #include "media/audio/linux/alsa_output.h" 12 #include "media/audio/linux/alsa_output.h"
13 #include "media/audio/linux/alsa_wrapper.h" 13 #include "media/audio/linux/alsa_wrapper.h"
14 #include "media/base/limits.h" 14 #include "media/base/limits.h"
15 #include "media/base/media_switches.h" 15 #include "media/base/media_switches.h"
16 16
17 namespace { 17 namespace {
18 18
19 const int kMaxInputChannels = 2; 19 const int kMaxInputChannels = 2;
20 const int kMaxSamplesPerPacket = media::Limits::kMaxSampleRate;
21 20
22 } // namespace 21 } // namespace
23 22
24 // Implementation of AudioManager. 23 // Implementation of AudioManager.
25 bool AudioManagerLinux::HasAudioOutputDevices() { 24 bool AudioManagerLinux::HasAudioOutputDevices() {
26 // TODO(ajwong): Make this actually query audio devices. 25 // TODO(ajwong): Make this actually query audio devices.
27 return true; 26 return true;
28 } 27 }
29 28
30 bool AudioManagerLinux::HasAudioInputDevices() { 29 bool AudioManagerLinux::HasAudioInputDevices() {
31 // TODO(satish): Make this actually query audio devices. 30 // TODO(satish): Make this actually query audio devices.
32 return true; 31 return true;
33 } 32 }
34 33
35 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( 34 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream(
36 AudioParameters params) { 35 AudioParameters params) {
37 // Early return for testing hook. Do this before checking for 36 // Early return for testing hook. Do this before checking for
38 // |initialized_|. 37 // |initialized_|.
39 if (params.format == AudioParameters::AUDIO_MOCK) { 38 if (params.format == AudioParameters::AUDIO_MOCK) {
40 return FakeAudioOutputStream::MakeFakeStream(); 39 return FakeAudioOutputStream::MakeFakeStream(params);
41 } 40 }
42 41
43 if (!initialized()) { 42 if (!initialized()) {
44 return NULL; 43 return NULL;
45 } 44 }
46 45
47 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; 46 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice;
48 if (CommandLine::ForCurrentProcess()->HasSwitch( 47 if (CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kAlsaOutputDevice)) { 48 switches::kAlsaOutputDevice)) {
50 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 49 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
51 switches::kAlsaOutputDevice); 50 switches::kAlsaOutputDevice);
52 } 51 }
53 AlsaPcmOutputStream* stream = 52 AlsaPcmOutputStream* stream =
54 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, 53 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this,
55 GetMessageLoop()); 54 GetMessageLoop());
56 55
57 AutoLock l(lock_); 56 AutoLock l(lock_);
58 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); 57 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream);
59 return stream; 58 return stream;
60 } 59 }
61 60
62 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( 61 AudioInputStream* AudioManagerLinux::MakeAudioInputStream(
63 AudioParameters params, int samples_per_packet) { 62 AudioParameters params) {
64 if (!params.IsValid() || params.channels > kMaxInputChannels || 63 if (!params.IsValid() || params.channels > kMaxInputChannels)
65 samples_per_packet < 0 || samples_per_packet > kMaxSamplesPerPacket)
66 return NULL; 64 return NULL;
67 65
68 if (params.format == AudioParameters::AUDIO_MOCK) { 66 if (params.format == AudioParameters::AUDIO_MOCK) {
69 return FakeAudioInputStream::MakeFakeStream(params, samples_per_packet); 67 return FakeAudioInputStream::MakeFakeStream(params);
70 } else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) { 68 } else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) {
71 return NULL; 69 return NULL;
72 } 70 }
73 71
74 if (!initialized()) 72 if (!initialized())
75 return NULL; 73 return NULL;
76 74
77 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; 75 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice;
78 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { 76 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) {
79 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 77 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
80 switches::kAlsaInputDevice); 78 switches::kAlsaInputDevice);
81 } 79 }
82 80
83 AlsaPcmInputStream* stream = new AlsaPcmInputStream( 81 AlsaPcmInputStream* stream = new AlsaPcmInputStream(
84 device_name, params, samples_per_packet, wrapper_.get()); 82 device_name, params, wrapper_.get());
85 83
86 return stream; 84 return stream;
87 } 85 }
88 86
89 AudioManagerLinux::AudioManagerLinux() { 87 AudioManagerLinux::AudioManagerLinux() {
90 } 88 }
91 89
92 AudioManagerLinux::~AudioManagerLinux() { 90 AudioManagerLinux::~AudioManagerLinux() {
93 // Make sure we stop the thread first. If we let the default destructor to 91 // Make sure we stop the thread first. If we let the default destructor to
94 // destruct the members, we may destroy audio streams before stopping the 92 // destruct the members, we may destroy audio streams before stopping the
(...skipping 21 matching lines...) Expand all
116 if (stream) { 114 if (stream) {
117 AutoLock l(lock_); 115 AutoLock l(lock_);
118 active_streams_.erase(stream); 116 active_streams_.erase(stream);
119 } 117 }
120 } 118 }
121 119
122 // static 120 // static
123 AudioManager* AudioManager::CreateAudioManager() { 121 AudioManager* AudioManager::CreateAudioManager() {
124 return new AudioManagerLinux(); 122 return new AudioManagerLinux();
125 } 123 }
OLDNEW
« no previous file with comments | « media/audio/linux/audio_manager_linux.h ('k') | media/audio/mac/audio_input_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698