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 WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/ppb_audio.h"
14 #include "ppapi/c/ppb_audio_config.h"
15 #include "ppapi/c/trusted/ppb_audio_trusted.h"
16 #include "ppapi/shared_impl/ppb_audio_config_shared.h"
17 #include "ppapi/shared_impl/ppb_audio_shared.h"
18 #include "ppapi/shared_impl/resource.h"
19 #include "ppapi/shared_impl/scoped_pp_resource.h"
20 #include "webkit/plugins/ppapi/audio_helper.h"
21 #include "webkit/plugins/ppapi/plugin_delegate.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
27 // Some of the backend functionality of this class is implemented by the
28 // PPB_Audio_Shared so it can be shared with the proxy.
29 class PPB_Audio_Impl
: public ::ppapi::Resource
,
30 public ::ppapi::PPB_Audio_Shared
,
33 // Trusted initialization. You must call Init after this.
35 // Untrusted initialization should just call the static Create() function
36 // to properly create & initialize this class.
37 explicit PPB_Audio_Impl(PP_Instance instance
);
39 virtual ~PPB_Audio_Impl();
41 // Creation function for untrusted plugins. This handles all initialization
42 // and will return 0 on failure.
43 static PP_Resource
Create(PP_Instance instance
,
44 PP_Resource config_id
,
45 PPB_Audio_Callback audio_callback
,
48 // Initialization function for trusted init.
49 bool Init(PP_Resource config_id
,
50 PPB_Audio_Callback user_callback
,
53 // Resource overrides.
54 virtual ::ppapi::thunk::PPB_Audio_API
* AsPPB_Audio_API();
56 // PPB_Audio_API implementation.
57 virtual PP_Resource
GetCurrentConfig() OVERRIDE
;
58 virtual PP_Bool
StartPlayback() OVERRIDE
;
59 virtual PP_Bool
StopPlayback() OVERRIDE
;
60 virtual int32_t OpenTrusted(
61 PP_Resource config_id
,
62 scoped_refptr
< ::ppapi::TrackedCallback
> create_callback
) OVERRIDE
;
63 virtual int32_t GetSyncSocket(int* sync_socket
) OVERRIDE
;
64 virtual int32_t GetSharedMemory(int* shm_handle
, uint32_t* shm_size
) OVERRIDE
;
67 // AudioHelper implementation.
68 virtual void OnSetStreamInfo(base::SharedMemoryHandle shared_memory_handle
,
69 size_t shared_memory_size_
,
70 base::SyncSocket::Handle socket
);
72 // AudioConfig used for creating this Audio object. We own a ref.
73 ::ppapi::ScopedPPResource config_
;
75 // PluginDelegate audio object that we delegate audio IPC through. We don't
76 // own this pointer but are responsible for calling Shutdown on it.
77 PluginDelegate::PlatformAudioOutput
* audio_
;
79 // Track frame count for passing on to PPB_Audio_Shared::SetStreamInfo().
80 int sample_frame_count_
;
82 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl
);
88 #endif // WEBKIT_PLUGINS_PPAPI_PPB_AUDIO_IMPL_H_