Chromium Code Reviews| Index: content/renderer/pepper/pepper_platform_audio_output.h |
| diff --git a/content/renderer/pepper/pepper_platform_audio_output.h b/content/renderer/pepper/pepper_platform_audio_output.h |
| index ad218839f54227b0e16546a44216189e69c81911..e5b2f6cf4f3e0f212d2acf9c8e233e8e2ee9e584 100644 |
| --- a/content/renderer/pepper/pepper_platform_audio_output.h |
| +++ b/content/renderer/pepper/pepper_platform_audio_output.h |
| @@ -10,17 +10,32 @@ |
| #include "base/macros.h" |
| #include "base/memory/ref_counted.h" |
| #include "media/audio/audio_output_ipc.h" |
| - |
| -namespace media { |
| -class AudioParameters; |
| -} |
| +#include "media/base/audio_parameters.h" |
| +#include "media/base/output_device_info.h" |
| namespace base { |
| +class OneShotTimer; |
| class SingleThreadTaskRunner; |
| } |
| +namespace { |
| +#if defined(OS_WIN) || defined(OS_MACOSX) |
| + const int64_t kMaxAuthorizationTimeoutMs = 4000; |
| +#else |
| + const int64_t kMaxAuthorizationTimeoutMs = 0; // No timeout. |
| +#endif |
| +} |
| + |
| namespace content { |
| class AudioHelper; |
| +class PepperAudioOutputHost; |
| + |
| +// We need to support both public PPAPI |PPB_Audio| and the new |
| +// dev PPAPI |PPB_AudioOutput_Dev| at the same time, so that the |
| +// existing users of |PPB_Audio| won't be affected. |
| +// To achieve this, we have to keep references to both |AudioHelper| |
| +// object and |PepperAudioOutputHost| object, so we can dispatch |
| +// 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
|
| class PepperPlatformAudioOutput |
| : public media::AudioOutputIPCDelegate, |
| @@ -33,8 +48,18 @@ class PepperPlatformAudioOutput |
| int source_render_frame_id, |
| AudioHelper* client); |
| + static PepperPlatformAudioOutput* Create(int render_frame_id, |
| + const std::string& device_id, |
| + const GURL& document_url, |
| + int sample_rate, |
| + int frames_per_buffer, |
| + PepperAudioOutputHost* client); |
| + |
| // The following three methods are all called on main thread. |
| + // 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.
|
| + void RequestDeviceAuthorization(); |
| + |
| // Starts the playback. Returns false on error or if called before the |
| // stream is created or after the stream is closed. |
| bool StartPlayback(); |
| @@ -65,25 +90,55 @@ class PepperPlatformAudioOutput |
| ~PepperPlatformAudioOutput() override; |
| private: |
| + enum State { |
| + IPC_CLOSED, // No more IPCs can take place. |
| + IDLE, // Not started. |
| + AUTHORIZING, // Sent device authorization request, waiting for reply. |
| + AUTHORIZED, // Successful device authorization received. |
| + CREATING_STREAM, // Waiting for OnStreamCreated() to be called back. |
| + PAUSED, // Paused. OnStreamCreated() has been called. Can Play()/Stop(). |
| + PLAYING, // Playing back. Can Pause()/Stop(). |
| + }; |
| + |
| friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>; |
| PepperPlatformAudioOutput(); |
| + PepperPlatformAudioOutput(int render_frame_id, |
| + const std::string& device_id, |
| + const GURL& document_url, |
| + base::TimeDelta authorization_timeout); |
| + // 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.
|
| bool Initialize(int sample_rate, |
| int frames_per_buffer, |
| int source_render_frame_id, |
| AudioHelper* client); |
| + // 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.
|
| + bool Initialize(int sample_rate, |
| + int frames_per_buffer, |
| + PepperAudioOutputHost* client); |
| + |
| // I/O thread backends to above functions. |
| + // Used only by old Pepper audio interface. |
|
bbudge
2017/03/23 18:05:45
ditto
Xing
2017/03/29 21:14:32
Done.
|
| void InitializeOnIOThread(const media::AudioParameters& params); |
| + |
| + 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.
|
| + void CreateStreamOnIOThread(const media::AudioParameters& params); |
| void StartPlaybackOnIOThread(); |
| void StopPlaybackOnIOThread(); |
| void SetVolumeOnIOThread(double volume); |
| void ShutDownOnIOThread(); |
| + void NotifyStreamCreationFailed(); |
| + |
| // The client to notify when the stream is created. THIS MUST ONLY BE |
| // ACCESSED ON THE MAIN THREAD. |
| AudioHelper* client_; |
| + // 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
|
| + // AudioHelper client. Only one of them can be valid. We keep them |
| + // for backward compatibility purpose. |
| + PepperAudioOutputHost* host_client_; |
| // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
| // I/O thread except to send messages and get the message loop. |
| @@ -92,6 +147,40 @@ class PepperPlatformAudioOutput |
| scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| + // The frame containing the Pepper widget. |
| + int render_frame_id_; |
| + |
| + // Initialized on the main thread and accessed on the I/O thread afterwards. |
| + media::AudioParameters params_; |
| + |
| + // Current state (must only be accessed from the IO thread). |
| + State state_; |
| + |
| + // State of Start() calls before OnDeviceAuthorized() is called. |
| + bool start_on_authorized_; |
| + |
| + // State of StartPlayback() calls before OnStreamCreated() is called. |
| + bool play_on_start_; |
| + |
| + // The media session ID used to identify which output device to be started. |
| + // Only used by Unified IO. |
|
bbudge
2017/03/23 18:05:44
What is Unified IO?
Xing
2017/03/29 21:14:32
Removed.
|
| + int session_id_; |
| + |
| + // ID of hardware output device to be used (provided session_id_ is zero) |
| + const std::string device_id_; |
| + const url::Origin security_origin_; |
| + |
| + // If |device_id_| is empty and |session_id_| is not, |matched_device_id_| is |
| + // received in OnDeviceAuthorized(). |
| + std::string matched_device_id_; |
| + |
| + base::WaitableEvent did_receive_auth_; |
| + media::AudioParameters output_params_; |
| + media::OutputDeviceStatus device_status_; |
| + |
| + const base::TimeDelta auth_timeout_; |
| + std::unique_ptr<base::OneShotTimer> auth_timeout_action_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput); |
| }; |