| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/video_frame_resource.h" | 5 #include "ppapi/proxy/audio_frame_resource.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "ppapi/c/pp_bool.h" | 7 #include "ppapi/c/pp_bool.h" |
| 9 #include "ppapi/shared_impl/var.h" | 8 #include "ppapi/shared_impl/var.h" |
| 10 | 9 |
| 11 namespace ppapi { | 10 namespace ppapi { |
| 12 namespace proxy { | 11 namespace proxy { |
| 13 | 12 |
| 14 VideoFrameResource::VideoFrameResource(PP_Instance instance, | 13 AudioFrameResource::AudioFrameResource(PP_Instance instance, |
| 15 int32_t index, | 14 int32_t index, |
| 16 MediaStreamFrame* frame) | 15 MediaStreamFrame* frame) |
| 17 : Resource(OBJECT_IS_PROXY, instance), | 16 : Resource(OBJECT_IS_PROXY, instance), |
| 18 index_(index), | 17 index_(index), |
| 19 frame_(frame) { | 18 frame_(frame) { |
| 20 DCHECK_EQ(frame_->header.type, MediaStreamFrame::TYPE_VIDEO); | 19 DCHECK_EQ(frame_->header.type, MediaStreamFrame::TYPE_AUDIO); |
| 21 } | 20 } |
| 22 | 21 |
| 23 VideoFrameResource::~VideoFrameResource() { | 22 AudioFrameResource::~AudioFrameResource() { |
| 24 CHECK(!frame_) << "An unused (or unrecycled) frame is destroyed."; | 23 CHECK(!frame_) << "An unused (or unrecycled) frame is destroyed."; |
| 25 } | 24 } |
| 26 | 25 |
| 27 thunk::PPB_VideoFrame_API* VideoFrameResource::AsPPB_VideoFrame_API() { | 26 thunk::PPB_AudioFrame_API* AudioFrameResource::AsPPB_AudioFrame_API() { |
| 28 return this; | 27 return this; |
| 29 } | 28 } |
| 30 | 29 |
| 31 PP_TimeDelta VideoFrameResource::GetTimestamp() { | 30 PP_TimeDelta AudioFrameResource::GetTimestamp() { |
| 32 if (!frame_) { | 31 if (!frame_) { |
| 33 VLOG(1) << "Frame is invalid"; | 32 VLOG(1) << "Frame is invalid"; |
| 34 return 0.0; | 33 return 0.0; |
| 35 } | 34 } |
| 36 return frame_->video.timestamp; | 35 return frame_->audio.timestamp; |
| 37 } | 36 } |
| 38 | 37 |
| 39 void VideoFrameResource::SetTimestamp(PP_TimeDelta timestamp) { | 38 void AudioFrameResource::SetTimestamp(PP_TimeDelta timestamp) { |
| 40 if (!frame_) { | 39 if (!frame_) { |
| 41 VLOG(1) << "Frame is invalid"; | 40 VLOG(1) << "Frame is invalid"; |
| 42 return; | 41 return; |
| 43 } | 42 } |
| 44 frame_->video.timestamp = timestamp; | 43 frame_->audio.timestamp = timestamp; |
| 45 } | 44 } |
| 46 | 45 |
| 47 PP_VideoFrame_Format VideoFrameResource::GetFormat() { | 46 PP_AudioSampleRate AudioFrameResource::GetSampleRate() { |
| 48 if (!frame_) { | 47 if (!frame_) { |
| 49 VLOG(1) << "Frame is invalid"; | 48 VLOG(1) << "Frame is invalid"; |
| 50 return PP_VIDEOFRAME_FORMAT_UNKNOWN; | 49 return PP_AUDIOSAMPLERATE_NONE; |
| 51 } | 50 } |
| 52 return frame_->video.format; | 51 return frame_->audio.sample_rate; |
| 53 } | 52 } |
| 54 | 53 |
| 55 PP_Bool VideoFrameResource::GetSize(PP_Size* size) { | 54 uint32_t AudioFrameResource::GetSampleSize() { |
| 56 if (!frame_) { | 55 if (!frame_) { |
| 57 VLOG(1) << "Frame is invalid"; | 56 VLOG(1) << "Frame is invalid"; |
| 58 return PP_FALSE; | 57 return 0; |
| 59 } | 58 } |
| 60 *size = frame_->video.size; | 59 return 2; |
| 61 return PP_TRUE; | |
| 62 } | 60 } |
| 63 | 61 |
| 64 void* VideoFrameResource::GetDataBuffer() { | 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() { |
| 65 if (!frame_) { | 79 if (!frame_) { |
| 66 VLOG(1) << "Frame is invalid"; | 80 VLOG(1) << "Frame is invalid"; |
| 67 return NULL; | 81 return NULL; |
| 68 } | 82 } |
| 69 return frame_->video.data; | 83 return frame_->audio.data; |
| 70 } | 84 } |
| 71 | 85 |
| 72 uint32_t VideoFrameResource::GetDataBufferSize() { | 86 uint32_t AudioFrameResource::GetDataBufferSize() { |
| 73 if (!frame_) { | 87 if (!frame_) { |
| 74 VLOG(1) << "Frame is invalid"; | 88 VLOG(1) << "Frame is invalid"; |
| 75 return 0; | 89 return 0; |
| 76 } | 90 } |
| 77 return frame_->video.data_size; | 91 return frame_->audio.data_size; |
| 78 } | 92 } |
| 79 | 93 |
| 80 MediaStreamFrame* VideoFrameResource::GetFrameBuffer() { | 94 MediaStreamFrame* AudioFrameResource::GetFrameBuffer() { |
| 81 return frame_; | 95 return frame_; |
| 82 } | 96 } |
| 83 | 97 |
| 84 int32_t VideoFrameResource::GetFrameBufferIndex() { | 98 int32_t AudioFrameResource::GetFrameBufferIndex() { |
| 85 return index_; | 99 return index_; |
| 86 } | 100 } |
| 87 | 101 |
| 88 void VideoFrameResource::Invalidate() { | 102 void AudioFrameResource::Invalidate() { |
| 89 DCHECK(frame_); | 103 DCHECK(frame_); |
| 90 DCHECK_GE(index_, 0); | 104 DCHECK_GE(index_, 0); |
| 91 frame_ = NULL; | 105 frame_ = NULL; |
| 92 index_ = -1; | 106 index_ = -1; |
| 93 } | 107 } |
| 94 | 108 |
| 95 } // namespace proxy | 109 } // namespace proxy |
| 96 } // namespace ppapi | 110 } // namespace ppapi |
| OLD | NEW |