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

Side by Side Diff: media/audio/pulse/pulse_output.h

Issue 1711823004: Let default device in PulseAudio be the system default device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/pulse/pulse_input.cc ('k') | media/audio/pulse/pulse_output.cc » ('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) 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
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 |default_system_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 // Initialize |pa_mainloop_| and |pa_context_| and prepare them for creating
75 // an output stream.
76 bool InitializeMainloopAndContext();
77
78 // Get default system output device for the output stream.
79 void GetSystemDefaultOutputDevice();
80
66 // Fulfill a write request from the write request callback. Outputs silence 81 // Fulfill a write request from the write request callback. Outputs silence
67 // if the request could not be fulfilled. 82 // if the request could not be fulfilled.
68 void FulfillWriteRequest(size_t requested_bytes); 83 void FulfillWriteRequest(size_t requested_bytes);
69 84
70 // Close() helper function to free internal structs. 85 // Close() helper function to free internal structs.
71 void Reset(); 86 void Reset();
72 87
73 // AudioParameters from the constructor. 88 // AudioParameters from the constructor.
74 const AudioParameters params_; 89 const AudioParameters params_;
75 90
76 // The device ID for the device to open. 91 // The device ID for the device to open.
77 const std::string device_id_; 92 const std::string device_id_;
93 // The name of the system default device. Set by
94 // GetSystemDefaultOutputDeviceCallback if |device_id_| is set to be the
95 // default device.
96 std::string default_system_device_name_;
78 97
79 // Audio manager that created us. Used to report that we've closed. 98 // Audio manager that created us. Used to report that we've closed.
80 AudioManagerBase* manager_; 99 AudioManagerBase* manager_;
81 100
82 // PulseAudio API structs. 101 // PulseAudio API structs.
83 pa_context* pa_context_; 102 pa_context* pa_context_;
84 pa_threaded_mainloop* pa_mainloop_; 103 pa_threaded_mainloop* pa_mainloop_;
85 pa_stream* pa_stream_; 104 pa_stream* pa_stream_;
86 105
87 // Float representation of volume from 0.0 to 1.0. 106 // Float representation of volume from 0.0 to 1.0.
88 float volume_; 107 float volume_;
89 108
90 // Callback to audio data source. Must only be modified while holding a lock 109 // Callback to audio data source. Must only be modified while holding a lock
91 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). 110 // on |pa_mainloop_| via pa_threaded_mainloop_lock().
92 AudioSourceCallback* source_callback_; 111 AudioSourceCallback* source_callback_;
93 112
94 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 113 // Container for retrieving data from AudioSourceCallback::OnMoreData().
95 scoped_ptr<AudioBus> audio_bus_; 114 scoped_ptr<AudioBus> audio_bus_;
96 115
97 base::ThreadChecker thread_checker_; 116 base::ThreadChecker thread_checker_;
98 117
99 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); 118 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream);
100 }; 119 };
101 120
102 } // namespace media 121 } // namespace media
103 122
104 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ 123 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_input.cc ('k') | media/audio/pulse/pulse_output.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698