Pepper_47_C++_interfaces
audio_config.cc
Go to the documentation of this file.
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.
4 
6 
8 #include "ppapi/cpp/module.h"
10 
11 namespace pp {
12 
13 namespace {
14 
15 template <> const char* interface_name<PPB_AudioConfig_1_1>() {
16  return PPB_AUDIO_CONFIG_INTERFACE_1_1;
17 }
18 
19 template <> const char* interface_name<PPB_AudioConfig_1_0>() {
20  return PPB_AUDIO_CONFIG_INTERFACE_1_0;
21 }
22 
23 } // namespace
24 
26  : sample_rate_(PP_AUDIOSAMPLERATE_NONE),
27  sample_frame_count_(0) {
28 }
29 
31  PP_AudioSampleRate sample_rate,
32  uint32_t sample_frame_count)
33  : sample_rate_(sample_rate),
34  sample_frame_count_(sample_frame_count) {
35  if (has_interface<PPB_AudioConfig_1_1>()) {
37  get_interface<PPB_AudioConfig_1_1>()->CreateStereo16Bit(
39  } else if (has_interface<PPB_AudioConfig_1_0>()) {
41  get_interface<PPB_AudioConfig_1_0>()->CreateStereo16Bit(
43  }
44 }
45 
46 // static
48  const InstanceHandle& instance) {
49  if (has_interface<PPB_AudioConfig_1_1>()) {
50  return get_interface<PPB_AudioConfig_1_1>()->
51  RecommendSampleRate(instance.pp_instance());
52  }
53  return PP_AUDIOSAMPLERATE_NONE;
54 }
55 
56 // static
58  const InstanceHandle& instance,
59  PP_AudioSampleRate sample_rate,
60  uint32_t requested_sample_frame_count) {
61  if (has_interface<PPB_AudioConfig_1_1>()) {
62  return get_interface<PPB_AudioConfig_1_1>()->
65  requested_sample_frame_count);
66  }
67  if (has_interface<PPB_AudioConfig_1_0>()) {
68  return get_interface<PPB_AudioConfig_1_0>()->
69  RecommendSampleFrameCount(sample_rate,
70  requested_sample_frame_count);
71  }
72  return 0;
73 }
74 
75 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
PP_AudioSampleRate sample_rate() const
Definition: audio_config.h:117
static uint32_t RecommendSampleFrameCount(const InstanceHandle &instance, PP_AudioSampleRate sample_rate, uint32_t requested_sample_frame_count)
Definition: audio_config.cc:57
uint32_t sample_frame_count() const
Definition: audio_config.h:122
static PP_AudioSampleRate RecommendSampleRate(const InstanceHandle &instance)
Definition: audio_config.cc:47
AudioConfig()
An empty constructor for an AudioConfig resource.
Definition: audio_config.cc:25
PP_Instance pp_instance() const