OLD | NEW |
---|---|
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" | |
8 #include "media/audio/audio_output_dispatcher.h" | |
9 #include "media/audio/fake_audio_input_stream.h" | |
10 #include "media/audio/fake_audio_output_stream.h" | |
11 #if defined(USE_PULSEAUDIO) | |
12 #include "media/audio/pulse/pulse_output.h" | |
13 #endif | |
14 #include "media/base/limits.h" | |
15 #include "media/base/media_switches.h" | |
16 | |
17 #include <fcntl.h> | |
18 | |
19 // Maximum number of output streams that can be open simultaneously. | |
20 static const size_t kMaxOutputStreams = 50; | |
21 | |
7 // Implementation of AudioManager. | 22 // Implementation of AudioManager. |
23 static bool HasAudioHardware() { | |
24 int fd; | |
25 const char *file; | |
26 | |
27 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') | |
28 file = "/dev/audioctl"; | |
29 | |
30 if ((fd = open(file, O_RDONLY)) < 0) | |
31 return false; | |
32 | |
33 close(fd); | |
34 return true; | |
35 } | |
36 | |
8 bool AudioManagerOpenBSD::HasAudioOutputDevices() { | 37 bool AudioManagerOpenBSD::HasAudioOutputDevices() { |
9 NOTIMPLEMENTED(); | 38 return HasAudioHardware(); |
10 return false; | |
11 } | 39 } |
12 | 40 |
13 bool AudioManagerOpenBSD::HasAudioInputDevices() { | 41 bool AudioManagerOpenBSD::HasAudioInputDevices() { |
14 NOTIMPLEMENTED(); | 42 return HasAudioHardware(); |
scherkus (not reviewing)
2011/11/09 01:10:54
does the presence of /dev/audioctl (or similar) gu
Robert Nagy
2011/11/09 07:44:39
If opening the audioctl device succeeds then there
| |
15 return false; | |
16 } | 43 } |
17 | 44 |
18 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( | 45 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( |
19 const AudioParameters& params) { | 46 const AudioParameters& params) { |
20 NOTIMPLEMENTED(); | 47 // Early return for testing hook. Do this before checking for |
21 return NULL; | 48 // |initialized_|. |
49 if (params.format == AudioParameters::AUDIO_MOCK) { | |
50 return FakeAudioOutputStream::MakeFakeStream(params); | |
51 } | |
52 | |
53 if (!initialized()) { | |
54 return NULL; | |
55 } | |
56 | |
57 // Don't allow opening more than |kMaxOutputStreams| streams. | |
58 if (active_streams_.size() >= kMaxOutputStreams) { | |
59 return NULL; | |
60 } | |
61 | |
62 AudioOutputStream* stream; | |
63 #if defined(USE_PULSEAUDIO) | |
64 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | |
65 stream = new PulseAudioOutputStream(params, this, GetMessageLoop()); | |
66 active_streams_.insert(stream); | |
67 return stream; | |
68 } else { | |
scherkus (not reviewing)
2011/11/09 01:10:54
nit: you don't need the since you're returning
Robert Nagy
2011/11/09 07:44:39
I need it in case kUsePulseAudio is not set throug
| |
69 #endif | |
70 NOTIMPLEMENTED(); | |
71 return NULL; | |
72 #if defined(USE_PULSEAUDIO) | |
73 } | |
74 #endif | |
22 } | 75 } |
23 | 76 |
24 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( | 77 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( |
25 const AudioParameters& params) { | 78 const AudioParameters& params) { |
26 NOTIMPLEMENTED(); | 79 NOTIMPLEMENTED(); |
27 return NULL; | 80 return NULL; |
28 } | 81 } |
29 | 82 |
30 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 83 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
31 } | 84 } |
32 | 85 |
33 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 86 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
34 } | 87 } |
35 | 88 |
36 void AudioManagerOpenBSD::MuteAll() { | 89 void AudioManagerOpenBSD::MuteAll() { |
37 NOTIMPLEMENTED(); | 90 NOTIMPLEMENTED(); |
38 } | 91 } |
39 | 92 |
40 void AudioManagerOpenBSD::UnMuteAll() { | 93 void AudioManagerOpenBSD::UnMuteAll() { |
41 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
42 } | 95 } |
43 | 96 |
97 void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) { | |
98 if (stream) { | |
99 active_streams_.erase(stream); | |
100 delete stream; | |
101 } | |
102 } | |
103 | |
44 bool AudioManagerOpenBSD::IsRecordingInProgress() { | 104 bool AudioManagerOpenBSD::IsRecordingInProgress() { |
45 NOTIMPLEMENTED(); | 105 NOTIMPLEMENTED(); |
46 return false; | 106 return false; |
47 } | 107 } |
48 | 108 |
49 // static | 109 // static |
50 AudioManager* AudioManager::CreateAudioManager() { | 110 AudioManager* AudioManager::CreateAudioManager() { |
51 return new AudioManagerOpenBSD(); | 111 return new AudioManagerOpenBSD(); |
52 } | 112 } |
OLD | NEW |