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

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: latest 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
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 13 matching lines...) Expand all
46 47
47 ~PulseAudioOutputStream() override; 48 ~PulseAudioOutputStream() override;
48 49
49 // Implementation of AudioOutputStream. 50 // Implementation of AudioOutputStream.
50 bool Open() override; 51 bool Open() override;
51 void Close() override; 52 void Close() override;
52 void Start(AudioSourceCallback* callback) override; 53 void Start(AudioSourceCallback* callback) override;
53 void Stop() override; 54 void Stop() override;
54 void SetVolume(double volume) override; 55 void SetVolume(double volume) override;
55 void GetVolume(double* volume) override; 56 void GetVolume(double* volume) override;
57 pa_threaded_mainloop* GetPAMainloop();
Henrik Grunell 2016/03/10 00:57:07 Empty line before.
rchtara 2016/03/10 13:20:35 Done.
58 void SetDefaultSystemDeviceName(const std::string& name);
56 59
57 private: 60 private:
58 // Called by PulseAudio when |pa_stream_| change state. If an unexpected 61 // Called by PulseAudio when |pa_stream_| change state. If an unexpected
59 // failure state change happens and |source_callback_| is set 62 // failure state change happens and |source_callback_| is set
60 // this method will forward the error via OnError(). 63 // this method will forward the error via OnError().
61 static void StreamNotifyCallback(pa_stream* s, void* p_this); 64 static void StreamNotifyCallback(pa_stream* s, void* p_this);
62 65
63 // Called by PulseAudio when it needs more audio data. 66 // Called by PulseAudio when it needs more audio data.
64 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);
68 // Initialize |pa_mainloop_| and |pa_context_| and prepare them for creating
Henrik Grunell 2016/03/10 00:57:07 Empty line before the comment.
rchtara 2016/03/10 13:20:35 Done.
69 // an output stream.
70 bool InitializeMainloopAndContext();
71
72 // Get default system output device for the output stream.
73 void GetSystemDefaultOutputDevice();
65 74
66 // Fulfill a write request from the write request callback. Outputs silence 75 // Fulfill a write request from the write request callback. Outputs silence
67 // if the request could not be fulfilled. 76 // if the request could not be fulfilled.
68 void FulfillWriteRequest(size_t requested_bytes); 77 void FulfillWriteRequest(size_t requested_bytes);
69 78
70 // Close() helper function to free internal structs. 79 // Close() helper function to free internal structs.
71 void Reset(); 80 void Reset();
72 81
73 // AudioParameters from the constructor. 82 // AudioParameters from the constructor.
74 const AudioParameters params_; 83 const AudioParameters params_;
75 84
76 // The device ID for the device to open. 85 // The device ID for the device to open.
77 const std::string device_id_; 86 const std::string device_id_;
87 // The name of the system default device. Set by
88 // GetSystemDefaultOutputDeviceCallback if |device_id_| is set to be the
89 // default device.
90 std::string default_system_device_name_;
78 91
79 // Audio manager that created us. Used to report that we've closed. 92 // Audio manager that created us. Used to report that we've closed.
80 AudioManagerBase* manager_; 93 AudioManagerBase* manager_;
81 94
82 // PulseAudio API structs. 95 // PulseAudio API structs.
83 pa_context* pa_context_; 96 pa_context* pa_context_;
84 pa_threaded_mainloop* pa_mainloop_; 97 pa_threaded_mainloop* pa_mainloop_;
85 pa_stream* pa_stream_; 98 pa_stream* pa_stream_;
86 99
87 // Float representation of volume from 0.0 to 1.0. 100 // Float representation of volume from 0.0 to 1.0.
88 float volume_; 101 float volume_;
89 102
90 // Callback to audio data source. Must only be modified while holding a lock 103 // Callback to audio data source. Must only be modified while holding a lock
91 // on |pa_mainloop_| via pa_threaded_mainloop_lock(). 104 // on |pa_mainloop_| via pa_threaded_mainloop_lock().
92 AudioSourceCallback* source_callback_; 105 AudioSourceCallback* source_callback_;
93 106
94 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 107 // Container for retrieving data from AudioSourceCallback::OnMoreData().
95 scoped_ptr<AudioBus> audio_bus_; 108 scoped_ptr<AudioBus> audio_bus_;
96 109
97 base::ThreadChecker thread_checker_; 110 base::ThreadChecker thread_checker_;
98 111
99 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); 112 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream);
100 }; 113 };
101 114
102 } // namespace media 115 } // namespace media
103 116
104 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ 117 #endif // MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698