15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/cpp/audio_buffer.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/cpp/module.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/cpp/module_impl.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace pp { 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)template <> const char* interface_name<PPB_AudioBuffer_0_1>() { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return PPB_AUDIOBUFFER_INTERFACE_0_1; 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AudioBuffer::AudioBuffer() { 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AudioBuffer::AudioBuffer(const AudioBuffer& other) : Resource(other) { 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AudioBuffer::AudioBuffer(const Resource& resource) : Resource(resource) { 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AudioBuffer::AudioBuffer(PassRef, PP_Resource resource) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : Resource(PASS_REF, resource) { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)AudioBuffer::~AudioBuffer() { 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PP_TimeDelta AudioBuffer::GetTimestamp() const { 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetTimestamp(pp_resource()); 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0.0; 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void AudioBuffer::SetTimestamp(PP_TimeDelta timestamp) { 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) { 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) get_interface<PPB_AudioBuffer_0_1>()->SetTimestamp(pp_resource(), 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) timestamp); 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PP_AudioBuffer_SampleRate AudioBuffer::GetSampleRate() const { 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetSampleRate(pp_resource()); 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN; 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)PP_AudioBuffer_SampleSize AudioBuffer::GetSampleSize() const { 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetSampleSize(pp_resource()); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)uint32_t AudioBuffer::GetNumberOfChannels() const { 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) { 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetNumberOfChannels( 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp_resource()); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)uint32_t AudioBuffer::GetNumberOfSamples() const { 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) { 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetNumberOfSamples( 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp_resource()); 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0; 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void* AudioBuffer::GetDataBuffer() { 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetDataBuffer(pp_resource()); 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NULL; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)uint32_t AudioBuffer::GetDataBufferSize() const { 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (has_interface<PPB_AudioBuffer_0_1>()) { 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return get_interface<PPB_AudioBuffer_0_1>()->GetDataBufferSize( 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp_resource()); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 0; 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace pp 92