| 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_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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "content/common/media/audio_output.mojom.h" |
| 11 #include "media/audio/audio_output_ipc.h" | 12 #include "media/audio/audio_output_ipc.h" |
| 12 | 13 |
| 13 namespace media { | 14 namespace media { |
| 14 class AudioParameters; | 15 class AudioParameters; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class AudioHelper; | 23 class AudioHelper; |
| 23 | 24 |
| 24 class PepperPlatformAudioOutput | 25 class PepperPlatformAudioOutput |
| 25 : public media::AudioOutputIPCDelegate, | 26 : public media::AudioOutputIPCDelegate, |
| 26 public base::RefCountedThreadSafe<PepperPlatformAudioOutput> { | 27 public base::RefCountedThreadSafe<PepperPlatformAudioOutput> { |
| 27 public: | 28 public: |
| 28 // Factory function, returns NULL on failure. StreamCreated() will be called | 29 // Factory function, returns NULL on failure. StreamCreated() will be called |
| 29 // when the stream is created. | 30 // when the stream is created. |
| 30 static PepperPlatformAudioOutput* Create(int sample_rate, | 31 static PepperPlatformAudioOutput* Create(int sample_rate, |
| 31 int frames_per_buffer, | 32 int frames_per_buffer, |
| 32 int source_render_frame_id, | 33 int source_render_frame_id, |
| 33 AudioHelper* client); | 34 AudioHelper* client); |
| 34 | 35 |
| 36 media::AudioOutputIPC* getIPC() override; |
| 37 |
| 35 // The following three methods are all called on main thread. | 38 // The following three methods are all called on main thread. |
| 36 | 39 |
| 37 // Starts the playback. Returns false on error or if called before the | 40 // Starts the playback. Returns false on error or if called before the |
| 38 // stream is created or after the stream is closed. | 41 // stream is created or after the stream is closed. |
| 39 bool StartPlayback(); | 42 bool StartPlayback(); |
| 40 | 43 |
| 41 // Stops the playback. Returns false on error or if called before the stream | 44 // Stops the playback. Returns false on error or if called before the stream |
| 42 // is created or after the stream is closed. | 45 // is created or after the stream is closed. |
| 43 bool StopPlayback(); | 46 bool StopPlayback(); |
| 44 | 47 |
| 45 // Closes the stream. Make sure to call this before the object is | 48 // Closes the stream. Make sure to call this before the object is |
| 46 // destructed. | 49 // destructed. |
| 47 void ShutDown(); | 50 void ShutDown(); |
| 48 | 51 |
| 49 // media::AudioOutputIPCDelegate implementation. | 52 // media::AudioOutputIPCDelegate implementation. |
| 50 void OnStateChanged(media::AudioOutputIPCDelegateState state) override; | 53 void OnStateChanged(media::AudioOutputIPCDelegateState state) override; |
| 51 void OnDeviceAuthorized(media::OutputDeviceStatus device_status, | 54 void OnDeviceAuthorized(media::OutputDeviceStatus device_status, |
| 52 const media::AudioParameters& output_params) override; | 55 const media::AudioParameters& output_params) override; |
| 53 void OnStreamCreated(base::SharedMemoryHandle handle, | 56 void OnStreamCreated(mojom::AudioOutputStreamPtr* stream, |
| 57 base::SharedMemoryHandle handle, |
| 54 base::SyncSocket::Handle socket_handle, | 58 base::SyncSocket::Handle socket_handle, |
| 55 int length) override; | 59 int length) override; |
| 56 void OnIPCClosed() override; | 60 void OnIPCClosed() override; |
| 57 | 61 |
| 58 protected: | 62 protected: |
| 59 ~PepperPlatformAudioOutput() override; | 63 ~PepperPlatformAudioOutput() override; |
| 60 | 64 |
| 61 private: | 65 private: |
| 62 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>; | 66 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>; |
| 63 | 67 |
| 64 PepperPlatformAudioOutput(); | 68 PepperPlatformAudioOutput(); |
| 65 | 69 |
| 66 bool Initialize(int sample_rate, | 70 bool Initialize(int sample_rate, |
| 67 int frames_per_buffer, | 71 int frames_per_buffer, |
| 68 int source_render_frame_id, | 72 int source_render_frame_id, |
| 69 AudioHelper* client); | 73 AudioHelper* client); |
| 70 | 74 |
| 71 // I/O thread backends to above functions. | 75 // I/O thread backends to above functions. |
| 72 void InitializeOnIOThread(const media::AudioParameters& params); | 76 void InitializeOnIOThread(const media::AudioParameters& params); |
| 73 void StartPlaybackOnIOThread(); | 77 void StartPlaybackOnIOThread(); |
| 74 void StopPlaybackOnIOThread(); | 78 void StopPlaybackOnIOThread(); |
| 75 void ShutDownOnIOThread(); | 79 void ShutDownOnIOThread(); |
| 76 | 80 |
| 77 // The client to notify when the stream is created. THIS MUST ONLY BE | 81 // The client to notify when the stream is created. THIS MUST ONLY BE |
| 78 // ACCESSED ON THE MAIN THREAD. | 82 // ACCESSED ON THE MAIN THREAD. |
| 79 AudioHelper* client_; | 83 AudioHelper* client_; |
| 80 | 84 |
| 85 mojom::AudioOutputStreamPtr* stream_; |
| 86 |
| 81 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE | 87 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
| 82 // I/O thread except to send messages and get the message loop. | 88 // I/O thread except to send messages and get the message loop. |
| 83 scoped_ptr<media::AudioOutputIPC> ipc_; | 89 scoped_ptr<media::AudioOutputIPC> ipc_; |
| 84 | 90 |
| 85 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 91 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 86 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 92 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 87 | 93 |
| 88 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput); | 94 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput); |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 } // namespace content | 97 } // namespace content |
| 92 | 98 |
| 93 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_ | 99 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_ |
| OLD | NEW |