summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorjiesun@google.com <jiesun@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 16:06:46 +0000
committerjiesun@google.com <jiesun@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 16:06:46 +0000
commit0ed5386b521ed354bc5748bf0b40894080890779 (patch)
treed970b71d2df931d9dd6ad9119ea04126ebd988d8 /media
parent7ba3818362289db0081fb869caf53084fca52eaa (diff)
downloadchromium_src-0ed5386b521ed354bc5748bf0b40894080890779.zip
chromium_src-0ed5386b521ed354bc5748bf0b40894080890779.tar.gz
chromium_src-0ed5386b521ed354bc5748bf0b40894080890779.tar.bz2
code fix for video frame
Review URL: http://codereview.chromium.org/1623011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44774 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/tools/player_x11/gl_video_renderer.cc49
-rw-r--r--media/tools/player_x11/gles_video_renderer.cc86
2 files changed, 63 insertions, 72 deletions
diff --git a/media/tools/player_x11/gl_video_renderer.cc b/media/tools/player_x11/gl_video_renderer.cc
index ebcb9b5..87ad6ed 100644
--- a/media/tools/player_x11/gl_video_renderer.cc
+++ b/media/tools/player_x11/gl_video_renderer.cc
@@ -10,6 +10,7 @@
#include <X11/extensions/Xcomposite.h>
#include "media/base/buffers.h"
+#include "media/base/video_frame.h"
#include "media/base/yuv_convert.h"
GlVideoRenderer* GlVideoRenderer::instance_ = NULL;
@@ -164,7 +165,7 @@ bool GlVideoRenderer::OnInitialize(media::VideoDecoder* decoder) {
// Create 3 textures, one for each plane, and bind them to different
// texture units.
- glGenTextures(media::VideoSurface::kNumYUVPlanes, textures_);
+ glGenTextures(media::VideoFrame::kNumYUVPlanes, textures_);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures_[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -283,32 +284,26 @@ void GlVideoRenderer::Paint() {
return;
// Convert YUV frame to RGB.
- media::VideoSurface frame_in;
- if (video_frame->Lock(&frame_in)) {
- DCHECK(frame_in.format == media::VideoSurface::YV12 ||
- frame_in.format == media::VideoSurface::YV16);
- DCHECK(frame_in.strides[media::VideoSurface::kUPlane] ==
- frame_in.strides[media::VideoSurface::kVPlane]);
- DCHECK(frame_in.planes == media::VideoSurface::kNumYUVPlanes);
-
- if (glXGetCurrentContext() != gl_context_ ||
- glXGetCurrentDrawable() != window_) {
- glXMakeCurrent(display_, window_, gl_context_);
- }
- for (unsigned int i = 0; i < media::VideoSurface::kNumYUVPlanes; ++i) {
- unsigned int width = (i == media::VideoSurface::kYPlane) ?
- frame_in.width : frame_in.width / 2;
- unsigned int height = (i == media::VideoSurface::kYPlane ||
- frame_in.format == media::VideoSurface::YV16) ?
- frame_in.height : frame_in.height / 2;
- glActiveTexture(GL_TEXTURE0 + i);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, frame_in.strides[i]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, frame_in.data[i]);
- }
- video_frame->Unlock();
- } else {
- NOTREACHED();
+ DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
+ video_frame->format() == media::VideoFrame::YV16);
+ DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
+ video_frame->stride(media::VideoFrame::kVPlane));
+ DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes);
+
+ if (glXGetCurrentContext() != gl_context_ ||
+ glXGetCurrentDrawable() != window_) {
+ glXMakeCurrent(display_, window_, gl_context_);
+ }
+ for (unsigned int i = 0; i < media::VideoFrame::kNumYUVPlanes; ++i) {
+ unsigned int width = (i == media::VideoFrame::kYPlane) ?
+ video_frame->width() : video_frame->width() / 2;
+ unsigned int height = (i == media::VideoFrame::kYPlane ||
+ video_frame->format() == media::VideoFrame::YV16) ?
+ video_frame->height() : video_frame->height() / 2;
+ glActiveTexture(GL_TEXTURE0 + i);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, video_frame->stride(i));
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, video_frame->data(i));
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
diff --git a/media/tools/player_x11/gles_video_renderer.cc b/media/tools/player_x11/gles_video_renderer.cc
index ebdd5e0..347a3dc 100644
--- a/media/tools/player_x11/gles_video_renderer.cc
+++ b/media/tools/player_x11/gles_video_renderer.cc
@@ -12,6 +12,7 @@
#include "media/base/buffers.h"
#include "media/base/pipeline.h"
#include "media/base/filter_host.h"
+#include "media/base/video_frame.h"
#include "media/base/yuv_convert.h"
GlesVideoRenderer* GlesVideoRenderer::instance_ = NULL;
@@ -149,52 +150,47 @@ void GlesVideoRenderer::Paint() {
return;
// Convert YUV frame to RGB.
- media::VideoSurface frame_in;
- if (video_frame->Lock(&frame_in)) {
- DCHECK(frame_in.format == media::VideoSurface::YV12 ||
- frame_in.format == media::VideoSurface::YV16);
- DCHECK(frame_in.strides[media::VideoSurface::kUPlane] ==
- frame_in.strides[media::VideoSurface::kVPlane]);
- DCHECK(frame_in.planes == media::VideoSurface::kNumYUVPlanes);
-
- for (unsigned int i = 0; i < media::VideoSurface::kNumYUVPlanes; ++i) {
- unsigned int width = (i == media::VideoSurface::kYPlane) ?
- frame_in.width : frame_in.width / 2;
- unsigned int height = (i == media::VideoSurface::kYPlane ||
- frame_in.format == media::VideoSurface::YV16) ?
- frame_in.height : frame_in.height / 2;
- glActiveTexture(GL_TEXTURE0 + i);
- // GLES2 supports a fixed set of unpack alignments that should match most
- // of the time what ffmpeg outputs.
- // TODO(piman): check if it is more efficient to prefer higher
- // alignments.
- unsigned int stride = frame_in.strides[i];
- uint8* data = frame_in.data[i];
- if (stride == width) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- } else if (stride == ((width + 1) & ~1)) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
- } else if (stride == ((width + 3) & ~3)) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- } else if (stride == ((width + 7) & ~7)) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
- } else {
- // Otherwise do it line-by-line.
- glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
- for (unsigned int y = 0; y < height; ++y) {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, width, 1,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
- data += stride;
- }
- continue;
- }
+ DCHECK(video_frame->format() == media::VideoFrame::YV12 ||
+ video_frame->format() == media::VideoFrame::YV16);
+ DCHECK(video_frame->stride(media::VideoFrame::kUPlane) ==
+ video_frame->stride(media::VideoFrame::kVPlane));
+ DCHECK(video_frame->planes() == media::VideoFrame::kNumYUVPlanes);
+
+ for (unsigned int i = 0; i < media::VideoFrame::kNumYUVPlanes; ++i) {
+ unsigned int width = (i == media::VideoFrame::kYPlane) ?
+ video_frame->width() : video_frame->width() / 2;
+ unsigned int height = (i == media::VideoFrame::kYPlane ||
+ video_frame->format() == media::VideoFrame::YV16) ?
+ video_frame->height() : video_frame->height() / 2;
+ glActiveTexture(GL_TEXTURE0 + i);
+ // GLES2 supports a fixed set of unpack alignments that should match most
+ // of the time what ffmpeg outputs.
+ // TODO(piman): check if it is more efficient to prefer higher
+ // alignments.
+ unsigned int stride = video_frame->stride(i);
+ uint8* data = video_frame->data(i);
+ if (stride == width) {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ } else if (stride == ((width + 1) & ~1)) {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+ } else if (stride == ((width + 3) & ~3)) {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+ } else if (stride == ((width + 7) & ~7)) {
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
+ } else {
+ // Otherwise do it line-by-line.
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);
+ for (unsigned int y = 0; y < height; ++y) {
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, width, 1,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
+ data += stride;
+ }
+ continue;
}
- video_frame->Unlock();
- } else {
- NOTREACHED();
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
+ GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
}
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -289,7 +285,7 @@ bool GlesVideoRenderer::InitializeGles() {
// Create 3 textures, one for each plane, and bind them to different
// texture units.
- glGenTextures(media::VideoSurface::kNumYUVPlanes, textures_);
+ glGenTextures(media::VideoFrame::kNumYUVPlanes, textures_);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures_[0]);