diff options
-rw-r--r-- | TOOLS/vdpau_functions.py | 58 | ||||
-rw-r--r-- | libmpcodecs/vf.h | 1 | ||||
-rw-r--r-- | libmpcodecs/vf_vo.c | 16 | ||||
-rw-r--r-- | libvo/vdpau_template.c | 39 | ||||
-rw-r--r-- | libvo/video_out.c | 51 | ||||
-rw-r--r-- | libvo/video_out.h | 174 | ||||
-rw-r--r-- | libvo/video_out_internal.h | 1 | ||||
-rw-r--r-- | libvo/vo_vdpau.c | 1864 | ||||
-rw-r--r-- | libvo/vo_xv.c | 6 | ||||
-rw-r--r-- | mencoder.c | 1 | ||||
-rw-r--r-- | mp_core.h | 4 | ||||
-rw-r--r-- | mplayer.c | 27 |
12 files changed, 1341 insertions, 901 deletions
diff --git a/TOOLS/vdpau_functions.py b/TOOLS/vdpau_functions.py new file mode 100644 index 0000000000..e628cb00c3 --- /dev/null +++ b/TOOLS/vdpau_functions.py @@ -0,0 +1,58 @@ +# Generate vdpau_template.c + +functions = """ +# get_error_string should be first, because the function lookup loop should +# have it available to print errors for other functions +get_error_string + +bitmap_surface_create +bitmap_surface_destroy +bitmap_surface_put_bits_native +bitmap_surface_query_capabilities +decoder_create +decoder_destroy +decoder_render +device_destroy +generate_csc_matrix GenerateCSCMatrix # CSC completely capitalized +output_surface_create +output_surface_destroy +output_surface_put_bits_indexed +output_surface_put_bits_native +output_surface_render_bitmap_surface +output_surface_render_output_surface +preemption_callback_register +presentation_queue_block_until_surface_idle +presentation_queue_create +presentation_queue_destroy +presentation_queue_display +presentation_queue_target_create_x11 +presentation_queue_target_destroy +video_mixer_create +video_mixer_destroy +video_mixer_render +video_mixer_set_attribute_values +video_mixer_set_feature_enables +video_surface_create +video_surface_destroy +video_surface_put_bits_y_cb_cr +""" + +print(""" +/* 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. + */ +""") +for line in functions.splitlines(): + parts = line.split('#')[0].strip().split() + if not parts: + continue # empty/comment line + if len(parts) > 1: + mp_name, vdpau_name = parts + else: + mp_name = parts[0] + vdpau_name = ''.join(part.capitalize() for part in mp_name.split('_')) + macro_name = mp_name.upper() + print('VDP_FUNCTION(Vdp%s, VDP_FUNC_ID_%s, %s)' % (vdpau_name, macro_name, mp_name)) diff --git a/libmpcodecs/vf.h b/libmpcodecs/vf.h index 99321b3afa..099135c5da 100644 --- a/libmpcodecs/vf.h +++ b/libmpcodecs/vf.h @@ -88,7 +88,6 @@ typedef struct vf_seteq_s #define VFCTRL_SCREENSHOT 14 /* Make a screenshot */ #define VFCTRL_INIT_EOSD 15 /* Select EOSD renderer */ #define VFCTRL_DRAW_EOSD 16 /* Render EOSD */ -#define VFCTRL_GET_PTS 17 /* Return last pts value that reached vf_vo*/ #define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */ #define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */ /* Hack to make the OSD state object available to vf_expand which accesses diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 7b3e16224f..c782a5517b 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -22,7 +22,6 @@ extern int sub_visibility; extern float sub_delay; struct vf_priv_s { - double pts; struct vo *vo; #ifdef CONFIG_ASS ASS_Renderer *ass_priv; @@ -127,7 +126,7 @@ static int control(struct vf_instance* vf, int request, void* data) case VFCTRL_DRAW_EOSD: { mp_eosd_images_t images = {NULL, 2}; - double pts = vf->priv->pts; + double pts = video_out->next_pts; if (!video_out->config_ok || !vf->priv->ass_priv) return CONTROL_FALSE; if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE)) { mp_eosd_res_t res; @@ -148,11 +147,6 @@ static int control(struct vf_instance* vf, int request, void* data) return vo_control(video_out, VOCTRL_DRAW_EOSD, &images) == VO_TRUE; } #endif - case VFCTRL_GET_PTS: - { - *(double *)data = vf->priv->pts; - return CONTROL_TRUE; - } } return CONTROL_UNKNOWN; } @@ -179,10 +173,9 @@ static void get_image(struct vf_instance* vf, static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){ if(!video_out->config_ok) return 0; // vo not configured? - // record pts (potentially modified by filters) for main loop - vf->priv->pts = pts; // first check, maybe the vo/vf plugin implements draw_image using mpi: - if (vo_control(video_out, VOCTRL_DRAW_IMAGE,mpi)==VO_TRUE) return 1; // done. + if (vo_draw_image(video_out, mpi, pts) >= 0) + return 1; // nope, fallback to old draw_frame/draw_slice: if(!(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))){ // blit frame: @@ -210,6 +203,9 @@ static void draw_slice(struct vf_instance* vf, static void uninit(struct vf_instance* vf) { if (vf->priv) { + /* Allow VO (which may live on to work with another instance of vf_vo) + * to get rid of numbered-mpi references that will now be invalid. */ + vo_control(video_out, VOCTRL_RESET, NULL); #ifdef CONFIG_ASS if (vf->priv->ass_priv) ass_renderer_done(vf->priv->ass_priv); 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 |