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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 virtual void SetVolume(double volume) OVERRIDE; | 47 virtual void SetVolume(double volume) OVERRIDE; |
48 virtual void GetVolume(double* volume) OVERRIDE; | 48 virtual void GetVolume(double* volume) OVERRIDE; |
49 | 49 |
50 private: | 50 private: |
51 // Called by PulseAudio when |pa_context_| and |pa_stream_| change state. If | 51 // Called by PulseAudio when |pa_context_| and |pa_stream_| change state. If |
52 // an unexpected failure state change happens and |source_callback_| is set | 52 // an unexpected failure state change happens and |source_callback_| is set |
53 // these methods will forward the error via OnError(). | 53 // these methods will forward the error via OnError(). |
54 static void ContextNotifyCallback(pa_context* c, void* p_this); | 54 static void ContextNotifyCallback(pa_context* c, void* p_this); |
55 static void StreamNotifyCallback(pa_stream* s, void* p_this); | 55 static void StreamNotifyCallback(pa_stream* s, void* p_this); |
56 | 56 |
57 // Triggers pa_threaded_mainloop_signal() to avoid deadlocks. | |
58 static void StreamSuccessCallback(pa_stream* s, int success, void* p_this); | |
59 | |
60 // Called by PulseAudio when it needs more audio data. | 57 // Called by PulseAudio when it needs more audio data. |
61 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); | 58 static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); |
62 | 59 |
63 // Fulfill a write request from the write request callback. Outputs silence | 60 // Fulfill a write request from the write request callback. Outputs silence |
64 // if the request could not be fulfilled. | 61 // if the request could not be fulfilled. |
65 void FulfillWriteRequest(size_t requested_bytes); | 62 void FulfillWriteRequest(size_t requested_bytes); |
66 | 63 |
67 // Close() helper function to free internal structs. | 64 // Close() helper function to free internal structs. |
68 void Reset(); | 65 void Reset(); |
69 | 66 |
70 // Returns the current hardware latency value in bytes. | |
71 int GetHardwareLatencyInBytes(); | |
72 | |
73 // Helper method for waiting on Pulse Audio operations to complete. | |
74 void WaitForPulseOperation(pa_operation* op); | |
75 | |
76 // AudioParameters from the constructor. | 67 // AudioParameters from the constructor. |
77 const AudioParameters params_; | 68 const AudioParameters params_; |
78 | 69 |
79 // Audio manager that created us. Used to report that we've closed. | 70 // Audio manager that created us. Used to report that we've closed. |
80 AudioManagerBase* manager_; | 71 AudioManagerBase* manager_; |
81 | 72 |
82 // PulseAudio API structs. | 73 // PulseAudio API structs. |
83 pa_context* pa_context_; | 74 pa_context* pa_context_; |
84 pa_threaded_mainloop* pa_mainloop_; | 75 pa_threaded_mainloop* pa_mainloop_; |
85 pa_stream* pa_stream_; | 76 pa_stream* pa_stream_; |
86 | 77 |
87 // Float representation of volume from 0.0 to 1.0. | 78 // Float representation of volume from 0.0 to 1.0. |
88 float volume_; | 79 float volume_; |
89 | 80 |
90 // Callback to audio data source. Must only be modified while holding a lock | 81 // Callback to audio data source. Must only be modified while holding a lock |
91 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). | 82 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). |
92 AudioSourceCallback* source_callback_; | 83 AudioSourceCallback* source_callback_; |
93 | 84 |
94 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 85 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
95 scoped_ptr<AudioBus> audio_bus_; | 86 scoped_ptr<AudioBus> audio_bus_; |
96 | 87 |
97 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); | 88 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); |
98 }; | 89 }; |
99 | 90 |
100 } // namespace media | 91 } // namespace media |
101 | 92 |
102 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ | 93 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
OLD | NEW |