OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/cpp/audio_encoder.h" |
| 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_audio_encoder.h" |
| 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/instance_handle.h" |
| 11 #include "ppapi/cpp/module.h" |
| 12 #include "ppapi/cpp/module_impl.h" |
| 13 |
| 14 namespace pp { |
| 15 |
| 16 namespace { |
| 17 |
| 18 template <> |
| 19 const char* interface_name<PPB_AudioEncoder_0_1>() { |
| 20 return PPB_AUDIOENCODER_INTERFACE_0_1; |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 AudioEncoder::AudioEncoder() { |
| 26 } |
| 27 |
| 28 AudioEncoder::AudioEncoder(const InstanceHandle& instance) { |
| 29 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 30 PassRefFromConstructor( |
| 31 get_interface<PPB_AudioEncoder_0_1>()->Create(instance.pp_instance())); |
| 32 } |
| 33 } |
| 34 |
| 35 AudioEncoder::AudioEncoder(const AudioEncoder& other) : Resource(other) { |
| 36 } |
| 37 |
| 38 int32_t AudioEncoder::GetSupportedProfiles(const CompletionCallbackWithOutput< |
| 39 std::vector<PP_AudioProfileDescription> >& cc) { |
| 40 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 41 return get_interface<PPB_AudioEncoder_0_1>()->GetSupportedProfiles( |
| 42 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 43 } |
| 44 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 45 } |
| 46 |
| 47 int32_t AudioEncoder::Initialize(uint32_t channels, |
| 48 PP_AudioBuffer_SampleRate input_sample_rate, |
| 49 PP_AudioBuffer_SampleSize input_sample_size, |
| 50 PP_AudioProfile output_profile, |
| 51 uint32_t initial_bitrate, |
| 52 PP_HardwareAcceleration acceleration, |
| 53 const CompletionCallback& cc) { |
| 54 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 55 return get_interface<PPB_AudioEncoder_0_1>()->Initialize( |
| 56 pp_resource(), channels, input_sample_rate, input_sample_size, |
| 57 output_profile, initial_bitrate, acceleration, |
| 58 cc.pp_completion_callback()); |
| 59 } |
| 60 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 61 } |
| 62 |
| 63 int32_t AudioEncoder::GetNumberOfSamples() { |
| 64 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 65 return get_interface<PPB_AudioEncoder_0_1>()->GetNumberOfSamples( |
| 66 pp_resource()); |
| 67 } |
| 68 return PP_ERROR_NOINTERFACE; |
| 69 } |
| 70 |
| 71 int32_t AudioEncoder::GetBuffer( |
| 72 const CompletionCallbackWithOutput<AudioBuffer>& cc) { |
| 73 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 74 return get_interface<PPB_AudioEncoder_0_1>()->GetBuffer( |
| 75 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 76 } |
| 77 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 78 } |
| 79 |
| 80 int32_t AudioEncoder::Encode(const AudioBuffer& audio_buffer, |
| 81 const CompletionCallback& cc) { |
| 82 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 83 return get_interface<PPB_AudioEncoder_0_1>()->Encode( |
| 84 pp_resource(), audio_buffer.pp_resource(), cc.pp_completion_callback()); |
| 85 } |
| 86 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 87 } |
| 88 |
| 89 int32_t AudioEncoder::GetBitstreamBuffer( |
| 90 const CompletionCallbackWithOutput<PP_AudioBitstreamBuffer>& cc) { |
| 91 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 92 return get_interface<PPB_AudioEncoder_0_1>()->GetBitstreamBuffer( |
| 93 pp_resource(), cc.output(), cc.pp_completion_callback()); |
| 94 } |
| 95 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 96 } |
| 97 |
| 98 void AudioEncoder::RecycleBitstreamBuffer( |
| 99 const PP_AudioBitstreamBuffer& bitstream_buffer) { |
| 100 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 101 get_interface<PPB_AudioEncoder_0_1>()->RecycleBitstreamBuffer( |
| 102 pp_resource(), &bitstream_buffer); |
| 103 } |
| 104 } |
| 105 |
| 106 void AudioEncoder::RequestBitrateChange(uint32_t bitrate) { |
| 107 if (has_interface<PPB_AudioEncoder_0_1>()) { |
| 108 get_interface<PPB_AudioEncoder_0_1>()->RequestBitrateChange(pp_resource(), |
| 109 bitrate); |
| 110 } |
| 111 } |
| 112 |
| 113 void AudioEncoder::Close() { |
| 114 if (has_interface<PPB_AudioEncoder_0_1>()) |
| 115 get_interface<PPB_AudioEncoder_0_1>()->Close(pp_resource()); |
| 116 } |
| 117 |
| 118 } // namespace pp |
OLD | NEW |