summaryrefslogtreecommitdiff
path: root/src/video_out/video_out_xcbshm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_out/video_out_xcbshm.c')
-rw-r--r--src/video_out/video_out_xcbshm.c661
1 files changed, 377 insertions, 284 deletions
diff --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c
index e3556d8e7..05e5ad731 100644
--- a/src/video_out/video_out_xcbshm.c
+++ b/src/video_out/video_out_xcbshm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000-2003, 2007 the xine project
+ * Copyright (C) 2000-2003, 2007-2008 the xine project
*
* This file is part of xine, a free video player.
*
@@ -25,8 +25,16 @@
* xine-specific code by Guenter Bartsch <bartscgr@studbox.uni-stuttgart.de>
*
* ported to xcb by Christoph Pfister - Feb 2007
+ *
+ * fullrange/HD color and crop support added by Torsten Jager <t.jager@gmx.de>
*/
+#define LOG_MODULE "video_out_xcbshm"
+#define LOG_VERBOSE
+/*
+#define LOG
+*/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -37,7 +45,7 @@
#include <math.h>
#include "xine.h"
-#include "video_out.h"
+#include <xine/video_out.h>
#include <errno.h>
@@ -50,18 +58,20 @@
#include <pthread.h>
#include <netinet/in.h>
-#define LOG_MODULE "video_out_xcbshm"
-#define LOG_VERBOSE
-/*
-#define LOG
-*/
+#ifdef HAVE_FFMPEG_AVUTIL_H
+# include <mem.h>
+#else
+# include <libavutil/mem.h>
+#endif
-#include "xine_internal.h"
+#include <xine/xine_internal.h>
#include "yuv2rgb.h"
-#include "xineutils.h"
-#include "vo_scale.h"
+#include <xine/xineutils.h>
+#include <xine/vo_scale.h>
#include "xcbosd.h"
+#include "xine_mmx.h"
+
typedef struct {
vo_frame_t vo_frame;
@@ -76,13 +86,19 @@ typedef struct {
int bytes_per_line;
xcb_shm_seg_t shmseg;
- uint8_t *chunk[3]; /* mem alloc by xmalloc_aligned */
-
yuv2rgb_t *yuv2rgb; /* yuv2rgb converter set up for this frame */
uint8_t *rgb_dst;
+ int state, offs0, offs1; /* crop helpers */
+ uint8_t *crop_start, *crop_flush, *crop_stop;
} xshm_frame_t;
+/* frame.state */
+#define FS_DONE 1
+#define FS_LATE 2
+#define FS_FLAGS 4
+
+
typedef struct {
vo_driver_t vo_driver;
@@ -97,12 +113,15 @@ typedef struct {
int scanline_pad;
int use_shm;
- int yuv2rgb_brightness;
- int yuv2rgb_contrast;
- int yuv2rgb_saturation;
+ int brightness;
+ int contrast;
+ int saturation;
uint8_t *yuv2rgb_cmap;
yuv2rgb_factory_t *yuv2rgb_factory;
+ /* color matrix switching */
+ int cm_active, cm_state;
+
vo_scale_t sc;
xshm_frame_t *cur_frame;
@@ -125,6 +144,10 @@ typedef struct {
} xshm_class_t;
+/* import common color matrix stuff */
+#define CM_DRIVER_T xshm_driver_t
+#include "color_matrix.c"
+
/*
* allocate an XImage, try XShm first but fall back to
* plain X11 if XShm should fail
@@ -147,8 +170,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (shmid < 0) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: %s: allocating image\n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"), strerror(errno));
+ _("%s: %s: allocating image\n"), LOG_MODULE, strerror(errno));
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail1;
}
@@ -156,8 +180,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (frame->image == ((void *) -1)) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: shared memory error (address error) when allocating image \n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: shared memory error (address error) when allocating image \n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
goto shm_fail2;
}
@@ -167,8 +192,9 @@ static void create_ximage(xshm_driver_t *this, xshm_frame_t *frame, int width, i
if (generic_error != NULL) {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: x11 error during shared memory XImage creation\n"
- "video_out_xcbshm: => not using MIT Shared Memory extension.\n"));
+ _("%s: x11 error during shared memory XImage creation\n"), LOG_MODULE);
+ xprintf(this->xine, XINE_VERBOSITY_LOG,
+ _("%s: => not using MIT Shared Memory extension.\n"), LOG_MODULE);
free(generic_error);
goto shm_fail3;
}
@@ -218,7 +244,8 @@ static void dispose_ximage(xshm_driver_t *this, xshm_frame_t *frame)
static uint32_t xshm_get_capabilities (vo_driver_t *this_gen) {
xshm_driver_t *this = (xshm_driver_t *) this_gen;
- uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2;
+ uint32_t capabilities = VO_CAP_CROP | VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS
+ | VO_CAP_CONTRAST | VO_CAP_SATURATION | VO_CAP_COLOR_MATRIX | VO_CAP_FULLRANGE;
if( this->xoverlay )
capabilities |= VO_CAP_UNSCALED_OVERLAY;
@@ -226,52 +253,230 @@ static uint32_t xshm_get_capabilities (vo_driver_t *this_gen) {
return capabilities;
}
-static void xshm_frame_proc_slice (vo_frame_t *vo_img, uint8_t **src) {
- xshm_frame_t *frame = (xshm_frame_t *) vo_img ;
- /*xshm_driver_t *this = (xshm_driver_t *) vo_img->driver; */
-
- vo_img->proc_called = 1;
-
- if( frame->vo_frame.crop_left || frame->vo_frame.crop_top ||
- frame->vo_frame.crop_right || frame->vo_frame.crop_bottom )
- {
- /* we don't support crop, so don't even waste cpu cycles.
- * cropping will be performed by video_out.c
- */
- return;
- }
+static void xshm_compute_ideal_size (xshm_driver_t *this, xshm_frame_t *frame) {
+ _x_vo_scale_compute_ideal_size( &frame->sc );
+}
- lprintf ("copy... (format %d)\n", frame->format);
+static void xshm_compute_rgb_size (xshm_driver_t *this, xshm_frame_t *frame) {
+ _x_vo_scale_compute_output_size( &frame->sc );
- if (frame->format == XINE_IMGFMT_YV12)
- frame->yuv2rgb->yuv2rgb_fun (frame->yuv2rgb, frame->rgb_dst,
- src[0], src[1], src[2]);
- else
- frame->yuv2rgb->yuy22rgb_fun (frame->yuv2rgb, frame->rgb_dst,
- src[0]);
+ /* avoid problems in yuv2rgb */
+ if (frame->sc.output_height < 1)
+ frame->sc.output_height = 1;
+ if (frame->sc.output_width < 8)
+ frame->sc.output_width = 8;
+ if (frame->sc.output_width & 1) /* yuv2rgb_mlib needs an even YUV2 width */
+ frame->sc.output_width++;
- lprintf ("copy...done\n");
+ lprintf("frame source (%d) %d x %d => screen output %d x %d%s\n",
+ frame->vo_frame.id,
+ frame->sc.delivered_width, frame->sc.delivered_height,
+ frame->sc.output_width, frame->sc.output_height,
+ ( frame->sc.delivered_width != frame->sc.output_width
+ || frame->sc.delivered_height != frame->sc.output_height
+ ? ", software scaling"
+ : "" )
+ );
}
static void xshm_frame_field (vo_frame_t *vo_img, int which_field) {
xshm_frame_t *frame = (xshm_frame_t *) vo_img ;
- /* xshm_driver_t *this = (xshm_driver_t *) vo_img->driver; */
switch (which_field) {
- case VO_TOP_FIELD:
- frame->rgb_dst = frame->image;
- break;
- case VO_BOTTOM_FIELD:
- frame->rgb_dst = frame->image + frame->bytes_per_line;
+ case VO_BOTH_FIELDS:
+ case VO_TOP_FIELD:
+ frame->rgb_dst = (uint8_t *)frame->image;
break;
- case VO_BOTH_FIELDS:
- frame->rgb_dst = frame->image;
+ case VO_BOTTOM_FIELD:
+ frame->rgb_dst = (uint8_t *)frame->image + frame->bytes_per_line ;
break;
}
frame->yuv2rgb->next_slice (frame->yuv2rgb, NULL);
}
+static void xshm_frame_proc_setup (vo_frame_t *vo_img) {
+ xshm_frame_t *frame = (xshm_frame_t *) vo_img ;
+ xshm_driver_t *this = (xshm_driver_t *) vo_img->driver;
+ int changed = 0, i;
+ int width, height, gui_width, gui_height;
+ double gui_pixel_aspect;
+
+ /* Aargh... libmpeg2 decoder calls frame->proc_slice directly, preferredly
+ while still in mmx mode. This will trash our floating point aspect ratio
+ calculations below. Switching back once per frame should not harm
+ performance too much. */
+#ifdef HAVE_MMX
+ emms ();
+#endif
+
+ if (!(frame->state & FS_LATE)) {
+ /* adjust cropping to what yuv2rgb can handle */
+ if (vo_img->format == XINE_IMGFMT_YV12) {
+ vo_img->crop_left &= ~7;
+ vo_img->crop_top &= ~1;
+ } else {
+ vo_img->crop_left &= ~3;
+ }
+ /* check for crop changes */
+ if ((vo_img->crop_left != frame->sc.crop_left)
+ || (vo_img->crop_top != frame->sc.crop_top)
+ || (vo_img->crop_right != frame->sc.crop_right)
+ || (vo_img->crop_bottom != frame->sc.crop_bottom)) {
+ frame->sc.crop_left = vo_img->crop_left;
+ frame->sc.crop_top = vo_img->crop_top;
+ frame->sc.crop_right = vo_img->crop_right;
+ frame->sc.crop_bottom = vo_img->crop_bottom;
+ changed = 1;
+ }
+ }
+
+ if (!(frame->state & FS_DONE))
+ changed = 1;
+
+ /* just deal with cropped part */
+ width = frame->sc.delivered_width - frame->sc.crop_left - frame->sc.crop_right;
+ height = frame->sc.delivered_height - frame->sc.crop_top - frame->sc.crop_bottom;
+
+ if (frame->sc.delivered_ratio == 0.0) {
+ frame->sc.delivered_ratio = height ? (double)width / (double)height : 1.0;
+ changed = 1;
+ }
+
+ /* ask gui what output size we'll have for this frame */
+ /* get the gui_pixel_aspect before calling xshm_compute_ideal_size() */
+ /* note: gui_width and gui_height may be bogus because we may have not yet */
+ /* updated video_pixel_aspect (see _x_vo_scale_compute_ideal_size). */
+ frame->sc.dest_size_cb (frame->sc.user_data, width, height,
+ frame->sc.video_pixel_aspect, &gui_width, &gui_height, &gui_pixel_aspect);
+
+ if (changed || (gui_pixel_aspect != frame->sc.gui_pixel_aspect)
+ || (this->sc.user_ratio != frame->sc.user_ratio)) {
+
+ frame->sc.gui_pixel_aspect = gui_pixel_aspect;
+ frame->sc.user_ratio = this->sc.user_ratio;
+
+ xshm_compute_ideal_size (this, frame);
+
+ /* now we have updated video_aspect_pixel we use the callback */
+ /* again to obtain the correct gui_width and gui_height values. */
+ frame->sc.dest_size_cb (frame->sc.user_data, width, height,
+ frame->sc.video_pixel_aspect, &gui_width, &gui_height, &gui_pixel_aspect);
+
+ changed = 1;
+ }
+
+ if (changed || (frame->sc.gui_width != gui_width)
+ || (frame->sc.gui_height != gui_height)) {
+ int w = frame->sc.output_width, h = frame->sc.output_height;
+
+ frame->sc.gui_width = gui_width;
+ frame->sc.gui_height = gui_height;
+
+ xshm_compute_rgb_size (this, frame);
+
+ if (!frame->image || (w != frame->sc.output_width) || (h != frame->sc.output_height)) {
+ /* (re)allocate XImage */
+ pthread_mutex_lock(&this->main_mutex);
+ if (frame->image)
+ dispose_ximage (this, frame);
+ create_ximage (this, frame, frame->sc.output_width, frame->sc.output_height);
+ pthread_mutex_unlock(&this->main_mutex);
+ }
+
+ changed = 1;
+ }
+
+ if (changed || !(frame->state & FS_FLAGS)) {
+ /* set up colorspace converter */
+ switch (vo_img->flags & VO_BOTH_FIELDS) {
+ case VO_TOP_FIELD:
+ case VO_BOTTOM_FIELD:
+ frame->yuv2rgb->configure (frame->yuv2rgb, width, height,
+ 2 * frame->vo_frame.pitches[0], 2 * frame->vo_frame.pitches[1],
+ frame->sc.output_width, frame->sc.output_height,
+ frame->bytes_per_line * 2);
+ break;
+ case VO_BOTH_FIELDS:
+ frame->yuv2rgb->configure (frame->yuv2rgb, width, height,
+ frame->vo_frame.pitches[0], frame->vo_frame.pitches[1],
+ frame->sc.output_width, frame->sc.output_height,
+ frame->bytes_per_line);
+ break;
+ }
+ }
+
+ frame->state |= FS_FLAGS | FS_DONE;
+
+ xshm_frame_field (vo_img, vo_img->flags & VO_BOTH_FIELDS);
+
+ /* cache helpers */
+ i = frame->sc.crop_top & 15;
+ if (i)
+ i -= 16;
+ if (vo_img->format == XINE_IMGFMT_YV12) {
+ frame->offs0 = i * vo_img->pitches[0] + frame->sc.crop_left;
+ frame->offs1 = (i * vo_img->pitches[1] + frame->sc.crop_left) / 2;
+ } else {
+ frame->offs0 = i * vo_img->pitches[0] + frame->sc.crop_left * 2;
+ }
+ frame->crop_start = vo_img->base[0] + frame->sc.crop_top * vo_img->pitches[0];
+ frame->crop_flush = frame->crop_stop = vo_img->base[0]
+ + (frame->sc.delivered_height - frame->sc.crop_bottom) * vo_img->pitches[0];
+ if (i + frame->sc.crop_bottom < 0)
+ frame->crop_flush -= 16 * vo_img->pitches[0];
+
+ /* switch color matrix/range */
+ i = cm_from_frame (vo_img);
+ if (i != this->cm_active) {
+ this->cm_active = i;
+ this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
+ this->brightness, this->contrast, this->saturation, i);
+ xprintf (this->xine, XINE_VERBOSITY_LOG,
+ "video_out_xcbshm: b %d c %d s %d [%s]\n",
+ this->brightness, this->contrast, this->saturation, cm_names[i]);
+ }
+}
+
+static void xshm_frame_proc_slice (vo_frame_t *vo_img, uint8_t **src) {
+ xshm_frame_t *frame = (xshm_frame_t *) vo_img ;
+ uint8_t *src0;
+
+ /* delayed setup */
+ if (!vo_img->proc_called) {
+ xshm_frame_proc_setup (vo_img);
+ vo_img->proc_called = 1;
+ }
+
+
+ src0 = src[0] + frame->offs0;
+ if ((src0 < frame->crop_start) || (src0 >= frame->crop_stop))
+ return;
+
+ lprintf ("copy... (format %d)\n", frame->format);
+
+ if (vo_img->format == XINE_IMGFMT_YV12)
+ frame->yuv2rgb->yuv2rgb_fun (frame->yuv2rgb, frame->rgb_dst,
+ src0, src[1] + frame->offs1, src[2] + frame->offs1);
+ else
+ frame->yuv2rgb->yuy22rgb_fun (frame->yuv2rgb, frame->rgb_dst,
+ src0);
+
+ if (src0 >= frame->crop_flush) {
+ if (vo_img->format == XINE_IMGFMT_YV12) {
+ frame->yuv2rgb->yuv2rgb_fun (frame->yuv2rgb, frame->rgb_dst,
+ src0 + 16 * vo_img->pitches[0],
+ src[1] + frame->offs1 + 8 * vo_img->pitches[1],
+ src[2] + frame->offs1 + 8 * vo_img->pitches[2]);
+ } else {
+ frame->yuv2rgb->yuy22rgb_fun (frame->yuv2rgb, frame->rgb_dst,
+ src0 + 16 * vo_img->pitches[0]);
+ }
+ }
+
+ lprintf ("copy...done\n");
+}
+
static void xshm_frame_dispose (vo_frame_t *vo_img) {
xshm_frame_t *frame = (xshm_frame_t *) vo_img ;
xshm_driver_t *this = (xshm_driver_t *) vo_img->driver;
@@ -284,9 +489,9 @@ static void xshm_frame_dispose (vo_frame_t *vo_img) {
frame->yuv2rgb->dispose (frame->yuv2rgb);
- free (frame->chunk[0]);
- free (frame->chunk[1]);
- free (frame->chunk[2]);
+ av_free (frame->vo_frame.base[0]);
+ av_free (frame->vo_frame.base[1]);
+ av_free (frame->vo_frame.base[2]);
free (frame);
}
@@ -322,185 +527,65 @@ static vo_frame_t *xshm_alloc_frame (vo_driver_t *this_gen) {
return (vo_frame_t *) frame;
}
-static void xshm_compute_ideal_size (xshm_driver_t *this, xshm_frame_t *frame) {
- _x_vo_scale_compute_ideal_size( &frame->sc );
-}
-
-static void xshm_compute_rgb_size (xshm_driver_t *this, xshm_frame_t *frame) {
- _x_vo_scale_compute_output_size( &frame->sc );
-
- /* avoid problems in yuv2rgb */
- if (frame->sc.output_height < 1)
- frame->sc.output_height = 1;
- if (frame->sc.output_width < 8)
- frame->sc.output_width = 8;
- if (frame->sc.output_width & 1) /* yuv2rgb_mlib needs an even YUV2 width */
- frame->sc.output_width++;
-
- lprintf("frame source (%d) %d x %d => screen output %d x %d%s\n",
- frame->vo_frame.id,
- frame->sc.delivered_width, frame->sc.delivered_height,
- frame->sc.output_width, frame->sc.output_height,
- ( frame->sc.delivered_width != frame->sc.output_width
- || frame->sc.delivered_height != frame->sc.output_height
- ? ", software scaling"
- : "" )
- );
-}
-
static void xshm_update_frame_format (vo_driver_t *this_gen,
vo_frame_t *frame_gen,
uint32_t width, uint32_t height,
double ratio, int format, int flags) {
- xshm_driver_t *this = (xshm_driver_t *) this_gen;
xshm_frame_t *frame = (xshm_frame_t *) frame_gen;
- int do_adapt;
- int gui_width;
- int gui_height;
- double gui_pixel_aspect;
+ int j, pitch;
flags &= VO_BOTH_FIELDS;
- /* ask gui what output size we'll have for this frame */
- /* get the gui_pixel_aspect before calling xshm_compute_ideal_size() */
- /* note: gui_width and gui_height may be bogus because we may have not yet*/
- /* updated video_pixel_aspect (see _x_vo_scale_compute_ideal_size). */
- frame->sc.dest_size_cb (frame->sc.user_data, width, height,
- frame->sc.video_pixel_aspect,
- &gui_width, &gui_height,
- &gui_pixel_aspect);
-
- /* find out if we need to adapt this frame */
- do_adapt = 0;
-
+ /* (re)allocate yuv buffers */
if ((width != frame->sc.delivered_width)
|| (height != frame->sc.delivered_height)
- || (ratio != frame->sc.delivered_ratio)
- || (flags != frame->flags)
- || (format != frame->format)
- || (gui_pixel_aspect != frame->sc.gui_pixel_aspect)
- || (this->sc.user_ratio != frame->sc.user_ratio)) {
-
- do_adapt = 1;
-
- lprintf ("frame format (from decoder) has changed => adapt\n");
-
- frame->sc.delivered_width = width;
- frame->sc.delivered_height = height;
- frame->sc.delivered_ratio = ratio;
- frame->sc.gui_pixel_aspect = gui_pixel_aspect;
- frame->flags = flags;
- frame->format = format;
- frame->sc.user_ratio = this->sc.user_ratio;
-
- xshm_compute_ideal_size (this, frame);
-
- /* now we have updated video_aspect_pixel we use the callback */
- /* again to obtain the correct gui_width and gui_height values. */
- frame->sc.dest_size_cb (frame->sc.user_data, width, height,
- frame->sc.video_pixel_aspect,
- &gui_width, &gui_height,
- &gui_pixel_aspect);
- }
-
- if ((frame->sc.gui_width != gui_width) ||
- (frame->sc.gui_height != gui_height) ||
- do_adapt) {
-
- do_adapt = 1;
- frame->sc.gui_width = gui_width;
- frame->sc.gui_height = gui_height;
-
- xshm_compute_rgb_size (this, frame);
-
- lprintf ("gui_size has changed => adapt\n");
- }
-
-
- /* ok, now do what we have to do */
-
- if (do_adapt) {
-
- lprintf ("updating frame to %d x %d\n",
- frame->sc.output_width, frame->sc.output_height);
-
- pthread_mutex_lock(&this->main_mutex);
-
- /*
- * (re-) allocate XImage
- */
+ || (format != frame->format)) {
- if (frame->image) {
+ frame->sc.delivered_width = width;
+ frame->sc.delivered_height = height;
+ frame->format = format;
- dispose_ximage(this, frame);
-
- if (frame->chunk[0]){
- free (frame->chunk[0]);
- frame->chunk[0] = NULL;
- }
- if (frame->chunk[1]) {
- free (frame->chunk[1]);
- frame->chunk[1] = NULL;
- }
- if (frame->chunk[2]) {
- free (frame->chunk[2]);
- frame->chunk[2] = NULL;
- }
- }
-
- create_ximage(this, frame, frame->sc.output_width, frame->sc.output_height);
-
- pthread_mutex_unlock(&this->main_mutex);
+ av_freep(&frame->vo_frame.base[0]);
+ av_freep(&frame->vo_frame.base[1]);
+ av_freep(&frame->vo_frame.base[2]);
+ /* bottom black pad for certain crop_top > crop_bottom cases */
if (format == XINE_IMGFMT_YV12) {
- frame->vo_frame.pitches[0] = 8*((width + 7) / 8);
- frame->vo_frame.pitches[1] = 8*((width + 15) / 16);
- frame->vo_frame.pitches[2] = 8*((width + 15) / 16);
- frame->vo_frame.base[0] = xine_xmalloc_aligned (16, frame->vo_frame.pitches[0] * height, (void **) &frame->chunk[0]);
- frame->vo_frame.base[1] = xine_xmalloc_aligned (16, frame->vo_frame.pitches[1] * ((height+1)/2), (void **) &frame->chunk[1]);
- frame->vo_frame.base[2] = xine_xmalloc_aligned (16, frame->vo_frame.pitches[2] * ((height+1)/2), (void **) &frame->chunk[2]);
+ pitch = (width + 7) & ~7;
+ frame->vo_frame.pitches[0] = pitch;
+ frame->vo_frame.base[0] = av_malloc (pitch * (height + 16));
+ memset (frame->vo_frame.base[0] + pitch * height, 0, pitch * 16);
+ pitch = ((width + 15) & ~15) >> 1;
+ frame->vo_frame.pitches[1] = pitch;
+ frame->vo_frame.pitches[2] = pitch;
+ frame->vo_frame.base[1] = av_malloc (pitch * ((height + 17) / 2));
+ memset (frame->vo_frame.base[1] + pitch * height / 2, 128, pitch * 8);
+ frame->vo_frame.base[2] = av_malloc (pitch * ((height + 17) / 2));
+ memset (frame->vo_frame.base[2] + pitch * height / 2, 128, pitch * 8);
} else {
- frame->vo_frame.pitches[0] = 8*((width + 3) / 4);
- frame->vo_frame.base[0] = xine_xmalloc_aligned (16, frame->vo_frame.pitches[0] * height, (void **) &frame->chunk[0]);
- frame->chunk[1] = NULL;
- frame->chunk[2] = NULL;
+ pitch = ((width + 3) & ~3) << 1;
+ frame->vo_frame.pitches[0] = pitch;
+ frame->vo_frame.base[0] = av_malloc (pitch * (height + 16));
+ for (j = pitch * height; j < pitch * (height + 16); j++)
+ (frame->vo_frame.base[0])[j] = (j & 1) << 7;
}
- lprintf ("stripe out_ht=%i, deliv_ht=%i\n",
- frame->sc.output_height, frame->sc.delivered_height);
-
- /*
- * set up colorspace converter
- */
-
- switch (flags) {
- case VO_TOP_FIELD:
- case VO_BOTTOM_FIELD:
- frame->yuv2rgb->configure (frame->yuv2rgb,
- frame->sc.delivered_width,
- frame->sc.delivered_height,
- 2*frame->vo_frame.pitches[0],
- 2*frame->vo_frame.pitches[1],
- frame->sc.output_width,
- frame->sc.output_height,
- frame->bytes_per_line*2);
- break;
- case VO_BOTH_FIELDS:
- frame->yuv2rgb->configure (frame->yuv2rgb,
- frame->sc.delivered_width,
- frame->sc.delivered_height,
- frame->vo_frame.pitches[0],
- frame->vo_frame.pitches[1],
- frame->sc.output_width,
- frame->sc.output_height,
- frame->bytes_per_line);
- break;
- }
+ /* defer the rest to xshm_frame_proc_setup () */
+ frame->state &= ~(FS_DONE | FS_LATE);
+ }
+ if (!isnan (ratio) && (ratio < 1000.0) && (ratio > 0.001)
+ && (ratio != frame->sc.delivered_ratio)) {
+ frame->sc.delivered_ratio = ratio;
+ frame->state &= ~FS_DONE;
}
- xshm_frame_field ((vo_frame_t *)frame, flags);
+ if (flags != frame->flags) {
+ frame->flags = flags;
+ frame->state &= ~FS_FLAGS;
+ }
}
+
static void xshm_overlay_clut_yuv2rgb(xshm_driver_t *this, vo_overlay_t *overlay,
xshm_frame_t *frame) {
size_t i;
@@ -557,6 +642,8 @@ static void xshm_overlay_blend (vo_driver_t *this_gen,
vo_frame_t *frame_gen, vo_overlay_t *overlay) {
xshm_driver_t *this = (xshm_driver_t *) this_gen;
xshm_frame_t *frame = (xshm_frame_t *) frame_gen;
+ int width = frame->sc.delivered_width - frame->sc.crop_left - frame->sc.crop_right;
+ int height = frame->sc.delivered_height - frame->sc.crop_top - frame->sc.crop_bottom;
/* Alpha Blend here */
if (overlay->rle) {
@@ -574,19 +661,19 @@ static void xshm_overlay_blend (vo_driver_t *this_gen,
case 16:
_x_blend_rgb16(frame->image, overlay,
frame->sc.output_width, frame->sc.output_height,
- frame->sc.delivered_width, frame->sc.delivered_height,
+ width, height,
&this->alphablend_extra_data);
break;
case 24:
_x_blend_rgb24(frame->image, overlay,
frame->sc.output_width, frame->sc.output_height,
- frame->sc.delivered_width, frame->sc.delivered_height,
+ width, height,
&this->alphablend_extra_data);
break;
case 32:
_x_blend_rgb32(frame->image, overlay,
frame->sc.output_width, frame->sc.output_height,
- frame->sc.delivered_width, frame->sc.delivered_height,
+ width, height,
&this->alphablend_extra_data);
break;
default:
@@ -636,6 +723,12 @@ static int xshm_redraw_needed (vo_driver_t *this_gen) {
this->sc.delivered_height = this->cur_frame->sc.delivered_height;
this->sc.delivered_width = this->cur_frame->sc.delivered_width;
this->sc.video_pixel_aspect = this->cur_frame->sc.video_pixel_aspect;
+
+ this->sc.crop_left = this->cur_frame->sc.crop_left;
+ this->sc.crop_right = this->cur_frame->sc.crop_right;
+ this->sc.crop_top = this->cur_frame->sc.crop_top;
+ this->sc.crop_bottom = this->cur_frame->sc.crop_bottom;
+
if( _x_vo_scale_redraw_needed( &this->sc ) ) {
clean_output_area (this, this->cur_frame);
@@ -665,6 +758,12 @@ static void xshm_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
this->sc.delivered_height = frame->sc.delivered_height;
this->sc.delivered_width = frame->sc.delivered_width;
this->sc.video_pixel_aspect = frame->sc.video_pixel_aspect;
+
+ this->sc.crop_left = frame->sc.crop_left;
+ this->sc.crop_right = frame->sc.crop_right;
+ this->sc.crop_top = frame->sc.crop_top;
+ this->sc.crop_bottom = frame->sc.crop_bottom;
+
if( _x_vo_scale_redraw_needed( &this->sc ) ) {
clean_output_area (this, frame);
@@ -707,6 +806,27 @@ static void xshm_display_frame (vo_driver_t *this_gen, vo_frame_t *frame_gen) {
pthread_mutex_unlock(&this->main_mutex);
lprintf ("display frame done\n");
+
+ /* just in case somebody changes crop this late - take over for next time */
+ /* adjust cropping to what yuv2rgb can handle */
+ if (frame_gen->format == XINE_IMGFMT_YV12) {
+ frame_gen->crop_left &= ~7;
+ frame_gen->crop_top &= ~1;
+ } else {
+ frame_gen->crop_left &= ~3;
+ }
+ /* check for crop changes */
+ if ((frame_gen->crop_left != frame->sc.crop_left)
+ || (frame_gen->crop_top != frame->sc.crop_top)
+ || (frame_gen->crop_right != frame->sc.crop_right)
+ || (frame_gen->crop_bottom != frame->sc.crop_bottom)) {
+ frame->sc.crop_left = frame_gen->crop_left;
+ frame->sc.crop_top = frame_gen->crop_top;
+ frame->sc.crop_right = frame_gen->crop_right;
+ frame->sc.crop_bottom = frame_gen->crop_bottom;
+ frame->state &= ~FS_DONE;
+ frame->state |= FS_LATE;
+ }
}
static int xshm_get_property (vo_driver_t *this_gen, int property) {
@@ -718,11 +838,11 @@ static int xshm_get_property (vo_driver_t *this_gen, int property) {
case VO_PROP_MAX_NUM_FRAMES:
return 15;
case VO_PROP_BRIGHTNESS:
- return this->yuv2rgb_brightness;
+ return this->brightness;
case VO_PROP_CONTRAST:
- return this->yuv2rgb_contrast;
+ return this->contrast;
case VO_PROP_SATURATION:
- return this->yuv2rgb_saturation;
+ return this->saturation;
case VO_PROP_WINDOW_WIDTH:
return this->sc.gui_width;
case VO_PROP_WINDOW_HEIGHT:
@@ -737,7 +857,7 @@ static int xshm_get_property (vo_driver_t *this_gen, int property) {
return this->cur_frame->sc.output_yoffset;
default:
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: tried to get unsupported property %d\n", property);
+ LOG_MODULE ": tried to get unsupported property %d\n", property);
}
return 0;
@@ -747,47 +867,36 @@ static int xshm_set_property (vo_driver_t *this_gen,
int property, int value) {
xshm_driver_t *this = (xshm_driver_t *) this_gen;
- if ( property == VO_PROP_ASPECT_RATIO) {
-
+ switch (property) {
+ case VO_PROP_ASPECT_RATIO:
if (value>=XINE_VO_ASPECT_NUM_RATIOS)
value = XINE_VO_ASPECT_AUTO;
this->sc.user_ratio = value;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name(value));
-
- } else if (property == VO_PROP_BRIGHTNESS) {
-
- this->yuv2rgb_brightness = value;
- this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
- this->yuv2rgb_brightness,
- this->yuv2rgb_contrast,
- this->yuv2rgb_saturation);
+ LOG_MODULE ": aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name_table[value]);
+ break;
+ case VO_PROP_BRIGHTNESS:
+ this->brightness = value;
+ this->cm_active = 0;
this->sc.force_redraw = 1;
+ break;
- } else if (property == VO_PROP_CONTRAST) {
-
- this->yuv2rgb_contrast = value;
- this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
- this->yuv2rgb_brightness,
- this->yuv2rgb_contrast,
- this->yuv2rgb_saturation);
-
+ case VO_PROP_CONTRAST:
+ this->contrast = value;
+ this->cm_active = 0;
this->sc.force_redraw = 1;
+ break;
- } else if (property == VO_PROP_SATURATION) {
-
- this->yuv2rgb_saturation = value;
- this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
- this->yuv2rgb_brightness,
- this->yuv2rgb_contrast,
- this->yuv2rgb_saturation);
-
+ case VO_PROP_SATURATION:
+ this->saturation = value;
+ this->cm_active = 0;
this->sc.force_redraw = 1;
+ break;
- } else {
+ default:
xprintf (this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: tried to set unsupported property %d\n", property);
+ LOG_MODULE ": tried to set unsupported property %d\n", property);
}
return value;
@@ -916,6 +1025,8 @@ static void xshm_dispose (vo_driver_t *this_gen) {
this->yuv2rgb_factory->dispose (this->yuv2rgb_factory);
+ cm_close (this);
+
pthread_mutex_lock(&this->main_mutex);
xcb_free_gc(this->connection, this->gc);
pthread_mutex_unlock(&this->main_mutex);
@@ -963,7 +1074,7 @@ static int ImlibPaletteLUTGet(xshm_driver_t *this) {
char *retval = xcb_get_property_value(prop_reply);
j = 1 + retval[0]*4;
- this->yuv2rgb_cmap = malloc(sizeof(uint8_t) * 32 * 32 * 32);
+ this->yuv2rgb_cmap = xine_xcalloc(sizeof(uint8_t), 32 * 32 * 32);
for (i = 0; i < 32 * 32 * 32 && j < num_ret; i++)
this->yuv2rgb_cmap[i] = retval[1+4*retval[j++]+3];
@@ -975,8 +1086,8 @@ static int ImlibPaletteLUTGet(xshm_driver_t *this) {
return 0;
}
-
-static char *visual_class_name(xcb_visualtype_t *visual) {
+/* TODO replace this with a string table. */
+static const char *visual_class_name(xcb_visualtype_t *visual) {
switch (visual->_class) {
case XCB_VISUAL_CLASS_STATIC_GRAY:
@@ -1111,7 +1222,7 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
}
else {
xprintf(this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: MIT shared memory extension not present on display.\n"));
+ _("%s: MIT shared memory extension not present on display.\n"), LOG_MODULE);
this->use_shm = 0;
}
@@ -1149,8 +1260,8 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
swapped = cpu_byte_order != image_byte_order;
xprintf(this->xine, XINE_VERBOSITY_DEBUG,
- "video_out_xcbshm: video mode depth is %d (%d bpp), %s, %sswapped,\n"
- "\tred: %08x, green: %08x, blue: %08x\n",
+ LOG_MODULE ": video mode depth is %d (%d bpp), %s, %sswapped,\n"
+ LOG_MODULE ": red: %08x, green: %08x, blue: %08x\n",
this->depth, this->bpp,
visual_class_name(visualtype),
swapped ? "" : "not ",
@@ -1210,20 +1321,17 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
if (!mode) {
xprintf (this->xine, XINE_VERBOSITY_LOG,
- _("video_out_xcbshm: your video mode was not recognized, sorry :-(\n"));
+ _("%s: your video mode was not recognized, sorry :-(\n"), LOG_MODULE);
return NULL;
}
- this->yuv2rgb_brightness = 0;
- this->yuv2rgb_contrast = 128;
- this->yuv2rgb_saturation = 128;
+ cm_init (this);
- this->yuv2rgb_factory = yuv2rgb_factory_init (mode, swapped,
- this->yuv2rgb_cmap);
- this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory,
- this->yuv2rgb_brightness,
- this->yuv2rgb_contrast,
- this->yuv2rgb_saturation);
+ this->brightness = 0;
+ this->contrast = 128;
+ this->saturation = 128;
+
+ this->yuv2rgb_factory = yuv2rgb_factory_init (mode, swapped, this->yuv2rgb_cmap);
this->xoverlay = xcbosd_create(this->xine, this->connection, this->screen,
this->window, XCBOSD_SHAPED);
@@ -1234,28 +1342,13 @@ static vo_driver_t *xshm_open_plugin(video_driver_class_t *class_gen, const void
/*
* class functions
*/
-
-static char* xshm_get_identifier (video_driver_class_t *this_gen) {
- return "XShm";
-}
-
-static char* xshm_get_description (video_driver_class_t *this_gen) {
- return _("xine video output plugin using the MIT X shared memory extension");
-}
-
-static void xshm_dispose_class (video_driver_class_t *this_gen) {
- xshm_class_t *this = (xshm_class_t *) this_gen;
-
- free (this);
-}
-
static void *xshm_init_class (xine_t *xine, void *visual_gen) {
xshm_class_t *this = (xshm_class_t *) calloc(1, sizeof(xshm_class_t));
this->driver_class.open_plugin = xshm_open_plugin;
- this->driver_class.get_identifier = xshm_get_identifier;
- this->driver_class.get_description = xshm_get_description;
- this->driver_class.dispose = xshm_dispose_class;
+ this->driver_class.identifier = "XShm";
+ this->driver_class.description = N_("xine video output plugin using the MIT X shared memory extension");
+ this->driver_class.dispose = default_video_driver_class_dispose;
this->config = xine->config;
this->xine = xine;
@@ -1275,6 +1368,6 @@ static const vo_info_t vo_info_xshm = {
const plugin_info_t xine_plugin_info[] EXPORTED = {
/* type, API, "name", version, special_info, init_function */
- { PLUGIN_VIDEO_OUT, 21, "xshm", XINE_VERSION_CODE, &vo_info_xshm, xshm_init_class },
+ { PLUGIN_VIDEO_OUT, 22, "xshm", XINE_VERSION_CODE, &vo_info_xshm, xshm_init_class },
{ PLUGIN_NONE, 0, "", 0, NULL, NULL }
};