VdpStatus vdp_decoder_create(VdpDevice device, VdpDecoderProfile profile, uint32_t width, uint32_t height, uint32_t max_references, VdpDecoder *decoder) { device_ctx_t *dev = handle_get(device); if (!dev) return VDP_STATUS_INVALID_HANDLE; if (max_references > 16) return VDP_STATUS_ERROR; decoder_ctx_t *dec = calloc(1, sizeof(decoder_ctx_t)); if (!dec) goto err_ctx; dec->device = dev; dec->profile = profile; dec->width = width; dec->height = height; dec->data = ve_malloc(VBV_SIZE); if (!(dec->data)) goto err_data; VdpStatus ret; switch (profile) { case VDP_DECODER_PROFILE_MPEG1: case VDP_DECODER_PROFILE_MPEG2_SIMPLE: case VDP_DECODER_PROFILE_MPEG2_MAIN: ret = new_decoder_mpeg12(dec); break; case VDP_DECODER_PROFILE_H264_BASELINE: case VDP_DECODER_PROFILE_H264_MAIN: case VDP_DECODER_PROFILE_H264_HIGH: ret = new_decoder_h264(dec); break; case VDP_DECODER_PROFILE_MPEG4_PART2_SP: case VDP_DECODER_PROFILE_MPEG4_PART2_ASP: ret = new_decoder_mp4(dec); break; default: ret = VDP_STATUS_INVALID_DECODER_PROFILE; break; } if (ret != VDP_STATUS_OK) goto err_decoder; int handle = handle_create(dec); if (handle == -1) goto err_handle; *decoder = handle; return VDP_STATUS_OK; err_handle: if (dec->private_free) dec->private_free(dec); err_decoder: ve_free(dec->data); err_data: free(dec); err_ctx: return VDP_STATUS_RESOURCES; }
VdpStatus vdp_decoder_create(VdpDevice device, VdpDecoderProfile profile, uint32_t width, uint32_t height, uint32_t max_references, VdpDecoder *decoder) { device_ctx_t *dev = handle_get(device); if (!dev) return VDP_STATUS_INVALID_HANDLE; if (max_references > 16) return VDP_STATUS_ERROR; decoder_ctx_t *dec = handle_create(sizeof(*dec), decoder, htype_decoder); if (!dec) goto err_ctx; VDPAU_DBG("vdpau decoder=%d created", *decoder); memset(dec, 0, sizeof(*dec)); dec->device = dev; dec->profile = profile; dec->width = width; dec->height = height; dec->data = cedarv_malloc(VBV_SIZE); if (! cedarv_isValid(dec->data)) goto err_data; dec->data_pos = 0; VdpStatus ret; switch (profile) { case VDP_DECODER_PROFILE_MPEG1: case VDP_DECODER_PROFILE_MPEG2_SIMPLE: case VDP_DECODER_PROFILE_MPEG2_MAIN: ret = new_decoder_mpeg12(dec); break; case VDP_DECODER_PROFILE_H264_BASELINE: case VDP_DECODER_PROFILE_H264_MAIN: case VDP_DECODER_PROFILE_H264_HIGH: ret = new_decoder_h264(dec); break; case VDP_DECODER_PROFILE_MPEG4_PART2_SP: case VDP_DECODER_PROFILE_MPEG4_PART2_ASP: case VDP_DECODER_PROFILE_DIVX4_QMOBILE: case VDP_DECODER_PROFILE_DIVX4_MOBILE: case VDP_DECODER_PROFILE_DIVX4_HOME_THEATER: case VDP_DECODER_PROFILE_DIVX4_HD_1080P: case VDP_DECODER_PROFILE_DIVX5_QMOBILE: case VDP_DECODER_PROFILE_DIVX5_MOBILE: case VDP_DECODER_PROFILE_DIVX5_HOME_THEATER: case VDP_DECODER_PROFILE_DIVX5_HD_1080P: ret = new_decoder_mpeg4(dec); break; case VDP_DECODER_PROFILE_DIVX3_HD_1080P: case VDP_DECODER_PROFILE_DIVX3_QMOBILE: case VDP_DECODER_PROFILE_DIVX3_MOBILE: case VDP_DECODER_PROFILE_DIVX3_HOME_THEATER: ret = new_decoder_msmpeg4(dec); break; default: ret = VDP_STATUS_INVALID_DECODER_PROFILE; break; } if (ret != VDP_STATUS_OK) goto err_decoder; handle_release(device); return VDP_STATUS_OK; err_handle: if (dec->private_free) dec->private_free(dec); err_decoder: cedarv_free(dec->data); err_data: handle_destroy(*decoder); err_ctx: handle_release(device); return VDP_STATUS_RESOURCES; }