Removed 'anonymous' from namespace, added whitespace in thread_restrictions.cc
[chromium-blink-merge.git] / ppapi / proxy / audio_buffer_resource.cc
blob1435b4cee75d26ad3d21d2aaf4f1967a3a47d81b
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"
12 namespace ppapi {
13 namespace proxy {
15 AudioBufferResource::AudioBufferResource(PP_Instance instance,
16 int32_t index,
17 MediaStreamBuffer* buffer)
18 : Resource(OBJECT_IS_PROXY, instance),
19 index_(index),
20 buffer_(buffer) {
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() {
29 return this;
32 PP_TimeDelta AudioBufferResource::GetTimestamp() {
33 if (!buffer_) {
34 VLOG(1) << "Buffer is invalid";
35 return 0.0;
37 return buffer_->audio.timestamp;
40 void AudioBufferResource::SetTimestamp(PP_TimeDelta timestamp) {
41 if (!buffer_) {
42 VLOG(1) << "Buffer is invalid";
43 return;
45 buffer_->audio.timestamp = timestamp;
48 PP_AudioBuffer_SampleRate AudioBufferResource::GetSampleRate() {
49 if (!buffer_) {
50 VLOG(1) << "Buffer is invalid";
51 return PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN;
53 return buffer_->audio.sample_rate;
56 PP_AudioBuffer_SampleSize AudioBufferResource::GetSampleSize() {
57 if (!buffer_) {
58 VLOG(1) << "Buffer is invalid";
59 return PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN;
61 return PP_AUDIOBUFFER_SAMPLESIZE_16_BITS;
64 uint32_t AudioBufferResource::GetNumberOfChannels() {
65 if (!buffer_) {
66 VLOG(1) << "Buffer is invalid";
67 return 0;
69 return buffer_->audio.number_of_channels;
72 uint32_t AudioBufferResource::GetNumberOfSamples() {
73 if (!buffer_) {
74 VLOG(1) << "Buffer is invalid";
75 return 0;
77 return buffer_->audio.number_of_samples;
80 void* AudioBufferResource::GetDataBuffer() {
81 if (!buffer_) {
82 VLOG(1) << "Buffer is invalid";
83 return NULL;
85 return buffer_->audio.data;
88 uint32_t AudioBufferResource::GetDataBufferSize() {
89 if (!buffer_) {
90 VLOG(1) << "Buffer is invalid";
91 return 0;
93 return buffer_->audio.data_size;
96 MediaStreamBuffer* AudioBufferResource::GetBuffer() {
97 return buffer_;
100 int32_t AudioBufferResource::GetBufferIndex() {
101 return index_;
104 void AudioBufferResource::Invalidate() {
105 DCHECK(buffer_);
106 DCHECK_GE(index_, 0);
107 buffer_ = NULL;
108 index_ = -1;
111 } // namespace proxy
112 } // namespace ppapi