summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2009-09-19 00:28:17 +0300
committerUoti Urpala <uau@glyph.nonexistent.invalid>2009-09-19 00:28:17 +0300
commit3f215c9f8e4d5d95ac9b45376460391669906236 (patch)
tree1f675ef31908400c3411ace5182ca015c57000aa /libvo
parent82bbf1a1ab1affc675e9b69b93e33accfa2ed0b8 (diff)
parentc2d0a9c8a78b20ed8e96ff5a7d3e8c936b82cae1 (diff)
downloadmpv-3f215c9f8e4d5d95ac9b45376460391669906236.tar.bz2
mpv-3f215c9f8e4d5d95ac9b45376460391669906236.tar.xz
Merge branch 'vdpau' into build
* vdpau: (22 commits) VO: Prefer vo_vdpau over vo_xv again vo_vdpau: Fix X event handling bugs vo_vdpau: Fix memory corruption bug with MP_IMGTYPE_NUMBERED core/VO: Allow VO drivers to add/modify frames video_out.h: Cosmetics VO interface: Remove obsolete draw_frame() from new interface vo_vdpau: Support recovering from VDPAU display preemption vo_vdpau: Support updating OSD while paused vo_vdpau.c: Reindent control() switch statement vo_vdpau: Allocate one large surface for EOSD content vo_vdpau.c: cosmetics vo_vdpau: reindent after GUI code removal vo_vpdau: Clean up uninit logic vo_vdpau: Make CHECK_ST macro safer vo_vdpau: Move all remaining static/global variables to context vo_vdpau: Move things to context struct vo_vdpau: Make info struct const vo_vdpau: Replace global function table with context variable vo_vdpau: Move VDPAU interface pointers into one struct vo_vdpau: Add template file for VDPAU functions ...
Diffstat (limited to 'libvo')
-rw-r--r--libvo/vdpau_template.c39
-rw-r--r--libvo/video_out.c51
-rw-r--r--libvo/video_out.h174
-rw-r--r--libvo/video_out_internal.h1
-rw-r--r--libvo/vo_vdpau.c1864
-rw-r--r--libvo/vo_xv.c6
6 files changed, 1263 insertions, 872 deletions
diff --git a/libvo/vdpau_template.c b/libvo/vdpau_template.c
new file mode 100644
index 0000000000..ca1a6f6056
--- /dev/null
+++ b/libvo/vdpau_template.c
@@ -0,0 +1,39 @@
+
+/* List the VDPAU functions used by MPlayer.
+ * Generated by vdpau_functions.py.
+ * First argument on each line is the VDPAU function type name,
+ * second macro name needed to get function address,
+ * third name MPlayer uses for the function.
+ */
+
+VDP_FUNCTION(VdpGetErrorString, VDP_FUNC_ID_GET_ERROR_STRING, get_error_string)
+VDP_FUNCTION(VdpBitmapSurfaceCreate, VDP_FUNC_ID_BITMAP_SURFACE_CREATE, bitmap_surface_create)
+VDP_FUNCTION(VdpBitmapSurfaceDestroy, VDP_FUNC_ID_BITMAP_SURFACE_DESTROY, bitmap_surface_destroy)
+VDP_FUNCTION(VdpBitmapSurfacePutBitsNative, VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE, bitmap_surface_put_bits_native)
+VDP_FUNCTION(VdpBitmapSurfaceQueryCapabilities, VDP_FUNC_ID_BITMAP_SURFACE_QUERY_CAPABILITIES, bitmap_surface_query_capabilities)
+VDP_FUNCTION(VdpDecoderCreate, VDP_FUNC_ID_DECODER_CREATE, decoder_create)
+VDP_FUNCTION(VdpDecoderDestroy, VDP_FUNC_ID_DECODER_DESTROY, decoder_destroy)
+VDP_FUNCTION(VdpDecoderRender, VDP_FUNC_ID_DECODER_RENDER, decoder_render)
+VDP_FUNCTION(VdpDeviceDestroy, VDP_FUNC_ID_DEVICE_DESTROY, device_destroy)
+VDP_FUNCTION(VdpGenerateCSCMatrix, VDP_FUNC_ID_GENERATE_CSC_MATRIX, generate_csc_matrix)
+VDP_FUNCTION(VdpOutputSurfaceCreate, VDP_FUNC_ID_OUTPUT_SURFACE_CREATE, output_surface_create)
+VDP_FUNCTION(VdpOutputSurfaceDestroy, VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY, output_surface_destroy)
+VDP_FUNCTION(VdpOutputSurfacePutBitsIndexed, VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED, output_surface_put_bits_indexed)
+VDP_FUNCTION(VdpOutputSurfacePutBitsNative, VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE, output_surface_put_bits_native)
+VDP_FUNCTION(VdpOutputSurfaceRenderBitmapSurface, VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE, output_surface_render_bitmap_surface)
+VDP_FUNCTION(VdpOutputSurfaceRenderOutputSurface, VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE, output_surface_render_output_surface)
+VDP_FUNCTION(VdpPreemptionCallbackRegister, VDP_FUNC_ID_PREEMPTION_CALLBACK_REGISTER, preemption_callback_register)
+VDP_FUNCTION(VdpPresentationQueueBlockUntilSurfaceIdle, VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE, presentation_queue_block_until_surface_idle)
+VDP_FUNCTION(VdpPresentationQueueCreate, VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE, presentation_queue_create)
+VDP_FUNCTION(VdpPresentationQueueDestroy, VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY, presentation_queue_destroy)
+VDP_FUNCTION(VdpPresentationQueueDisplay, VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY, presentation_queue_display)
+VDP_FUNCTION(VdpPresentationQueueTargetCreateX11, VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11, presentation_queue_target_create_x11)
+VDP_FUNCTION(VdpPresentationQueueTargetDestroy, VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY, presentation_queue_target_destroy)
+VDP_FUNCTION(VdpVideoMixerCreate, VDP_FUNC_ID_VIDEO_MIXER_CREATE, video_mixer_create)
+VDP_FUNCTION(VdpVideoMixerDestroy, VDP_FUNC_ID_VIDEO_MIXER_DESTROY, video_mixer_destroy)
+VDP_FUNCTION(VdpVideoMixerRender, VDP_FUNC_ID_VIDEO_MIXER_RENDER, video_mixer_render)
+VDP_FUNCTION(VdpVideoMixerSetAttributeValues, VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES, video_mixer_set_attribute_values)
+VDP_FUNCTION(VdpVideoMixerSetFeatureEnables, VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES, video_mixer_set_feature_enables)
+VDP_FUNCTION(VdpVideoSurfaceCreate, VDP_FUNC_ID_VIDEO_SURFACE_CREATE, video_surface_create)
+VDP_FUNCTION(VdpVideoSurfaceDestroy, VDP_FUNC_ID_VIDEO_SURFACE_DESTROY, video_surface_destroy)
+VDP_FUNCTION(VdpVideoSurfacePutBitsYCbCr, VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR, video_surface_put_bits_y_cb_cr)
diff --git a/libvo/video_out.c b/libvo/video_out.c
index 01c04f3ca6..7a41fcf1d4 100644
--- a/libvo/video_out.c
+++ b/libvo/video_out.c
@@ -21,6 +21,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
+#include <stdbool.h>
#include <unistd.h>
//#include <sys/mman.h>
@@ -31,6 +33,7 @@
#include "video_out.h"
#include "aspect.h"
#include "geometry.h"
+#include "old_vo_wrapper.h"
#include "mp_msg.h"
#include "help_mp.h"
@@ -162,12 +165,12 @@ const struct vo_driver *video_out_drivers[] =
#ifdef CONFIG_3DFX
&video_out_3dfx,
#endif
-#ifdef CONFIG_XV
- &video_out_xv,
-#endif
#if CONFIG_VDPAU
&video_out_vdpau,
#endif
+#ifdef CONFIG_XV
+ &video_out_xv,
+#endif
#ifdef CONFIG_X11
&video_out_x11,
&video_out_xover,
@@ -276,11 +279,41 @@ int vo_control(struct vo *vo, uint32_t request, void *data)
return vo->driver->control(vo, request, data);
}
+// Return -1 if driver appears not to support a draw_image interface,
+// 0 otherwise (whether the driver actually drew something or not).
+int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts)
+{
+ if (!vo->config_ok)
+ return 0;
+ if (vo->driver->buffer_frames) {
+ vo->driver->draw_image(vo, mpi, pts);
+ return 0;
+ }
+ vo->frame_loaded = true;
+ vo->next_pts = pts;
+ if (vo_control(vo, VOCTRL_DRAW_IMAGE, mpi) == VO_NOTIMPL)
+ return -1;
+ return 0;
+}
+
+int vo_get_buffered_frame(struct vo *vo, bool eof)
+{
+ if (!vo->config_ok)
+ return -1;
+ if (vo->frame_loaded)
+ return 0;
+ if (!vo->driver->buffer_frames)
+ return -1;
+ vo->driver->get_buffered_frame(vo, eof);
+ return vo->frame_loaded ? 0 : -1;
+}
+
int vo_draw_frame(struct vo *vo, uint8_t *src[])
{
+ assert(!vo->driver->is_new);
if (!vo->config_ok)
return 0;
- return vo->driver->draw_frame(vo, src);
+ return old_vo_draw_frame(vo, src);
}
int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y)
@@ -299,6 +332,8 @@ void vo_flip_page(struct vo *vo)
{
if (!vo->config_ok)
return;
+ vo->frame_loaded = false;
+ vo->next_pts = (-1LL<<63); // MP_NOPTS_VALUE
vo->driver->flip_page(vo);
}
@@ -309,6 +344,14 @@ void vo_check_events(struct vo *vo)
vo->driver->check_events(vo);
}
+void vo_seek_reset(struct vo *vo)
+{
+ if (!vo->config_ok)
+ return;
+ vo_control(vo, VOCTRL_RESET, NULL);
+ vo->frame_loaded = false;
+}
+
void vo_destroy(struct vo *vo)
{
vo->driver->uninit(vo);
diff --git a/libvo/video_out.h b/libvo/video_out.h
index a55a2f87be..9bbfd3dc41 100644
--- a/libvo/video_out.h
+++ b/libvo/video_out.h
@@ -24,7 +24,7 @@
#define MPLAYER_VIDEO_OUT_H
#include <inttypes.h>
-#include <stdarg.h>
+#include <stdbool.h>
//#include "font_load.h"
#include "libmpcodecs/img_format.h"
@@ -117,91 +117,98 @@ typedef struct {
typedef struct vo_info_s
{
- /* driver name ("Matrox Millennium G200/G400" */
- const char *name;
- /* short name (for config strings) ("mga") */
- const char *short_name;
- /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
- const char *author;
- /* any additional comments */
- const char *comment;
+ /* driver name ("Matrox Millennium G200/G400" */
+ const char *name;
+ /* short name (for config strings) ("mga") */
+ const char *short_name;
+ /* author ("Aaron Holtzman <aholtzma@ess.engr.uvic.ca>") */
+ const char *author;
+ /* any additional comments */
+ const char *comment;
} vo_info_t;
struct vo;
struct osd_state;
+struct mp_image;
struct vo_driver {
- // Driver uses new API
- int is_new;
-
- // This is set if the driver is not new and contains pointers to
- // old-API functions to be used instead of the ones below.
- struct vo_old_functions *old_functions;
-
- const vo_info_t *info;
- /*
- * Preinitializes driver (real INITIALIZATION)
- * arg - currently it's vo_subdevice
- * returns: zero on successful initialization, non-zero on error.
- */
- int (*preinit)(struct vo *vo, const char *arg);
- /*
- * Initialize (means CONFIGURE) the display driver.
- * params:
- * width,height: image source size
- * d_width,d_height: size of the requested window size, just a hint
- * fullscreen: flag, 0=windowd 1=fullscreen, just a hint
- * title: window title, if available
- * format: fourcc of pixel format
- * returns : zero on successful initialization, non-zero on error.
- */
- int (*config)(struct vo *vo, uint32_t width, uint32_t height,
- uint32_t d_width, uint32_t d_height, uint32_t fullscreen,
- char *title, uint32_t format);
-
- /*
- * Control interface
- */
- int (*control)(struct vo *vo, uint32_t request, void *data);
-
- /*
- * Display a new RGB/BGR frame of the video to the screen.
- * params:
- * src[0] - pointer to the image
- */
- int (*draw_frame)(struct vo *vo, uint8_t *src[]);
-
- /*
- * Draw a planar YUV slice to the buffer:
- * params:
- * src[3] = source image planes (Y,U,V)
- * stride[3] = source image planes line widths (in bytes)
- * w,h = width*height of area to be copied (in Y pixels)
- * x,y = position at the destination image (in Y pixels)
- */
- int (*draw_slice)(struct vo *vo, uint8_t *src[], int stride[], int w,
- int h, int x, int y);
-
- /*
- * Draws OSD to the screen buffer
- */
- void (*draw_osd)(struct vo *vo, struct osd_state *osd);
-
- /*
- * Blit/Flip buffer to the screen. Must be called after each frame!
- */
- void (*flip_page)(struct vo *vo);
-
- /*
- * This func is called after every frames to handle keyboard and
- * other events. It's called in PAUSE mode too!
- */
- void (*check_events)(struct vo *vo);
-
- /*
- * Closes driver. Should restore the original state of the system.
- */
- void (*uninit)(struct vo *vo);
+ // Driver uses new API
+ bool is_new;
+ // Driver buffers or adds (deinterlace) frames and will keep track
+ // of pts values itself
+ bool buffer_frames;
+
+ // This is set if the driver is not new and contains pointers to
+ // old-API functions to be used instead of the ones below.
+ struct vo_old_functions *old_functions;
+
+ const vo_info_t *info;
+ /*
+ * Preinitializes driver (real INITIALIZATION)
+ * arg - currently it's vo_subdevice
+ * returns: zero on successful initialization, non-zero on error.
+ */
+ int (*preinit)(struct vo *vo, const char *arg);
+ /*
+ * Initialize (means CONFIGURE) the display driver.
+ * params:
+ * width,height: image source size
+ * d_width,d_height: size of the requested window size, just a hint
+ * fullscreen: flag, 0=windowd 1=fullscreen, just a hint
+ * title: window title, if available
+ * format: fourcc of pixel format
+ * returns : zero on successful initialization, non-zero on error.
+ */
+ int (*config)(struct vo *vo, uint32_t width, uint32_t height,
+ uint32_t d_width, uint32_t d_height, uint32_t fullscreen,
+ char *title, uint32_t format);
+
+ /*
+ * Control interface
+ */
+ int (*control)(struct vo *vo, uint32_t request, void *data);
+
+ void (*draw_image)(struct vo *vo, struct mp_image *mpi, double pts);
+
+ /*
+ * Get extra frames from the VO, such as those added by VDPAU
+ * deinterlace. Preparing the next such frame if any could be done
+ * automatically by the VO after a previous flip_page(), but having
+ * it as a separate step seems to allow making code more robust.
+ */
+ void (*get_buffered_frame)(struct vo *vo, bool eof);
+
+ /*
+ * Draw a planar YUV slice to the buffer:
+ * params:
+ * src[3] = source image planes (Y,U,V)
+ * stride[3] = source image planes line widths (in bytes)
+ * w,h = width*height of area to be copied (in Y pixels)
+ * x,y = position at the destination image (in Y pixels)
+ */
+ int (*draw_slice)(struct vo *vo, uint8_t *src[], int stride[], int w,
+ int h, int x, int y);
+
+ /*
+ * Draws OSD to the screen buffer
+ */
+ void (*draw_osd)(struct vo *vo, struct osd_state *osd);
+
+ /*
+ * Blit/Flip buffer to the screen. Must be called after each frame!
+ */
+ void (*flip_page)(struct vo *vo);
+
+ /*
+ * This func is called after every frames to handle keyboard and
+ * other events. It's called in PAUSE mode too!
+ */
+ void (*check_events)(struct vo *vo);
+
+ /*
+ * Closes driver. Should restore the original state of the system.
+ */
+ void (*uninit)(struct vo *vo);
};
struct vo_old_functions {
@@ -221,6 +228,10 @@ struct vo_old_functions {
struct vo {
int config_ok; // Last config call was successful?
int config_count; // Total number of successful config calls
+
+ bool frame_loaded; // Is there a next frame the VO could flip to?
+ double next_pts; // pts value of the next frame if any
+
const struct vo_driver *driver;
void *priv;
struct MPOpts *opts;
@@ -258,11 +269,14 @@ int vo_config(struct vo *vo, uint32_t width, uint32_t height,
void list_video_out(void);
int vo_control(struct vo *vo, uint32_t request, void *data);
+int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts);
+int vo_get_buffered_frame(struct vo *vo, bool eof);
int vo_draw_frame(struct vo *vo, uint8_t *src[]);
int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y);
void vo_draw_osd(struct vo *vo, struct osd_state *osd);
void vo_flip_page(struct vo *vo);
void vo_check_events(struct vo *vo);
+void vo_seek_reset(struct vo *vo);
void vo_destroy(struct vo *vo);
diff --git a/libvo/video_out_internal.h b/libvo/video_out_internal.h
index 166a91cc1c..8595d4ef05 100644
--- a/libvo/video_out_internal.h
+++ b/libvo/video_out_internal.h
@@ -50,7 +50,6 @@ static int preinit(const char *);
.preinit = old_vo_preinit,\
.config = old_vo_config,\
.control = old_vo_control,\
- .draw_frame = old_vo_draw_frame,\
.draw_slice = old_vo_draw_slice,\
.draw_osd = old_vo_draw_osd,\
.flip_page = old_vo_flip_page,\
diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c
index 486a6e699f..e613205834 100644
--- a/libvo/vo_vdpau.c
+++ b/libvo/vo_vdpau.c
@@ -20,58 +20,56 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/**
- * \defgroup VDPAU_Presentation VDPAU Presentation
- * \ingroup Decoder
- *
+/*
* 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>
+#include <stdlib.h>
#include <dlfcn.h>
+#include <stdint.h>
+#include <stdbool.h>
#include "config.h"
#include "mp_msg.h"
+#include "options.h"
+#include "talloc.h"
#include "video_out.h"
-#include "video_out_internal.h"
#include "x11_common.h"
#include "aspect.h"
#include "sub.h"
#include "subopt-helper.h"
-#include "font_load.h"
+#include "libmpcodecs/vfcap.h"
+#include "libmpcodecs/mp_image.h"
+#include "osdep/timer.h"
#include "libavcodec/vdpau.h"
+#include "font_load.h"
+
#include "libavutil/common.h"
#include "libavutil/mathematics.h"
#include "ass_mp.h"
-static vo_info_t info = {
- "VDPAU with X11",
- "vdpau",
- "Rajib Mahapatra <rmahapatra@nvidia.com> and others",
- ""
-};
-
-LIBVO_EXTERN(vdpau)
-
#define CHECK_ST_ERROR(message) \
- 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; \
- }
+ 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)
#define CHECK_ST_WARNING(message) \
- if (vdp_st != VDP_STATUS_OK) \
- mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] %s: %s\n", \
- message, vdp_get_error_string(vdp_st));
+ 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)
/* number of video and output surfaces */
#define NUM_OUTPUT_SURFACES 2
@@ -80,423 +78,456 @@ LIBVO_EXTERN(vdpau)
/* number of palette entries */
#define PALETTE_SIZE 256
-/* Initial maximum number of EOSD surfaces */
-#define EOSD_SURFACES_INITIAL 512
+/* Initial size of EOSD surface in pixels (x*x) */
+#define EOSD_SURFACE_INITIAL_SIZE 256
/*
* Global variable declaration - VDPAU specific
*/
-/* Declaration for all variables of win_x11_init_vdpau_procs() and
- * win_x11_init_vdpau_flip_queue() functions
- */
-static VdpDevice vdp_device;
-static VdpDeviceCreateX11 *vdp_device_create;
-static VdpGetProcAddress *vdp_get_proc_address;
+struct vdp_functions {
+#define VDP_FUNCTION(vdp_type, _, mp_name) vdp_type *mp_name;
+#include "vdpau_template.c"
+#undef VDP_FUNCTION
+};
-static VdpPresentationQueueTarget vdp_flip_target;
-static VdpPresentationQueue vdp_flip_queue;
+struct vdpctx {
+ struct vdp_functions *vdp;
+
+ VdpDevice vdp_device;
+ bool is_preempted;
+ bool preemption_acked;
+ bool preemption_user_notified;
+ unsigned int last_preemption_retry_fail;
+ VdpDeviceCreateX11 *vdp_device_create;
+ VdpGetProcAddress *vdp_get_proc_address;
+
+ VdpPresentationQueueTarget flip_target;
+ VdpPresentationQueue flip_queue;
+
+ void *vdpau_lib_handle;
+
+ /* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
+#define osd_surface vc->output_surfaces[NUM_OUTPUT_SURFACES]
+ VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1];
+ VdpVideoSurface deint_surfaces[3];
+ double deint_pts[3];
+ int deint_queue_pos;
+ mp_image_t *deint_mpi[3];
+ int output_surface_width, output_surface_height;
+
+ VdpVideoMixer video_mixer;
+ int deint;
+ int deint_type;
+ int deint_counter;
+ int pullup;
+ float denoise;
+ float sharpen;
+ int chroma_deint;
+ int top_field_first;
+
+ 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;
+ 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];
+
+ // EOSD
+ // Pool of surfaces
+ struct eosd_bitmap_surface {
+ VdpBitmapSurface surface;
+ int w;
+ int h;
+ uint32_t max_width;
+ uint32_t max_height;
+ } eosd_surface;
+
+ // List of surfaces to be rendered
+ struct eosd_target {
+ VdpRect source;
+ VdpRect dest;
+ VdpColor color;
+ } *eosd_targets;
+ int eosd_targets_size;
+ int *eosd_scratch;
+
+ int eosd_render_count;
+
+ // Video equalizer
+ VdpProcamp procamp;
+
+ bool visible_buf;
+ bool paused;
+
+ // These tell what's been initialized and uninit() should free/uninitialize
+ bool mode_switched;
+};
-static VdpDeviceDestroy *vdp_device_destroy;
-static VdpVideoSurfaceCreate *vdp_video_surface_create;
-static VdpVideoSurfaceDestroy *vdp_video_surface_destroy;
-static VdpGetErrorString *vdp_get_error_string;
+static void flip_page(struct vo *vo);
+static int video_to_output_surface(struct vo *vo)
+{
+ struct vdpctx *vc = vo->priv;
+ struct vdp_functions *vdp = vc->vdp;
+ VdpTime dummy;
+ VdpStatus vdp_st;
+ if (vc->deint_queue_pos < 0)
+ return -1;
-/* May be used in software filtering/postprocessing options
- * in MPlayer (./mplayer -vf ..) if we copy video_surface data to
- * system memory.
- */
-static VdpVideoSurfacePutBitsYCbCr *vdp_video_surface_put_bits_y_cb_cr;
-static VdpOutputSurfacePutBitsNative *vdp_output_surface_put_bits_native;
-
-static VdpOutputSurfaceCreate *vdp_output_surface_create;
-static VdpOutputSurfaceDestroy *vdp_output_surface_destroy;
-
-/* VideoMixer puts video_surface data on displayable output_surface. */
-static VdpVideoMixerCreate *vdp_video_mixer_create;
-static VdpVideoMixerDestroy *vdp_video_mixer_destroy;
-static VdpVideoMixerRender *vdp_video_mixer_render;
-static VdpVideoMixerSetFeatureEnables *vdp_video_mixer_set_feature_enables;
-static VdpVideoMixerSetAttributeValues *vdp_video_mixer_set_attribute_values;
-
-static VdpPresentationQueueTargetDestroy *vdp_presentation_queue_target_destroy;
-static VdpPresentationQueueCreate *vdp_presentation_queue_create;
-static VdpPresentationQueueDestroy *vdp_presentation_queue_destroy;
-static VdpPresentationQueueDisplay *vdp_presentation_queue_display;
-static VdpPresentationQueueBlockUntilSurfaceIdle *vdp_presentation_queue_block_until_surface_idle;
-static VdpPresentationQueueTargetCreateX11 *vdp_presentation_queue_target_create_x11;
-
-static VdpOutputSurfaceRenderOutputSurface *vdp_output_surface_render_output_surface;
-static VdpOutputSurfacePutBitsIndexed *vdp_output_surface_put_bits_indexed;
-static VdpOutputSurfaceRenderBitmapSurface *vdp_output_surface_render_bitmap_surface;
-
-static VdpBitmapSurfaceCreate *vdp_bitmap_surface_create;
-static VdpBitmapSurfaceDestroy *vdp_bitmap_surface_destroy;
-static VdpBitmapSurfacePutBitsNative *vdp_bitmap_surface_putbits_native;
-
-static VdpDecoderCreate *vdp_decoder_create;
-static VdpDecoderDestroy *vdp_decoder_destroy;
-static VdpDecoderRender *vdp_decoder_render;
-
-static VdpGenerateCSCMatrix *vdp_generate_csc_matrix;
-
-static void *vdpau_lib_handle;
-/* output_surfaces[NUM_OUTPUT_SURFACES] is misused for OSD. */
-#define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
-static VdpOutputSurface output_surfaces[NUM_OUTPUT_SURFACES + 1];
-static VdpVideoSurface deint_surfaces[3];
-static mp_image_t *deint_mpi[2];
-static int output_surface_width, output_surface_height;
-
-static VdpVideoMixer video_mixer;
-static int deint;
-static int deint_type;
-static int deint_counter;
-static int deint_buffer_past_frames;
-static int pullup;
-static float denoise;
-static float sharpen;
-static int chroma_deint;
-static int top_field_first;
-
-static VdpDecoder decoder;
-static int decoder_max_refs;
-
-static VdpRect src_rect_vid;
-static VdpRect out_rect_vid;
-static int border_x, border_y;
-
-static struct vdpau_render_state surface_render[MAX_VIDEO_SURFACES];
-static int surface_num;
-static int vid_surface_num;
-static uint32_t vid_width, vid_height;
-static uint32_t image_format;
-static VdpChromaType vdp_chroma_type;
-static VdpYCbCrFormat vdp_pixel_format;
-
-/* draw_osd */
-static unsigned char *index_data;
-static int index_data_size;
-static uint32_t palette[PALETTE_SIZE];
-
-// EOSD
-// Pool of surfaces
-struct {
- VdpBitmapSurface surface;
- int w;
- int h;
- char in_use;
-} *eosd_surfaces;
-
-// List of surfaces to be rendered
-struct {
- VdpBitmapSurface surface;
- VdpRect source;
- VdpRect dest;
- VdpColor color;
-} *eosd_targets;
-
-static int eosd_render_count;
-static int eosd_surface_count;
-
-// Video equalizer
-static VdpProcamp procamp;
+ 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;
+ }
+ VdpVideoSurface *q = vc->deint_surfaces;
+ const VdpVideoSurface *past_fields = (const VdpVideoSurface []){
+ q[(dp+1)/2], q[(dp+2)/2]};
+ const VdpVideoSurface *future_fields = (const VdpVideoSurface []){
+ q[(dp-1)/2]};
+ 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,
+ vc->deint_surfaces[dp/2], 1, future_fields,
+ &vc->src_rect_vid, output_surface,
+ NULL, &vc->out_rect_vid, 0, NULL);
+ CHECK_ST_WARNING("Error when calling vdp_video_mixer_render");
+ return 0;
+}
-/*
- * X11 specific
- */
-static int visible_buf;
-static int int_pause;
+static void add_new_video_surface(struct vo *vo, VdpVideoSurface surface,
+ struct mp_image *reserved_mpi, double pts)
+{
+ struct vdpctx *vc = vo->priv;
-static void draw_eosd(void);
+ if (reserved_mpi)
+ reserved_mpi->usage_count++;
+ if (vc->deint_mpi[2])
+ vc->deint_mpi[2]->usage_count--;
-static void push_deint_surface(VdpVideoSurface surface)
-{
- deint_surfaces[2] = deint_surfaces[1];
- deint_surfaces[1] = deint_surfaces[0];
- deint_surfaces[0] = surface;
+ for (int i = 2; i > 0; i--) {
+ vc->deint_mpi[i] = vc->deint_mpi[i - 1];
+ vc->deint_surfaces[i] = vc->deint_surfaces[i - 1];
+ vc->deint_pts[i] = vc->deint_pts[i - 1];
+ }
+ vc->deint_mpi[0] = reserved_mpi;
+ vc->deint_surfaces[0] = surface;
+ vc->deint_pts[0] = pts;
+
+ vo->frame_loaded = true;
+ vo->next_pts = pts;
+ if (vc->deint >= 2 && vc->deint_queue_pos >= 0) {
+ vc->deint_queue_pos = 2;
+ double diff = vc->deint_pts[0] - vc->deint_pts[1];
+ if (diff > 0 && diff < 0.5)
+ vo->next_pts = (vc->deint_pts[0] + vc->deint_pts[1]) / 2;
+ else
+ vo->next_pts = vc->deint_pts[1];
+ } else
+ vc->deint_queue_pos = 1;
+ video_to_output_surface(vo);
}
-static void video_to_output_surface(void)
+static void forget_frames(struct vo *vo)
{
- VdpTime dummy;
- VdpStatus vdp_st;
- int i;
- if (vid_surface_num < 0)
- return;
-
- if (deint < 2 || deint_surfaces[0] == VDP_INVALID_HANDLE)
- push_deint_surface(surface_render[vid_surface_num].surface);
-
- for (i = 0; i <= !!(deint > 1); i++) {
- int field = VDP_VIDEO_MIXER_PICTURE_STRUCTURE_FRAME;
- VdpOutputSurface output_surface;
- if (i) {
- draw_eosd();
- draw_osd();
- flip_page();
- }
- if (deint)
- field = (top_field_first == i) ^ (deint > 1) ?
- VDP_VIDEO_MIXER_PICTURE_STRUCTURE_BOTTOM_FIELD:
- VDP_VIDEO_MIXER_PICTURE_STRUCTURE_TOP_FIELD;
- output_surface = output_surfaces[surface_num];
- vdp_st = vdp_presentation_queue_block_until_surface_idle(vdp_flip_queue,
- output_surface,
- &dummy);
- CHECK_ST_WARNING("Error when calling vdp_presentation_queue_block_until_surface_idle")
-
- vdp_st = vdp_video_mixer_render(video_mixer, VDP_INVALID_HANDLE, 0,
- field, 2, deint_surfaces + 1,
- deint_surfaces[0],
- 1, &surface_render[vid_surface_num].surface,
- &src_rect_vid,
- output_surface,
- NULL, &out_rect_vid, 0, NULL);
- CHECK_ST_WARNING("Error when calling vdp_video_mixer_render")
- push_deint_surface(surface_render[vid_surface_num].surface);
+ struct vdpctx *vc = vo->priv;
+
+ vc->deint_queue_pos = -1;
+ for (int i = 0; i < 3; i++) {
+ vc->deint_surfaces[i] = VDP_INVALID_HANDLE;
+ if (vc->deint_mpi[i])
+ vc->deint_mpi[i]->usage_count--;
+ vc->deint_mpi[i] = NULL;
}
}
-static void resize(void)
+static void resize(struct vo *vo)
{
+ struct vdpctx *vc = vo->priv;
+ struct vdp_functions *vdp = vc->vdp;
VdpStatus vdp_st;
int i;
struct vo_rect src_rect;
struct vo_rect dst_rect;
struct vo_rect borders;
- calc_src_dst_rects(vid_width, vid_height, &src_rect, &dst_rect, &borders, NULL);
- out_rect_vid.x0 = dst_rect.left;
- out_rect_vid.x1 = dst_rect.right;
- out_rect_vid.y0 = dst_rect.top;
- out_rect_vid.y1 = dst_rect.bottom;
- src_rect_vid.x0 = src_rect.left;
- src_rect_vid.x1 = src_rect.right;
- src_rect_vid.y0 = src_rect.top;
- src_rect_vid.y1 = src_rect.bottom;
- border_x = borders.left;
- border_y = borders.top;
+ calc_src_dst_rects(vo, vc->vid_width, vc->vid_height, &src_rect, &dst_rect,
+ &borders, NULL);
+ 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;
+ vc->src_rect_vid.y0 = src_rect.top;
+ vc->src_rect_vid.y1 = src_rect.bottom;
+ vc->border_x = borders.left;
+ vc->border_y = borders.top;
#ifdef CONFIG_FREETYPE
// adjust font size to display size
force_load_font = 1;
#endif
vo_osd_changed(OSDTYPE_OSD);
- if (output_surface_width < vo_dwidth || output_surface_height < vo_dheight) {
- if (output_surface_width < vo_dwidth) {
- output_surface_width += output_surface_width >> 1;
- output_surface_width = FFMAX(output_surface_width, vo_dwidth);
+ if (vc->output_surface_width < vo->dwidth
+ || vc->output_surface_height < vo->dheight) {
+ if (vc->output_surface_width < vo->dwidth) {
+ vc->output_surface_width += vc->output_surface_width >> 1;
+ vc->output_surface_width = FFMAX(vc->output_surface_width,
+ vo->dwidth);
}
- if (output_surface_height < vo_dheight) {
- output_surface_height += output_surface_height >> 1;
- output_surface_height = FFMAX(output_surface_height, vo_dheight);
+ if (vc->output_surface_height < vo->dheight) {
+ vc->output_surface_height += vc->output_surface_height >> 1;
+ vc->output_surface_height = FFMAX(vc->output_surface_height,
+ vo->dheight);
}
// Creation of output_surfaces
for (i = 0; i <= NUM_OUTPUT_SURFACES; i++) {
- if (output_surfaces[i] != VDP_INVALID_HANDLE)
- vdp_output_surface_destroy(output_surfaces[i]);
- vdp_st = vdp_output_surface_create(vdp_device, VDP_RGBA_FORMAT_B8G8R8A8,
-