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.
5 #include "ppapi/proxy/audio_buffer_resource.h"
7 #include "base/logging.h"
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/shared_impl/media_stream_buffer.h"
10 #include "ppapi/shared_impl/var.h"
15 AudioBufferResource::AudioBufferResource(PP_Instance instance
,
17 MediaStreamBuffer
* buffer
)
18 : Resource(OBJECT_IS_PROXY
, instance
),
21 DCHECK_EQ(buffer_
->header
.type
, MediaStreamBuffer::TYPE_AUDIO
);
24 AudioBufferResource::~AudioBufferResource() {
25 CHECK(!buffer_
) << "An unused (or unrecycled) buffer is destroyed.";
28 thunk::PPB_AudioBuffer_API
* AudioBufferResource::AsPPB_AudioBuffer_API() {
32 PP_TimeDelta
AudioBufferResource::GetTimestamp() {
34 VLOG(1) << "Buffer is invalid";
37 return buffer_
->audio
.timestamp
;
40 void AudioBufferResource::SetTimestamp(PP_TimeDelta timestamp
) {
42 VLOG(1) << "Buffer is invalid";
45 buffer_
->audio
.timestamp
= timestamp
;
48 PP_AudioBuffer_SampleRate
AudioBufferResource::GetSampleRate() {
50 VLOG(1) << "Buffer is invalid";
51 return PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN
;
53 return buffer_
->audio
.sample_rate
;
56 PP_AudioBuffer_SampleSize
AudioBufferResource::GetSampleSize() {
58 VLOG(1) << "Buffer is invalid";
59 return PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN
;
61 return PP_AUDIOBUFFER_SAMPLESIZE_16_BITS
;
64 uint32_t AudioBufferResource::GetNumberOfChannels() {
66 VLOG(1) << "Buffer is invalid";
69 return buffer_
->audio
.number_of_channels
;
72 uint32_t AudioBufferResource::GetNumberOfSamples() {
74 VLOG(1) << "Buffer is invalid";
77 return buffer_
->audio
.number_of_samples
;
80 void* AudioBufferResource::GetDataBuffer() {
82 VLOG(1) << "Buffer is invalid";
85 return buffer_
->audio
.data
;
88 uint32_t AudioBufferResource::GetDataBufferSize() {
90 VLOG(1) << "Buffer is invalid";
93 return buffer_
->audio
.data_size
;
96 MediaStreamBuffer
* AudioBufferResource::GetBuffer() {
100 int32_t AudioBufferResource::GetBufferIndex() {
104 void AudioBufferResource::Invalidate() {
106 DCHECK_GE(index_
, 0);