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"
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
,
33 public PluginInstanceThrottler::Observer
{
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(base::SharedMemory
** shm
,
48 uint32_t* shm_size
) override
;
51 ~PPB_Audio_Impl() override
;
53 // AudioHelper implementation.
54 void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle
,
55 size_t shared_memory_size_
,
56 base::SyncSocket::Handle socket
) override
;
58 // PluginInstanceThrottler::Observer implementation.
59 void OnThrottleStateChange() override
;
61 // Starts the deferred playback and unsubscribes from the throttler.
62 void StartDeferredPlayback();
64 // AudioConfig used for creating this Audio object. We own a ref.
65 ppapi::ScopedPPResource config_
;
67 // PluginDelegate audio object that we delegate audio IPC through. We don't
68 // own this pointer but are responsible for calling Shutdown on it.
69 PepperPlatformAudioOutput
* audio_
;
71 // Stream is playing, but throttled due to Plugin Power Saver.
72 bool playback_throttled_
;
74 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl
);
77 } // namespace content
79 #endif // CONTENT_RENDERER_PEPPER_PPB_AUDIO_IMPL_H_