Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ppapi / thunk / ppb_audio_encoder_thunk.cc
blob25f890702e4ff0e545baeef6fce095f30577f6f1
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 // From ppb_audio_encoder.idl modified Mon Sep 7 10:17:53 2015.
7 #include "ppapi/c/pp_completion_callback.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/c/ppb_audio_encoder.h"
10 #include "ppapi/shared_impl/tracked_callback.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppapi_thunk_export.h"
13 #include "ppapi/thunk/ppb_audio_encoder_api.h"
15 namespace ppapi {
16 namespace thunk {
18 namespace {
20 PP_Resource Create(PP_Instance instance) {
21 VLOG(4) << "PPB_AudioEncoder::Create()";
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateAudioEncoder(instance);
28 PP_Bool IsAudioEncoder(PP_Resource resource) {
29 VLOG(4) << "PPB_AudioEncoder::IsAudioEncoder()";
30 EnterResource<PPB_AudioEncoder_API> enter(resource, false);
31 return PP_FromBool(enter.succeeded());
34 int32_t GetSupportedProfiles(PP_Resource audio_encoder,
35 struct PP_ArrayOutput output,
36 struct PP_CompletionCallback callback) {
37 VLOG(4) << "PPB_AudioEncoder::GetSupportedProfiles()";
38 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true);
39 if (enter.failed())
40 return enter.retval();
41 return enter.SetResult(
42 enter.object()->GetSupportedProfiles(output, enter.callback()));
45 int32_t Initialize(PP_Resource audio_encoder,
46 uint32_t channels,
47 PP_AudioBuffer_SampleRate input_sample_rate,
48 PP_AudioBuffer_SampleSize input_sample_size,
49 PP_AudioProfile output_profile,
50 uint32_t initial_bitrate,
51 PP_HardwareAcceleration acceleration,
52 struct PP_CompletionCallback callback) {
53 VLOG(4) << "PPB_AudioEncoder::Initialize()";
54 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true);
55 if (enter.failed())
56 return enter.retval();
57 return enter.SetResult(enter.object()->Initialize(channels,
58 input_sample_rate,
59 input_sample_size,
60 output_profile,
61 initial_bitrate,
62 acceleration,
63 enter.callback()));
66 int32_t GetNumberOfSamples(PP_Resource audio_encoder) {
67 VLOG(4) << "PPB_AudioEncoder::GetNumberOfSamples()";
68 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true);
69 if (enter.failed())
70 return enter.retval();
71 return enter.object()->GetNumberOfSamples();
74 int32_t GetBuffer(PP_Resource audio_encoder,
75 PP_Resource* audio_buffer,
76 struct PP_CompletionCallback callback) {
77 VLOG(4) << "PPB_AudioEncoder::GetBuffer()";
78 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true);
79 if (enter.failed())
80 return enter.retval();
81 return enter.SetResult(
82 enter.object()->GetBuffer(audio_buffer, enter.callback()));
85 int32_t Encode(PP_Resource audio_encoder,
86 PP_Resource audio_buffer,
87 struct PP_CompletionCallback callback) {
88 VLOG(4) << "PPB_AudioEncoder::Encode()";
89 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true);
90 if (enter.failed())
91 return enter.retval();
92 return enter.SetResult(
93 enter.object()->Encode(audio_buffer, enter.callback()));
96 int32_t GetBitstreamBuffer(PP_Resource audio_encoder,
97 struct PP_AudioBitstreamBuffer* bitstream_buffer,
98 struct PP_CompletionCallback callback) {
99 VLOG(4) << "PPB_AudioEncoder::GetBitstreamBuffer()";
100 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, callback, true);
101 if (enter.failed())
102 return enter.retval();
103 return enter.SetResult(
104 enter.object()->GetBitstreamBuffer(bitstream_buffer, enter.callback()));
107 void RecycleBitstreamBuffer(
108 PP_Resource audio_encoder,
109 const struct PP_AudioBitstreamBuffer* bitstream_buffer) {
110 VLOG(4) << "PPB_AudioEncoder::RecycleBitstreamBuffer()";
111 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true);
112 if (enter.failed())
113 return;
114 enter.object()->RecycleBitstreamBuffer(bitstream_buffer);
117 void RequestBitrateChange(PP_Resource audio_encoder, uint32_t bitrate) {
118 VLOG(4) << "PPB_AudioEncoder::RequestBitrateChange()";
119 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true);
120 if (enter.failed())
121 return;
122 enter.object()->RequestBitrateChange(bitrate);
125 void Close(PP_Resource audio_encoder) {
126 VLOG(4) << "PPB_AudioEncoder::Close()";
127 EnterResource<PPB_AudioEncoder_API> enter(audio_encoder, true);
128 if (enter.failed())
129 return;
130 enter.object()->Close();
133 const PPB_AudioEncoder_0_1 g_ppb_audioencoder_thunk_0_1 = {
134 &Create,
135 &IsAudioEncoder,
136 &GetSupportedProfiles,
137 &Initialize,
138 &GetNumberOfSamples,
139 &GetBuffer,
140 &Encode,
141 &GetBitstreamBuffer,
142 &RecycleBitstreamBuffer,
143 &RequestBitrateChange,
144 &Close};
146 } // namespace
148 PPAPI_THUNK_EXPORT const PPB_AudioEncoder_0_1* GetPPB_AudioEncoder_0_1_Thunk() {
149 return &g_ppb_audioencoder_thunk_0_1;
152 } // namespace thunk
153 } // namespace ppapi