blob: 9590034cbcdbf03f0dc4e7ea8c5d9c2d60272d57 [file] [log] [blame]
[email protected]937df95112010-07-30 21:24:391// Copyright (c) 2010 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.
4
[email protected]0bd753682010-12-16 18:15:525#ifndef WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_
6#define WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_
[email protected]6f2e3912010-11-05 14:45:447
[email protected]0bd753682010-12-16 18:15:528#include "base/basictypes.h"
[email protected]937df95112010-07-30 21:24:399#include "base/ref_counted.h"
[email protected]937df95112010-07-30 21:24:3910#include "base/shared_memory.h"
[email protected]937df95112010-07-30 21:24:3911#include "base/sync_socket.h"
[email protected]06417272010-11-25 00:29:2512#include "ppapi/c/pp_completion_callback.h"
[email protected]b9a59842011-01-15 01:04:0013#include "ppapi/c/ppb_audio.h"
14#include "ppapi/c/ppb_audio_config.h"
15#include "ppapi/c/trusted/ppb_audio_trusted.h"
[email protected]5d84d012010-12-02 17:17:2116#include "ppapi/shared_impl/audio_impl.h"
[email protected]0bd753682010-12-16 18:15:5217#include "webkit/plugins/ppapi/plugin_delegate.h"
[email protected]0bd753682010-12-16 18:15:5218#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
19#include "webkit/plugins/ppapi/resource.h"
[email protected]937df95112010-07-30 21:24:3920
[email protected]0bd753682010-12-16 18:15:5221namespace webkit {
22namespace ppapi {
[email protected]937df95112010-07-30 21:24:3923
24class PluginInstance;
[email protected]937df95112010-07-30 21:24:3925
[email protected]0bd753682010-12-16 18:15:5226class PPB_AudioConfig_Impl : public Resource {
[email protected]937df95112010-07-30 21:24:3927 public:
[email protected]859a7f32011-01-15 03:44:1328 PPB_AudioConfig_Impl(PluginInstance* instance,
[email protected]b9a59842011-01-15 01:04:0029 PP_AudioSampleRate sample_rate,
[email protected]0bd753682010-12-16 18:15:5230 uint32_t sample_frame_count);
[email protected]39690e12010-10-05 21:58:4531 size_t BufferSize();
[email protected]b9a59842011-01-15 01:04:0032 static const PPB_AudioConfig* GetInterface();
[email protected]937df95112010-07-30 21:24:3933
[email protected]b9a59842011-01-15 01:04:0034 PP_AudioSampleRate sample_rate() { return sample_rate_; }
[email protected]937df95112010-07-30 21:24:3935 uint32_t sample_frame_count() { return sample_frame_count_; }
36
37 private:
38 // Resource override.
[email protected]0bd753682010-12-16 18:15:5239 virtual PPB_AudioConfig_Impl* AsPPB_AudioConfig_Impl();
[email protected]937df95112010-07-30 21:24:3940
[email protected]b9a59842011-01-15 01:04:0041 PP_AudioSampleRate sample_rate_;
[email protected]39690e12010-10-05 21:58:4542 uint32_t sample_frame_count_;
[email protected]937df95112010-07-30 21:24:3943};
44
[email protected]5d84d012010-12-02 17:17:2145// Some of the backend functionality of this class is implemented by the
46// AudioImpl so it can be shared with the proxy.
[email protected]0bd753682010-12-16 18:15:5247class PPB_Audio_Impl : public Resource,
48 public pp::shared_impl::AudioImpl,
49 public PluginDelegate::PlatformAudio::Client {
[email protected]937df95112010-07-30 21:24:3950 public:
[email protected]859a7f32011-01-15 03:44:1351 explicit PPB_Audio_Impl(PluginInstance* instance);
[email protected]0bd753682010-12-16 18:15:5252 virtual ~PPB_Audio_Impl();
[email protected]937df95112010-07-30 21:24:3953
[email protected]b9a59842011-01-15 01:04:0054 static const PPB_Audio* GetInterface();
55 static const PPB_AudioTrusted* GetTrustedInterface();
[email protected]937df95112010-07-30 21:24:3956
[email protected]5d84d012010-12-02 17:17:2157 // PPB_Audio implementation.
58 bool Init(PluginDelegate* plugin_delegate,
59 PP_Resource config_id,
60 PPB_Audio_Callback user_callback, void* user_data);
61 PP_Resource GetCurrentConfig();
[email protected]b0deb152010-08-31 17:37:3562 bool StartPlayback();
[email protected]b0deb152010-08-31 17:37:3563 bool StopPlayback();
[email protected]937df95112010-07-30 21:24:3964
[email protected]5d84d012010-12-02 17:17:2165 // PPB_Audio_Trusted implementation.
66 int32_t Open(PluginDelegate* plugin_delegate,
67 PP_Resource config_id,
68 PP_CompletionCallback create_callback);
69 int32_t GetSyncSocket(int* sync_socket);
70 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size);
71
[email protected]937df95112010-07-30 21:24:3972 // Resource override.
[email protected]0bd753682010-12-16 18:15:5273 virtual PPB_Audio_Impl* AsPPB_Audio_Impl();
[email protected]937df95112010-07-30 21:24:3974
75 private:
[email protected]0bd753682010-12-16 18:15:5276 // PluginDelegate::PlatformAudio::Client implementation.
[email protected]937df95112010-07-30 21:24:3977 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle,
78 size_t shared_memory_size_,
79 base::SyncSocket::Handle socket);
[email protected]b0deb152010-08-31 17:37:3580
[email protected]937df95112010-07-30 21:24:3981 // AudioConfig used for creating this Audio object.
[email protected]0bd753682010-12-16 18:15:5282 scoped_refptr<PPB_AudioConfig_Impl> config_;
[email protected]937df95112010-07-30 21:24:3983
[email protected]9ca245e2011-03-18 01:50:3184 // PluginDelegate audio object that we delegate audio IPC through. We don't
85 // own this pointer but are responsible for calling Shutdown on it.
[email protected]06417272010-11-25 00:29:2586 PluginDelegate::PlatformAudio* audio_;
[email protected]937df95112010-07-30 21:24:3987
[email protected]06417272010-11-25 00:29:2588 // Is a create callback pending to fire?
89 bool create_callback_pending_;
90
91 // Trusted callback invoked from StreamCreated.
92 PP_CompletionCallback create_callback_;
[email protected]5d84d012010-12-02 17:17:2193
94 // When a create callback is being issued, these will save the info for
95 // querying from the callback. The proxy uses this to get the handles to the
96 // other process instead of mapping them in the renderer. These will be
97 // invalid all other times.
98 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_;
99 size_t shared_memory_size_for_create_callback_;
100 scoped_ptr<base::SyncSocket> socket_for_create_callback_;
[email protected]0bd753682010-12-16 18:15:52101
102 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl);
[email protected]937df95112010-07-30 21:24:39103};
104
[email protected]0bd753682010-12-16 18:15:52105} // namespace ppapi
106} // namespace webkit
[email protected]937df95112010-07-30 21:24:39107
[email protected]0bd753682010-12-16 18:15:52108#endif // WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_