| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 | |
| 5 #include "ppapi/shared_impl/ppb_audio_config_shared.h" | |
| 6 | |
| 7 namespace ppapi { | |
| 8 | |
| 9 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance) | |
| 10 : Resource(instance), | |
| 11 sample_rate_(PP_AUDIOSAMPLERATE_NONE), | |
| 12 sample_frame_count_(0) { | |
| 13 } | |
| 14 | |
| 15 PPB_AudioConfig_Shared::PPB_AudioConfig_Shared( | |
| 16 const HostResource& host_resource) | |
| 17 : Resource(host_resource), | |
| 18 sample_rate_(PP_AUDIOSAMPLERATE_NONE), | |
| 19 sample_frame_count_(0) { | |
| 20 } | |
| 21 | |
| 22 PPB_AudioConfig_Shared::~PPB_AudioConfig_Shared() { | |
| 23 } | |
| 24 | |
| 25 // static | |
| 26 PP_Resource PPB_AudioConfig_Shared::CreateAsImpl( | |
| 27 PP_Instance instance, | |
| 28 PP_AudioSampleRate sample_rate, | |
| 29 uint32_t sample_frame_count) { | |
| 30 scoped_refptr<PPB_AudioConfig_Shared> object( | |
| 31 new PPB_AudioConfig_Shared(instance)); | |
| 32 if (!object->Init(sample_rate, sample_frame_count)) | |
| 33 return 0; | |
| 34 return object->GetReference(); | |
| 35 } | |
| 36 | |
| 37 // static | |
| 38 PP_Resource PPB_AudioConfig_Shared::CreateAsProxy( | |
| 39 PP_Instance instance, | |
| 40 PP_AudioSampleRate sample_rate, | |
| 41 uint32_t sample_frame_count) { | |
| 42 scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared( | |
| 43 HostResource::MakeInstanceOnly(instance))); | |
| 44 if (!object->Init(sample_rate, sample_frame_count)) | |
| 45 return 0; | |
| 46 return object->GetReference(); | |
| 47 } | |
| 48 | |
| 49 thunk::PPB_AudioConfig_API* PPB_AudioConfig_Shared::AsPPB_AudioConfig_API() { | |
| 50 return this; | |
| 51 } | |
| 52 | |
| 53 PP_AudioSampleRate PPB_AudioConfig_Shared::GetSampleRate() { | |
| 54 return sample_rate_; | |
| 55 } | |
| 56 | |
| 57 uint32_t PPB_AudioConfig_Shared::GetSampleFrameCount() { | |
| 58 return sample_frame_count_; | |
| 59 } | |
| 60 | |
| 61 bool PPB_AudioConfig_Shared::Init(PP_AudioSampleRate sample_rate, | |
| 62 uint32_t sample_frame_count) { | |
| 63 // TODO(brettw): Currently we don't actually check what the hardware | |
| 64 // supports, so just allow sample rates of the "guaranteed working" ones. | |
| 65 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && | |
| 66 sample_rate != PP_AUDIOSAMPLERATE_48000) | |
| 67 return false; | |
| 68 | |
| 69 // TODO(brettw): Currently we don't actually query to get a value from the | |
| 70 // hardware, so just validate the range. | |
| 71 if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || | |
| 72 sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | |
| 73 return false; | |
| 74 | |
| 75 sample_rate_ = sample_rate; | |
| 76 sample_frame_count_ = sample_frame_count; | |
| 77 return true; | |
| 78 } | |
| 79 | |
| 80 } // namespace ppapi | |
| OLD | NEW |