Roll src/third_party/skia 2440fcd:4de8c3a
[chromium-blink-merge.git] / content / renderer / pepper / pepper_platform_audio_output.h
blobf51d0bcf7dcff21575536511e43eac25d9ad9a0c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "media/audio/audio_output_ipc.h"
13 namespace media {
14 class AudioParameters;
17 namespace base {
18 class SingleThreadTaskRunner;
21 namespace content {
22 class AudioHelper;
24 class PepperPlatformAudioOutput
25 : public media::AudioOutputIPCDelegate,
26 public base::RefCountedThreadSafe<PepperPlatformAudioOutput> {
27 public:
28 // Factory function, returns NULL on failure. StreamCreated() will be called
29 // when the stream is created.
30 static PepperPlatformAudioOutput* Create(int sample_rate,
31 int frames_per_buffer,
32 int source_render_frame_id,
33 AudioHelper* client);
35 // The following three methods are all called on main thread.
37 // Starts the playback. Returns false on error or if called before the
38 // stream is created or after the stream is closed.
39 bool StartPlayback();
41 // Stops the playback. Returns false on error or if called before the stream
42 // is created or after the stream is closed.
43 bool StopPlayback();
45 // Closes the stream. Make sure to call this before the object is
46 // destructed.
47 void ShutDown();
49 // media::AudioOutputIPCDelegate implementation.
50 void OnStateChanged(media::AudioOutputIPCDelegateState state) override;
51 void OnDeviceAuthorized(bool success,
52 const media::AudioParameters& output_params) override;
53 void OnStreamCreated(base::SharedMemoryHandle handle,
54 base::SyncSocket::Handle socket_handle,
55 int length) override;
56 void OnOutputDeviceSwitched(media::SwitchOutputDeviceResult result) override;
57 void OnIPCClosed() override;
59 protected:
60 ~PepperPlatformAudioOutput() override;
62 private:
63 friend class base::RefCountedThreadSafe<PepperPlatformAudioOutput>;
65 PepperPlatformAudioOutput();
67 bool Initialize(int sample_rate,
68 int frames_per_buffer,
69 int source_render_frame_id,
70 AudioHelper* client);
72 // I/O thread backends to above functions.
73 void InitializeOnIOThread(const media::AudioParameters& params);
74 void StartPlaybackOnIOThread();
75 void StopPlaybackOnIOThread();
76 void ShutDownOnIOThread();
78 // The client to notify when the stream is created. THIS MUST ONLY BE
79 // ACCESSED ON THE MAIN THREAD.
80 AudioHelper* client_;
82 // Used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
83 // I/O thread except to send messages and get the message loop.
84 scoped_ptr<media::AudioOutputIPC> ipc_;
86 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
87 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
89 DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutput);
92 } // namespace content
94 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_H_