1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/proxy/ppb_audio_config_proxy.h"
#include "ppapi/c/dev/ppb_audio_config_dev.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
#include "ppapi/proxy/ppapi_messages.h"
namespace pp {
namespace proxy {
class AudioConfig : public PluginResource {
public:
AudioConfig(PP_AudioSampleRate_Dev sample_rate, uint32_t sample_frame_count)
: sample_rate_(sample_rate),
sample_frame_count_(sample_frame_count) {
}
virtual ~AudioConfig() {}
// Resource overrides.
virtual AudioConfig* AsAudioConfig() { return this; }
PP_AudioSampleRate_Dev sample_rate() const { return sample_rate_; }
uint32_t sample_frame_count() const { return sample_frame_count_; }
private:
PP_AudioSampleRate_Dev sample_rate_;
uint32_t sample_frame_count_;
DISALLOW_COPY_AND_ASSIGN(AudioConfig);
};
namespace {
PP_Resource CreateStereo16bit(PP_Module module_id,
PP_AudioSampleRate_Dev sample_rate,
uint32_t sample_frame_count) {
PP_Resource result = 0;
PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudioConfig_Create(
INTERFACE_ID_PPB_AUDIO_CONFIG, module_id,
static_cast<int32_t>(sample_rate), sample_frame_count,
&result));
if (!result)
return 0;
linked_ptr<AudioConfig> object(
new AudioConfig(sample_rate, sample_frame_count));
PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
result, object);
return result;
}
uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) {
uint32_t result = 0;
PluginDispatcher::Get()->Send(
new PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount(
INTERFACE_ID_PPB_AUDIO_CONFIG, requested_sample_frame_count,
&result));
return result;
}
PP_Bool IsAudioConfig(PP_Resource resource) {
AudioConfig* object = PluginResource::GetAs<AudioConfig>(resource);
return BoolToPPBool(!!object);
}
PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) {
AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id);
if (!object)
return PP_AUDIOSAMPLERATE_NONE;
return object->sample_rate();
}
uint32_t GetSampleFrameCount(PP_Resource config_id) {
AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id);
if (!object)
return 0;
return object->sample_frame_count();
}
const PPB_AudioConfig_Dev audio_config_interface = {
&CreateStereo16bit,
&RecommendSampleFrameCount,
&IsAudioConfig,
&GetSampleRate,
&GetSampleFrameCount
};
} // namespace
PPB_AudioConfig_Proxy::PPB_AudioConfig_Proxy(Dispatcher* dispatcher,
const void* target_interface)
: InterfaceProxy(dispatcher, target_interface) {
}
PPB_AudioConfig_Proxy::~PPB_AudioConfig_Proxy() {
}
const void* PPB_AudioConfig_Proxy::GetSourceInterface() const {
return &audio_config_interface;
}
InterfaceID PPB_AudioConfig_Proxy::GetInterfaceId() const {
return INTERFACE_ID_PPB_AUDIO_CONFIG;
}
bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_AudioConfig_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_Create,
OnMsgCreateStereo16Bit)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount,
OnMsgRecommendSampleFrameCount)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Module module,
int32_t sample_rate,
uint32_t sample_frame_count,
PP_Resource* result) {
*result = ppb_audio_config_target()->CreateStereo16Bit(
module, static_cast<PP_AudioSampleRate_Dev>(sample_rate),
sample_frame_count);
}
void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount(
uint32_t requested,
uint32_t* result) {
*result = ppb_audio_config_target()->RecommendSampleFrameCount(requested);
}
} // namespace proxy
} // namespace pp
|