summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_out/video_out_xcbshm.c408
1 files changed, 257 insertions, 151 deletions
diff --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c
index 9ca0beeb3..7f2e45fca 100644
--- a/src/video_out/video_out_xcbshm.c
+++ b/src/video_out/video_out_xcbshm.c
@@ -25,8 +25,16 @@
* xine-specific code by Guenter Bartsch <bartscgr@studbox.uni-stuttgart.de>
*
* ported to xcb by Christoph Pfister - Feb 2007
+ *
+ * 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
@@ -56,18 +64,14 @@
# include <libavutil/mem.h>
#endif
-#define LOG_MODULE "video_out_xcbshm"
-#define LOG_VERBOSE
-/*
-#define LOG
-*/
-
#include <xine/xine_internal.h>
#include "yuv2rgb.h"
#include <xine/xineutils.h>
#include <xine/vo_scale.h>
#include "xcbosd.h"
+#include "xine_mmx.h"
+
typedef struct {
vo_frame_t vo_frame;
@@ -85,8 +89,16 @@ typedef struct {
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;
@@ -225,7 +237,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 | VO_CAP_BRIGHTNESS | VO_CAP_CONTRAST | VO_CAP_SATURATION;
+ uint32_t capabilities = VO_CAP_CROP | VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS
+ | VO_CAP_CONTRAST | VO_CAP_SATURATION;
if( this->xoverlay )
capabilities |= VO_CAP_UNSCALED_OVERLAY;
@@ -261,46 +274,187 @@ static void xshm_compute_rgb_size (xshm_driver_t *this, xshm_frame_t *frame) {
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];
+}
+
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; */
+ uint8_t *src0;
- vo_img->proc_called = 1;
+ /* delayed setup */
+ if (!vo_img->proc_called) {
+ xshm_frame_proc_setup (vo_img);
+ 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
- */
+
+ src0 = src[0] + frame->offs0;
+ if ((src0 < frame->crop_start) || (src0 >= frame->crop_stop))
return;
- }
lprintf ("copy... (format %d)\n", frame->format);
- if (frame->format == XINE_IMGFMT_YV12)
+ if (vo_img->format == XINE_IMGFMT_YV12)
frame->yuv2rgb->yuv2rgb_fun (frame->yuv2rgb, frame->rgb_dst,
- src[0], src[1], src[2]);
+ src0, src[1] + frame->offs1, src[2] + frame->offs1);
else
frame->yuv2rgb->yuy22rgb_fun (frame->yuv2rgb, frame->rgb_dst,
- src[0]);
+ 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");
}
@@ -359,144 +513,61 @@ 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");
- }
-
+ || (format != frame->format)) {
- /* ok, now do what we have to do */
+ frame->sc.delivered_width = width;
+ frame->sc.delivered_height = height;
+ frame->format = format;
- 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
- */
-
- if (frame->image) {
-
- dispose_ximage(this, frame);
-
- av_freep(&frame->vo_frame.base[0]);
- av_freep(&frame->vo_frame.base[1]);
- av_freep(&frame->vo_frame.base[2]);
- }
-
- 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] = av_mallocz(frame->vo_frame.pitches[0] * height);
- frame->vo_frame.base[1] = av_mallocz(frame->vo_frame.pitches[1] * ((height+1)/2));
- frame->vo_frame.base[2] = av_mallocz(frame->vo_frame.pitches[2] * ((height+1)/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] = av_mallocz(frame->vo_frame.pitches[0] * height);
+ 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;
@@ -553,6 +624,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) {
@@ -570,19 +643,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:
@@ -632,6 +705,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);
@@ -661,6 +740,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);
@@ -703,6 +788,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) {