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

Side by Side Diff: media/audio/openbsd/audio_manager_openbsd.cc

Issue 9570014: Move some generic functions to AudioManagerBase to be inherited by platform-specific AudioManager*** (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the memory leak in the alsa unittests Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/openbsd/audio_manager_openbsd.h" 5 #include "media/audio/openbsd/audio_manager_openbsd.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "media/audio/audio_output_dispatcher.h" 9 #include "media/audio/audio_output_dispatcher.h"
10 #include "media/audio/fake_audio_input_stream.h"
11 #include "media/audio/fake_audio_output_stream.h"
12 #if defined(USE_PULSEAUDIO) 10 #if defined(USE_PULSEAUDIO)
13 #include "media/audio/pulse/pulse_output.h" 11 #include "media/audio/pulse/pulse_output.h"
14 #endif 12 #endif
15 #include "media/base/limits.h" 13 #include "media/base/limits.h"
16 #include "media/base/media_switches.h" 14 #include "media/base/media_switches.h"
17 15
18 #include <fcntl.h> 16 #include <fcntl.h>
19 17
20 // Maximum number of output streams that can be open simultaneously. 18 // Maximum number of output streams that can be open simultaneously.
21 static const size_t kMaxOutputStreams = 50; 19 static const int kMaxOutputStreams = 50;
22 20
23 // Implementation of AudioManager. 21 // Implementation of AudioManager.
24 static bool HasAudioHardware() { 22 static bool HasAudioHardware() {
25 int fd; 23 int fd;
26 const char *file; 24 const char *file;
27 25
28 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') 26 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0')
29 file = "/dev/audioctl"; 27 file = "/dev/audioctl";
30 28
31 if ((fd = open(file, O_RDONLY)) < 0) 29 if ((fd = open(file, O_RDONLY)) < 0)
32 return false; 30 return false;
33 31
34 close(fd); 32 close(fd);
35 return true; 33 return true;
36 } 34 }
37 35
38 bool AudioManagerOpenBSD::HasAudioOutputDevices() { 36 bool AudioManagerOpenBSD::HasAudioOutputDevices() {
39 return HasAudioHardware(); 37 return HasAudioHardware();
40 } 38 }
41 39
42 bool AudioManagerOpenBSD::HasAudioInputDevices() { 40 bool AudioManagerOpenBSD::HasAudioInputDevices() {
43 return HasAudioHardware(); 41 return HasAudioHardware();
44 } 42 }
45 43
46 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream(
47 const AudioParameters& params) {
48 // Early return for testing hook. Do this before checking for
49 // |initialized_|.
50 if (params.format == AudioParameters::AUDIO_MOCK) {
51 return FakeAudioOutputStream::MakeFakeStream(params);
52 }
53
54 if (!initialized()) {
55 return NULL;
56 }
57
58 // Don't allow opening more than |kMaxOutputStreams| streams.
59 if (active_streams_.size() >= kMaxOutputStreams) {
60 return NULL;
61 }
62
63 AudioOutputStream* stream;
64 #if defined(USE_PULSEAUDIO)
65 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
66 stream = new PulseAudioOutputStream(params, this);
67 active_streams_.insert(stream);
68 return stream;
69 }
70 #endif
71
72 NOTIMPLEMENTED();
73 return NULL;
74 }
75
76 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream(
77 const AudioParameters& params, const std::string& device_id) {
78 NOTIMPLEMENTED();
79 return NULL;
80 }
81
82 AudioManagerOpenBSD::AudioManagerOpenBSD() { 44 AudioManagerOpenBSD::AudioManagerOpenBSD() {
83 } 45 }
84 46
85 AudioManagerOpenBSD::~AudioManagerOpenBSD() { 47 AudioManagerOpenBSD::~AudioManagerOpenBSD() {
86 // Make sure we stop the thread first. If we allow the default destructor to 48 // Make sure we stop the thread first. If we allow the default destructor to
87 // destroy the members, we may destroy audio streams before stopping the 49 // destroy the members, we may destroy audio streams before stopping the
88 // thread, resulting an unexpected behavior. 50 // thread, resulting an unexpected behavior.
89 // This way we make sure activities of the audio streams are all stopped 51 // This way we make sure activities of the audio streams are all stopped
90 // before we destroy them. 52 // before we destroy them.
91 audio_thread_.Stop(); 53 audio_thread_.Stop();
92 54
93 // Free output dispatchers, closing all remaining open streams. 55 // Free output dispatchers, closing all remaining open streams.
94 output_dispatchers_.clear(); 56 output_dispatchers_.clear();
95
96 // Delete all the streams. Have to do it manually, we don't have ScopedSet<>,
97 // and we are not using ScopedVector<> because search there is slow.
98 STLDeleteElements(&active_streams_);
99 } 57 }
100 58
101 void AudioManagerOpenBSD::Init() { 59 void AudioManagerOpenBSD::Init() {
102 AudioManagerBase::Init(); 60 AudioManagerBase::Init();
103 } 61 }
104 62
105 void AudioManagerOpenBSD::MuteAll() { 63 void AudioManagerOpenBSD::MuteAll() {
106 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
107 } 65 }
108 66
109 void AudioManagerOpenBSD::UnMuteAll() { 67 void AudioManagerOpenBSD::UnMuteAll() {
110 NOTIMPLEMENTED(); 68 NOTIMPLEMENTED();
111 } 69 }
112 70
113 void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) { 71 int AudioManagerOpenBSD::GetMaxAudioOutputStreamsAllowed() {
114 if (stream) { 72 return kMaxOutputStreams;
115 active_streams_.erase(stream); 73 }
116 delete stream; 74
75 AudioOutputStream* AudioManagerOpenBSD::MakeAudioLinearOutputStream(
76 const AudioParameters& params) {
77 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format);
78 return MakeOutputStream(params);
79 }
80
81 AudioOutputStream* AudioManagerOpenBSD::MakeAudioLowLatencyOutputStream(
82 const AudioParameters& params) {
83 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format);
84 return MakeOutputStream(params);
85 }
86
87 AudioInputStream* AudioManagerOpenBSD::MakeAudioLinearInputStream(
88 const AudioParameters& params, const std::string& device_id) {
89 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format);
90 NOTIMPLEMENTED();
91 return NULL;
92 }
93
94 AudioInputStream* AudioManagerOpenBSD::MakeAudioLowLatencyInputStream(
95 const AudioParameters& params, const std::string& device_id) {
96 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format);
97 NOTIMPLEMENTED();
98 return NULL;
99 }
100
101 AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream(
102 const AudioParameters& params) {
103 if (!initialized()) {
104 return NULL;
117 } 105 }
106
107 #if defined(USE_PULSEAUDIO)
108 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
109 return new PulseAudioOutputStream(params, this);
110 }
111 #endif
112
113 NOTIMPLEMENTED();
114 return NULL;
118 } 115 }
119 116
120 // static 117 // static
121 AudioManager* CreateAudioManager() { 118 AudioManager* CreateAudioManager() {
122 return new AudioManagerOpenBSD(); 119 return new AudioManagerOpenBSD();
123 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698