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 10using namespace WebKit; 11 12namespace webkit_glue { 13 14media::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 23WebVideoFrameImpl::WebVideoFrameImpl( 24 scoped_refptr<media::VideoFrame> video_frame) 25 : video_frame_(video_frame) { 26} 27 28WebVideoFrameImpl::~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) 34COMPILE_ASSERT_MATCHING_ENUM(FormatInvalid, INVALID); 35COMPILE_ASSERT_MATCHING_ENUM(FormatRGB555, RGB555); 36COMPILE_ASSERT_MATCHING_ENUM(FormatRGB565, RGB565); 37COMPILE_ASSERT_MATCHING_ENUM(FormatRGB24, RGB24); 38COMPILE_ASSERT_MATCHING_ENUM(FormatRGB32, RGB32); 39COMPILE_ASSERT_MATCHING_ENUM(FormatRGBA, RGBA); 40COMPILE_ASSERT_MATCHING_ENUM(FormatYV12, YV12); 41COMPILE_ASSERT_MATCHING_ENUM(FormatYV16, YV16); 42COMPILE_ASSERT_MATCHING_ENUM(FormatNV12, NV12); 43COMPILE_ASSERT_MATCHING_ENUM(FormatEmpty, EMPTY); 44COMPILE_ASSERT_MATCHING_ENUM(FormatASCII, ASCII); 45 46COMPILE_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 50WebVideoFrame::SurfaceType WebVideoFrameImpl::surfaceType() const { 51 if (video_frame_.get()) 52 return static_cast<WebVideoFrame::SurfaceType>(video_frame_->type()); 53 return WebVideoFrame::SurfaceTypeSystemMemory; 54} 55 56WebVideoFrame::Format WebVideoFrameImpl::format() const { 57 if (video_frame_.get()) 58 return static_cast<WebVideoFrame::Format>(video_frame_->format()); 59 return WebVideoFrame::FormatInvalid; 60} 61 62unsigned WebVideoFrameImpl::width() const { 63 if (video_frame_.get()) 64 return video_frame_->width(); 65 return 0; 66} 67 68unsigned WebVideoFrameImpl::height() const { 69 if (video_frame_.get()) 70 return video_frame_->height(); 71 return 0; 72} 73 74unsigned WebVideoFrameImpl::planes() const { 75 if (video_frame_.get()) 76 return video_frame_->planes(); 77 return 0; 78} 79 80int WebVideoFrameImpl::stride(unsigned plane) const { 81 if (video_frame_.get()) 82 return static_cast<int>(video_frame_->stride(plane)); 83 return 0; 84} 85 86const 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 92unsigned 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