OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Creates an audio output stream based on the PulseAudio asynchronous API; | 5 // Creates an audio output stream based on the PulseAudio asynchronous API; |
6 // specifically using the pa_threaded_mainloop model. | 6 // specifically using the pa_threaded_mainloop model. |
7 // | 7 // |
8 // If the stream is successfully opened, Close() must be called before the | 8 // If the stream is successfully opened, Close() must be called before the |
9 // stream is deleted as Close() is responsible for ensuring resource cleanup | 9 // stream is deleted as Close() is responsible for ensuring resource cleanup |
10 // occurs. | 10 // occurs. |
11 // | 11 // |
12 // This object is designed so that all AudioOutputStream methods will be called | 12 // This object is designed so that all AudioOutputStream methods will be called |
13 // on the same thread that created the object. | 13 // on the same thread that created the object. |
14 // | 14 // |
15 // WARNING: This object blocks on internal PulseAudio calls in Open() while | 15 // WARNING: This object blocks on internal PulseAudio calls in Open() while |
16 // waiting for PulseAudio's context structure to be ready. It also blocks in | 16 // waiting for PulseAudio's context structure to be ready. It also blocks in |
17 // inside PulseAudio in Start() and repeated during playback, waiting for | 17 // inside PulseAudio in Start() and repeated during playback, waiting for |
18 // PulseAudio write callbacks to occur. | 18 // PulseAudio write callbacks to occur. |
19 | 19 |
20 #ifndef MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 20 #ifndef MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
21 #define MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 21 #define MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
22 | 22 |
| 23 #include <string> |
| 24 |
23 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
24 #include "media/audio/audio_io.h" | 26 #include "media/audio/audio_io.h" |
25 #include "media/audio/audio_parameters.h" | 27 #include "media/audio/audio_parameters.h" |
26 | 28 |
27 struct pa_context; | 29 struct pa_context; |
28 struct pa_operation; | 30 struct pa_operation; |
29 struct pa_stream; | 31 struct pa_stream; |
30 struct pa_threaded_mainloop; | 32 struct pa_threaded_mainloop; |
31 | 33 |
32 namespace media { | 34 namespace media { |
33 class AudioManagerBase; | 35 class AudioManagerBase; |
34 | 36 |
35 class PulseAudioOutputStream : public AudioOutputStream { | 37 class PulseAudioOutputStream : public AudioOutputStream { |
36 public: | 38 public: |
37 PulseAudioOutputStream(const AudioParameters& params, | 39 PulseAudioOutputStream(const AudioParameters& params, |
| 40 const std::string& device_id, |
38 AudioManagerBase* manager); | 41 AudioManagerBase* manager); |
39 | 42 |
40 virtual ~PulseAudioOutputStream(); | 43 virtual ~PulseAudioOutputStream(); |
41 | 44 |
42 // Implementation of AudioOutputStream. | 45 // Implementation of AudioOutputStream. |
43 virtual bool Open() OVERRIDE; | 46 virtual bool Open() OVERRIDE; |
44 virtual void Close() OVERRIDE; | 47 virtual void Close() OVERRIDE; |
45 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | 48 virtual void Start(AudioSourceCallback* callback) OVERRIDE; |
46 virtual void Stop() OVERRIDE; | 49 virtual void Stop() OVERRIDE; |
47 virtual void SetVolume(double volume) OVERRIDE; | 50 virtual void SetVolume(double volume) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
59 // Fulfill a write request from the write request callback. Outputs silence | 62 // Fulfill a write request from the write request callback. Outputs silence |
60 // if the request could not be fulfilled. | 63 // if the request could not be fulfilled. |
61 void FulfillWriteRequest(size_t requested_bytes); | 64 void FulfillWriteRequest(size_t requested_bytes); |
62 | 65 |
63 // Close() helper function to free internal structs. | 66 // Close() helper function to free internal structs. |
64 void Reset(); | 67 void Reset(); |
65 | 68 |
66 // AudioParameters from the constructor. | 69 // AudioParameters from the constructor. |
67 const AudioParameters params_; | 70 const AudioParameters params_; |
68 | 71 |
| 72 // The device ID for the device to open. |
| 73 const std::string device_id_; |
| 74 |
69 // Audio manager that created us. Used to report that we've closed. | 75 // Audio manager that created us. Used to report that we've closed. |
70 AudioManagerBase* manager_; | 76 AudioManagerBase* manager_; |
71 | 77 |
72 // PulseAudio API structs. | 78 // PulseAudio API structs. |
73 pa_context* pa_context_; | 79 pa_context* pa_context_; |
74 pa_threaded_mainloop* pa_mainloop_; | 80 pa_threaded_mainloop* pa_mainloop_; |
75 pa_stream* pa_stream_; | 81 pa_stream* pa_stream_; |
76 | 82 |
77 // Float representation of volume from 0.0 to 1.0. | 83 // Float representation of volume from 0.0 to 1.0. |
78 float volume_; | 84 float volume_; |
79 | 85 |
80 // Callback to audio data source. Must only be modified while holding a lock | 86 // Callback to audio data source. Must only be modified while holding a lock |
81 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). | 87 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). |
82 AudioSourceCallback* source_callback_; | 88 AudioSourceCallback* source_callback_; |
83 | 89 |
84 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 90 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
85 scoped_ptr<AudioBus> audio_bus_; | 91 scoped_ptr<AudioBus> audio_bus_; |
86 | 92 |
87 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); | 93 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); |
88 }; | 94 }; |
89 | 95 |
90 } // namespace media | 96 } // namespace media |
91 | 97 |
92 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 98 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
OLD | NEW |