Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: ppapi/proxy/ppb_audio_config_proxy.cc

Issue 4985001: Initial audio implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_audio_config_proxy.h ('k') | ppapi/proxy/ppb_audio_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // 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
5 #include "ppapi/proxy/ppb_audio_config_proxy.h"
6
7 #include "ppapi/c/dev/ppb_audio_config_dev.h"
8 #include "ppapi/proxy/plugin_dispatcher.h"
9 #include "ppapi/proxy/plugin_resource.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11
12 namespace pp {
13 namespace proxy {
14
15 class AudioConfig : public PluginResource {
16 public:
17 AudioConfig(PP_AudioSampleRate_Dev sample_rate, uint32_t sample_frame_count)
18 : sample_rate_(sample_rate),
19 sample_frame_count_(sample_frame_count) {
20 }
21 virtual ~AudioConfig() {}
22
23 // Resource overrides.
24 virtual AudioConfig* AsAudioConfig() { return this; }
25
26 PP_AudioSampleRate_Dev sample_rate() const { return sample_rate_; }
27 uint32_t sample_frame_count() const { return sample_frame_count_; }
28
29 private:
30 PP_AudioSampleRate_Dev sample_rate_;
31 uint32_t sample_frame_count_;
32
33 DISALLOW_COPY_AND_ASSIGN(AudioConfig);
34 };
35
36 namespace {
37
38 PP_Resource CreateStereo16bit(PP_Module module_id,
39 PP_AudioSampleRate_Dev sample_rate,
40 uint32_t sample_frame_count) {
41 PP_Resource result = 0;
42 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudioConfig_Create(
43 INTERFACE_ID_PPB_AUDIO_CONFIG, module_id,
44 static_cast<int32_t>(sample_rate), sample_frame_count,
45 &result));
46 if (!result)
47 return 0;
48
49 linked_ptr<AudioConfig> object(
50 new AudioConfig(sample_rate, sample_frame_count));
51 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
52 result, object);
53 return result;
54 }
55
56 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) {
57 uint32_t result = 0;
58 PluginDispatcher::Get()->Send(
59 new PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount(
60 INTERFACE_ID_PPB_AUDIO_CONFIG, requested_sample_frame_count,
61 &result));
62 return result;
63 }
64
65 PP_Bool IsAudioConfig(PP_Resource resource) {
66 AudioConfig* object = PluginResource::GetAs<AudioConfig>(resource);
67 return BoolToPPBool(!!object);
68 }
69
70 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) {
71 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id);
72 if (!object)
73 return PP_AUDIOSAMPLERATE_NONE;
74 return object->sample_rate();
75 }
76
77 uint32_t GetSampleFrameCount(PP_Resource config_id) {
78 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id);
79 if (!object)
80 return 0;
81 return object->sample_frame_count();
82 }
83
84 const PPB_AudioConfig_Dev audio_config_interface = {
85 &CreateStereo16bit,
86 &RecommendSampleFrameCount,
87 &IsAudioConfig,
88 &GetSampleRate,
89 &GetSampleFrameCount
90 };
91
92 } // namespace
93
94 PPB_AudioConfig_Proxy::PPB_AudioConfig_Proxy(Dispatcher* dispatcher,
95 const void* target_interface)
96 : InterfaceProxy(dispatcher, target_interface) {
97 }
98
99 PPB_AudioConfig_Proxy::~PPB_AudioConfig_Proxy() {
100 }
101
102 const void* PPB_AudioConfig_Proxy::GetSourceInterface() const {
103 return &audio_config_interface;
104 }
105
106 InterfaceID PPB_AudioConfig_Proxy::GetInterfaceId() const {
107 return INTERFACE_ID_PPB_AUDIO_CONFIG;
108 }
109
110 void PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) {
111 IPC_BEGIN_MESSAGE_MAP(PPB_AudioConfig_Proxy, msg)
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_Create,
113 OnMsgCreateStereo16Bit)
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount,
115 OnMsgRecommendSampleFrameCount)
116 IPC_END_MESSAGE_MAP()
117 }
118
119 void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Module module,
120 int32_t sample_rate,
121 uint32_t sample_frame_count,
122 PP_Resource* result) {
123 *result = ppb_audio_config_target()->CreateStereo16Bit(
124 module, static_cast<PP_AudioSampleRate_Dev>(sample_rate),
125 sample_frame_count);
126 }
127
128 void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount(
129 uint32_t requested,
130 uint32_t* result) {
131 *result = ppb_audio_config_target()->RecommendSampleFrameCount(requested);
132 }
133
134 } // namespace proxy
135 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_audio_config_proxy.h ('k') | ppapi/proxy/ppb_audio_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698