blob: 941471256eebe5750ffabc9807deb01c9cde41a2 [file] [log] [blame]
[email protected]03bf382f2014-01-16 05:49:501// 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/video_frame_resource.h"
6
7#include "base/logging.h"
8#include "ppapi/c/pp_bool.h"
9#include "ppapi/shared_impl/var.h"
10
11namespace ppapi {
12namespace proxy {
13
14VideoFrameResource::VideoFrameResource(PP_Instance instance,
15 int32_t index,
[email protected]a2c5dcd2014-02-08 03:20:1516 MediaStreamBuffer* buffer)
[email protected]03bf382f2014-01-16 05:49:5017 : Resource(OBJECT_IS_PROXY, instance),
18 index_(index),
[email protected]a2c5dcd2014-02-08 03:20:1519 buffer_(buffer) {
20 DCHECK_EQ(buffer_->header.type, MediaStreamBuffer::TYPE_VIDEO);
[email protected]03bf382f2014-01-16 05:49:5021}
22
23VideoFrameResource::~VideoFrameResource() {
[email protected]a2c5dcd2014-02-08 03:20:1524 CHECK(!buffer_) << "An unused (or unrecycled) frame is destroyed.";
[email protected]03bf382f2014-01-16 05:49:5025}
26
27thunk::PPB_VideoFrame_API* VideoFrameResource::AsPPB_VideoFrame_API() {
28 return this;
29}
30
31PP_TimeDelta VideoFrameResource::GetTimestamp() {
[email protected]a2c5dcd2014-02-08 03:20:1532 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5033 VLOG(1) << "Frame is invalid";
34 return 0.0;
35 }
[email protected]a2c5dcd2014-02-08 03:20:1536 return buffer_->video.timestamp;
[email protected]03bf382f2014-01-16 05:49:5037}
38
39void VideoFrameResource::SetTimestamp(PP_TimeDelta timestamp) {
[email protected]a2c5dcd2014-02-08 03:20:1540 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5041 VLOG(1) << "Frame is invalid";
42 return;
43 }
[email protected]a2c5dcd2014-02-08 03:20:1544 buffer_->video.timestamp = timestamp;
[email protected]03bf382f2014-01-16 05:49:5045}
46
47PP_VideoFrame_Format VideoFrameResource::GetFormat() {
[email protected]a2c5dcd2014-02-08 03:20:1548 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5049 VLOG(1) << "Frame is invalid";
50 return PP_VIDEOFRAME_FORMAT_UNKNOWN;
51 }
[email protected]a2c5dcd2014-02-08 03:20:1552 return buffer_->video.format;
[email protected]03bf382f2014-01-16 05:49:5053}
54
55PP_Bool VideoFrameResource::GetSize(PP_Size* size) {
[email protected]a2c5dcd2014-02-08 03:20:1556 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5057 VLOG(1) << "Frame is invalid";
58 return PP_FALSE;
59 }
[email protected]a2c5dcd2014-02-08 03:20:1560 *size = buffer_->video.size;
[email protected]03bf382f2014-01-16 05:49:5061 return PP_TRUE;
62}
63
64void* VideoFrameResource::GetDataBuffer() {
[email protected]a2c5dcd2014-02-08 03:20:1565 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5066 VLOG(1) << "Frame is invalid";
67 return NULL;
68 }
[email protected]a2c5dcd2014-02-08 03:20:1569 return buffer_->video.data;
[email protected]03bf382f2014-01-16 05:49:5070}
71
72uint32_t VideoFrameResource::GetDataBufferSize() {
[email protected]a2c5dcd2014-02-08 03:20:1573 if (!buffer_) {
[email protected]03bf382f2014-01-16 05:49:5074 VLOG(1) << "Frame is invalid";
75 return 0;
76 }
[email protected]a2c5dcd2014-02-08 03:20:1577 return buffer_->video.data_size;
[email protected]03bf382f2014-01-16 05:49:5078}
79
[email protected]a2c5dcd2014-02-08 03:20:1580MediaStreamBuffer* VideoFrameResource::GetBuffer() {
81 return buffer_;
[email protected]03bf382f2014-01-16 05:49:5082}
83
[email protected]a2c5dcd2014-02-08 03:20:1584int32_t VideoFrameResource::GetBufferIndex() {
[email protected]03bf382f2014-01-16 05:49:5085 return index_;
86}
87
88void VideoFrameResource::Invalidate() {
[email protected]a2c5dcd2014-02-08 03:20:1589 DCHECK(buffer_);
[email protected]03bf382f2014-01-16 05:49:5090 DCHECK_GE(index_, 0);
[email protected]a2c5dcd2014-02-08 03:20:1591 buffer_ = NULL;
[email protected]03bf382f2014-01-16 05:49:5092 index_ = -1;
93}
94
95} // namespace proxy
96} // namespace ppapi