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

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_output.h

Issue 2755613002: Support audio output device enumeration and selection in PPAPI (Closed)
Patch Set: Should not include local change to ppapi/generators/idl_outfile.py Created 3 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_ 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "media/audio/audio_output_ipc.h" 12 #include "media/audio/audio_output_ipc.h"
13 #include "media/base/audio_parameters.h"
14 #include "media/base/output_device_info.h"
13 15
14 namespace media { 16 namespace base {
15 class AudioParameters; 17 class OneShotTimer;
18 class SingleThreadTaskRunner;
16 } 19 }
17 20
18 namespace base { 21 namespace {
19 class SingleThreadTaskRunner; 22 #if defined(OS_WIN) || defined(OS_MACOSX)
23 const int64_t kMaxAuthorizationTimeoutMs = 4000;
24 #else
25 const int64_t kMaxAuthorizationTimeoutMs = 0; // No timeout.
26 #endif
20 } 27 }
21 28
22 namespace content { 29 namespace content {
23 class AudioHelper; 30 class AudioHelper;
31 class PepperAudioOutputHost;
32
33 // We need to support both public PPAPI |PPB_Audio| and the new
34 // dev PPAPI |PPB_AudioOutput_Dev| at the same time, so that the
35 // existing users of |PPB_Audio| won't be affected.
36 // To achieve this, we have to keep references to both |AudioHelper|
37 // object and |PepperAudioOutputHost| object, so we can dispatch
38 // callbacks properly.
bbudge 2017/03/23 18:05:45 Your changes to this class risk breaking the old P
Xing 2017/03/29 21:14:32 New implementation has been moved to pepper_platfo
24 39
25 class PepperPlatformAudioOutput 40 class PepperPlatformAudioOutput
26 : public media::AudioOutputIPCDelegate, 41 : public media::AudioOutputIPCDelegate,
27 public base::RefCountedThreadSafe<PepperPlatformAudioOutput> { 42 public base::RefCountedThreadSafe<PepperPlatformAudioOutput> {
28 public: 43 public:
29 // Factory function, returns NULL on failure. StreamCreated() will be called 44 // Factory function, returns NULL on failure. StreamCreated() will be called
30 // when the stream is created. 45 // when the stream is created.
31 static PepperPlatformAudioOutput* Create(int sample_rate, 46 static PepperPlatformAudioOutput* Create(int sample_rate,
32 int frames_per_buffer, 47 int frames_per_buffer,
33 int source_render_frame_id, 48 int source_render_frame_id,
34 AudioHelper* client); 49 AudioHelper* client);
35 50
51 static PepperPlatformAudioOutput* Create(int render_frame_id,
52 const std::string& device_id,
53 const GURL& document_url,
54 int sample_rate,
55 int frames_per_buffer,
56 PepperAudioOutputHost* client);
57
36 // The following three methods are all called on main thread. 58 // The following three methods are all called on main thread.
37 59
60 // Request authorization to use the device.
bbudge 2017/03/23 18:05:45 nit: comment isn't necessary
Xing 2017/03/29 21:14:32 Done.
61 void RequestDeviceAuthorization();
62
38 // Starts the playback. Returns false on error or if called before the 63 // Starts the playback. Returns false on error or if called before the
39 // stream is created or after the stream is closed. 64 // stream is created or after the stream is closed.
40 bool StartPlayback(); 65 bool StartPlayback();
41 66
42 // Stops the playback. Returns false on error or if called before the stream 67 // Stops the playback. Returns false on error or if called before the stream
43 // is created or after the stream is closed. 68 // is created or after the stream is closed.
44 bool StopPlayback(); 69 bool StopPlayback();
45 70
46 // Sets the volume. Returns false on error or if called before the stream 71 // Sets the volume. Returns false on error or if called before the stream
47 // is created or after the stream is closed. 72 // is created or after the stream is closed.
(...skipping 10 matching lines...) Expand all
58 const std::string& matched_device_id) override; 83 const std::string& matched_device_id) override;
59 void OnStreamCreated(base::SharedMemoryHandle handle, 84 void OnStreamCreated(base::SharedMemoryHandle handle,
60 base::SyncSocket::Handle socket_handle, 85 base::SyncSocket::Handle socket_handle,
61 int length) override; 86 int length) override;
62 void OnIPCClosed() override; 87 void OnIPCClosed() override;
63 88
64 protected: 89 protected:
65 ~PepperPlatformAudioOutput() override; 90 ~PepperPlatformAudioOutput() override;
66 91
67 private: 92 private:
93 enum State {
94 IPC_CLOSED, // No more IPCs can take place.
95 IDLE, // Not started.
96 AUTHORIZING, // Sent device authorization request, waiting for reply.
97 AUTHORIZED, // Successful device authorization received.
98 CREATING_STREAM, // Waiting for OnStreamCreated() to be called back.
99 PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop().
100 PLAYING, // Playing back. Can Pause()/Stop().
101 };
102
68 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>; 103 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>;
69 104
70 PepperPlatformAudioOutput(); 105 PepperPlatformAudioOutput();
106 PepperPlatformAudioOutput(int render_frame_id,
107 const std::string& device_id,
108 const GURL& document_url,
109 base::TimeDelta authorization_timeout);
71 110
111 // Used for old Pepper audio interface.
bbudge 2017/03/23 18:05:45 nit: be specific, PPB_Audio
Xing 2017/03/29 21:14:32 Done.
72 bool Initialize(int sample_rate, 112 bool Initialize(int sample_rate,
73 int frames_per_buffer, 113 int frames_per_buffer,
74 int source_render_frame_id, 114 int source_render_frame_id,
75 AudioHelper* client); 115 AudioHelper* client);
76 116
117 // Creates audio stream. Used for new Pepper audio output interface.
bbudge 2017/03/23 18:05:45 ditto: PPB_AudioOutput_Dev
Xing 2017/03/29 21:14:32 Done.
118 bool Initialize(int sample_rate,
119 int frames_per_buffer,
120 PepperAudioOutputHost* client);
121
77 // I/O thread backends to above functions. 122 // I/O thread backends to above functions.
123 // Used only by old Pepper audio interface.
bbudge 2017/03/23 18:05:45 ditto
Xing 2017/03/29 21:14:32 Done.
78 void InitializeOnIOThread(const media::AudioParameters& params); 124 void InitializeOnIOThread(const media::AudioParameters& params);
125
126 void RequestDeviceAuthorizationOnIOThread();
bbudge 2017/03/23 18:05:44 I assume these are only used to support PPB_AudioO
Xing 2017/03/29 21:14:32 Done.
127 void CreateStreamOnIOThread(const media::AudioParameters& params);
79 void StartPlaybackOnIOThread(); 128 void StartPlaybackOnIOThread();
80 void StopPlaybackOnIOThread(); 129 void StopPlaybackOnIOThread();
81 void SetVolumeOnIOThread(double volume); 130 void SetVolumeOnIOThread(double volume);
82 void ShutDownOnIOThread(); 131 void ShutDownOnIOThread();
83 132
133 void NotifyStreamCreationFailed();
134
84 // The client to notify when the stream is created. THIS MUST ONLY BE 135 // The client to notify when the stream is created. THIS MUST ONLY BE
85 // ACCESSED ON THE MAIN THREAD. 136 // ACCESSED ON THE MAIN THREAD.
86 AudioHelper* client_; 137 AudioHelper* client_;
138 // TODO: This PepperAudioOutputHost client will eventually replace
bbudge 2017/03/23 18:05:45 nit: chromium style requires TODO(owner), e.g. TOD
Xing 2017/03/29 21:14:32 Removed this TODO comment, since future modificati
139 // AudioHelper client. Only one of them can be valid. We keep them
140 // for backward compatibility purpose.
141 PepperAudioOutputHost* host_client_;
87 142
88 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE 143 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
89 // I/O thread except to send messages and get the message loop. 144 // I/O thread except to send messages and get the message loop.
90 std::unique_ptr<media::AudioOutputIPC> ipc_; 145 std::unique_ptr<media::AudioOutputIPC> ipc_;
91 146
92 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 147 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
93 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 148 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
94 149
150 // The frame containing the Pepper widget.
151 int render_frame_id_;
152
153 // Initialized on the main thread and accessed on the I/O thread afterwards.
154 media::AudioParameters params_;
155
156 // Current state (must only be accessed from the IO thread).
157 State state_;
158
159 // State of Start() calls before OnDeviceAuthorized() is called.
160 bool start_on_authorized_;
161
162 // State of StartPlayback() calls before OnStreamCreated() is called.
163 bool play_on_start_;
164
165 // The media session ID used to identify which output device to be started.
166 // Only used by Unified IO.
bbudge 2017/03/23 18:05:44 What is Unified IO?
Xing 2017/03/29 21:14:32 Removed.
167 int session_id_;
168
169 // ID of hardware output device to be used (provided session_id_ is zero)
170 const std::string device_id_;
171 const url::Origin security_origin_;
172
173 // If |device_id_| is empty and |session_id_| is not, |matched_device_id_| is
174 // received in OnDeviceAuthorized().
175 std::string matched_device_id_;
176
177 base::WaitableEvent did_receive_auth_;
178 media::AudioParameters output_params_;
179 media::OutputDeviceStatus device_status_;
180
181 const base::TimeDelta auth_timeout_;
182 std::unique_ptr<base::OneShotTimer> auth_timeout_action_;
183
95 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput); 184 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput);
96 }; 185 };
97 186
98 } // namespace content 187 } // namespace content
99 188
100 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_ 189 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698