Remove XvRenderer.

One test renderer per platform is sufficient, multiple code paths are
bad.

BUG=
R=mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1612004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4170 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pbos@webrtc.org 2013-06-04 11:56:06 +00:00
parent 8ad3ec9722
commit 6998c8ef7a
5 changed files with 5 additions and 296 deletions

View File

@ -136,6 +136,11 @@ void GlxRenderer::Resize(size_t width, size_t height) {
size_hints->min_aspect.y = size_hints->max_aspect.y = height_;
XSetWMNormalHints(display_, window_, size_hints);
XFree(size_hints);
XWindowChanges wc;
wc.width = static_cast<int>(width);
wc.height = static_cast<int>(height);
XConfigureWindow(display_, window_, CWWidth | CWHeight, &wc);
}
void GlxRenderer::RenderFrame(const webrtc::I420VideoFrame& frame,

View File

@ -7,15 +7,9 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/video_engine/test/common/video_renderer.h"
#ifdef WEBRTC_TEST_XV
#include "webrtc/video_engine/test/common/linux/xv_renderer.h"
#endif // WEBRTC_TEST_XV
#ifdef WEBRTC_TEST_GLX
#include "webrtc/video_engine/test/common/linux/glx_renderer.h"
#endif // WEBRTC_TEST_GLX
namespace webrtc {
namespace test {
@ -23,18 +17,10 @@ namespace test {
VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
size_t width,
size_t height) {
#ifdef WEBRTC_TEST_XV
XvRenderer* xv_renderer = XvRenderer::Create(window_title, width, height);
if (xv_renderer != NULL) {
return xv_renderer;
}
#endif // WEBRTC_TEST_XV
#ifdef WEBRTC_TEST_GLX
GlxRenderer* glx_renderer = GlxRenderer::Create(window_title, width, height);
if (glx_renderer != NULL) {
return glx_renderer;
}
#endif // WEBRTC_TEST_GLX
return NULL;
}
} // test

View File

@ -1,210 +0,0 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/video_engine/test/common/linux/xv_renderer.h"
#include <X11/Xutil.h>
#include <X11/extensions/Xvlib.h>
#include <sys/shm.h>
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
#define GUID_I420_PLANAR 0x30323449
namespace webrtc {
namespace test {
XvRenderer::XvRenderer(size_t width, size_t height)
: width(width),
height(height),
is_init(false),
display(NULL),
gc(NULL),
image(NULL) {
assert(width > 0);
assert(height > 0);
}
bool XvRenderer::Init(const char* window_title) {
assert(!is_init);
is_init = true;
if ((display = XOpenDisplay(NULL)) == NULL) {
Destroy();
return false;
}
int screen = DefaultScreen(display);
XVisualInfo vinfo;
if (!XMatchVisualInfo(display, screen, 24, TrueColor, &vinfo)) {
Destroy();
return false;
}
XSetWindowAttributes xswa;
xswa.colormap = XCreateColormap(display, DefaultRootWindow(display),
vinfo.visual, AllocNone);
xswa.event_mask = StructureNotifyMask | ExposureMask;
xswa.background_pixel = 0;
xswa.border_pixel = 0;
window = XCreateWindow(display, DefaultRootWindow(display), 0, 0, width,
height, 0, vinfo.depth, InputOutput, vinfo.visual,
CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
&xswa);
XStoreName(display, window, window_title);
XSetIconName(display, window, window_title);
XSelectInput(display, window, StructureNotifyMask);
XMapRaised(display, window);
XEvent event;
do {
XNextEvent(display, &event);
} while (event.type != MapNotify || event.xmap.event != window);
if (!XShmQueryExtension(display)) {
Destroy();
return false;
}
xv_complete = XShmGetEventBase(display) + ShmCompletion;
XvAdaptorInfo* ai;
unsigned int p_num_adaptors;
if (XvQueryAdaptors(display, DefaultRootWindow(display), &p_num_adaptors,
&ai) !=
Success) {
Destroy();
return false;
}
if (p_num_adaptors <= 0) {
XvFreeAdaptorInfo(ai);
Destroy();
return false;
}
xv_port = ai[p_num_adaptors - 1].base_id;
XvFreeAdaptorInfo(ai);
if (xv_port == -1) {
Destroy();
return false;
}
gc = XCreateGC(display, window, 0, 0);
if (gc == NULL) {
Destroy();
return false;
}
Resize(width, height);
return true;
}
void XvRenderer::Destroy() {
if (image != NULL) {
XFree(image);
image = NULL;
}
if (gc != NULL) {
XFreeGC(display, gc);
gc = NULL;
}
if (display != NULL) {
XCloseDisplay(display);
display = NULL;
}
}
XvRenderer* XvRenderer::Create(const char* window_title, size_t width,
size_t height) {
XvRenderer* xv_renderer = new XvRenderer(width, height);
if (!xv_renderer->Init(window_title)) {
// TODO(pbos): Add Xv-failed warning here?
delete xv_renderer;
return NULL;
}
return xv_renderer;
}
XvRenderer::~XvRenderer() { Destroy(); }
void XvRenderer::Resize(size_t width, size_t height) {
this->width = width;
this->height = height;
if (image != NULL) {
XFree(image);
}
image = XvShmCreateImage(display, xv_port, GUID_I420_PLANAR, 0, width, height,
&shm_info);
assert(image != NULL);
shm_info.shmid = shmget(IPC_PRIVATE, image->data_size, IPC_CREAT | 0777);
shm_info.shmaddr = image->data =
reinterpret_cast<char*>(shmat(shm_info.shmid, 0, 0));
shm_info.readOnly = False;
if (!XShmAttach(display, &shm_info)) {
abort();
}
XSizeHints* size_hints = XAllocSizeHints();
if (size_hints == NULL) {
abort();
}
size_hints->flags = PAspect;
size_hints->min_aspect.x = size_hints->max_aspect.x = width;
size_hints->min_aspect.y = size_hints->max_aspect.y = height;
XSetWMNormalHints(display, window, size_hints);
XFree(size_hints);
XWindowChanges wc;
wc.width = width;
wc.height = height;
XConfigureWindow(display, window, CWWidth | CWHeight, &wc);
}
void XvRenderer::RenderFrame(const webrtc::I420VideoFrame& frame,
int /*render_delay_ms*/) {
int size = webrtc::ExtractBuffer(frame, image->data_size,
reinterpret_cast<uint8_t*>(image->data));
if (static_cast<size_t>(frame.width()) != width ||
static_cast<size_t>(frame.height()) != height) {
Resize(static_cast<size_t>(frame.width()),
static_cast<size_t>(frame.height()));
}
assert(size > 0);
Window root;
int temp;
unsigned int window_width, window_height, u_temp;
XGetGeometry(display, window, &root, &temp, &temp, &window_width,
&window_height, &u_temp, &u_temp);
XvShmPutImage(display, xv_port, window, gc, image, 0, 0, image->width,
image->height, 0, 0, window_width, window_height, True);
XFlush(display);
XEvent event;
while (XPending(display)) {
XNextEvent(display, &event);
}
}
} // test
} // webrtc

View File

@ -1,54 +0,0 @@
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_LINUX_XV_RENDERER_H_
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_LINUX_XV_RENDERER_H_
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/Xvlib.h>
#include "webrtc/video_engine/test/common/video_renderer.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace test {
class XvRenderer : public VideoRenderer {
public:
~XvRenderer();
virtual void RenderFrame(const webrtc::I420VideoFrame& frame, int delta)
OVERRIDE;
static XvRenderer* Create(const char *window_title, size_t width,
size_t height);
private:
XvRenderer(size_t width, size_t height);
bool Init(const char *window_title);
void Resize(size_t width, size_t height);
void Destroy();
size_t width, height;
bool is_init;
Display* display;
Window window;
GC gc;
XvImage* image;
XShmSegmentInfo shm_info;
int xv_port, xv_complete;
};
} // test
} // webrtc
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_LINUX_XV_RENDERER_H_

View File

@ -7,9 +7,6 @@
# be found in the AUTHORS file in the root of the source tree.
{
'variables': {
'xv_renderer%': 0,
},
'targets': [
{
'target_name': 'video_tests_common',
@ -41,15 +38,6 @@
'common/video_renderer.h',
],
'conditions': [
['xv_renderer==1', {
'defines': [
'WEBRTC_TEST_XV',
],
'sources': [
'common/linux/xv_renderer.cc',
'common/linux/xv_renderer.h',
],
}],
['OS=="linux"', {
'sources!': [
'common/null_platform_renderer.cc',
@ -77,11 +65,6 @@
'-lGL',
],
}],
['xv_renderer==1', {
'libraries': [
'-lXv',
],
}],
#TODO(pbos) : These dependencies should not have to be here, they
# aren't used by test code directly, only by components
# used by the tests.
@ -120,7 +103,6 @@
],
'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(webrtc_root)/modules/modules.gyp:video_capture_module',
'video_tests_common',
],
},