Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / cpp / audio_encoder.cc
blobbea733bb5b61b7a00afb2cf23c29c9c8e2cf8a38
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.
5 #include "ppapi/cpp/audio_encoder.h"
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"
14 namespace pp {
16 namespace {
18 template <>
19 const char* interface_name<PPB_AudioEncoder_0_1>() {
20 return PPB_AUDIOENCODER_INTERFACE_0_1;
23 } // namespace
25 AudioEncoder::AudioEncoder() {
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()));
35 AudioEncoder::AudioEncoder(const AudioEncoder& other) : Resource(other) {
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());
44 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
60 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
68 return PP_ERROR_NOINTERFACE;
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());
77 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
86 return cc.MayForce(PP_ERROR_NOINTERFACE);
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());
95 return cc.MayForce(PP_ERROR_NOINTERFACE);
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);
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);
113 void AudioEncoder::Close() {
114 if (has_interface<PPB_AudioEncoder_0_1>())
115 get_interface<PPB_AudioEncoder_0_1>()->Close(pp_resource());
118 } // namespace pp