summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorvrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:01:21 +0000
committervrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 18:01:21 +0000
commite81283bbf1beafe0a5dafbca2e7484b1d7a6a055 (patch)
tree3b9a98ff9ba4dc7f7d48d5e63db98e1281481503 /webkit
parent44af30973fa42b01e622e4c15c0f4428ddce066f (diff)
downloadchromium_src-e81283bbf1beafe0a5dafbca2e7484b1d7a6a055.zip
chromium_src-e81283bbf1beafe0a5dafbca2e7484b1d7a6a055.tar.gz
chromium_src-e81283bbf1beafe0a5dafbca2e7484b1d7a6a055.tar.bz2
Adding way to pass video frames between Chromium and WebKit
This patch adds an implementation of the WebVideoFrame interface defined in WebKit, and it adds behavior to WebMediaPlayerImpl to pass video frame data between WebKit and Chromium. BUG=none TEST=none Review URL: http://codereview.chromium.org/3155050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/media/video_renderer_impl.cc10
-rw-r--r--webkit/glue/media/video_renderer_impl.h2
-rw-r--r--webkit/glue/media/web_video_renderer.h16
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/glue/webmediaplayer_impl.cc33
-rw-r--r--webkit/glue/webmediaplayer_impl.h5
-rw-r--r--webkit/glue/webvideoframe_impl.cc92
-rw-r--r--webkit/glue/webvideoframe_impl.h36
8 files changed, 193 insertions, 3 deletions
diff --git a/webkit/glue/media/video_renderer_impl.cc b/webkit/glue/media/video_renderer_impl.cc
index 796d07f..6d7323d 100644
--- a/webkit/glue/media/video_renderer_impl.cc
+++ b/webkit/glue/media/video_renderer_impl.cc
@@ -95,6 +95,16 @@ void VideoRendererImpl::Paint(skia::PlatformCanvas* canvas,
PutCurrentFrame(video_frame);
}
+void VideoRendererImpl::GetCurrentFrame(
+ scoped_refptr<media::VideoFrame>* frame_out) {
+ VideoRendererBase::GetCurrentFrame(frame_out);
+}
+
+void VideoRendererImpl::PutCurrentFrame(
+ scoped_refptr<media::VideoFrame> frame) {
+ VideoRendererBase::PutCurrentFrame(frame);
+}
+
// CanFastPaint is a helper method to determine the conditions for fast
// painting. The conditions are:
// 1. No skew in canvas matrix.
diff --git a/webkit/glue/media/video_renderer_impl.h b/webkit/glue/media/video_renderer_impl.h
index 30f2e38..39ce1b2 100644
--- a/webkit/glue/media/video_renderer_impl.h
+++ b/webkit/glue/media/video_renderer_impl.h
@@ -27,6 +27,8 @@ class VideoRendererImpl : public WebVideoRenderer {
// WebVideoRenderer implementation.
virtual void SetRect(const gfx::Rect& rect);
virtual void Paint(skia::PlatformCanvas* canvas, const gfx::Rect& dest_rect);
+ virtual void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out);
+ virtual void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame);
// Static method for creating factory for this object.
static media::FilterFactory* CreateFactory(WebMediaPlayerImpl::Proxy* proxy,
diff --git a/webkit/glue/media/web_video_renderer.h b/webkit/glue/media/web_video_renderer.h
index 8bafb1a..d8b47ad0 100644
--- a/webkit/glue/media/web_video_renderer.h
+++ b/webkit/glue/media/web_video_renderer.h
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef WEBKIT_GLUE_MEDIA_WEB_VIDEO_RENDERER_H_
#define WEBKIT_GLUE_MEDIA_WEB_VIDEO_RENDERER_H_
+#include "media/base/video_frame.h"
#include "media/filters/video_renderer_base.h"
namespace webkit_glue {
@@ -30,6 +31,15 @@ class WebVideoRenderer : public media::VideoRendererBase {
virtual void Paint(skia::PlatformCanvas* canvas,
const gfx::Rect& dest_rect) = 0;
+ // Clients of this class (painter/compositor) should use GetCurrentFrame()
+ // obtain ownership of VideoFrame, it should always relinquish the ownership
+ // by use PutCurrentFrame(). Current frame is not guaranteed to be non-NULL.
+ // It expects clients to use color-fill the background if current frame
+ // is NULL. This could happen when before pipeline is pre-rolled or during
+ // pause/flush/seek.
+ virtual void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out) {}
+ virtual void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame) {}
+
private:
DISALLOW_COPY_AND_ASSIGN(WebVideoRenderer);
};
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 3233afe..c1d5677 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -370,6 +370,8 @@
'webthemeengine_impl_win.cc',
'weburlloader_impl.cc',
'weburlloader_impl.h',
+ 'webvideoframe_impl.cc',
+ 'webvideoframe_impl.h',
'window_open_disposition.h',
'window_open_disposition.cc',
diff --git a/webkit/glue/webmediaplayer_impl.cc b/webkit/glue/webmediaplayer_impl.cc
index 4de52a3..d5c667d 100644
--- a/webkit/glue/webmediaplayer_impl.cc
+++ b/webkit/glue/webmediaplayer_impl.cc
@@ -11,6 +11,7 @@
#include "media/base/limits.h"
#include "media/base/media_format.h"
#include "media/base/media_switches.h"
+#include "media/base/video_frame.h"
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer.h"
#include "media/filters/ffmpeg_video_decoder.h"
@@ -19,8 +20,10 @@
#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVideoFrame.h"
#include "webkit/glue/media/video_renderer_impl.h"
#include "webkit/glue/media/web_video_renderer.h"
+#include "webkit/glue/webvideoframe_impl.h"
using WebKit::WebCanvas;
using WebKit::WebRect;
@@ -180,6 +183,18 @@ void WebMediaPlayerImpl::Proxy::NetworkEventTask() {
}
}
+void WebMediaPlayerImpl::Proxy::GetCurrentFrame(
+ scoped_refptr<media::VideoFrame>* frame_out) {
+ if (video_renderer_)
+ video_renderer_->GetCurrentFrame(frame_out);
+}
+
+void WebMediaPlayerImpl::Proxy::PutCurrentFrame(
+ scoped_refptr<media::VideoFrame> frame) {
+ if (video_renderer_)
+ video_renderer_->PutCurrentFrame(frame);
+}
+
/////////////////////////////////////////////////////////////////////////////
// WebMediaPlayerImpl implementation
@@ -567,6 +582,24 @@ WebKit::WebMediaPlayer::MovieLoadType
return WebKit::WebMediaPlayer::Unknown;
}
+WebKit::WebVideoFrame* WebMediaPlayerImpl::getCurrentFrame() {
+ scoped_refptr<media::VideoFrame> video_frame;
+ proxy_->GetCurrentFrame(&video_frame);
+ if (video_frame.get())
+ return new WebVideoFrameImpl(video_frame);
+ return NULL;
+}
+
+void WebMediaPlayerImpl::putCurrentFrame(
+ WebKit::WebVideoFrame* web_video_frame) {
+ if (web_video_frame) {
+ scoped_refptr<media::VideoFrame> video_frame =
+ WebVideoFrameImpl::toVideoFrame(web_video_frame);
+ proxy_->PutCurrentFrame(video_frame);
+ delete web_video_frame;
+ }
+}
+
void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() {
Destroy();
main_loop_ = NULL;
diff --git a/webkit/glue/webmediaplayer_impl.h b/webkit/glue/webmediaplayer_impl.h
index b8aa6be..eefe1a9 100644
--- a/webkit/glue/webmediaplayer_impl.h
+++ b/webkit/glue/webmediaplayer_impl.h
@@ -101,6 +101,8 @@ class WebMediaPlayerImpl : public WebKit::WebMediaPlayer,
void Paint(skia::PlatformCanvas* canvas, const gfx::Rect& dest_rect);
void SetSize(const gfx::Rect& rect);
void Detach();
+ void GetCurrentFrame(scoped_refptr<media::VideoFrame>* frame_out);
+ void PutCurrentFrame(scoped_refptr<media::VideoFrame> frame);
// Public methods called from the pipeline via callback issued by
// WebMediaPlayerImpl.
@@ -228,6 +230,9 @@ class WebMediaPlayerImpl : public WebKit::WebMediaPlayer,
virtual bool hasSingleSecurityOrigin() const;
virtual WebKit::WebMediaPlayer::MovieLoadType movieLoadType() const;
+ virtual WebKit::WebVideoFrame* getCurrentFrame();
+ virtual void putCurrentFrame(WebKit::WebVideoFrame* web_video_frame);
+
// As we are closing the tab or even the browser, |main_loop_| is destroyed
// even before this object gets destructed, so we need to know when
// |main_loop_| is being destroyed and we can stop posting repaint task
diff --git a/webkit/glue/webvideoframe_impl.cc b/webkit/glue/webvideoframe_impl.cc
new file mode 100644
index 0000000..0cb9de7
--- /dev/null
+++ b/webkit/glue/webvideoframe_impl.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/webvideoframe_impl.h"
+
+#include "media/base/video_frame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVideoFrame.h"
+
+using namespace WebKit;
+
+namespace webkit_glue {
+
+media::VideoFrame* WebVideoFrameImpl::toVideoFrame(
+ WebVideoFrame* web_video_frame) {
+ WebVideoFrameImpl* wrapped_frame =
+ static_cast<WebVideoFrameImpl*>(web_video_frame);
+ if (wrapped_frame)
+ return wrapped_frame->video_frame_.get();
+ return NULL;
+}
+
+WebVideoFrameImpl::WebVideoFrameImpl(
+ scoped_refptr<media::VideoFrame> video_frame)
+ : video_frame_(video_frame) {
+}
+
+#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
+ COMPILE_ASSERT(int(WebKit::WebVideoFrame::webkit_name) == \
+ int(media::VideoFrame::chromium_name), \
+ mismatching_enums)
+COMPILE_ASSERT_MATCHING_ENUM(FormatInvalid, INVALID);
+COMPILE_ASSERT_MATCHING_ENUM(FormatRGB555, RGB555);
+COMPILE_ASSERT_MATCHING_ENUM(FormatRGB565, RGB565);
+COMPILE_ASSERT_MATCHING_ENUM(FormatRGB24, RGB24);
+COMPILE_ASSERT_MATCHING_ENUM(FormatRGB32, RGB32);
+COMPILE_ASSERT_MATCHING_ENUM(FormatRGBA, RGBA);
+COMPILE_ASSERT_MATCHING_ENUM(FormatYV12, YV12);
+COMPILE_ASSERT_MATCHING_ENUM(FormatYV16, YV16);
+COMPILE_ASSERT_MATCHING_ENUM(FormatNV12, NV12);
+COMPILE_ASSERT_MATCHING_ENUM(FormatEmpty, EMPTY);
+COMPILE_ASSERT_MATCHING_ENUM(FormatASCII, ASCII);
+
+COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeSystemMemory, TYPE_SYSTEM_MEMORY);
+COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeOMXBufferHead, TYPE_OMXBUFFERHEAD);
+COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeEGLImage, TYPE_EGL_IMAGE);
+COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeMFBuffer, TYPE_MFBUFFER);
+COMPILE_ASSERT_MATCHING_ENUM(SurfaceTypeDirect3DSurface, TYPE_DIRECT3DSURFACE);
+
+WebVideoFrame::SurfaceType WebVideoFrameImpl::surfaceType() const {
+ if (video_frame_.get())
+ return static_cast<WebVideoFrame::SurfaceType>(video_frame_->type());
+ return WebVideoFrame::SurfaceTypeSystemMemory;
+}
+
+WebVideoFrame::Format WebVideoFrameImpl::format() const {
+ if (video_frame_.get())
+ return static_cast<WebVideoFrame::Format>(video_frame_->format());
+ return WebVideoFrame::FormatInvalid;
+}
+
+unsigned WebVideoFrameImpl::width() const {
+ if (video_frame_.get())
+ return video_frame_->width();
+ return NULL;
+}
+
+unsigned WebVideoFrameImpl::height() const {
+ if (video_frame_.get())
+ return video_frame_->height();
+ return NULL;
+}
+
+unsigned WebVideoFrameImpl::planes() const {
+ if (video_frame_.get())
+ return video_frame_->planes();
+ return NULL;
+}
+
+int WebVideoFrameImpl::stride(unsigned plane) const {
+ if (video_frame_.get())
+ return static_cast<int>(video_frame_->stride(plane));
+ return NULL;
+}
+
+const void* WebVideoFrameImpl::data(unsigned plane) const {
+ if (video_frame_.get())
+ return static_cast<const void*>(video_frame_->data(plane));
+ return NULL;
+}
+
+} // namespace webkit_glue
diff --git a/webkit/glue/webvideoframe_impl.h b/webkit/glue/webvideoframe_impl.h
new file mode 100644
index 0000000..6dc9cde
--- /dev/null
+++ b/webkit/glue/webvideoframe_impl.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_WEBVIDEOFRAME_IMPL_H_
+#define WEBKIT_GLUE_WEBVIDEOFRAME_IMPL_H_
+
+#include "media/base/video_frame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVideoFrame.h"
+
+using namespace WebKit;
+
+namespace webkit_glue {
+
+class WebVideoFrameImpl : public WebVideoFrame {
+ public:
+ // This converts a WebKit::WebVideoFrame to a media::VideoFrame.
+ static media::VideoFrame* toVideoFrame(WebVideoFrame* web_video_frame);
+
+ WebVideoFrameImpl(scoped_refptr<media::VideoFrame> video_frame);
+ virtual WebVideoFrame::SurfaceType surfaceType() const;
+ virtual WebVideoFrame::Format format() const;
+ virtual unsigned width() const;
+ virtual unsigned height() const;
+ virtual unsigned planes() const;
+ virtual int stride(unsigned plane) const;
+ virtual const void* data(unsigned plane) const;
+
+ private:
+ scoped_refptr<media::VideoFrame> video_frame_;
+ DISALLOW_COPY_AND_ASSIGN(WebVideoFrameImpl);
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_WEBVIDEOFRAME_IMPL_H_