15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/audio_config.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/instance_handle.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/module_impl.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <> const char* interface_name<PPB_AudioConfig_1_1>() {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return PPB_AUDIO_CONFIG_INTERFACE_1_1;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <> const char* interface_name<PPB_AudioConfig_1_0>() {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return PPB_AUDIO_CONFIG_INTERFACE_1_0;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AudioConfig::AudioConfig()
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : sample_rate_(PP_AUDIOSAMPLERATE_NONE),
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      sample_frame_count_(0) {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AudioConfig::AudioConfig(const InstanceHandle& instance,
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         PP_AudioSampleRate sample_rate,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         uint32_t sample_frame_count)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : sample_rate_(sample_rate),
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      sample_frame_count_(sample_frame_count) {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_AudioConfig_1_1>()) {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PassRefFromConstructor(
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        get_interface<PPB_AudioConfig_1_1>()->CreateStereo16Bit(
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        instance.pp_instance(), sample_rate, sample_frame_count));
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else if (has_interface<PPB_AudioConfig_1_0>()) {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PassRefFromConstructor(
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        get_interface<PPB_AudioConfig_1_0>()->CreateStereo16Bit(
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        instance.pp_instance(), sample_rate, sample_frame_count));
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PP_AudioSampleRate AudioConfig::RecommendSampleRate(
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const InstanceHandle& instance) {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_AudioConfig_1_1>()) {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return get_interface<PPB_AudioConfig_1_1>()->
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        RecommendSampleRate(instance.pp_instance());
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return PP_AUDIOSAMPLERATE_NONE;
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)uint32_t AudioConfig::RecommendSampleFrameCount(
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const InstanceHandle& instance,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PP_AudioSampleRate sample_rate,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    uint32_t requested_sample_frame_count) {
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_AudioConfig_1_1>()) {
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return get_interface<PPB_AudioConfig_1_1>()->
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        RecommendSampleFrameCount(instance.pp_instance(),
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  sample_rate,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  requested_sample_frame_count);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (has_interface<PPB_AudioConfig_1_0>()) {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return get_interface<PPB_AudioConfig_1_0>()->
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        RecommendSampleFrameCount(sample_rate,
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  requested_sample_frame_count);
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return 0;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace pp
76