OLD | NEW |
(Empty) | |
| 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 #include "ppapi/proxy/audio_frame_resource.h" |
| 6 |
| 7 #include "ppapi/c/pp_bool.h" |
| 8 #include "ppapi/shared_impl/var.h" |
| 9 |
| 10 namespace ppapi { |
| 11 namespace proxy { |
| 12 |
| 13 AudioFrameResource::AudioFrameResource(PP_Instance instance, |
| 14 int32_t index, |
| 15 MediaStreamFrame* frame) |
| 16 : Resource(OBJECT_IS_PROXY, instance), |
| 17 index_(index), |
| 18 frame_(frame) { |
| 19 DCHECK_EQ(frame_->header.type, MediaStreamFrame::TYPE_AUDIO); |
| 20 } |
| 21 |
| 22 AudioFrameResource::~AudioFrameResource() { |
| 23 CHECK(!frame_) << "An unused (or unrecycled) frame is destroyed."; |
| 24 } |
| 25 |
| 26 thunk::PPB_AudioFrame_API* AudioFrameResource::AsPPB_AudioFrame_API() { |
| 27 return this; |
| 28 } |
| 29 |
| 30 PP_TimeDelta AudioFrameResource::GetTimestamp() { |
| 31 if (!frame_) { |
| 32 VLOG(1) << "Frame is invalid"; |
| 33 return 0.0; |
| 34 } |
| 35 return frame_->audio.timestamp; |
| 36 } |
| 37 |
| 38 void AudioFrameResource::SetTimestamp(PP_TimeDelta timestamp) { |
| 39 if (!frame_) { |
| 40 VLOG(1) << "Frame is invalid"; |
| 41 return; |
| 42 } |
| 43 frame_->audio.timestamp = timestamp; |
| 44 } |
| 45 |
| 46 PP_AudioFrame_SampleRate AudioFrameResource::GetSampleRate() { |
| 47 if (!frame_) { |
| 48 VLOG(1) << "Frame is invalid"; |
| 49 return PP_AUDIOFRAME_SAMPLERATE_UNKNOWN; |
| 50 } |
| 51 return frame_->audio.sample_rate; |
| 52 } |
| 53 |
| 54 PP_AudioFrame_SampleSize AudioFrameResource::GetSampleSize() { |
| 55 if (!frame_) { |
| 56 VLOG(1) << "Frame is invalid"; |
| 57 return PP_AUDIOFRAME_SAMPLESIZE_UNKNOWN; |
| 58 } |
| 59 return PP_AUDIOFRAME_SAMPLESIZE_16_BITS; |
| 60 } |
| 61 |
| 62 uint32_t AudioFrameResource::GetNumberOfChannels() { |
| 63 if (!frame_) { |
| 64 VLOG(1) << "Frame is invalid"; |
| 65 return 0; |
| 66 } |
| 67 return frame_->audio.number_of_channels; |
| 68 } |
| 69 |
| 70 uint32_t AudioFrameResource::GetNumberOfSamples() { |
| 71 if (!frame_) { |
| 72 VLOG(1) << "Frame is invalid"; |
| 73 return 0; |
| 74 } |
| 75 return frame_->audio.number_of_samples; |
| 76 } |
| 77 |
| 78 void* AudioFrameResource::GetDataBuffer() { |
| 79 if (!frame_) { |
| 80 VLOG(1) << "Frame is invalid"; |
| 81 return NULL; |
| 82 } |
| 83 return frame_->audio.data; |
| 84 } |
| 85 |
| 86 uint32_t AudioFrameResource::GetDataBufferSize() { |
| 87 if (!frame_) { |
| 88 VLOG(1) << "Frame is invalid"; |
| 89 return 0; |
| 90 } |
| 91 return frame_->audio.data_size; |
| 92 } |
| 93 |
| 94 MediaStreamFrame* AudioFrameResource::GetFrameBuffer() { |
| 95 return frame_; |
| 96 } |
| 97 |
| 98 int32_t AudioFrameResource::GetFrameBufferIndex() { |
| 99 return index_; |
| 100 } |
| 101 |
| 102 void AudioFrameResource::Invalidate() { |
| 103 DCHECK(frame_); |
| 104 DCHECK_GE(index_, 0); |
| 105 frame_ = NULL; |
| 106 index_ = -1; |
| 107 } |
| 108 |
| 109 } // namespace proxy |
| 110 } // namespace ppapi |
OLD | NEW |