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
|
// Copyright (c) 2011 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/shared_impl/ppb_audio_config_shared.h"
namespace ppapi {
PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance)
: Resource(instance),
sample_rate_(PP_AUDIOSAMPLERATE_NONE),
sample_frame_count_(0) {
}
PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(
const HostResource& host_resource)
: Resource(host_resource),
sample_rate_(PP_AUDIOSAMPLERATE_NONE),
sample_frame_count_(0) {
}
PPB_AudioConfig_Shared::~PPB_AudioConfig_Shared() {
}
// static
PP_Resource PPB_AudioConfig_Shared::CreateAsImpl(
PP_Instance instance,
PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count) {
scoped_refptr<PPB_AudioConfig_Shared> object(
new PPB_AudioConfig_Shared(instance));
if (!object->Init(sample_rate, sample_frame_count))
return 0;
return object->GetReference();
}
// static
PP_Resource PPB_AudioConfig_Shared::CreateAsProxy(
PP_Instance instance,
PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count) {
scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared(
HostResource::MakeInstanceOnly(instance)));
if (!object->Init(sample_rate, sample_frame_count))
return 0;
return object->GetReference();
}
thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() {
return this;
}
PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() {
return sample_rate_;
}
uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() {
return sample_frame_count_;
}
bool PPB_AudioConfig_Shared::Init(PP_AudioSampleRate sample_rate,
uint32_t sample_frame_count) {
// TODO(brettw): Currently we don't actually check what the hardware
// supports, so just allow sample rates of the "guaranteed working" ones.
if (sample_rate != PP_AUDIOSAMPLERATE_44100 &&
sample_rate != PP_AUDIOSAMPLERATE_48000)
return false;
// TODO(brettw): Currently we don't actually query to get a value from the
// hardware, so just validate the range.
if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT ||
sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
return false;
sample_rate_ = sample_rate;
sample_frame_count_ = sample_frame_count;
return true;
}
} // namespace ppapi
|