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

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

Issue 160497: Reimplement the AlsaPcmOutputStream and fix the threading issues. (Closed)
Patch Set: Address Andrew's comments. Diff aginst Patch 8 please. Created 11 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/linux/audio_manager_linux.h ('k') | media/media.gyp » ('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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "media/audio/fake_audio_output_stream.h" 9 #include "media/audio/fake_audio_output_stream.h"
10 #include "media/audio/linux/alsa_output.h" 10 #include "media/audio/linux/alsa_output.h"
11 #include "media/audio/linux/alsa_wrapper.h"
11 12
12 namespace { 13 namespace {
13 AudioManagerLinux* g_audio_manager = NULL; 14 AudioManagerLinux* g_audio_manager = NULL;
14 } // namespace 15 } // namespace
15 16
16 // Implementation of AudioManager. 17 // Implementation of AudioManager.
17 bool AudioManagerLinux::HasAudioDevices() { 18 bool AudioManagerLinux::HasAudioDevices() {
18 // TODO(ajwong): Make this actually query audio devices. 19 // TODO(ajwong): Make this actually query audio devices.
19 return true; 20 return true;
20 } 21 }
21 22
22 AudioOutputStream* AudioManagerLinux::MakeAudioStream(Format format, 23 AudioOutputStream* AudioManagerLinux::MakeAudioStream(Format format,
23 int channels, 24 int channels,
24 int sample_rate, 25 int sample_rate,
25 char bits_per_sample) { 26 char bits_per_sample) {
27 // Early return for testing hook. Do this before checking for
28 // |initialized_|.
29 if (format == AudioManager::AUDIO_MOCK) {
30 return FakeAudioOutputStream::MakeFakeStream();
31 }
32
33 if (!initialized_) {
34 return NULL;
35 }
36
26 // TODO(ajwong): Do we want to be able to configure the device? default 37 // TODO(ajwong): Do we want to be able to configure the device? default
27 // should work correctly for all mono/stereo, but not surround, which needs 38 // should work correctly for all mono/stereo, but not surround, which needs
28 // surround40, surround51, etc. 39 // surround40, surround51, etc.
29 // 40 //
30 // http://0pointer.de/blog/projects/guide-to-sound-apis.html 41 // http://0pointer.de/blog/projects/guide-to-sound-apis.html
31 if (format == AudioManager::AUDIO_MOCK) { 42 AlsaPcmOutputStream* stream =
32 return FakeAudioOutputStream::MakeFakeStream(); 43 new AlsaPcmOutputStream(AlsaPcmOutputStream::kDefaultDevice,
33 } else { 44 format, channels, sample_rate, bits_per_sample,
34 AlsaPCMOutputStream* stream = 45 wrapper_.get(), audio_thread_.message_loop());
35 new AlsaPCMOutputStream(AlsaPCMOutputStream::kDefaultDevice, 46
36 100 /* 100ms minimal buffer */, 47 // TODO(ajwong): Set up this to clear itself when the stream closes.
37 format, channels, sample_rate, bits_per_sample); 48 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream);
38 return stream; 49 return stream;
39 }
40 } 50 }
41 51
42 AudioManagerLinux::AudioManagerLinux() { 52 AudioManagerLinux::AudioManagerLinux()
53 : audio_thread_("AudioThread"),
54 initialized_(false) {
43 } 55 }
44 56
45 AudioManagerLinux::~AudioManagerLinux() { 57 AudioManagerLinux::~AudioManagerLinux() {
46 } 58 }
47 59
60 void AudioManagerLinux::Init() {
61 initialized_ = audio_thread_.Start();
62 wrapper_.reset(new AlsaWrapper());
63 }
64
48 void AudioManagerLinux::MuteAll() { 65 void AudioManagerLinux::MuteAll() {
49 // TODO(ajwong): Implement. 66 // TODO(ajwong): Implement.
50 NOTIMPLEMENTED(); 67 NOTIMPLEMENTED();
51 } 68 }
52 69
53 void AudioManagerLinux::UnMuteAll() { 70 void AudioManagerLinux::UnMuteAll() {
54 // TODO(ajwong): Implement. 71 // TODO(ajwong): Implement.
55 NOTIMPLEMENTED(); 72 NOTIMPLEMENTED();
56 } 73 }
57 74
58 // TODO(ajwong): Collapse this with the windows version. 75 // TODO(ajwong): Collapse this with the windows version.
59 void DestroyAudioManagerLinux(void* not_used) { 76 void DestroyAudioManagerLinux(void* not_used) {
60 delete g_audio_manager; 77 delete g_audio_manager;
61 g_audio_manager = NULL; 78 g_audio_manager = NULL;
62 } 79 }
63 80
64 AudioManager* AudioManager::GetAudioManager() { 81 AudioManager* AudioManager::GetAudioManager() {
65 if (!g_audio_manager) { 82 if (!g_audio_manager) {
66 g_audio_manager = new AudioManagerLinux(); 83 g_audio_manager = new AudioManagerLinux();
84 g_audio_manager->Init();
67 base::AtExitManager::RegisterCallback(&DestroyAudioManagerLinux, NULL); 85 base::AtExitManager::RegisterCallback(&DestroyAudioManagerLinux, NULL);
68 } 86 }
69 return g_audio_manager; 87 return g_audio_manager;
70 } 88 }
OLDNEW
« no previous file with comments | « media/audio/linux/audio_manager_linux.h ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698