Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / pepper / ppb_audio_impl.h
blob6c0af8f90fbf3222f73c5e188463e6a600ec270b
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_PPB_AUDIO_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "content/public/renderer/plugin_instance_throttler.h"
13 #include "content/renderer/pepper/audio_helper.h"
14 #include "ppapi/c/pp_completion_callback.h"
15 #include "ppapi/c/ppb_audio.h"
16 #include "ppapi/c/ppb_audio_config.h"
17 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
18 #include "ppapi/shared_impl/ppb_audio_shared.h"
19 #include "ppapi/shared_impl/resource.h"
20 #include "ppapi/shared_impl/scoped_pp_resource.h"
22 namespace content {
23 class PepperPlatformAudioOutput;
25 // Some of the backend functionality of this class is implemented by the
26 // PPB_Audio_Shared so it can be shared with the proxy.
28 // TODO(teravest): PPB_Audio is no longer supported in-process. Clean this up
29 // to look more like typical HostResource implementations.
30 class PPB_Audio_Impl : public ppapi::Resource,
31 public ppapi::PPB_Audio_Shared,
32 public AudioHelper,
33 public PluginInstanceThrottler::Observer {
34 public:
35 explicit PPB_Audio_Impl(PP_Instance instance);
37 // Resource overrides.
38 ppapi::thunk::PPB_Audio_API* AsPPB_Audio_API() override;
40 // PPB_Audio_API implementation.
41 PP_Resource GetCurrentConfig() override;
42 PP_Bool StartPlayback() override;
43 PP_Bool StopPlayback() override;
44 int32_t Open(PP_Resource config_id,
45 scoped_refptr<ppapi::TrackedCallback> create_callback) override;
46 int32_t GetSyncSocket(int* sync_socket) override;
47 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) override;
49 private:
50 ~PPB_Audio_Impl() override;
52 // AudioHelper implementation.
53 void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle,
54 size_t shared_memory_size_,
55 base::SyncSocket::Handle socket) override;
57 // PluginInstanceThrottler::Observer implementation.
58 void OnThrottleStateChange() override;
60 // Starts the deferred playback and unsubscribes from the throttler.
61 void StartDeferredPlayback();
63 // AudioConfig used for creating this Audio object. We own a ref.
64 ppapi::ScopedPPResource config_;
66 // PluginDelegate audio object that we delegate audio IPC through. We don't
67 // own this pointer but are responsible for calling Shutdown on it.
68 PepperPlatformAudioOutput* audio_;
70 // Stream is playing, but throttled due to Plugin Power Saver.
71 bool playback_throttled_;
73 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl);
76 } // namespace content
78 #endif // CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_