Add git cl format presubmit warning for extension and apps.
[chromium-blink-merge.git] / ppapi / proxy / audio_frame_resource.cc
blob4954857239a750dd7b49fe691034295663df1e84
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_frame_resource.h"
7 #include "base/logging.h"
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/shared_impl/var.h"
11 namespace ppapi {
12 namespace proxy {
14 AudioFrameResource::AudioFrameResource(PP_Instance instance,
15 int32_t index,
16 MediaStreamFrame* frame)
17 : Resource(OBJECT_IS_PROXY, instance),
18 index_(index),
19 frame_(frame) {
20 DCHECK_EQ(frame_->header.type, MediaStreamFrame::TYPE_AUDIO);
23 AudioFrameResource::~AudioFrameResource() {
24 CHECK(!frame_) << "An unused (or unrecycled) frame is destroyed.";
27 thunk::PPB_AudioFrame_API* AudioFrameResource::AsPPB_AudioFrame_API() {
28 return this;
31 PP_TimeDelta AudioFrameResource::GetTimestamp() {
32 if (!frame_) {
33 VLOG(1) << "Frame is invalid";
34 return 0.0;
36 return frame_->audio.timestamp;
39 void AudioFrameResource::SetTimestamp(PP_TimeDelta timestamp) {
40 if (!frame_) {
41 VLOG(1) << "Frame is invalid";
42 return;
44 frame_->audio.timestamp = timestamp;
47 PP_AudioFrame_SampleRate AudioFrameResource::GetSampleRate() {
48 if (!frame_) {
49 VLOG(1) << "Frame is invalid";
50 return PP_AUDIOFRAME_SAMPLERATE_UNKNOWN;
52 return frame_->audio.sample_rate;
55 PP_AudioFrame_SampleSize AudioFrameResource::GetSampleSize() {
56 if (!frame_) {
57 VLOG(1) << "Frame is invalid";
58 return PP_AUDIOFRAME_SAMPLESIZE_UNKNOWN;
60 return PP_AUDIOFRAME_SAMPLESIZE_16_BITS;
63 uint32_t AudioFrameResource::GetNumberOfChannels() {
64 if (!frame_) {
65 VLOG(1) << "Frame is invalid";
66 return 0;
68 return frame_->audio.number_of_channels;
71 uint32_t AudioFrameResource::GetNumberOfSamples() {
72 if (!frame_) {
73 VLOG(1) << "Frame is invalid";
74 return 0;
76 return frame_->audio.number_of_samples;
79 void* AudioFrameResource::GetDataBuffer() {
80 if (!frame_) {
81 VLOG(1) << "Frame is invalid";
82 return NULL;
84 return frame_->audio.data;
87 uint32_t AudioFrameResource::GetDataBufferSize() {
88 if (!frame_) {
89 VLOG(1) << "Frame is invalid";
90 return 0;
92 return frame_->audio.data_size;
95 MediaStreamFrame* AudioFrameResource::GetFrameBuffer() {
96 return frame_;
99 int32_t AudioFrameResource::GetFrameBufferIndex() {
100 return index_;
103 void AudioFrameResource::Invalidate() {
104 DCHECK(frame_);
105 DCHECK_GE(index_, 0);
106 frame_ = NULL;
107 index_ = -1;
110 } // namespace proxy
111 } // namespace ppapi