2009-02-16 21:58:13 +01:00
|
|
|
/*
|
|
|
|
* VDPAU video output driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 NVIDIA
|
2009-11-15 03:39:22 +01:00
|
|
|
* Copyright (C) 2009 Uoti Urpala
|
2009-02-16 21:58:13 +01:00
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-09 17:08:30 +02:00
|
|
|
/*
|
2009-02-16 21:58:13 +01:00
|
|
|
* Actual decoding and presentation are implemented here.
|
|
|
|
* All necessary frame information is collected through
|
|
|
|
* the "vdpau_render_state" structure after parsing all headers
|
|
|
|
* etc. in libavcodec for different codecs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-09-18 15:27:55 +02:00
|
|
|
#include <stdlib.h>
|
2009-05-06 22:49:51 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2009-11-15 03:39:22 +01:00
|
|
|
#include <limits.h>
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
2009-05-04 02:09:50 +02:00
|
|
|
#include "options.h"
|
2009-05-06 20:04:37 +02:00
|
|
|
#include "talloc.h"
|
2009-02-16 21:58:13 +01:00
|
|
|
#include "video_out.h"
|
|
|
|
#include "x11_common.h"
|
|
|
|
#include "aspect.h"
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
#include "csputils.h"
|
2011-01-26 18:40:52 +01:00
|
|
|
#include "sub/sub.h"
|
2009-02-20 10:45:48 +01:00
|
|
|
#include "subopt-helper.h"
|
2009-05-04 02:09:50 +02:00
|
|
|
#include "libmpcodecs/vfcap.h"
|
|
|
|
#include "libmpcodecs/mp_image.h"
|
2009-09-07 01:02:24 +02:00
|
|
|
#include "osdep/timer.h"
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#include "libavcodec/vdpau.h"
|
|
|
|
|
2011-01-26 18:40:52 +01:00
|
|
|
#include "sub/font_load.h"
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#include "libavutil/common.h"
|
2009-02-28 16:45:24 +01:00
|
|
|
#include "libavutil/mathematics.h"
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2011-01-26 18:40:52 +01:00
|
|
|
#include "sub/ass_mp.h"
|
2009-02-23 10:21:57 +01:00
|
|
|
|
2010-05-06 03:46:10 +02:00
|
|
|
#define WRAP_ADD(x, a, m) ((a) < 0 \
|
|
|
|
? ((x)+(a)+(m) < (m) ? (x)+(a)+(m) : (x)+(a)) \
|
|
|
|
: ((x)+(a) < (m) ? (x)+(a) : (x)+(a)-(m)))
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
#define CHECK_ST_ERROR(message) \
|
2009-05-08 19:57:22 +02:00
|
|
|
do { \
|
|
|
|
if (vdp_st != VDP_STATUS_OK) { \
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] %s: %s\n", \
|
|
|
|
message, vdp->get_error_string(vdp_st)); \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#define CHECK_ST_WARNING(message) \
|
2009-05-08 19:57:22 +02:00
|
|
|
do { \
|
|
|
|
if (vdp_st != VDP_STATUS_OK) \
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "[ vdpau] %s: %s\n", \
|
|
|
|
message, vdp->get_error_string(vdp_st)); \
|
|
|
|
} while (0)
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
/* number of video and output surfaces */
|
2010-05-14 04:18:38 +02:00
|
|
|
#define MAX_OUTPUT_SURFACES 15
|
2009-02-16 21:58:13 +01:00
|
|
|
#define MAX_VIDEO_SURFACES 50
|
2009-10-14 03:12:10 +02:00
|
|
|
#define NUM_BUFFERED_VIDEO 4
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
/* number of palette entries */
|
|
|
|
#define PALETTE_SIZE 256
|
|
|
|
|
2009-09-02 19:21:24 +02:00
|
|
|
/* Initial size of EOSD surface in pixels (x*x) */
|
|
|
|
#define EOSD_SURFACE_INITIAL_SIZE 256
|
2009-02-23 10:21:57 +01:00
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
/*
|
|
|
|
* Global variable declaration - VDPAU specific
|
|
|
|
*/
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdp_functions {
|
|
|
|
#define VDP_FUNCTION(vdp_type, _, mp_name) vdp_type *mp_name;
|
|
|
|
#include "vdpau_template.c"
|
|
|
|
#undef VDP_FUNCTION
|
|
|
|
};
|
2009-02-28 14:20:01 +01:00
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx {
|
|
|
|
struct vdp_functions *vdp;
|
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
VdpDevice vdp_device;
|
2009-09-07 01:02:24 +02:00
|
|
|
bool is_preempted;
|
|
|
|
bool preemption_acked;
|
|
|
|
bool preemption_user_notified;
|
|
|
|
unsigned int last_preemption_retry_fail;
|
2009-05-06 22:42:24 +02:00
|
|
|
VdpGetProcAddress *vdp_get_proc_address;
|
|
|
|
|
|
|
|
VdpPresentationQueueTarget flip_target;
|
|
|
|
VdpPresentationQueue flip_queue;
|
2009-11-15 03:39:22 +01:00
|
|
|
uint64_t last_vdp_time;
|
|
|
|
unsigned int last_sync_update;
|
2009-05-06 22:42:24 +02:00
|
|
|
|
2010-05-14 04:18:38 +02:00
|
|
|
/* an extra last output surface is misused for OSD. */
|
|
|
|
VdpOutputSurface output_surfaces[MAX_OUTPUT_SURFACES + 1];
|
|
|
|
int num_output_surfaces;
|
2009-10-14 03:12:10 +02:00
|
|
|
struct buffered_video_surface {
|
|
|
|
VdpVideoSurface surface;
|
|
|
|
double pts;
|
|
|
|
mp_image_t *mpi;
|
|
|
|
} buffered_video[NUM_BUFFERED_VIDEO];
|
2009-09-18 15:27:55 +02:00
|
|
|
int deint_queue_pos;
|
2009-05-06 22:42:24 +02:00
|
|
|
int output_surface_width, output_surface_height;
|
|
|
|
|
|
|
|
VdpVideoMixer video_mixer;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
struct mp_csp_details colorspace;
|
2009-05-06 22:42:24 +02:00
|
|
|
int deint;
|
|
|
|
int deint_type;
|
|
|
|
int deint_counter;
|
|
|
|
int pullup;
|
|
|
|
float denoise;
|
|
|
|
float sharpen;
|
2009-11-15 17:39:48 +01:00
|
|
|
int hqscaling;
|
2009-05-06 22:42:24 +02:00
|
|
|
int chroma_deint;
|
2010-02-05 19:13:33 +01:00
|
|
|
int flip_offset_window;
|
|
|
|
int flip_offset_fs;
|
2009-05-06 22:42:24 +02:00
|
|
|
int top_field_first;
|
2009-11-15 14:50:28 +01:00
|
|
|
bool flip;
|
2009-05-06 22:42:24 +02:00
|
|
|
|
|
|
|
VdpDecoder decoder;
|
|
|
|
int decoder_max_refs;
|
|
|
|
|
|
|
|
VdpRect src_rect_vid;
|
|
|
|
VdpRect out_rect_vid;
|
|
|
|
int border_x, border_y;
|
|
|
|
|
|
|
|
struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
|
|
|
|
int surface_num;
|
2010-05-14 04:18:38 +02:00
|
|
|
int query_surface_num;
|
2009-11-15 03:39:22 +01:00
|
|
|
VdpTime recent_vsync_time;
|
|
|
|
float user_fps;
|
|
|
|
unsigned int vsync_interval;
|
|
|
|
uint64_t last_queue_time;
|
2010-05-14 04:18:38 +02:00
|
|
|
uint64_t queue_time[MAX_OUTPUT_SURFACES];
|
2009-11-15 03:39:22 +01:00
|
|
|
uint64_t last_ideal_time;
|
|
|
|
bool dropped_frame;
|
|
|
|
uint64_t dropped_time;
|
2009-05-06 22:42:24 +02:00
|
|
|
uint32_t vid_width, vid_height;
|
|
|
|
uint32_t image_format;
|
|
|
|
VdpChromaType vdp_chroma_type;
|
|
|
|
VdpYCbCrFormat vdp_pixel_format;
|
|
|
|
|
|
|
|
/* draw_osd */
|
|
|
|
unsigned char *index_data;
|
|
|
|
int index_data_size;
|
|
|
|
uint32_t palette[PALETTE_SIZE];
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-06 22:49:51 +02:00
|
|
|
// EOSD
|
|
|
|
// Pool of surfaces
|
2009-09-02 19:21:24 +02:00
|
|
|
struct eosd_bitmap_surface {
|
2009-05-06 22:49:51 +02:00
|
|
|
VdpBitmapSurface surface;
|
|
|
|
int w;
|
|
|
|
int h;
|
2009-09-02 19:21:24 +02:00
|
|
|
uint32_t max_width;
|
|
|
|
uint32_t max_height;
|
|
|
|
} eosd_surface;
|
2009-05-06 22:49:51 +02:00
|
|
|
|
|
|
|
// List of surfaces to be rendered
|
2009-05-09 17:08:30 +02:00
|
|
|
struct eosd_target {
|
2009-05-06 22:49:51 +02:00
|
|
|
VdpRect source;
|
|
|
|
VdpRect dest;
|
|
|
|
VdpColor color;
|
|
|
|
} *eosd_targets;
|
2009-09-02 19:21:24 +02:00
|
|
|
int eosd_targets_size;
|
|
|
|
int *eosd_scratch;
|
2009-05-06 22:49:51 +02:00
|
|
|
|
|
|
|
int eosd_render_count;
|
|
|
|
|
|
|
|
// Video equalizer
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
struct mp_csp_equalizer video_eq;
|
2009-05-06 22:49:51 +02:00
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
int num_shown_frames;
|
2009-05-06 22:49:51 +02:00
|
|
|
bool paused;
|
2009-05-08 20:48:01 +02:00
|
|
|
|
|
|
|
// These tell what's been initialized and uninit() should free/uninitialize
|
|
|
|
bool mode_switched;
|
2009-05-06 22:49:51 +02:00
|
|
|
};
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
static int change_vdptime_sync(struct vdpctx *vc, unsigned int *t)
|
|
|
|
{
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
VdpTime vdp_time;
|
|
|
|
vdp_st = vdp->presentation_queue_get_time(vc->flip_queue, &vdp_time);
|
|
|
|
CHECK_ST_ERROR("Error when calling vdp_presentation_queue_get_time");
|
|
|
|
unsigned int t1 = *t;
|
|
|
|
unsigned int t2 = GetTimer();
|
|
|
|
uint64_t old = vc->last_vdp_time + (t1 - vc->last_sync_update) * 1000ULL;
|
|
|
|
if (vdp_time > old)
|
|
|
|
if (vdp_time > old + (t2 - t1) * 1000ULL)
|
|
|
|
vdp_time -= (t2 - t1) * 1000ULL;
|
|
|
|
else
|
|
|
|
vdp_time = old;
|
2011-07-04 23:48:41 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "[vdpau] adjusting VdpTime offset by %f µs\n",
|
2009-11-15 03:39:22 +01:00
|
|
|
(int64_t)(vdp_time - old) / 1000.);
|
|
|
|
vc->last_vdp_time = vdp_time;
|
|
|
|
vc->last_sync_update = t1;
|
|
|
|
*t = t2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t sync_vdptime(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
|
|
|
unsigned int t = GetTimer();
|
|
|
|
if (t - vc->last_sync_update > 5000000)
|
|
|
|
change_vdptime_sync(vc, &t);
|
|
|
|
uint64_t now = (t - vc->last_sync_update) * 1000ULL + vc->last_vdp_time;
|
|
|
|
// Make sure nanosecond inaccuracies don't make things inconsistent
|
|
|
|
now = FFMAX(now, vc->recent_vsync_time);
|
|
|
|
return now;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t convert_to_vdptime(struct vo *vo, unsigned int t)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
return (int)(t - vc->last_sync_update) * 1000LL + vc->last_vdp_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flip_page_timed(struct vo *vo, unsigned int pts_us, int duration);
|
2009-03-06 11:39:58 +01:00
|
|
|
|
2009-09-18 23:00:42 +02:00
|
|
|
static int video_to_output_surface(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpTime dummy;
|
|
|
|
VdpStatus vdp_st;
|
2009-09-18 15:27:55 +02:00
|
|
|
if (vc->deint_queue_pos < 0)
|
2009-09-18 23:00:42 +02:00
|
|
|
return -1;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
struct buffered_video_surface *bv = vc->buffered_video;
|
2009-09-18 15:27:55 +02:00
|
|
|
int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
|
|
|
|
unsigned int dp = vc->deint_queue_pos;
|
|
|
|
// dp==0 means last field of latest frame, 1 earlier field of latest frame,
|
|
|
|
// 2 last field of previous frame and so on
|
|
|
|
if (vc->deint) {
|
|
|
|
field = vc->top_field_first ^ (dp & 1) ?
|
|
|
|
VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
|
|
|
|
VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
|
|
|
|
}
|
|
|
|
const VdpVideoSurface *past_fields = (const VdpVideoSurface []){
|
2009-10-14 03:12:10 +02:00
|
|
|
bv[(dp+1)/2].surface, bv[(dp+2)/2].surface};
|
2009-09-18 15:27:55 +02:00
|
|
|
const VdpVideoSurface *future_fields = (const VdpVideoSurface []){
|
2009-10-14 03:12:10 +02:00
|
|
|
dp >= 1 ? bv[(dp-1)/2].surface : VDP_INVALID_HANDLE};
|
2009-09-18 15:27:55 +02:00
|
|
|
VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num];
|
|
|
|
vdp_st = vdp->presentation_queue_block_until_surface_idle(vc->flip_queue,
|
|
|
|
output_surface,
|
|
|
|
&dummy);
|
|
|
|
CHECK_ST_WARNING("Error when calling "
|
|
|
|
"vdp_presentation_queue_block_until_surface_idle");
|
|
|
|
|
|
|
|
vdp_st = vdp->video_mixer_render(vc->video_mixer, VDP_INVALID_HANDLE,
|
|
|
|
0, field, 2, past_fields,
|
2009-10-14 03:12:10 +02:00
|
|
|
bv[dp/2].surface, 1, future_fields,
|
2009-09-18 15:27:55 +02:00
|
|
|
&vc->src_rect_vid, output_surface,
|
|
|
|
NULL, &vc->out_rect_vid, 0, NULL);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_video_mixer_render");
|
2009-09-18 23:00:42 +02:00
|
|
|
return 0;
|
2009-09-18 15:27:55 +02:00
|
|
|
}
|
2009-03-26 00:32:27 +01:00
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
static void get_buffered_frame(struct vo *vo, bool eof)
|
2009-09-18 15:27:55 +02:00
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
int dqp = vc->deint_queue_pos;
|
|
|
|
if (dqp < 0)
|
|
|
|
dqp += 1000;
|
|
|
|
else
|
|
|
|
dqp = vc->deint >= 2 ? dqp - 1 : dqp - 2 | 1;
|
|
|
|
if (dqp < (eof ? 0 : 3))
|
|
|
|
return;
|
2009-09-18 15:27:55 +02:00
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
dqp = FFMIN(dqp, 4);
|
|
|
|
vc->deint_queue_pos = dqp;
|
2009-09-18 15:27:55 +02:00
|
|
|
vo->frame_loaded = true;
|
2009-10-14 03:12:10 +02:00
|
|
|
|
|
|
|
// Set pts values
|
|
|
|
struct buffered_video_surface *bv = vc->buffered_video;
|
|
|
|
int idx = vc->deint_queue_pos >> 1;
|
|
|
|
if (idx == 0) { // no future frame/pts available
|
|
|
|
vo->next_pts = bv[0].pts;
|
|
|
|
vo->next_pts2 = MP_NOPTS_VALUE;
|
|
|
|
} else if (!(vc->deint >= 2)) { // no field-splitting deinterlace
|
|
|
|
vo->next_pts = bv[idx].pts;
|
|
|
|
vo->next_pts2 = bv[idx - 1].pts;
|
|
|
|
} else { // deinterlace with separate fields
|
|
|
|
double intermediate_pts;
|
|
|
|
double diff = bv[idx - 1].pts - bv[idx].pts;
|
2009-09-18 15:27:55 +02:00
|
|
|
if (diff > 0 && diff < 0.5)
|
2009-10-14 03:12:10 +02:00
|
|
|
intermediate_pts = (bv[idx].pts + bv[idx - 1].pts) / 2;
|
2009-09-18 15:27:55 +02:00
|
|
|
else
|
2009-10-14 03:12:10 +02:00
|
|
|
intermediate_pts = bv[idx].pts;
|
|
|
|
if (vc->deint_queue_pos & 1) { // first field
|
|
|
|
vo->next_pts = bv[idx].pts;
|
|
|
|
vo->next_pts2 = intermediate_pts;
|
|
|
|
} else {
|
|
|
|
vo->next_pts = intermediate_pts;
|
|
|
|
vo->next_pts2 = bv[idx - 1].pts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-18 15:27:55 +02:00
|
|
|
video_to_output_surface(vo);
|
|
|
|
}
|
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
static void add_new_video_surface(struct vo *vo, VdpVideoSurface surface,
|
|
|
|
struct mp_image *reserved_mpi, double pts)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct buffered_video_surface *bv = vc->buffered_video;
|
|
|
|
|
|
|
|
if (reserved_mpi)
|
|
|
|
reserved_mpi->usage_count++;
|
|
|
|
if (bv[NUM_BUFFERED_VIDEO - 1].mpi)
|
|
|
|
bv[NUM_BUFFERED_VIDEO - 1].mpi->usage_count--;
|
|
|
|
|
|
|
|
for (int i = NUM_BUFFERED_VIDEO - 1; i > 0; i--)
|
|
|
|
bv[i] = bv[i - 1];
|
|
|
|
bv[0] = (struct buffered_video_surface){
|
|
|
|
.mpi = reserved_mpi,
|
|
|
|
.surface = surface,
|
|
|
|
.pts = pts,
|
|
|
|
};
|
|
|
|
|
|
|
|
vc->deint_queue_pos += 2;
|
|
|
|
get_buffered_frame(vo, false);
|
|
|
|
}
|
|
|
|
|
2009-09-18 15:27:55 +02:00
|
|
|
static void forget_frames(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
vc->deint_queue_pos = -1001;
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->dropped_frame = false;
|
2009-10-14 03:12:10 +02:00
|
|
|
for (int i = 0; i < NUM_BUFFERED_VIDEO; i++) {
|
|
|
|
struct buffered_video_surface *p = vc->buffered_video + i;
|
|
|
|
if (p->mpi)
|
|
|
|
p->mpi->usage_count--;
|
|
|
|
*p = (struct buffered_video_surface){
|
|
|
|
.surface = VDP_INVALID_HANDLE,
|
|
|
|
};
|
2009-02-24 22:46:25 +01:00
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static void resize(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
|
|
|
int i;
|
|
|
|
struct vo_rect src_rect;
|
|
|
|
struct vo_rect dst_rect;
|
2009-02-17 12:59:49 +01:00
|
|
|
struct vo_rect borders;
|
2009-05-06 22:42:24 +02:00
|
|
|
calc_src_dst_rects(vo, vc->vid_width, vc->vid_height, &src_rect, &dst_rect,
|
2009-05-04 02:09:50 +02:00
|
|
|
&borders, NULL);
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->out_rect_vid.x0 = dst_rect.left;
|
|
|
|
vc->out_rect_vid.x1 = dst_rect.right;
|
|
|
|
vc->out_rect_vid.y0 = dst_rect.top;
|
|
|
|
vc->out_rect_vid.y1 = dst_rect.bottom;
|
|
|
|
vc->src_rect_vid.x0 = src_rect.left;
|
|
|
|
vc->src_rect_vid.x1 = src_rect.right;
|
2009-11-15 14:50:28 +01:00
|
|
|
vc->src_rect_vid.y0 = vc->flip ? src_rect.bottom : src_rect.top;
|
|
|
|
vc->src_rect_vid.y1 = vc->flip ? src_rect.top : src_rect.bottom;
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->border_x = borders.left;
|
|
|
|
vc->border_y = borders.top;
|
2009-02-16 21:58:13 +01:00
|
|
|
#ifdef CONFIG_FREETYPE
|
|
|
|
// adjust font size to display size
|
|
|
|
force_load_font = 1;
|
|
|
|
#endif
|
|
|
|
vo_osd_changed(OSDTYPE_OSD);
|
2010-02-05 19:13:33 +01:00
|
|
|
int flip_offset_ms = vo_fs ? vc->flip_offset_fs : vc->flip_offset_window;
|
|
|
|
vo->flip_queue_offset = flip_offset_ms / 1000.;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
bool had_frames = vc->num_shown_frames;
|
2009-05-09 17:08:30 +02:00
|
|
|
if (vc->output_surface_width < vo->dwidth
|
|
|
|
|| vc->output_surface_height < vo->dheight) {
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->output_surface_width < vo->dwidth) {
|
|
|
|
vc->output_surface_width += vc->output_surface_width >> 1;
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->output_surface_width = FFMAX(vc->output_surface_width,
|
|
|
|
vo->dwidth);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->output_surface_height < vo->dheight) {
|
|
|
|
vc->output_surface_height += vc->output_surface_height >> 1;
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->output_surface_height = FFMAX(vc->output_surface_height,
|
|
|
|
vo->dheight);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
// Creation of output_surfaces
|
2010-05-14 04:18:38 +02:00
|
|
|
for (i = 0; i <= vc->num_output_surfaces; i++) {
|
2010-05-26 07:54:09 +02:00
|
|
|
if (vc->output_surfaces[i] != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->output_surface_destroy(vc->output_surfaces[i]);
|
|
|
|
CHECK_ST_WARNING("Error when calling "
|
|
|
|
"vdp_output_surface_destroy");
|
|
|
|
}
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st = vdp->output_surface_create(vc->vdp_device,
|
|
|
|
VDP_RGBA_FORMAT_B8G8R8A8,
|
|
|
|
vc->output_surface_width,
|
|
|
|
vc->output_surface_height,
|
|
|
|
&vc->output_surfaces[i]);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_output_surface_create");
|
2011-07-04 23:48:41 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "vdpau out create: %u\n",
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->output_surfaces[i]);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->num_shown_frames = 0;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-11-15 03:39:22 +01:00
|
|
|
if (vc->paused && had_frames)
|
2009-09-18 23:00:42 +02:00
|
|
|
if (video_to_output_surface(vo) >= 0)
|
2009-11-15 03:39:22 +01:00
|
|
|
flip_page_timed(vo, 0, -1);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
static void preemption_callback(VdpDevice device, void *context)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = context;
|
|
|
|
vc->is_preempted = true;
|
|
|
|
vc->preemption_acked = false;
|
|
|
|
}
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
/* Initialize vdp_get_proc_address, called from preinit() */
|
2009-05-04 02:09:50 +02:00
|
|
|
static int win_x11_init_vdpau_procs(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-04 02:09:50 +02:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-09-07 01:02:24 +02:00
|
|
|
talloc_free(vc->vdp); // In case this is reinitialization after preemption
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdp_functions *vdp = talloc_zero(vc, struct vdp_functions);
|
|
|
|
vc->vdp = vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
|
|
|
struct vdp_function {
|
|
|
|
const int id;
|
2009-05-06 20:04:37 +02:00
|
|
|
int offset;
|
2009-02-16 21:58:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct vdp_function *dsc;
|
|
|
|
|
|
|
|
static const struct vdp_function vdp_func[] = {
|
2009-05-06 20:04:37 +02:00
|
|
|
#define VDP_FUNCTION(_, macro_name, mp_name) {macro_name, offsetof(struct vdp_functions, mp_name)},
|
2009-05-05 23:17:21 +02:00
|
|
|
#include "vdpau_template.c"
|
|
|
|
#undef VDP_FUNCTION
|
2009-05-06 20:04:37 +02:00
|
|
|
{0, -1}
|
2009-02-16 21:58:13 +01:00
|
|
|
};
|
|
|
|
|
2010-12-20 05:42:04 +01:00
|
|
|
vdp_st = vdp_device_create_x11(x11->display, x11->screen, &vc->vdp_device,
|
2009-05-09 17:08:30 +02:00
|
|
|
&vc->vdp_get_proc_address);
|
2009-02-16 21:58:13 +01:00
|
|
|
if (vdp_st != VDP_STATUS_OK) {
|
2009-05-09 17:08:30 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling "
|
|
|
|
"vdp_device_create_x11: %i\n", vdp_st);
|
2009-02-16 21:58:13 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
vdp->get_error_string = NULL;
|
|
|
|
for (dsc = vdp_func; dsc->offset >= 0; dsc++) {
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vc->vdp_get_proc_address(vc->vdp_device, dsc->id,
|
2009-05-06 20:04:37 +02:00
|
|
|
(void **)((char *)vdp + dsc->offset));
|
2009-02-16 21:58:13 +01:00
|
|
|
if (vdp_st != VDP_STATUS_OK) {
|
2009-05-09 17:08:30 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error when calling "
|
|
|
|
"vdp_get_proc_address(function id %d): %s\n", dsc->id,
|
|
|
|
vdp->get_error_string ? vdp->get_error_string(vdp_st) : "?");
|
2009-02-16 21:58:13 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2009-09-07 01:02:24 +02:00
|
|
|
vdp_st = vdp->preemption_callback_register(vc->vdp_device,
|
|
|
|
preemption_callback, vc);
|
2009-02-16 21:58:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static int win_x11_init_vdpau_flip_queue(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-05-04 02:09:50 +02:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (vc->flip_target == VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->presentation_queue_target_create_x11(vc->vdp_device,
|
|
|
|
x11->window,
|
|
|
|
&vc->flip_target);
|
|
|
|
CHECK_ST_ERROR("Error when calling "
|
|
|
|
"vdp_presentation_queue_target_create_x11");
|
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
/* Emperically this seems to be the first call which fails when we
|
|
|
|
* try to reinit after preemption while the user is still switched
|
|
|
|
* from X to a virtual terminal (creating the vdp_device initially
|
|
|
|
* succeeds, as does creating the flip_target above). This is
|
|
|
|
* probably not guaranteed behavior, but we'll assume it as a simple
|
|
|
|
* way to reduce warnings while trying to recover from preemption.
|
|
|
|
*/
|
|
|
|
if (vc->flip_queue == VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->presentation_queue_create(vc->vdp_device, vc->flip_target,
|
|
|
|
&vc->flip_queue);
|
|
|
|
if (vc->is_preempted && vdp_st != VDP_STATUS_OK) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_DBG2, "[vdpau] Failed to create flip queue "
|
|
|
|
"while preempted: %s\n", vdp->get_error_string(vdp_st));
|
|
|
|
return -1;
|
|
|
|
} else
|
|
|
|
CHECK_ST_ERROR("Error when calling vdp_presentation_queue_create");
|
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
VdpTime vdp_time;
|
|
|
|
vdp_st = vdp->presentation_queue_get_time(vc->flip_queue, &vdp_time);
|
|
|
|
CHECK_ST_ERROR("Error when calling vdp_presentation_queue_get_time");
|
|
|
|
vc->last_vdp_time = vdp_time;
|
|
|
|
vc->last_sync_update = GetTimer();
|
|
|
|
|
|
|
|
vc->vsync_interval = 1;
|
|
|
|
if (vc->user_fps > 0) {
|
|
|
|
vc->vsync_interval = 1e9 / vc->user_fps;
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[vdpau] Assuming user-specified display "
|
|
|
|
"refresh rate of %.3f Hz.\n", vc->user_fps);
|
|
|
|
} else if (vc->user_fps == 0) {
|
|
|
|
#ifdef CONFIG_XF86VM
|
|
|
|
double fps = vo_vm_get_fps(vo);
|
|
|
|
if (!fps)
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] Failed to get display FPS\n");
|
|
|
|
else {
|
|
|
|
vc->vsync_interval = 1e9 / fps;
|
|
|
|
// This is verbose, but I'm not yet sure how common wrong values are
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO,
|
|
|
|
"[vdpau] Got display refresh rate %.3f Hz.\n"
|
|
|
|
"[vdpau] If that value looks wrong give the "
|
|
|
|
"-vo vdpau:fps=X suboption manually.\n", fps);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[vdpau] This binary has been compiled "
|
|
|
|
"without XF86VidMode support.\n");
|
|
|
|
mp_msg(MSGT_VO, MSGL_INFO, "[vdpau] Can't use vsync-aware timing "
|
|
|
|
"without manually provided -vo vdpau:fps=X suboption.\n");
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] framedrop/timing logic disabled by "
|
|
|
|
"user.\n");
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-17 05:18:14 +01:00
|
|
|
static int set_video_attribute(struct vdpctx *vc, VdpVideoMixerAttribute attr,
|
|
|
|
const void *value, char *attr_name)
|
|
|
|
{
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
|
|
|
vdp_st = vdp->video_mixer_set_attribute_values(vc->video_mixer, 1, &attr,
|
|
|
|
&value);
|
|
|
|
if (vdp_st != VDP_STATUS_OK) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Error setting video mixer "
|
|
|
|
"attribute %s: %s\n", attr_name, vdp->get_error_string(vdp_st));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-15 14:21:40 +01:00
|
|
|
static void update_csc_matrix(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] Updating CSC matrix\n");
|
2009-11-15 14:21:40 +01:00
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
// VdpCSCMatrix happens to be compatible with mplayer's CSC matrix type
|
|
|
|
// both are float[3][4]
|
2009-11-15 14:21:40 +01:00
|
|
|
VdpCSCMatrix matrix;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
|
|
|
|
struct mp_csp_params cparams = { .colorspace = vc->colorspace };
|
|
|
|
mp_csp_copy_equalizer_values(&cparams, &vc->video_eq);
|
|
|
|
mp_get_yuv2rgb_coeffs(&cparams, matrix);
|
2010-05-12 02:52:43 +02:00
|
|
|
|
2009-11-17 05:18:14 +01:00
|
|
|
set_video_attribute(vc, VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX,
|
|
|
|
&matrix, "CSC matrix");
|
2009-11-15 14:21:40 +01:00
|
|
|
}
|
|
|
|
|
2009-11-17 05:18:14 +01:00
|
|
|
#define SET_VIDEO_ATTR(attr_name, attr_type, value) set_video_attribute(vc, \
|
|
|
|
VDP_VIDEO_MIXER_ATTRIBUTE_ ## attr_name, &(attr_type){value},\
|
|
|
|
# attr_name)
|
2009-05-06 20:04:37 +02:00
|
|
|
static int create_vdp_mixer(struct vo *vo, VdpChromaType vdp_chroma_type)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
#define VDP_NUM_MIXER_PARAMETER 3
|
2009-11-15 17:39:48 +01:00
|
|
|
#define MAX_NUM_FEATURES 6
|
2009-02-20 10:45:48 +01:00
|
|
|
int i;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-09-07 01:02:24 +02:00
|
|
|
|
|
|
|
if (vc->video_mixer != VDP_INVALID_HANDLE)
|
|
|
|
return 0;
|
|
|
|
|
2009-02-20 10:45:48 +01:00
|
|
|
int feature_count = 0;
|
|
|
|
VdpVideoMixerFeature features[MAX_NUM_FEATURES];
|
|
|
|
VdpBool feature_enables[MAX_NUM_FEATURES];
|
2009-02-16 21:58:13 +01:00
|
|
|
static const VdpVideoMixerParameter parameters[VDP_NUM_MIXER_PARAMETER] = {
|
|
|
|
VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH,
|
|
|
|
VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT,
|
2009-05-09 17:08:30 +02:00
|
|
|
VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE,
|
2009-02-16 21:58:13 +01:00
|
|
|
};
|
|
|
|
const void *const parameter_values[VDP_NUM_MIXER_PARAMETER] = {
|
2009-05-06 22:42:24 +02:00
|
|
|
&vc->vid_width,
|
|
|
|
&vc->vid_height,
|
2009-05-09 17:08:30 +02:00
|
|
|
&vdp_chroma_type,
|
2009-02-16 21:58:13 +01:00
|
|
|
};
|
2009-03-15 22:26:10 +01:00
|
|
|
features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL;
|
2011-01-04 22:51:31 +01:00
|
|
|
if (vc->deint_type == 4)
|
2009-05-09 17:08:30 +02:00
|
|
|
features[feature_count++] =
|
|
|
|
VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->pullup)
|
2009-02-20 10:45:48 +01:00
|
|
|
features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_INVERSE_TELECINE;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->denoise)
|
2009-02-20 10:45:48 +01:00
|
|
|
features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->sharpen)
|
2009-02-20 10:45:48 +01:00
|
|
|
features[feature_count++] = VDP_VIDEO_MIXER_FEATURE_SHARPNESS;
|
2009-11-15 17:39:48 +01:00
|
|
|
if (vc->hqscaling) {
|
|
|
|
VdpVideoMixerFeature hqscaling_feature =
|
|
|
|
VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1 + vc->hqscaling-1;
|
|
|
|
VdpBool hqscaling_available;
|
|
|
|
vdp_st = vdp->video_mixer_query_feature_support(vc->vdp_device,
|
|
|
|
hqscaling_feature,
|
|
|
|
&hqscaling_available);
|
|
|
|
CHECK_ST_ERROR("Error when calling video_mixer_query_feature_support");
|
|
|
|
if (hqscaling_available)
|
|
|
|
features[feature_count++] = hqscaling_feature;
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Your hardware or VDPAU "
|
|
|
|
"library does not support requested hqscaling.\n");
|
2009-11-29 00:32:30 +01:00
|
|
|
}
|
2009-02-20 10:45:48 +01:00
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vdp->video_mixer_create(vc->vdp_device, feature_count, features,
|
2009-05-09 17:08:30 +02:00
|
|
|
VDP_NUM_MIXER_PARAMETER,
|
|
|
|
parameters, parameter_values,
|
|
|
|
&vc->video_mixer);
|
2009-05-08 19:57:22 +02:00
|
|
|
CHECK_ST_ERROR("Error when calling vdp_video_mixer_create");
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-09 17:08:30 +02:00
|
|
|
for (i = 0; i < feature_count; i++)
|
|
|
|
feature_enables[i] = VDP_TRUE;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->deint < 3)
|
2009-03-15 22:20:06 +01:00
|
|
|
feature_enables[0] = VDP_FALSE;
|
2011-01-04 22:51:31 +01:00
|
|
|
if (vc->deint_type == 4 && vc->deint < 4)
|
|
|
|
feature_enables[1] = VDP_FALSE;
|
2009-11-17 22:22:10 +01:00
|
|
|
if (feature_count) {
|
|
|
|
vdp_st = vdp->video_mixer_set_feature_enables(vc->video_mixer,
|
|
|
|
feature_count, features,
|
|
|
|
feature_enables);
|
|
|
|
CHECK_ST_WARNING("Error calling vdp_video_mixer_set_feature_enables");
|
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->denoise)
|
2009-11-17 05:18:14 +01:00
|
|
|
SET_VIDEO_ATTR(NOISE_REDUCTION_LEVEL, float, vc->denoise);
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->sharpen)
|
2009-11-17 05:18:14 +01:00
|
|
|
SET_VIDEO_ATTR(SHARPNESS_LEVEL, float, vc->sharpen);
|
2009-05-06 22:42:24 +02:00
|
|
|
if (!vc->chroma_deint)
|
2009-11-17 05:18:14 +01:00
|
|
|
SET_VIDEO_ATTR(SKIP_CHROMA_DEINTERLACE, uint8_t, 1);
|
2009-02-20 10:45:48 +01:00
|
|
|
|
2009-11-15 14:21:40 +01:00
|
|
|
update_csc_matrix(vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free everything specific to a certain video file
|
2009-05-06 20:04:37 +02:00
|
|
|
static void free_video_specific(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
int i;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->decoder != VDP_INVALID_HANDLE)
|
|
|
|
vdp->decoder_destroy(vc->decoder);
|
|
|
|
vc->decoder = VDP_INVALID_HANDLE;
|
|
|
|
vc->decoder_max_refs = -1;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-10-14 03:12:10 +02:00
|
|
|
forget_frames(vo);
|
2009-03-18 18:02:29 +01:00
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
for (i = 0; i < MAX_VIDEO_SURFACES; i++) {
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->surface_render[i].surface != VDP_INVALID_HANDLE) {
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st = vdp->video_surface_destroy(vc->surface_render[i].surface);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_video_surface_destroy");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->surface_render[i].surface = VDP_INVALID_HANDLE;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->video_mixer != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->video_mixer_destroy(vc->video_mixer);
|
2009-05-08 19:57:22 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_video_mixer_destroy");
|
2009-02-23 10:22:57 +01:00
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->video_mixer = VDP_INVALID_HANDLE;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static int create_vdp_decoder(struct vo *vo, int max_refs)
|
2009-03-21 18:10:19 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-03-21 18:10:19 +01:00
|
|
|
VdpStatus vdp_st;
|
|
|
|
VdpDecoderProfile vdp_decoder_profile;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->decoder != VDP_INVALID_HANDLE)
|
|
|
|
vdp->decoder_destroy(vc->decoder);
|
|
|
|
switch (vc->image_format) {
|
2010-10-29 17:43:31 +02:00
|
|
|
case IMGFMT_VDPAU_MPEG1:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG1;
|
|
|
|
break;
|
|
|
|
case IMGFMT_VDPAU_MPEG2:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG2_MAIN;
|
|
|
|
break;
|
|
|
|
case IMGFMT_VDPAU_H264:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_H264_HIGH;
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] Creating H264 hardware decoder "
|
|
|
|
"for %d reference frames.\n", max_refs);
|
|
|
|
break;
|
|
|
|
case IMGFMT_VDPAU_WMV3:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_MAIN;
|
|
|
|
break;
|
|
|
|
case IMGFMT_VDPAU_VC1:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
|
|
|
|
break;
|
|
|
|
case IMGFMT_VDPAU_MPEG4:
|
|
|
|
vdp_decoder_profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
|
|
|
|
break;
|
2010-10-29 17:38:22 +02:00
|
|
|
default:
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] Unknown image format!\n");
|
2010-12-20 05:42:04 +01:00
|
|
|
goto fail;
|
2009-03-21 18:10:19 +01:00
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vdp->decoder_create(vc->vdp_device, vdp_decoder_profile,
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->vid_width, vc->vid_height, max_refs,
|
|
|
|
&vc->decoder);
|
2009-03-21 18:10:19 +01:00
|
|
|
CHECK_ST_WARNING("Failed creating VDPAU decoder");
|
|
|
|
if (vdp_st != VDP_STATUS_OK) {
|
2010-10-29 17:38:22 +02:00
|
|
|
fail:
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->decoder = VDP_INVALID_HANDLE;
|
|
|
|
vc->decoder_max_refs = 0;
|
2009-03-21 20:59:35 +01:00
|
|
|
return 0;
|
2009-03-21 18:10:19 +01:00
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->decoder_max_refs = max_refs;
|
2009-03-21 20:59:35 +01:00
|
|
|
return 1;
|
2009-03-21 18:10:19 +01:00
|
|
|
}
|
|
|
|
|
2009-10-22 03:21:14 +02:00
|
|
|
static int initialize_vdpau_objects(struct vo *vo)
|
2009-09-07 01:02:24 +02:00
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
|
|
|
vc->vdp_chroma_type = VDP_CHROMA_TYPE_420;
|
|
|
|
switch (vc->image_format) {
|
2010-10-29 17:43:31 +02:00
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YV12;
|
|
|
|
break;
|
|
|
|
case IMGFMT_NV12:
|
|
|
|
vc->vdp_pixel_format = VDP_YCBCR_FORMAT_NV12;
|
|
|
|
break;
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
vc->vdp_pixel_format = VDP_YCBCR_FORMAT_YUYV;
|
|
|
|
vc->vdp_chroma_type = VDP_CHROMA_TYPE_422;
|
|
|
|
break;
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
vc->vdp_pixel_format = VDP_YCBCR_FORMAT_UYVY;
|
|
|
|
vc->vdp_chroma_type = VDP_CHROMA_TYPE_422;
|
2009-09-07 01:02:24 +02:00
|
|
|
}
|
|
|
|
if (win_x11_init_vdpau_flip_queue(vo) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (create_vdp_mixer(vo, vc->vdp_chroma_type) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
vdp_st = vdp->
|
|
|
|
bitmap_surface_query_capabilities(vc->vdp_device,
|
|
|
|
VDP_RGBA_FORMAT_A8,
|
|
|
|
&(VdpBool){0},
|
|
|
|
&vc->eosd_surface.max_width,
|
|
|
|
&vc->eosd_surface.max_height);
|
|
|
|
CHECK_ST_WARNING("Query to get max EOSD surface size failed");
|
2009-09-18 15:27:55 +02:00
|
|
|
forget_frames(vo);
|
2009-09-07 01:02:24 +02:00
|
|
|
resize(vo);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mark_vdpau_objects_uninitialized(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
|
|
|
vc->decoder = VDP_INVALID_HANDLE;
|
|
|
|
for (int i = 0; i < MAX_VIDEO_SURFACES; i++)
|
|
|
|
vc->surface_render[i].surface = VDP_INVALID_HANDLE;
|
2009-09-18 15:27:55 +02:00
|
|
|
forget_frames(vo);
|
2009-09-07 01:02:24 +02:00
|
|
|
vc->video_mixer = VDP_INVALID_HANDLE;
|
|
|
|
vc->flip_queue = VDP_INVALID_HANDLE;
|
|
|
|
vc->flip_target = VDP_INVALID_HANDLE;
|
2010-05-26 07:54:09 +02:00
|
|
|
for (int i = 0; i <= MAX_OUTPUT_SURFACES; i++)
|
2009-09-07 01:02:24 +02:00
|
|
|
vc->output_surfaces[i] = VDP_INVALID_HANDLE;
|
|
|
|
vc->vdp_device = VDP_INVALID_HANDLE;
|
|
|
|
vc->eosd_surface = (struct eosd_bitmap_surface){
|
|
|
|
.surface = VDP_INVALID_HANDLE,
|
|
|
|
};
|
|
|
|
vc->output_surface_width = vc->output_surface_height = -1;
|
|
|
|
vc->eosd_render_count = 0;
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->num_shown_frames = 0;
|
2009-09-07 01:02:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_preemption(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
|
|
|
|
if (!vc->is_preempted)
|
|
|
|
return 0;
|
|
|
|
if (!vc->preemption_acked)
|
|
|
|
mark_vdpau_objects_uninitialized(vo);
|
|
|
|
vc->preemption_acked = true;
|
|
|
|
if (!vc->preemption_user_notified) {
|
|
|
|
mp_tmsg(MSGT_VO, MSGL_ERR, "[vdpau] Got display preemption notice! "
|
|
|
|
"Will attempt to recover.\n");
|
|
|
|
vc->preemption_user_notified = true;
|
|
|
|
}
|
|
|
|
/* Trying to initialize seems to be quite slow, so only try once a
|
|
|
|
* second to avoid using 100% CPU. */
|
|
|
|
if (vc->last_preemption_retry_fail
|
|
|
|
&& GetTimerMS() - vc->last_preemption_retry_fail < 1000)
|
|
|
|
return -1;
|
|
|
|
if (win_x11_init_vdpau_procs(vo) < 0 || initialize_vdpau_objects(vo) < 0) {
|
|
|
|
vc->last_preemption_retry_fail = GetTimerMS() | 1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vc->last_preemption_retry_fail = 0;
|
|
|
|
vc->is_preempted = false;
|
|
|
|
vc->preemption_user_notified = false;
|
|
|
|
mp_tmsg(MSGT_VO, MSGL_INFO, "[vdpau] Recovered from display preemption.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
/*
|
|
|
|
* connect to X server, create and map window, initialize all
|
|
|
|
* VDPAU objects, create different surfaces etc.
|
|
|
|
*/
|
2009-05-04 02:09:50 +02:00
|
|
|
static int config(struct vo *vo, uint32_t width, uint32_t height,
|
|
|
|
uint32_t d_width, uint32_t d_height, uint32_t flags,
|
|
|
|
char *title, uint32_t format)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 22:42:24 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-05-04 02:09:50 +02:00
|
|
|
struct vo_x11_state *x11 = vo->x11;
|
2009-02-16 21:58:13 +01:00
|
|
|
XVisualInfo vinfo;
|
|
|
|
XSetWindowAttributes xswa;
|
|
|
|
XWindowAttributes attribs;
|
|
|
|
unsigned long xswamask;
|
|
|
|
int depth;
|
|
|
|
|
|
|
|
#ifdef CONFIG_XF86VM
|
|
|
|
int vm = flags & VOFLAG_MODESWITCHING;
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return -1;
|
2009-11-15 14:50:28 +01:00
|
|
|
|
|
|
|
vc->flip = flags & VOFLAG_FLIPPING;
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->image_format = format;
|
|
|
|
vc->vid_width = width;
|
|
|
|
vc->vid_height = height;
|
2009-05-06 20:04:37 +02:00
|
|
|
free_video_specific(vo);
|
2009-05-06 22:42:24 +02:00
|
|
|
if (IMGFMT_IS_VDPAU(vc->image_format) && !create_vdp_decoder(vo, 2))
|
2009-03-23 00:58:40 +01:00
|
|
|
return -1;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_XF86VM
|
2009-05-08 20:49:52 +02:00
|
|
|
if (vm) {
|
|
|
|
vo_vm_switch(vo);
|
|
|
|
vc->mode_switched = true;
|
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
#endif
|
2009-05-08 20:49:52 +02:00
|
|
|
XGetWindowAttributes(x11->display, DefaultRootWindow(x11->display),
|
|
|
|
&attribs);
|
|
|
|
depth = attribs.depth;
|
|
|
|
if (depth != 15 && depth != 16 && depth != 24 && depth != 32)
|
|
|
|
depth = 24;
|
|
|
|
XMatchVisualInfo(x11->display, x11->screen, depth, TrueColor, &vinfo);
|
|
|
|
|
|
|
|
xswa.background_pixel = 0;
|
|
|
|
xswa.border_pixel = 0;
|
|
|
|
/* Do not use CWBackPixel: It leads to VDPAU errors after
|
|
|
|
* aspect ratio changes. */
|
|
|
|
xswamask = CWBorderPixel;
|
|
|
|
|
|
|
|
vo_x11_create_vo_window(vo, &vinfo, vo->dx, vo->dy, d_width, d_height,
|
|
|
|
flags, CopyFromParent, "vdpau", title);
|
|
|
|
XChangeWindowAttributes(x11->display, x11->window, xswamask, &xswa);
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_XF86VM
|
2009-05-08 20:49:52 +02:00
|
|
|
if (vm) {
|
|
|
|
/* Grab the mouse pointer in our window */
|
|
|
|
if (vo_grabpointer)
|
|
|
|
XGrabPointer(x11->display, x11->window, True, 0,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
x11->window, None, CurrentTime);
|
|
|
|
XSetInputFocus(x11->display, x11->window, RevertToNone, CurrentTime);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-05-08 20:49:52 +02:00
|
|
|
#endif
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
if ((flags & VOFLAG_FULLSCREEN) && WinID <= 0)
|
|
|
|
vo_fs = 1;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (initialize_vdpau_objects(vo) < 0)
|
2009-02-16 21:58:13 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static void check_events(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return;
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
int e = vo_x11_check_events(vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
if (e & VO_EVENT_RESIZE)
|
2009-05-04 02:09:50 +02:00
|
|
|
resize(vo);
|
2009-09-18 23:00:42 +02:00
|
|
|
else if (e & VO_EVENT_EXPOSE && vc->paused) {
|
2009-02-16 21:58:13 +01:00
|
|
|
/* did we already draw a buffer */
|
2009-11-15 03:39:22 +01:00
|
|
|
if (vc->num_shown_frames) {
|
2009-02-16 21:58:13 +01:00
|
|
|
/* redraw the last visible buffer */
|
|
|
|
VdpStatus vdp_st;
|
2010-05-06 03:46:10 +02:00
|
|
|
int last_surface = WRAP_ADD(vc->surface_num, -1,
|
2010-05-14 04:18:38 +02:00
|
|
|
vc->num_output_surfaces);
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vdp->presentation_queue_display(vc->flip_queue,
|
2009-09-18 23:00:42 +02:00
|
|
|
vc->output_surfaces[last_surface],
|
2009-05-09 17:08:30 +02:00
|
|
|
vo->dwidth, vo->dheight, 0);
|
|
|
|
CHECK_ST_WARNING("Error when calling "
|
|
|
|
"vdp_presentation_queue_display");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static void draw_osd_I8A8(void *ctx, int x0, int y0, int w, int h,
|
|
|
|
unsigned char *src, unsigned char *srca, int stride)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vo *vo = ctx;
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-05-06 22:42:24 +02:00
|
|
|
VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num];
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-05-09 17:08:30 +02:00
|
|
|
int i;
|
2009-02-16 21:58:13 +01:00
|
|
|
int pitch;
|
|
|
|
int index_data_size_required;
|
|
|
|
VdpRect output_indexed_rect_vid;
|
|
|
|
|
|
|
|
if (!w || !h)
|
|
|
|
return;
|
|
|
|
|
|
|
|
index_data_size_required = 2*w*h;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->index_data_size < index_data_size_required) {
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->index_data = talloc_realloc_size(vc, vc->index_data,
|
|
|
|
index_data_size_required);
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->index_data_size = index_data_size_required;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// index_data creation, component order - I, A, I, A, .....
|
|
|
|
for (i = 0; i < h; i++)
|
2009-05-09 17:08:30 +02:00
|
|
|
for (int j = 0; j < w; j++) {
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->index_data[i*2*w + j*2] = src [i*stride+j];
|
|
|
|
vc->index_data[i*2*w + j*2 + 1] = -srca[i*stride+j];
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
output_indexed_rect_vid.x0 = x0;
|
|
|
|
output_indexed_rect_vid.y0 = y0;
|
|
|
|
output_indexed_rect_vid.x1 = x0 + w;
|
|
|
|
output_indexed_rect_vid.y1 = y0 + h;
|
|
|
|
|
|
|
|
pitch = w*2;
|
|
|
|
|
2009-02-25 13:01:00 +01:00
|
|
|
// write source_data to osd_surface.
|
2010-05-14 04:18:38 +02:00
|
|
|
VdpOutputSurface osd_surface = vc->output_surfaces[vc->num_output_surfaces];
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st = vdp->
|
|
|
|
output_surface_put_bits_indexed(osd_surface, VDP_INDEXED_FORMAT_I8A8,
|
|
|
|
(const void *const*)&vc->index_data,
|
|
|
|
&pitch, &output_indexed_rect_vid,
|
|
|
|
VDP_COLOR_TABLE_FORMAT_B8G8R8X8,
|
|
|
|
(void *)vc->palette);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_output_surface_put_bits_indexed");
|
|
|
|
|
|
|
|
VdpOutputSurfaceRenderBlendState blend_state = {
|
|
|
|
.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION,
|
|
|
|
.blend_factor_source_color =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
|
|
|
|
.blend_factor_source_alpha =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
|
|
|
|
.blend_factor_destination_color =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.blend_factor_destination_alpha =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
|
|
|
|
.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
|
|
|
|
};
|
|
|
|
|
|
|
|
vdp_st = vdp->
|
|
|
|
output_surface_render_output_surface(output_surface,
|
|
|
|
&output_indexed_rect_vid,
|
|
|
|
osd_surface,
|
|
|
|
&output_indexed_rect_vid,
|
|
|
|
NULL, &blend_state,
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
|
|
|
|
CHECK_ST_WARNING("Error when calling "
|
|
|
|
"vdp_output_surface_render_output_surface");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static void draw_eosd(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-23 10:21:57 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-05-06 22:42:24 +02:00
|
|
|
VdpOutputSurface output_surface = vc->output_surfaces[vc->surface_num];
|
2009-02-23 10:21:57 +01:00
|
|
|
int i;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return;
|
|
|
|
|
2009-05-09 17:08:30 +02:00
|
|
|
VdpOutputSurfaceRenderBlendState blend_state = {
|
|
|
|
.struct_version = VDP_OUTPUT_SURFACE_RENDER_BLEND_STATE_VERSION,
|
|
|
|
.blend_factor_source_color =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA,
|
|
|
|
.blend_factor_source_alpha =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE,
|
|
|
|
.blend_factor_destination_color =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.blend_factor_destination_alpha =
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_BLEND_FACTOR_SRC_ALPHA,
|
|
|
|
.blend_equation_color = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
|
|
|
|
.blend_equation_alpha = VDP_OUTPUT_SURFACE_RENDER_BLEND_EQUATION_ADD,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < vc->eosd_render_count; i++) {
|
|
|
|
vdp_st = vdp->
|
|
|
|
output_surface_render_bitmap_surface(output_surface,
|
|
|
|
&vc->eosd_targets[i].dest,
|
2009-09-02 19:21:24 +02:00
|
|
|
vc->eosd_surface.surface,
|
2009-05-09 17:08:30 +02:00
|
|
|
&vc->eosd_targets[i].source,
|
|
|
|
&vc->eosd_targets[i].color,
|
|
|
|
&blend_state,
|
|
|
|
VDP_OUTPUT_SURFACE_RENDER_ROTATE_0);
|
2009-05-08 19:57:22 +02:00
|
|
|
CHECK_ST_WARNING("EOSD: Error when rendering");
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 19:21:24 +02:00
|
|
|
#define HEIGHT_SORT_BITS 4
|
|
|
|
static int size_index(struct eosd_target *r)
|
|
|
|
{
|
|
|
|
unsigned int h = r->source.y1;
|
|
|
|
int n = av_log2_16bit(h);
|
|
|
|
return (n << HEIGHT_SORT_BITS)
|
|
|
|
+ (- 1 - (h << HEIGHT_SORT_BITS >> n) & (1 << HEIGHT_SORT_BITS) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pack the given rectangles into an area of size w * h.
|
|
|
|
* The size of each rectangle is read from .source.x1/.source.y1.
|
|
|
|
* The height of each rectangle must be at least 1 and less than 65536.
|
|
|
|
* The .source rectangle is then set corresponding to the packed position.
|
|
|
|
* 'scratch' must point to work memory for num_rects+16 ints.
|
|
|
|
* Return 0 on success, -1 if the rectangles did not fit in w*h.
|
|
|
|
*
|
|
|
|
* The rectangles are placed in rows in order approximately sorted by
|
|
|
|
* height (the approximate sorting is simpler than a full one would be,
|
|
|
|
* and allows the algorithm to work in linear time). Additionally, to
|
|
|
|
* reduce wasted space when there are a few tall rectangles, empty
|
|
|
|
* lower-right parts of rows are filled recursively when the size of
|
|
|
|
* rectangles in the row drops past a power-of-two threshold. So if a
|
|
|
|
* row starts with rectangles of size 3x50, 10x40 and 5x20 then the
|
|
|
|
* free rectangle with corners (13, 20)-(w, 50) is filled recursively.
|
|
|
|
*/
|
|
|
|
static int pack_rectangles(struct eosd_target *rects, int num_rects,
|
2010-12-20 05:42:04 +01:00
|
|
|
int w, int h, int *scratch)
|
2009-09-02 19:21:24 +02:00
|
|
|
{
|
|
|
|
int bins[16 << HEIGHT_SORT_BITS];
|
|
|
|
int sizes[16 << HEIGHT_SORT_BITS] = {};
|
|
|
|
for (int i = 0; i < num_rects; i++)
|
|
|
|
sizes[size_index(rects + i)]++;
|
|
|
|
int idx = 0;
|
|
|
|
for (int i = 0; i < 16 << HEIGHT_SORT_BITS; i += 1 << HEIGHT_SORT_BITS) {
|
|
|
|
for (int j = 0; j < 1 << HEIGHT_SORT_BITS; j++) {
|
|
|
|
bins[i + j] = idx;
|
|
|
|
idx += sizes[i + j];
|
|
|
|
}
|
|
|
|
scratch[idx++] = -1;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < num_rects; i++)
|
|
|
|
scratch[bins[size_index(rects + i)]++] = i;
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
bins[i] = bins[i << HEIGHT_SORT_BITS] - sizes[i << HEIGHT_SORT_BITS];
|
|
|
|
struct {
|
|
|
|
int size, x, bottom;
|
|
|
|
} stack[16] = {{15, 0, h}}, s = {};
|
|
|
|
int stackpos = 1;
|
|
|
|
int y;
|
|
|
|
while (stackpos) {
|
|
|
|
y = s.bottom;
|
|
|
|
s = stack[--stackpos];
|
|
|
|
s.size++;
|
|
|
|
while (s.size--) {
|
|
|
|
int maxy = -1;
|
|
|
|
int obj;
|
|
|
|
while ((obj = scratch[bins[s.size]]) >= 0) {
|
|
|
|
int bottom = y + rects[obj].source.y1;
|
|
|
|
if (bottom > s.bottom)
|
|
|
|
break;
|
|
|
|
int right = s.x + rects[obj].source.x1;
|
|
|
|
if (right > w)
|
|
|
|
break;
|
|
|
|
bins[s.size]++;
|
|
|
|
rects[obj].source.x0 = s.x;
|
|
|
|
rects[obj].source.x1 += s.x;
|
|
|
|
rects[obj].source.y0 = y;
|
|
|
|
rects[obj].source.y1 += y;
|
|
|
|
num_rects--;
|
|
|
|
if (maxy <= 0)
|
|
|
|
stack[stackpos++] = s;
|
|
|
|
s.x = right;
|
|
|
|
maxy = FFMAX(maxy, bottom);
|
|
|
|
}
|
|
|
|
if (maxy > 0)
|
|
|
|
s.bottom = maxy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_rects ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-23 10:21:57 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-09-02 19:21:24 +02:00
|
|
|
int i;
|
2009-08-06 22:58:31 +02:00
|
|
|
ASS_Image *img = imgs->imgs;
|
2009-08-29 20:21:16 +02:00
|
|
|
ASS_Image *p;
|
2009-09-02 19:21:24 +02:00
|
|
|
struct eosd_bitmap_surface *sfc = &vc->eosd_surface;
|
|
|
|
bool need_upload = false;
|
2009-02-23 10:21:57 +01:00
|
|
|
|
|
|
|
if (imgs->changed == 0)
|
2009-05-09 17:08:30 +02:00
|
|
|
return; // Nothing changed, no need to redraw
|
|
|
|
|
2009-05-06 22:49:51 +02:00
|
|
|
vc->eosd_render_count = 0;
|
2009-05-09 17:08:30 +02:00
|
|
|
|
2009-02-23 10:21:57 +01:00
|
|
|
if (!img)
|
2009-05-09 17:08:30 +02:00
|
|
|
return; // There's nothing to render!
|
2009-02-23 10:21:57 +01:00
|
|
|
|
|
|
|
if (imgs->changed == 1)
|
|
|
|
goto eosd_skip_upload;
|
|
|
|
|
2009-09-02 19:21:24 +02:00
|
|
|
need_upload = true;
|
|
|
|
bool reallocate = false;
|
|
|
|
while (1) {
|
|
|
|
for (p = img, i = 0; p; p = p->next) {
|
|
|
|
if (p->w <= 0 || p->h <= 0)
|
|
|
|
continue;
|
2009-02-23 10:21:57 +01:00
|
|
|
// Allocate new space for surface/target arrays
|
2009-09-02 19:21:24 +02:00
|
|
|
if (i >= vc->eosd_targets_size) {
|
|
|
|
vc->eosd_targets_size = FFMAX(vc->eosd_targets_size * 2, 512);
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->eosd_targets =
|
|
|
|
talloc_realloc_size(vc, vc->eosd_targets,
|
2009-09-02 19:21:24 +02:00
|
|
|
vc->eosd_targets_size
|
2009-05-09 17:08:30 +02:00
|
|
|
* sizeof(*vc->eosd_targets));
|
2009-09-02 19:21:24 +02:00
|
|
|
vc->eosd_scratch =
|
|
|
|
talloc_realloc_size(vc, vc->eosd_scratch,
|
|
|
|
(vc->eosd_targets_size + 16)
|
|
|
|
* sizeof(*vc->eosd_scratch));
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
2009-09-02 19:21:24 +02:00
|
|
|
vc->eosd_targets[i].source.x1 = p->w;
|
|
|
|
vc->eosd_targets[i].source.y1 = p->h;
|
|
|
|
i++;
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
2009-09-02 19:21:24 +02:00
|
|
|
if (pack_rectangles(vc->eosd_targets, i, sfc->w, sfc->h,
|
|
|
|
vc->eosd_scratch) >= 0)
|
|
|
|
break;
|
|
|
|
int w = FFMIN(FFMAX(sfc->w * 2, EOSD_SURFACE_INITIAL_SIZE),
|
|
|
|
sfc->max_width);
|
|
|
|
int h = FFMIN(FFMAX(sfc->h * 2, EOSD_SURFACE_INITIAL_SIZE),
|
|
|
|
sfc->max_height);
|
|
|
|
if (w == sfc->w && h == sfc->h) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] EOSD bitmaps do not fit on "
|
|
|
|
"a surface with the maximum supported size\n");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
sfc->w = w;
|
|
|
|
sfc->h = h;
|
|
|
|
}
|
|
|
|
reallocate = true;
|
|
|
|
}
|
|
|
|
if (reallocate) {
|
2010-05-26 07:54:09 +02:00
|
|
|
if (sfc->surface != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->bitmap_surface_destroy(sfc->surface);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy");
|
|
|
|
}
|
2009-09-02 19:21:24 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] Allocating a %dx%d surface for "
|
|
|
|
"EOSD bitmaps.\n", sfc->w, sfc->h);
|
|
|
|
vdp_st = vdp->bitmap_surface_create(vc->vdp_device, VDP_RGBA_FORMAT_A8,
|
|
|
|
sfc->w, sfc->h, true,
|
|
|
|
&sfc->surface);
|
|
|
|
if (vdp_st != VDP_STATUS_OK)
|
|
|
|
sfc->surface = VDP_INVALID_HANDLE;
|
|
|
|
CHECK_ST_WARNING("EOSD: error when creating surface");
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
eosd_skip_upload:
|
2009-09-02 19:21:24 +02:00
|
|
|
if (sfc->surface == VDP_INVALID_HANDLE)
|
|
|
|
return;
|
2009-05-09 17:08:30 +02:00
|
|
|
for (p = img; p; p = p->next) {
|
2009-09-02 19:21:24 +02:00
|
|
|
if (p->w <= 0 || p->h <= 0)
|
|
|
|
continue;
|
2009-05-09 17:08:30 +02:00
|
|
|
struct eosd_target *target = &vc->eosd_targets[vc->eosd_render_count];
|
2009-09-02 19:21:24 +02:00
|
|
|
if (need_upload) {
|
|
|
|
vdp_st = vdp->
|
|
|
|
bitmap_surface_put_bits_native(sfc->surface,
|
|
|
|
(const void *) &p->bitmap,
|
|
|
|
&p->stride, &target->source);
|
|
|
|
CHECK_ST_WARNING("EOSD: putbits failed");
|
|
|
|
}
|
|
|
|
// Render dest, color, etc.
|
2009-05-09 17:08:30 +02:00
|
|
|
target->color.alpha = 1.0 - ((p->color >> 0) & 0xff) / 255.0;
|
|
|
|
target->color.blue = ((p->color >> 8) & 0xff) / 255.0;
|
|
|
|
target->color.green = ((p->color >> 16) & 0xff) / 255.0;
|
|
|
|
target->color.red = ((p->color >> 24) & 0xff) / 255.0;
|
|
|
|
target->dest.x0 = p->dst_x;
|
|
|
|
target->dest.y0 = p->dst_y;
|
|
|
|
target->dest.x1 = p->w + p->dst_x;
|
|
|
|
target->dest.y1 = p->h + p->dst_y;
|
2009-05-06 22:49:51 +02:00
|
|
|
vc->eosd_render_count++;
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static void draw_osd(struct vo *vo, struct osd_state *osd)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 22:42:24 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return;
|
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
osd_draw_text_ext(osd, vo->dwidth, vo->dheight, vc->border_x, vc->border_y,
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->border_x, vc->border_y, vc->vid_width,
|
|
|
|
vc->vid_height, draw_osd_I8A8, vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2010-05-14 04:18:38 +02:00
|
|
|
static int update_presentation_queue_status(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-05-09 17:08:30 +02:00
|
|
|
|
2010-05-14 04:18:38 +02:00
|
|
|
while (vc->query_surface_num != vc->surface_num) {
|
|
|
|
VdpTime vtime;
|
|
|
|
VdpPresentationQueueStatus status;
|
|
|
|
VdpOutputSurface surface = vc->output_surfaces[vc->query_surface_num];
|
|
|
|
vdp_st = vdp->presentation_queue_query_surface_status(vc->flip_queue,
|
|
|
|
surface,
|
|
|
|
&status, &vtime);
|
|
|
|
CHECK_ST_WARNING("Error calling "
|
|
|
|
"presentation_queue_query_surface_status");
|
|
|
|
if (status == VDP_PRESENTATION_QUEUE_STATUS_QUEUED)
|
|
|
|
break;
|
|
|
|
if (vc->vsync_interval > 1) {
|
|
|
|
uint64_t qtime = vc->queue_time[vc->query_surface_num];
|
|
|
|
if (vtime < qtime + vc->vsync_interval / 2)
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] Frame shown too early\n");
|
|
|
|
if (vtime > qtime + vc->vsync_interval)
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vdpau] Frame shown late\n");
|
|
|
|
}
|
|
|
|
vc->query_surface_num = WRAP_ADD(vc->query_surface_num, 1,
|
|
|
|
vc->num_output_surfaces);
|
|
|
|
vc->recent_vsync_time = vtime;
|
|
|
|
}
|
|
|
|
int num_queued = WRAP_ADD(vc->surface_num, -vc->query_surface_num,
|
|
|
|
vc->num_output_surfaces);
|
2011-07-04 23:48:41 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG3, "[vdpau] Queued surface count (before add): "
|
2010-05-14 04:18:38 +02:00
|
|
|
"%d\n", num_queued);
|
|
|
|
return num_queued;
|
2009-11-15 03:39:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t prev_vs2(struct vdpctx *vc, uint64_t ts, int shift)
|
|
|
|
{
|
|
|
|
uint64_t offset = ts - vc->recent_vsync_time;
|
|
|
|
// Fix negative values for 1<<shift vsyncs before vc->recent_vsync_time
|
|
|
|
offset += (uint64_t)vc->vsync_interval << shift;
|
|
|
|
offset %= vc->vsync_interval;
|
|
|
|
return ts - offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void flip_page_timed(struct vo *vo, unsigned int pts_us, int duration)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
uint32_t vsync_interval = vc->vsync_interval;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return;
|
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
if (duration > INT_MAX / 1000)
|
|
|
|
duration = -1;
|
|
|
|
else
|
|
|
|
duration *= 1000;
|
|
|
|
|
|
|
|
if (vc->user_fps < 0)
|
|
|
|
duration = -1; // Make sure drop logic is disabled
|
|
|
|
|
|
|
|
uint64_t now = sync_vdptime(vo);
|
|
|
|
uint64_t pts = pts_us ? convert_to_vdptime(vo, pts_us) : now;
|
|
|
|
uint64_t ideal_pts = pts;
|
|
|
|
uint64_t npts = duration >= 0 ? pts + duration : UINT64_MAX;
|
|
|
|
|
|
|
|
#define PREV_VS2(ts, shift) prev_vs2(vc, ts, shift)
|
|
|
|
// Only gives accurate results for ts >= vc->recent_vsync_time
|
|
|
|
#define PREV_VSYNC(ts) PREV_VS2(ts, 0)
|
|
|
|
|
|
|
|
/* We hope to be here at least one vsync before the frame should be shown.
|
|
|
|
* If we are running late then don't drop the frame unless there is
|
|
|
|
* already one queued for the next vsync; even if we _hope_ to show the
|
|
|
|
* next frame soon enough to mean this one should be dropped we might
|
|
|
|
* not make the target time in reality. Without this check we could drop
|
|
|
|
* every frame, freezing the display completely if video lags behind.
|
|
|
|
*/
|
2010-05-06 03:46:10 +02:00
|
|
|
if (now > PREV_VSYNC(FFMAX(pts, vc->last_queue_time + vsync_interval)))
|
2009-11-15 03:39:22 +01:00
|
|
|
npts = UINT64_MAX;
|
|
|
|
|
|
|
|
/* Allow flipping a frame at a vsync if its presentation time is a
|
|
|
|
* bit after that vsync and the change makes the flip time delta
|
|
|
|
* from previous frame better match the target timestamp delta.
|
|
|
|
* This avoids instability with frame timestamps falling near vsyncs.
|
|
|
|
* For example if the frame timestamps were (with vsyncs at
|
|
|
|
* integer values) 0.01, 1.99, 4.01, 5.99, 8.01, ... then
|
|
|
|
* straightforward timing at next vsync would flip the frames at
|
|
|
|
* 1, 2, 5, 6, 9; this changes it to 1, 2, 4, 6, 8 and so on with
|
|
|
|
* regular 2-vsync intervals.
|
|
|
|
*
|
|
|
|
* Also allow moving the frame forward if it looks like we dropped
|
|
|
|
* the previous frame incorrectly (now that we know better after
|
|
|
|
* having final exact timestamp information for this frame) and
|
|
|
|
* there would unnecessarily be a vsync without a frame change.
|
|
|
|
*/
|
|
|
|
uint64_t vsync = PREV_VSYNC(pts);
|
|
|
|
if (pts < vsync + vsync_interval / 4
|
|
|
|
&& (vsync - PREV_VS2(vc->last_queue_time, 16)
|
|
|
|
> pts - vc->last_ideal_time + vsync_interval / 2
|
|
|
|
|| vc->dropped_frame && vsync > vc->dropped_time))
|
|
|
|
pts -= vsync_interval / 2;
|
|
|
|
|
|
|
|
vc->dropped_frame = true; // changed at end if false
|
|
|
|
vc->dropped_time = ideal_pts;
|
|
|
|
|
|
|
|
pts = FFMAX(pts, vc->last_queue_time + vsync_interval);
|
|
|
|
pts = FFMAX(pts, now);
|
|
|
|
if (npts < PREV_VSYNC(pts) + vsync_interval)
|
|
|
|
return;
|
|
|
|
|
2010-05-14 04:18:38 +02:00
|
|
|
int num_flips = update_presentation_queue_status(vo);
|
|
|
|
vsync = vc->recent_vsync_time + num_flips * vc->vsync_interval;
|
2009-11-15 03:39:22 +01:00
|
|
|
now = sync_vdptime(vo);
|
|
|
|
pts = FFMAX(pts, now);
|
2010-05-14 04:18:38 +02:00
|
|
|
pts = FFMAX(pts, vsync + (vsync_interval >> 2));
|
2009-11-15 03:39:22 +01:00
|
|
|
vsync = PREV_VSYNC(pts);
|
|
|
|
if (npts < vsync + vsync_interval)
|
|
|
|
return;
|
|
|
|
pts = vsync + (vsync_interval >> 2);
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st =
|
|
|
|
vdp->presentation_queue_display(vc->flip_queue,
|
|
|
|
vc->output_surfaces[vc->surface_num],
|
2009-11-15 03:39:22 +01:00
|
|
|
vo->dwidth, vo->dheight, pts);
|
2009-05-09 17:08:30 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_presentation_queue_display");
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->last_queue_time = pts;
|
2010-05-14 04:18:38 +02:00
|
|
|
vc->queue_time[vc->surface_num] = pts;
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->last_ideal_time = ideal_pts;
|
|
|
|
vc->dropped_frame = false;
|
2010-05-14 04:18:38 +02:00
|
|
|
vc->surface_num = WRAP_ADD(vc->surface_num, 1, vc->num_output_surfaces);
|
2009-11-15 03:39:22 +01:00
|
|
|
vc->num_shown_frames = FFMIN(vc->num_shown_frames + 1, 1000);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static int draw_slice(struct vo *vo, uint8_t *image[], int stride[], int w,
|
|
|
|
int h, int x, int y)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-09-07 01:02:24 +02:00
|
|
|
|
|
|
|
if (handle_preemption(vo) < 0)
|
|
|
|
return VO_TRUE;
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
struct vdpau_render_state *rndr = (struct vdpau_render_state *)image[0];
|
2009-05-09 17:08:30 +02:00
|
|
|
int max_refs = vc->image_format == IMGFMT_VDPAU_H264 ?
|
|
|
|
rndr->info.h264.num_ref_frames : 2;
|
2009-05-06 22:42:24 +02:00
|
|
|
if (!IMGFMT_IS_VDPAU(vc->image_format))
|
2009-02-16 21:58:13 +01:00
|
|
|
return VO_FALSE;
|
2009-05-06 22:42:24 +02:00
|
|
|
if ((vc->decoder == VDP_INVALID_HANDLE || vc->decoder_max_refs < max_refs)
|
2009-05-06 20:04:37 +02:00
|
|
|
&& !create_vdp_decoder(vo, max_refs))
|
2009-03-21 18:10:19 +01:00
|
|
|
return VO_FALSE;
|
2009-07-07 01:26:13 +02:00
|
|
|
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st = vdp->decoder_render(vc->decoder, rndr->surface,
|
|
|
|
(void *)&rndr->info,
|
|
|
|
rndr->bitstream_buffers_used,
|
|
|
|
rndr->bitstream_buffers);
|
2009-02-16 21:58:13 +01:00
|
|
|
CHECK_ST_WARNING("Failed VDPAU decoder rendering");
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static struct vdpau_render_state *get_surface(struct vo *vo, int number)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
if (number > MAX_VIDEO_SURFACES)
|
|
|
|
return NULL;
|
2009-09-07 01:02:24 +02:00
|
|
|
if (vc->surface_render[number].surface == VDP_INVALID_HANDLE
|
|
|
|
&& !vc->is_preempted) {
|
2009-02-16 21:58:13 +01:00
|
|
|
VdpStatus vdp_st;
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vdp->video_surface_create(vc->vdp_device, vc->vdp_chroma_type,
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->vid_width, vc->vid_height,
|
|
|
|
&vc->surface_render[number].surface);
|
2009-05-08 19:57:22 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_video_surface_create");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2011-07-04 23:48:41 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_DBG3, "vdpau vid create: %u\n",
|
2009-05-09 17:08:30 +02:00
|
|
|
vc->surface_render[number].surface);
|
2009-05-06 22:42:24 +02:00
|
|
|
return &vc->surface_render[number];
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-09-18 15:27:55 +02:00
|
|
|
static void draw_image(struct vo *vo, mp_image_t *mpi, double pts)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
2009-09-18 15:27:55 +02:00
|
|
|
struct mp_image *reserved_mpi = NULL;
|
|
|
|
struct vdpau_render_state *rndr;
|
|
|
|
|
|
|
|
if (vc->is_preempted) {
|
|
|
|
vo->frame_loaded = true;
|
|
|
|
return;
|
|
|
|
}
|
2009-05-06 20:04:37 +02:00
|
|
|
|
2009-05-06 22:42:24 +02:00
|
|
|
if (IMGFMT_IS_VDPAU(vc->image_format)) {
|
2009-09-18 15:27:55 +02:00
|
|
|
rndr = mpi->priv;
|
|
|
|
reserved_mpi = mpi;
|
2009-02-16 21:58:13 +01:00
|
|
|
} else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
|
2009-09-18 15:27:55 +02:00
|
|
|
rndr = get_surface(vo, vc->deint_counter);
|
2010-05-06 03:46:10 +02:00
|
|
|
vc->deint_counter = WRAP_ADD(vc->deint_counter, 1, NUM_BUFFERED_VIDEO);
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->image_format == IMGFMT_NV12)
|
2009-03-30 23:17:42 +02:00
|
|
|
destdata[1] = destdata[2];
|
2009-05-09 17:08:30 +02:00
|
|
|
vdp_st =
|
|
|
|
vdp->video_surface_put_bits_y_cb_cr(rndr->surface,
|
|
|
|
vc->vdp_pixel_format,
|
|
|
|
(const void *const*)destdata,
|
|
|
|
mpi->stride); // pitch
|
2009-09-18 15:27:55 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling "
|
2010-12-20 05:42:04 +01:00
|
|
|
"vdp_video_surface_put_bits_y_cb_cr");
|
2009-09-18 15:27:55 +02:00
|
|
|
} else
|
|
|
|
// We don't support slice callbacks so this shouldn't occur -
|
|
|
|
// I think the flags test above in pointless, but I'm adding
|
|
|
|
// this instead of removing it just in case.
|
|
|
|
abort();
|
2009-03-29 13:15:22 +02:00
|
|
|
if (mpi->fields & MP_IMGFIELD_ORDERED)
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->top_field_first = !!(mpi->fields & MP_IMGFIELD_TOP_FIRST);
|
2009-03-29 13:15:22 +02:00
|
|
|
else
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->top_field_first = 1;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2010-12-13 17:50:22 +01:00
|
|
|
add_new_video_surface(vo, rndr->surface, reserved_mpi, pts);
|
2009-09-18 15:27:55 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static uint32_t get_image(struct vo *vo, mp_image_t *mpi)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 22:42:24 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-02-16 21:58:13 +01:00
|
|
|
struct vdpau_render_state *rndr;
|
|
|
|
|
|
|
|
// no dr for non-decoding for now
|
2009-05-09 17:08:30 +02:00
|
|
|
if (!IMGFMT_IS_VDPAU(vc->image_format))
|
|
|
|
return VO_FALSE;
|
|
|
|
if (mpi->type != MP_IMGTYPE_NUMBERED)
|
|
|
|
return VO_FALSE;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
rndr = get_surface(vo, mpi->number);
|
2009-02-16 21:58:13 +01:00
|
|
|
if (!rndr) {
|
2009-05-09 17:08:30 +02:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] no surfaces available in "
|
|
|
|
"get_image\n");
|
2009-02-16 21:58:13 +01:00
|
|
|
// TODO: this probably breaks things forever, provide a dummy buffer?
|
|
|
|
return VO_FALSE;
|
|
|
|
}
|
|
|
|
mpi->flags |= MP_IMGFLAG_DIRECT;
|
|
|
|
mpi->stride[0] = mpi->stride[1] = mpi->stride[2] = 0;
|
|
|
|
mpi->planes[0] = mpi->planes[1] = mpi->planes[2] = NULL;
|
|
|
|
// hack to get around a check and to avoid a special-case in vd_ffmpeg.c
|
|
|
|
mpi->planes[0] = (void *)rndr;
|
|
|
|
mpi->num_planes = 1;
|
|
|
|
mpi->priv = rndr;
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int query_format(uint32_t format)
|
|
|
|
{
|
2009-05-09 17:08:30 +02:00
|
|
|
int default_flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW
|
|
|
|
| VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_OSD | VFCAP_EOSD
|
2009-11-15 14:50:28 +01:00
|
|
|
| VFCAP_EOSD_UNSCALED | VFCAP_FLIP;
|
2009-02-16 21:58:13 +01:00
|
|
|
switch (format) {
|
2010-10-29 17:43:31 +02:00
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_NV12:
|
|
|
|
case IMGFMT_YUY2:
|
|
|
|
case IMGFMT_UYVY:
|
|
|
|
return default_flags | VOCAP_NOSLICES;
|
|
|
|
case IMGFMT_VDPAU_MPEG1:
|
|
|
|
case IMGFMT_VDPAU_MPEG2:
|
|
|
|
case IMGFMT_VDPAU_H264:
|
|
|
|
case IMGFMT_VDPAU_WMV3:
|
|
|
|
case IMGFMT_VDPAU_VC1:
|
|
|
|
case IMGFMT_VDPAU_MPEG4:
|
|
|
|
return default_flags;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static void destroy_vdpau_objects(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
int i;
|
|
|
|
VdpStatus vdp_st;
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
free_video_specific(vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-08 19:57:22 +02:00
|
|
|
if (vc->flip_queue != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->presentation_queue_destroy(vc->flip_queue);
|
2009-05-09 17:08:30 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_presentation_queue_destroy");
|
2009-05-08 19:57:22 +02:00
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-08 19:57:22 +02:00
|
|
|
if (vc->flip_target != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->presentation_queue_target_destroy(vc->flip_target);
|
2009-05-09 17:08:30 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling "
|
|
|
|
"vdp_presentation_queue_target_destroy");
|
2009-05-08 19:57:22 +02:00
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2010-05-14 04:18:38 +02:00
|
|
|
for (i = 0; i <= vc->num_output_surfaces; i++) {
|
2009-05-08 19:57:22 +02:00
|
|
|
if (vc->output_surfaces[i] == VDP_INVALID_HANDLE)
|
|
|
|
continue;
|
2009-05-06 22:42:24 +02:00
|
|
|
vdp_st = vdp->output_surface_destroy(vc->output_surfaces[i]);
|
2009-05-09 17:08:30 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_output_surface_destroy");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 19:21:24 +02:00
|
|
|
if (vc->eosd_surface.surface != VDP_INVALID_HANDLE) {
|
|
|
|
vdp_st = vdp->bitmap_surface_destroy(vc->eosd_surface.surface);
|
2009-05-09 17:08:30 +02:00
|
|
|
CHECK_ST_WARNING("Error when calling vdp_bitmap_surface_destroy");
|
2009-02-23 10:21:57 +01:00
|
|
|
}
|
|
|
|
|
2009-05-08 20:48:01 +02:00
|
|
|
vdp_st = vdp->device_destroy(vc->vdp_device);
|
|
|
|
CHECK_ST_WARNING("Error when calling vdp_device_destroy");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static void uninit(struct vo *vo)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 22:42:24 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
/* Destroy all vdpau objects */
|
2009-05-06 20:04:37 +02:00
|
|
|
destroy_vdpau_objects(vo);
|
2009-02-23 10:21:57 +01:00
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
#ifdef CONFIG_XF86VM
|
2009-05-08 20:48:01 +02:00
|
|
|
if (vc->mode_switched)
|
|
|
|
vo_vm_close(vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
#endif
|
2009-05-04 02:09:50 +02:00
|
|
|
vo_x11_uninit(vo);
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-11-15 14:41:25 +01:00
|
|
|
// Free bitstream buffers allocated by FFmpeg
|
|
|
|
for (int i = 0; i < MAX_VIDEO_SURFACES; i++)
|
|
|
|
av_freep(&vc->surface_render[i].bitstream_buffers);
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static int preinit(struct vo *vo, const char *arg)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
|
|
|
int i;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
int user_colorspace = 0;
|
|
|
|
int studio_levels = 0;
|
2009-05-06 20:04:37 +02:00
|
|
|
|
|
|
|
struct vdpctx *vc = talloc_zero(vo, struct vdpctx);
|
|
|
|
vo->priv = vc;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2009-05-08 20:48:01 +02:00
|
|
|
// Mark everything as invalid first so uninit() can tell what has been
|
|
|
|
// allocated
|
2009-09-07 01:02:24 +02:00
|
|
|
mark_vdpau_objects_uninitialized(vo);
|
2009-05-08 20:48:01 +02:00
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
vc->colorspace = (struct mp_csp_details) MP_CSP_DETAILS_DEFAULTS;
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->deint_type = 3;
|
|
|
|
vc->chroma_deint = 1;
|
2010-02-05 19:13:33 +01:00
|
|
|
vc->flip_offset_window = 50;
|
|
|
|
vc->flip_offset_fs = 50;
|
2010-05-14 04:18:38 +02:00
|
|
|
vc->num_output_surfaces = 3;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
vc->video_eq.capabilities = MP_CSP_EQ_CAPS_COLORMATRIX;
|
2009-05-06 22:42:24 +02:00
|
|
|
const opt_t subopts[] = {
|
2011-01-04 22:51:31 +01:00
|
|
|
{"deint", OPT_ARG_INT, &vc->deint, NULL},
|
2009-05-06 22:42:24 +02:00
|
|
|
{"chroma-deint", OPT_ARG_BOOL, &vc->chroma_deint, NULL},
|
|
|
|
{"pullup", OPT_ARG_BOOL, &vc->pullup, NULL},
|
|
|
|
{"denoise", OPT_ARG_FLOAT, &vc->denoise, NULL},
|
|
|
|
{"sharpen", OPT_ARG_FLOAT, &vc->sharpen, NULL},
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
{"colorspace", OPT_ARG_INT, &user_colorspace, NULL},
|
|
|
|
{"studio", OPT_ARG_BOOL, &studio_levels, NULL},
|
2009-11-15 17:39:48 +01:00
|
|
|
{"hqscaling", OPT_ARG_INT, &vc->hqscaling, NULL},
|
2009-11-15 03:39:22 +01:00
|
|
|
{"fps", OPT_ARG_FLOAT, &vc->user_fps, NULL},
|
2010-02-05 19:13:33 +01:00
|
|
|
{"queuetime_windowed", OPT_ARG_INT, &vc->flip_offset_window, NULL},
|
|
|
|
{"queuetime_fs", OPT_ARG_INT, &vc->flip_offset_fs, NULL},
|
2010-05-14 04:18:38 +02:00
|
|
|
{"output_surfaces", OPT_ARG_INT, &vc->num_output_surfaces, NULL},
|
2009-05-06 22:42:24 +02:00
|
|
|
{NULL}
|
|
|
|
};
|
2009-11-15 23:50:01 +01:00
|
|
|
if (subopt_parse(arg, subopts) != 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "[vdpau] Could not parse suboptions.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (vc->hqscaling < 0 || vc->hqscaling > 9) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "[vdpau] Invalid value for suboption "
|
|
|
|
"hqscaling\n");
|
2009-02-20 10:45:48 +01:00
|
|
|
return -1;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2010-05-14 04:18:38 +02:00
|
|
|
if (vc->num_output_surfaces < 2) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, "[vdpau] Invalid suboption "
|
|
|
|
"output_surfaces: can't use less than 2 surfaces\n");
|
|
|
|
return -1;
|
|
|
|
}
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
if (user_colorspace != 0 || studio_levels != 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vdpau] \"colorspace\" and \"studio\""
|
|
|
|
" suboptions have been removed. Use options --colormatrix and"
|
|
|
|
" --colormatrix-output-range=limited instead.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-05-14 04:18:38 +02:00
|
|
|
if (vc->num_output_surfaces > MAX_OUTPUT_SURFACES) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] Number of output surfaces "
|
|
|
|
"is limited to %d.\n", MAX_OUTPUT_SURFACES);
|
|
|
|
vc->num_output_surfaces = MAX_OUTPUT_SURFACES;
|
|
|
|
}
|
2009-05-06 22:42:24 +02:00
|
|
|
if (vc->deint)
|
2011-01-04 22:51:31 +01:00
|
|
|
vc->deint_type = FFABS(vc->deint);
|
|
|
|
if (vc->deint < 0)
|
|
|
|
vc->deint = 0;
|
2009-02-16 21:58:13 +01:00
|
|
|
|
2010-02-26 17:37:19 +01:00
|
|
|
if (!vo_init(vo))
|
2009-02-16 21:58:13 +01:00
|
|
|
return -1;
|
|
|
|
|
2009-05-08 20:48:01 +02:00
|
|
|
// After this calling uninit() should work to free resources
|
|
|
|
|
|
|
|
if (win_x11_init_vdpau_procs(vo) < 0) {
|
|
|
|
if (vc->vdp->device_destroy)
|
|
|
|
vc->vdp->device_destroy(vc->vdp_device);
|
|
|
|
vo_x11_uninit(vo);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-16 21:58:13 +01:00
|
|
|
|
|
|
|
// full grayscale palette.
|
|
|
|
for (i = 0; i < PALETTE_SIZE; ++i)
|
2009-05-06 22:42:24 +02:00
|
|
|
vc->palette[i] = (i << 16) | (i << 8) | i;
|
2009-02-23 10:21:57 +01:00
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static int get_equalizer(struct vo *vo, const char *name, int *value)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
return mp_csp_equalizer_get(&vc->video_eq, name, value) >= 0 ?
|
|
|
|
VO_TRUE : VO_NOTIMPL;
|
2009-02-28 14:20:01 +01:00
|
|
|
}
|
|
|
|
|
2011-08-11 20:13:34 +02:00
|
|
|
static bool status_ok(struct vo *vo)
|
|
|
|
{
|
|
|
|
if (!vo->config_ok || handle_preemption(vo) < 0)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-06 20:04:37 +02:00
|
|
|
static int set_equalizer(struct vo *vo, const char *name, int value)
|
|
|
|
{
|
|
|
|
struct vdpctx *vc = vo->priv;
|
2009-02-28 14:20:01 +01:00
|
|
|
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
if (mp_csp_equalizer_set(&vc->video_eq, name, value) < 0)
|
2009-02-28 14:20:01 +01:00
|
|
|
return VO_NOTIMPL;
|
|
|
|
|
2011-08-11 20:13:34 +02:00
|
|
|
if (status_ok(vo))
|
|
|
|
update_csc_matrix(vo);
|
2009-11-15 14:21:40 +01:00
|
|
|
return true;
|
2009-02-28 14:20:01 +01:00
|
|
|
}
|
|
|
|
|
2011-08-11 20:13:34 +02:00
|
|
|
static void checked_resize(struct vo *vo)
|
|
|
|
{
|
|
|
|
if (!status_ok(vo))
|
|
|
|
return;
|
|
|
|
resize(vo);
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
2009-02-16 21:58:13 +01:00
|
|
|
{
|
2009-05-06 20:04:37 +02:00
|
|
|
struct vdpctx *vc = vo->priv;
|
|
|
|
struct vdp_functions *vdp = vc->vdp;
|
|
|
|
|
2009-09-07 01:02:24 +02:00
|
|
|
handle_preemption(vo);
|
|
|
|
|
2009-02-16 21:58:13 +01:00
|
|
|
switch (request) {
|
2009-09-05 05:20:03 +02:00
|
|
|
case VOCTRL_GET_DEINTERLACE:
|
2010-12-20 05:42:04 +01:00
|
|
|
*(int *)data = vc->deint;
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_DEINTERLACE:
|
2010-12-20 05:42:04 +01:00
|
|
|
vc->deint = *(int *)data;
|
2009-09-05 05:20:03 +02:00
|
|
|
if (vc->deint)
|
|
|
|
vc->deint = vc->deint_type;
|
2011-08-11 20:13:34 +02:00
|
|
|
if (vc->deint_type > 2 && status_ok(vo)) {
|
2009-09-05 05:20:03 +02:00
|
|
|
VdpStatus vdp_st;
|
|
|
|
VdpVideoMixerFeature features[1] =
|
|
|
|
{vc->deint_type == 3 ?
|
|
|
|
VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL :
|
|
|
|
VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL_SPATIAL};
|
|
|
|
VdpBool feature_enables[1] = {vc->deint ? VDP_TRUE : VDP_FALSE};
|
|
|
|
vdp_st = vdp->video_mixer_set_feature_enables(vc->video_mixer,
|
|
|
|
1, features,
|
|
|
|
feature_enables);
|
|
|
|
CHECK_ST_WARNING("Error changing deinterlacing settings");
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_PAUSE:
|
2009-11-15 03:39:22 +01:00
|
|
|
if (vc->dropped_frame)
|
|
|
|
flip_page_timed(vo, 0, -1);
|
2009-09-05 05:20:03 +02:00
|
|
|
return (vc->paused = true);
|
|
|
|
case VOCTRL_RESUME:
|
|
|
|
return (vc->paused = false);
|
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*(uint32_t *)data);
|
|
|
|
case VOCTRL_GET_IMAGE:
|
|
|
|
return get_image(vo, data);
|
|
|
|
case VOCTRL_DRAW_IMAGE:
|
2009-09-18 15:27:55 +02:00
|
|
|
abort(); // draw_image() should get called directly
|
2009-09-05 05:20:03 +02:00
|
|
|
case VOCTRL_BORDER:
|
|
|
|
vo_x11_border(vo);
|
2011-08-11 20:13:34 +02:00
|
|
|
checked_resize(vo);
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_FULLSCREEN:
|
|
|
|
vo_x11_fullscreen(vo);
|
2011-08-11 20:13:34 +02:00
|
|
|
checked_resize(vo);
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_GET_PANSCAN:
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_PANSCAN:
|
2011-08-11 20:13:34 +02:00
|
|
|
checked_resize(vo);
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_EQUALIZER: {
|
|
|
|
struct voctrl_set_equalizer_args *args = data;
|
|
|
|
return set_equalizer(vo, args->name, args->value);
|
|
|
|
}
|
|
|
|
case VOCTRL_GET_EQUALIZER: {
|
|
|
|
struct voctrl_get_equalizer_args *args = data;
|
|
|
|
return get_equalizer(vo, args->name, args->valueptr);
|
|
|
|
}
|
2009-11-15 14:21:40 +01:00
|
|
|
case VOCTRL_SET_YUV_COLORSPACE:
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
vc->colorspace = *(struct mp_csp_details *)data;
|
2011-08-11 20:13:34 +02:00
|
|
|
if (status_ok(vo))
|
|
|
|
update_csc_matrix(vo);
|
2009-11-15 14:21:40 +01:00
|
|
|
return true;
|
|
|
|
case VOCTRL_GET_YUV_COLORSPACE:
|
video, options: implement better YUV->RGB conversion control
Rewrite control of the colorspace and input/output level parameters
used in YUV-RGB conversions, replacing VO-specific suboptions with new
common options and adding configuration support to more cases.
Add new option --colormatrix which selects the colorspace the original
video is assumed to have in YUV->RGB conversions. The default
behavior changes from assuming BT.601 to colorspace autoselection
between BT.601 and BT.709 using a simple heuristic based on video
size. Add new options --colormatrix-input-range and
--colormatrix-output-range which select input YUV and output RGB range.
Disable the previously existing VO-specific colorspace and level
conversion suboptions in vo_gl and vo_vdpau. Remove the
"yuv_colorspace" property and replace it with one named "colormatrix"
and semantics matching the new option. Add new properties matching the
options for level conversion.
Colorspace selection is currently supported by vo_gl, vo_vdpau, vo_xv
and vf_scale, and all can change it at runtime (previously only
vo_vdpau and vo_xv could). vo_vdpau now uses the same conversion
matrix generation as vo_gl instead of libvdpau functionality; the main
functional difference is that the "contrast" equalizer control behaves
somewhat differently (it scales the Y component around 1/2 instead of
around 0, so that contrast 0 makes the image gray rather than black).
vo_xv does not support level conversion. vf_scale supports range
setting for input, but always outputs full-range RGB.
The value of the slave properties is the policy setting used for
conversions. This means they can be set to any value regardless of
whether the current VO supports that value or whether there currently
even is any video. Possibly separate properties could be added to
query the conversion actually used at the moment, if any.
Because the colorspace and level settings are now set with a single
VF/VO control call, the return value of that is no longer used to
signal whether all the settings are actually supported. Instead code
should set all the details it can support, and ignore the rest. The
core will use GET_YUV_COLORSPACE to check which colorspace details
have been set and which not. In other words, the return value for
SET_YUV_COLORSPACE only signals whether any kind of YUV colorspace
conversion handling exists at all, and VOs have to take care to return
the actual state with GET_YUV_COLORSPACE instead.
To be changed in later commits: add missing option documentation.
2011-10-15 23:50:21 +02:00
|
|
|
*(struct mp_csp_details *)data = vc->colorspace;
|
2009-11-15 14:21:40 +01:00
|
|
|
return true;
|
2009-09-05 05:20:03 +02:00
|
|
|
case VOCTRL_ONTOP:
|
|
|
|
vo_x11_ontop(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
|
|
|
update_xinerama_info(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_DRAW_EOSD:
|
|
|
|
if (!data)
|
|
|
|
return VO_FALSE;
|
|
|
|
generate_eosd(vo, data);
|
|
|
|
draw_eosd(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_GET_EOSD_RES: {
|
2011-01-19 17:00:22 +01:00
|
|
|
struct mp_eosd_res *r = data;
|
2010-02-22 01:07:16 +01:00
|
|
|
r->w = vo->dwidth;
|
|
|
|
r->h = vo->dheight;
|
|
|
|
r->ml = r->mr = vc->border_x;
|
|
|
|
r->mt = r->mb = vc->border_y;
|
2009-09-05 05:20:03 +02:00
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2009-09-05 05:33:33 +02:00
|
|
|
case VOCTRL_REDRAW_OSD:
|
|
|
|
video_to_output_surface(vo);
|
|
|
|
draw_eosd(vo);
|
|
|
|
draw_osd(vo, data);
|
2009-11-15 03:39:22 +01:00
|
|
|
flip_page_timed(vo, 0, -1);
|
2009-09-05 05:33:33 +02:00
|
|
|
return true;
|
2009-09-18 15:27:55 +02:00
|
|
|
case VOCTRL_RESET:
|
|
|
|
forget_frames(vo);
|
|
|
|
return true;
|
2009-02-16 21:58:13 +01:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:09:50 +02:00
|
|
|
const struct vo_driver video_out_vdpau = {
|
2009-09-18 15:27:55 +02:00
|
|
|
.is_new = true,
|
|
|
|
.buffer_frames = true,
|
2009-05-06 21:21:19 +02:00
|
|
|
.info = &(const struct vo_info_s){
|
2009-05-04 02:09:50 +02:00
|
|
|
"VDPAU with X11",
|
|
|
|
"vdpau",
|
|
|
|
"Rajib Mahapatra <rmahapatra@nvidia.com> and others",
|
|
|
|
""
|
|
|
|
},
|
|
|
|
.preinit = preinit,
|
|
|
|
.config = config,
|
|
|
|
.control = control,
|
2009-09-18 15:27:55 +02:00
|
|
|
.draw_image = draw_image,
|
|
|
|
.get_buffered_frame = get_buffered_frame,
|
2009-05-04 02:09:50 +02:00
|
|
|
.draw_slice = draw_slice,
|
|
|
|
.draw_osd = draw_osd,
|
2009-11-15 03:39:22 +01:00
|
|
|
.flip_page_timed = flip_page_timed,
|
2009-05-04 02:09:50 +02:00
|
|
|
.check_events = check_events,
|
|
|
|
.uninit = uninit,
|
|
|
|
};
|