| 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 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "media/audio/audio_output_ipc.h" | 10 #include "media/audio/audio_output_ipc.h" |
| 11 #include "webkit/plugins/ppapi/plugin_delegate.h" | 11 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 12 | 12 |
| 13 class AudioOutputIPCImpl; |
| 14 |
| 13 namespace media { | 15 namespace media { |
| 14 class AudioParameters; | 16 class AudioParameters; |
| 15 } | 17 } |
| 16 | 18 |
| 17 namespace base { | 19 namespace base { |
| 18 class MessageLoopProxy; | 20 class MessageLoopProxy; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 | 24 |
| 23 class PepperPlatformAudioOutputImpl | 25 class PepperPlatformAudioOutputImpl |
| 24 : public webkit::ppapi::PluginDelegate::PlatformAudioOutput, | 26 : public webkit::ppapi::PluginDelegate::PlatformAudioOutput, |
| 25 public media::AudioOutputIPCDelegate, | 27 public media::AudioOutputIPCDelegate, |
| 26 public base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl> { | 28 public base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl> { |
| 27 public: | 29 public: |
| 28 // Factory function, returns NULL on failure. StreamCreated() will be called | 30 // Factory function, returns NULL on failure. StreamCreated() will be called |
| 29 // when the stream is created. | 31 // when the stream is created. |
| 30 static PepperPlatformAudioOutputImpl* Create( | 32 static PepperPlatformAudioOutputImpl* Create( |
| 33 int render_view_id, |
| 31 int sample_rate, | 34 int sample_rate, |
| 32 int frames_per_buffer, | 35 int frames_per_buffer, |
| 33 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client); | 36 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client); |
| 34 | 37 |
| 35 // PlatformAudioOutput implementation (called on main thread). | 38 // PlatformAudioOutput implementation (called on main thread). |
| 36 virtual bool StartPlayback() OVERRIDE; | 39 virtual bool StartPlayback() OVERRIDE; |
| 37 virtual bool StopPlayback() OVERRIDE; | 40 virtual bool StopPlayback() OVERRIDE; |
| 38 virtual void ShutDown() OVERRIDE; | 41 virtual void ShutDown() OVERRIDE; |
| 39 | 42 |
| 40 // media::AudioOutputIPCDelegate implementation. | 43 // media::AudioOutputIPCDelegate implementation. |
| 41 virtual void OnStateChanged( | 44 virtual void OnStateChanged( |
| 42 media::AudioOutputIPCDelegate::State state) OVERRIDE; | 45 media::AudioOutputIPCDelegate::State state) OVERRIDE; |
| 43 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 46 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 44 base::SyncSocket::Handle socket_handle, | 47 base::SyncSocket::Handle socket_handle, |
| 45 int length) OVERRIDE; | 48 int length) OVERRIDE; |
| 46 virtual void OnIPCClosed() OVERRIDE; | 49 virtual void OnIPCClosed() OVERRIDE; |
| 47 | 50 |
| 48 protected: | 51 protected: |
| 49 virtual ~PepperPlatformAudioOutputImpl(); | 52 virtual ~PepperPlatformAudioOutputImpl(); |
| 50 | 53 |
| 51 private: | 54 private: |
| 52 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl>; | 55 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl>; |
| 53 | 56 |
| 54 PepperPlatformAudioOutputImpl(); | 57 PepperPlatformAudioOutputImpl(int render_view_id); |
| 55 | 58 |
| 56 bool Initialize( | 59 bool Initialize( |
| 57 int sample_rate, | 60 int sample_rate, |
| 58 int frames_per_buffer, | 61 int frames_per_buffer, |
| 59 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client); | 62 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client); |
| 60 | 63 |
| 61 // I/O thread backends to above functions. | 64 // I/O thread backends to above functions. |
| 62 void InitializeOnIOThread(const media::AudioParameters& params); | 65 void InitializeOnIOThread(const media::AudioParameters& params); |
| 63 void StartPlaybackOnIOThread(); | 66 void StartPlaybackOnIOThread(); |
| 64 void StopPlaybackOnIOThread(); | 67 void StopPlaybackOnIOThread(); |
| 65 void ShutDownOnIOThread(); | 68 void ShutDownOnIOThread(); |
| 66 | 69 |
| 67 // The client to notify when the stream is created. THIS MUST ONLY BE | 70 // The client to notify when the stream is created. THIS MUST ONLY BE |
| 68 // ACCESSED ON THE MAIN THREAD. | 71 // ACCESSED ON THE MAIN THREAD. |
| 69 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client_; | 72 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client_; |
| 70 | 73 |
| 71 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE | 74 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
| 72 // I/O thread except to send messages and get the message loop. | 75 // I/O thread except to send messages and get the message loop. |
| 73 media::AudioOutputIPC* ipc_; | 76 scoped_ptr<AudioOutputIPCImpl> ipc_; |
| 74 | 77 |
| 75 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD | 78 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD |
| 76 // or else you could race with the initialize function which sets it. | 79 // or else you could race with the initialize function which sets it. |
| 77 int32 stream_id_; | 80 int32 stream_id_; |
| 78 | 81 |
| 79 base::MessageLoopProxy* main_message_loop_proxy_; | 82 base::MessageLoopProxy* main_message_loop_proxy_; |
| 80 | 83 |
| 81 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutputImpl); | 84 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutputImpl); |
| 82 }; | 85 }; |
| 83 | 86 |
| 84 } // namespace content | 87 } // namespace content |
| 85 | 88 |
| 86 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ | 89 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_ |
| OLD | NEW |