From 8c820cce4849b6ef22a1df78bc846893512c5f98 Mon Sep 17 00:00:00 2001 From: cehoyos Date: Sat, 21 Mar 2009 17:10:19 +0000 Subject: [PATCH] Factorize create_vdp_decoder(). git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29024 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/vo_vdpau.c | 72 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/libvo/vo_vdpau.c b/libvo/vo_vdpau.c index 6bda1b55e5..0caf27521d 100644 --- a/libvo/vo_vdpau.c +++ b/libvo/vo_vdpau.c @@ -479,6 +479,42 @@ static void free_video_specific(void) { video_mixer = VDP_INVALID_HANDLE; } +static int create_vdp_decoder(int max_refs) +{ + VdpStatus vdp_st; + VdpDecoderProfile vdp_decoder_profile; + if (decoder != VDP_INVALID_HANDLE) + vdp_decoder_destroy(decoder); + switch (image_format) { + 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; + } + vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile, + vid_width, vid_height, max_refs, &decoder); + CHECK_ST_WARNING("Failed creating VDPAU decoder"); + if (vdp_st != VDP_STATUS_OK) { + decoder = VDP_INVALID_HANDLE; + decoder_max_refs = 0; + return -1; + } + decoder_max_refs = max_refs; + return 0; +} + /* * connect to X server, create and map window, initialize all * VDPAU objects, create different surfaces etc. @@ -791,38 +827,10 @@ static int draw_slice(uint8_t *image[], int stride[], int w, int h, int max_refs = image_format == IMGFMT_VDPAU_H264 ? rndr->info.h264.num_ref_frames : 2; if (!IMGFMT_IS_VDPAU(image_format)) return VO_FALSE; - if (decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs) { - VdpDecoderProfile vdp_decoder_profile; - if (decoder != VDP_INVALID_HANDLE) - vdp_decoder_destroy(decoder); - decoder = VDP_INVALID_HANDLE; - switch (image_format) { - 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; - } - vdp_st = vdp_decoder_create(vdp_device, vdp_decoder_profile, vid_width, vid_height, max_refs, &decoder); - CHECK_ST_WARNING("Failed creating VDPAU decoder"); - if (vdp_st != VDP_STATUS_OK) { - decoder = VDP_INVALID_HANDLE; - decoder_max_refs = 0; - return VO_FALSE; - } - decoder_max_refs = max_refs; - } + if ((decoder == VDP_INVALID_HANDLE || decoder_max_refs < max_refs) + && create_vdp_decoder(max_refs) < 0) + return VO_FALSE; + vdp_st = vdp_decoder_render(decoder, rndr->surface, (void *)&rndr->info, rndr->bitstream_buffers_used, rndr->bitstream_buffers); CHECK_ST_WARNING("Failed VDPAU decoder rendering"); return VO_TRUE;