1// Copyright 2014 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// From ppb_audio_buffer.idl modified Thu Feb  6 15:31:48 2014.
6
7#include "ppapi/c/pp_errors.h"
8#include "ppapi/c/ppb_audio_buffer.h"
9#include "ppapi/shared_impl/tracked_callback.h"
10#include "ppapi/thunk/enter.h"
11#include "ppapi/thunk/ppapi_thunk_export.h"
12#include "ppapi/thunk/ppb_audio_buffer_api.h"
13
14namespace ppapi {
15namespace thunk {
16
17namespace {
18
19PP_Bool IsAudioBuffer(PP_Resource resource) {
20  VLOG(4) << "PPB_AudioBuffer::IsAudioBuffer()";
21  EnterResource<PPB_AudioBuffer_API> enter(resource, false);
22  return PP_FromBool(enter.succeeded());
23}
24
25PP_TimeDelta GetTimestamp(PP_Resource buffer) {
26  VLOG(4) << "PPB_AudioBuffer::GetTimestamp()";
27  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
28  if (enter.failed())
29    return 0.0;
30  return enter.object()->GetTimestamp();
31}
32
33void SetTimestamp(PP_Resource buffer, PP_TimeDelta timestamp) {
34  VLOG(4) << "PPB_AudioBuffer::SetTimestamp()";
35  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
36  if (enter.failed())
37    return;
38  enter.object()->SetTimestamp(timestamp);
39}
40
41PP_AudioBuffer_SampleRate GetSampleRate(PP_Resource buffer) {
42  VLOG(4) << "PPB_AudioBuffer::GetSampleRate()";
43  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
44  if (enter.failed())
45    return PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN;
46  return enter.object()->GetSampleRate();
47}
48
49PP_AudioBuffer_SampleSize GetSampleSize(PP_Resource buffer) {
50  VLOG(4) << "PPB_AudioBuffer::GetSampleSize()";
51  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
52  if (enter.failed())
53    return PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN;
54  return enter.object()->GetSampleSize();
55}
56
57uint32_t GetNumberOfChannels(PP_Resource buffer) {
58  VLOG(4) << "PPB_AudioBuffer::GetNumberOfChannels()";
59  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
60  if (enter.failed())
61    return 0;
62  return enter.object()->GetNumberOfChannels();
63}
64
65uint32_t GetNumberOfSamples(PP_Resource buffer) {
66  VLOG(4) << "PPB_AudioBuffer::GetNumberOfSamples()";
67  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
68  if (enter.failed())
69    return 0;
70  return enter.object()->GetNumberOfSamples();
71}
72
73void* GetDataBuffer(PP_Resource buffer) {
74  VLOG(4) << "PPB_AudioBuffer::GetDataBuffer()";
75  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
76  if (enter.failed())
77    return NULL;
78  return enter.object()->GetDataBuffer();
79}
80
81uint32_t GetDataBufferSize(PP_Resource buffer) {
82  VLOG(4) << "PPB_AudioBuffer::GetDataBufferSize()";
83  EnterResource<PPB_AudioBuffer_API> enter(buffer, true);
84  if (enter.failed())
85    return 0;
86  return enter.object()->GetDataBufferSize();
87}
88
89const PPB_AudioBuffer_0_1 g_ppb_audiobuffer_thunk_0_1 = {
90  &IsAudioBuffer,
91  &GetTimestamp,
92  &SetTimestamp,
93  &GetSampleRate,
94  &GetSampleSize,
95  &GetNumberOfChannels,
96  &GetNumberOfSamples,
97  &GetDataBuffer,
98  &GetDataBufferSize
99};
100
101}  // namespace
102
103PPAPI_THUNK_EXPORT const PPB_AudioBuffer_0_1* GetPPB_AudioBuffer_0_1_Thunk() {
104  return &g_ppb_audiobuffer_thunk_0_1;
105}
106
107}  // namespace thunk
108}  // namespace ppapi
109