Chromium Code Reviews| 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 <pulse/pulseaudio.h> | |
| 23 #include <stddef.h> | 24 #include <stddef.h> |
| 24 | 25 |
| 25 #include <string> | 26 #include <string> |
| 26 | 27 |
| 27 #include "base/macros.h" | 28 #include "base/macros.h" |
| 28 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
| 29 #include "base/threading/thread_checker.h" | 30 #include "base/threading/thread_checker.h" |
| 30 #include "media/audio/audio_io.h" | 31 #include "media/audio/audio_io.h" |
| 31 #include "media/audio/audio_parameters.h" | 32 #include "media/audio/audio_parameters.h" |
| 32 | 33 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 // Called by PulseAudio when |pa_stream_| change state. If an unexpected | 59 // Called by PulseAudio when |pa_stream_| change state. If an unexpected |
| 59 // failure state change happens and |source_callback_| is set | 60 // failure state change happens and |source_callback_| is set |
| 60 // this method will forward the error via OnError(). | 61 // this method will forward the error via OnError(). |
| 61 static void StreamNotifyCallback(pa_stream* s, void* p_this); | 62 static void StreamNotifyCallback(pa_stream* s, void* p_this); |
| 62 | 63 |
| 63 // Called by PulseAudio when it needs more audio data. | 64 // Called by PulseAudio when it needs more audio data. |
| 64 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); | 65 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); |
| 65 | 66 |
| 67 // pa_context_get_server_info callback. It's used by | |
| 68 // GetSystemDefaultOutputDevice to set |device_name_| to the | |
| 69 // default system output device. | |
| 70 static void GetSystemDefaultOutputDeviceCallback(pa_context* context, | |
| 71 const pa_server_info* info, | |
| 72 void* user_data); | |
| 73 | |
| 74 bool InitializeMainloopAndContext(std::string& app_name, | |
|
Henrik Grunell
2016/03/09 00:49:17
Add comment with description.
Henrik Grunell
2016/03/09 00:49:17
const std::string& (both arguments).
rchtara
2016/03/09 16:16:10
Done.
rchtara
2016/03/09 16:16:10
Done.
| |
| 75 std::string& device_to_use_); | |
|
Henrik Grunell
2016/03/09 00:49:17
Remove trailing "_".
rchtara
2016/03/09 16:16:10
Done.
| |
| 76 | |
| 77 // Get default system output device for the output stream. | |
| 78 void GetSystemDefaultOutputDevice(); | |
| 79 | |
| 66 // Fulfill a write request from the write request callback. Outputs silence | 80 // Fulfill a write request from the write request callback. Outputs silence |
| 67 // if the request could not be fulfilled. | 81 // if the request could not be fulfilled. |
| 68 void FulfillWriteRequest(size_t requested_bytes); | 82 void FulfillWriteRequest(size_t requested_bytes); |
| 69 | 83 |
| 70 // Close() helper function to free internal structs. | 84 // Close() helper function to free internal structs. |
| 71 void Reset(); | 85 void Reset(); |
| 72 | 86 |
| 73 // AudioParameters from the constructor. | 87 // AudioParameters from the constructor. |
| 74 const AudioParameters params_; | 88 const AudioParameters params_; |
| 75 | 89 |
| 76 // The device ID for the device to open. | 90 // The device ID for the device to open. |
| 77 const std::string device_id_; | 91 const std::string device_id_; |
| 92 // The name of the system default device. Returned | |
| 93 // by GetSystemDefaultOutputDeviceCallback. | |
| 94 std::string default_system_device_name_; | |
| 78 | 95 |
| 79 // Audio manager that created us. Used to report that we've closed. | 96 // Audio manager that created us. Used to report that we've closed. |
| 80 AudioManagerBase* manager_; | 97 AudioManagerBase* manager_; |
| 81 | 98 |
| 82 // PulseAudio API structs. | 99 // PulseAudio API structs. |
| 83 pa_context* pa_context_; | 100 pa_context* pa_context_; |
| 84 pa_threaded_mainloop* pa_mainloop_; | 101 pa_threaded_mainloop* pa_mainloop_; |
| 85 pa_stream* pa_stream_; | 102 pa_stream* pa_stream_; |
| 86 | 103 |
| 87 // Float representation of volume from 0.0 to 1.0. | 104 // Float representation of volume from 0.0 to 1.0. |
| 88 float volume_; | 105 float volume_; |
| 89 | 106 |
| 90 // Callback to audio data source. Must only be modified while holding a lock | 107 // Callback to audio data source. Must only be modified while holding a lock |
| 91 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). | 108 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). |
| 92 AudioSourceCallback* source_callback_; | 109 AudioSourceCallback* source_callback_; |
| 93 | 110 |
| 94 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 111 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 95 scoped_ptr<AudioBus> audio_bus_; | 112 scoped_ptr<AudioBus> audio_bus_; |
| 96 | 113 |
| 97 base::ThreadChecker thread_checker_; | 114 base::ThreadChecker thread_checker_; |
| 98 | 115 |
| 99 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); | 116 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); |
| 100 }; | 117 }; |
| 101 | 118 |
| 102 } // namespace media | 119 } // namespace media |
| 103 | 120 |
| 104 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 121 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
| OLD | NEW |