1 // Copyright (c) 2012 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 "webkit/media/webvideoframe_impl.h"
7 #include "base/logging.h"
8 #include "media/base/video_frame.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
11 using WebKit::WebVideoFrame
;
13 namespace webkit_media
{
15 media::VideoFrame
* WebVideoFrameImpl::toVideoFrame(
16 WebVideoFrame
* web_video_frame
) {
17 WebVideoFrameImpl
* wrapped_frame
=
18 static_cast<WebVideoFrameImpl
*>(web_video_frame
);
20 return wrapped_frame
->video_frame_
.get();
24 WebVideoFrameImpl::WebVideoFrameImpl(
25 scoped_refptr
<media::VideoFrame
> video_frame
)
26 : video_frame_(video_frame
) {
29 WebVideoFrameImpl::~WebVideoFrameImpl() {}
31 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
32 COMPILE_ASSERT(int(WebKit::WebVideoFrame::webkit_name) == \
33 int(media::VideoFrame::chromium_name), \
35 COMPILE_ASSERT_MATCHING_ENUM(FormatInvalid
, INVALID
);
36 COMPILE_ASSERT_MATCHING_ENUM(FormatRGB32
, RGB32
);
37 COMPILE_ASSERT_MATCHING_ENUM(FormatYV12
, YV12
);
38 COMPILE_ASSERT_MATCHING_ENUM(FormatYV16
, YV16
);
39 COMPILE_ASSERT_MATCHING_ENUM(FormatEmpty
, EMPTY
);
40 COMPILE_ASSERT_MATCHING_ENUM(FormatI420
, I420
);
41 COMPILE_ASSERT_MATCHING_ENUM(FormatNativeTexture
, NATIVE_TEXTURE
);
43 WebVideoFrame::Format
WebVideoFrameImpl::format() const {
44 if (video_frame_
.get())
45 return static_cast<WebVideoFrame::Format
>(video_frame_
->format());
46 return WebVideoFrame::FormatInvalid
;
49 unsigned WebVideoFrameImpl::width() const {
50 if (video_frame_
.get())
51 return video_frame_
->width();
55 unsigned WebVideoFrameImpl::height() const {
56 if (video_frame_
.get())
57 return video_frame_
->height();
61 unsigned WebVideoFrameImpl::planes() const {
62 if (!video_frame_
.get())
64 switch (video_frame_
->format()) {
65 case media::VideoFrame::RGB32
:
67 case media::VideoFrame::YV12
:
68 case media::VideoFrame::YV16
:
70 case media::VideoFrame::INVALID
:
71 case media::VideoFrame::EMPTY
:
72 case media::VideoFrame::I420
:
74 case media::VideoFrame::NATIVE_TEXTURE
:
81 int WebVideoFrameImpl::stride(unsigned plane
) const {
82 if (video_frame_
.get())
83 return static_cast<int>(video_frame_
->stride(plane
));
87 const void* WebVideoFrameImpl::data(unsigned plane
) const {
88 if (!video_frame_
.get() || format() == FormatNativeTexture
)
90 return static_cast<const void*>(video_frame_
->data(plane
));
93 unsigned WebVideoFrameImpl::textureId() const {
94 if (!video_frame_
.get() || format() != FormatNativeTexture
)
96 return video_frame_
->texture_id();
99 unsigned WebVideoFrameImpl::textureTarget() const {
100 if (!video_frame_
.get() || format() != FormatNativeTexture
)
102 return video_frame_
->texture_target();
105 } // namespace webkit_media