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. |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "base/macros.h" | 28 #include "base/macros.h" |
29 #include "base/threading/thread_checker.h" | 29 #include "base/threading/thread_checker.h" |
30 #include "media/audio/audio_io.h" | 30 #include "media/audio/audio_io.h" |
31 #include "media/base/audio_parameters.h" | 31 #include "media/base/audio_parameters.h" |
32 | 32 |
33 struct pa_context; | 33 struct pa_context; |
34 struct pa_stream; | 34 struct pa_stream; |
35 struct pa_threaded_mainloop; | 35 struct pa_threaded_mainloop; |
36 | 36 |
37 namespace media { | 37 namespace media { |
| 38 |
| 39 class AudioDebugRecordingHelper; |
38 class AudioManagerBase; | 40 class AudioManagerBase; |
39 | 41 |
40 class PulseAudioOutputStream : public AudioOutputStream { | 42 class PulseAudioOutputStream : public AudioOutputStream { |
41 public: | 43 public: |
42 PulseAudioOutputStream(const AudioParameters& params, | 44 PulseAudioOutputStream(const AudioParameters& params, |
43 const std::string& device_id, | 45 const std::string& device_id, |
44 AudioManagerBase* manager); | 46 AudioManagerBase* manager); |
45 | 47 |
46 ~PulseAudioOutputStream() override; | 48 ~PulseAudioOutputStream() override; |
47 | 49 |
48 // Implementation of AudioOutputStream. | 50 // Implementation of AudioOutputStream. |
49 bool Open() override; | 51 bool Open() override; |
50 void Close() override; | 52 void Close() override; |
51 void Start(AudioSourceCallback* callback) override; | 53 void Start(AudioSourceCallback* callback) override; |
52 void Stop() override; | 54 void Stop() override; |
53 void SetVolume(double volume) override; | 55 void SetVolume(double volume) override; |
54 void GetVolume(double* volume) override; | 56 void GetVolume(double* volume) override; |
| 57 void EnableDebugRecording(const base::FilePath& file_name) override; |
| 58 void DisableDebugRecording() override; |
55 | 59 |
56 private: | 60 private: |
57 // Called by PulseAudio when |pa_stream_| change state. If an unexpected | 61 // Called by PulseAudio when |pa_stream_| change state. If an unexpected |
58 // failure state change happens and |source_callback_| is set | 62 // failure state change happens and |source_callback_| is set |
59 // this method will forward the error via OnError(). | 63 // this method will forward the error via OnError(). |
60 static void StreamNotifyCallback(pa_stream* s, void* p_this); | 64 static void StreamNotifyCallback(pa_stream* s, void* p_this); |
61 | 65 |
62 // Called by PulseAudio when it needs more audio data. | 66 // Called by PulseAudio when it needs more audio data. |
63 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); | 67 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); |
64 | 68 |
(...skipping 21 matching lines...) Expand all Loading... |
86 // Float representation of volume from 0.0 to 1.0. | 90 // Float representation of volume from 0.0 to 1.0. |
87 float volume_; | 91 float volume_; |
88 | 92 |
89 // Callback to audio data source. Must only be modified while holding a lock | 93 // Callback to audio data source. Must only be modified while holding a lock |
90 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). | 94 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). |
91 AudioSourceCallback* source_callback_; | 95 AudioSourceCallback* source_callback_; |
92 | 96 |
93 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 97 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
94 std::unique_ptr<AudioBus> audio_bus_; | 98 std::unique_ptr<AudioBus> audio_bus_; |
95 | 99 |
| 100 // Used for audio debug recordings. |
| 101 std::unique_ptr<AudioDebugRecordingHelper> debug_recording_helper_; |
| 102 |
96 base::ThreadChecker thread_checker_; | 103 base::ThreadChecker thread_checker_; |
97 | 104 |
98 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); | 105 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); |
99 }; | 106 }; |
100 | 107 |
101 } // namespace media | 108 } // namespace media |
102 | 109 |
103 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 110 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
OLD | NEW |