1 // Copyright (c) 2010 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 "webkit/glue/webvideoframe_impl.h"
6
7 #include "media/base/video_frame.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"
9
10 using namespace WebKit;
11
12 namespace webkit_glue {
13
toVideoFrame(WebVideoFrame * web_video_frame)14 media::VideoFrame* WebVideoFrameImpl::toVideoFrame(
15 WebVideoFrame* web_video_frame) {
16 WebVideoFrameImpl* wrapped_frame =
17 static_cast<WebVideoFrameImpl*>(web_video_frame);
18 if (wrapped_frame)
19 return wrapped_frame->video_frame_.get();
20 return NULL;
21 }
22
WebVideoFrameImpl(scoped_refptr<media::VideoFrame> video_frame)23 WebVideoFrameImpl::WebVideoFrameImpl(
24 scoped_refptr<media::VideoFrame> video_frame)
25 : video_frame_(video_frame) {
26 }
27
~WebVideoFrameImpl()28 WebVideoFrameImpl::~WebVideoFrameImpl() {}
29
30 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
31 COMPILE_ASSERT(int(WebKit::WebVideoFrame::webkit_name) == \
32 int(media::VideoFrame::chromium_name), \
33 mismatching_enums)
34 COMPILE_ASSERT_MATCHING_ENUM(FormatInvalid, INVALID);
35 COMPILE_ASSERT_MATCHING_ENUM(FormatRGB555, RGB555);
36 COMPILE_ASSERT_MATCHING_ENUM(FormatRGB565, RGB565);
37 COMPILE_ASSERT_MATCHING_ENUM(FormatRGB24, RGB24);
38 COMPILE_ASSERT_MATCHING_ENUM(FormatRGB32, RGB32);
39 COMPILE_ASSERT_MATCHING_ENUM(FormatRGBA, RGBA);
40 COMPILE_ASSERT_MATCHING_ENUM(FormatYV12, YV12);
41 COMPILE_ASSERT_MATCHING_ENUM(FormatYV16, YV16);
42 COMPILE_ASSERT_MATCHING_ENUM(FormatNV12, NV12);
43 COMPILE_ASSERT_MATCHING_ENUM(FormatEmpty, EMPTY);
44 COMPILE_ASSERT_MATCHING_ENUM(FormatASCII, ASCII);
45
46 COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeSystemMemory, TYPE_SYSTEM_MEMORY);
47 // TODO(hclam): Add checks for newly added surface types like GL texture and
48 // D3D texture.
49
surfaceType() const50 WebVideoFrame::SurfaceType WebVideoFrameImpl::surfaceType() const {
51 if (video_frame_.get())
52 return static_cast<WebVideoFrame::SurfaceType>(video_frame_->type());
53 return WebVideoFrame::SurfaceTypeSystemMemory;
54 }
55
format() const56 WebVideoFrame::Format WebVideoFrameImpl::format() const {
57 if (video_frame_.get())
58 return static_cast<WebVideoFrame::Format>(video_frame_->format());
59 return WebVideoFrame::FormatInvalid;
60 }
61
width() const62 unsigned WebVideoFrameImpl::width() const {
63 if (video_frame_.get())
64 return video_frame_->width();
65 return 0;
66 }
67
height() const68 unsigned WebVideoFrameImpl::height() const {
69 if (video_frame_.get())
70 return video_frame_->height();
71 return 0;
72 }
73
planes() const74 unsigned WebVideoFrameImpl::planes() const {
75 if (video_frame_.get())
76 return video_frame_->planes();
77 return 0;
78 }
79
stride(unsigned plane) const80 int WebVideoFrameImpl::stride(unsigned plane) const {
81 if (video_frame_.get())
82 return static_cast<int>(video_frame_->stride(plane));
83 return 0;
84 }
85
data(unsigned plane) const86 const void* WebVideoFrameImpl::data(unsigned plane) const {
87 if (video_frame_.get())
88 return static_cast<const void*>(video_frame_->data(plane));
89 return NULL;
90 }
91
texture(unsigned plane) const92 unsigned WebVideoFrameImpl::texture(unsigned plane) const {
93 if (video_frame_.get())
94 return video_frame_->gl_texture(plane);
95 return 0;
96 }
97
98 } // namespace webkit_glue
99