You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

614 lines
24KB

  1. /*
  2. * Video Decode and Presentation API for UNIX (VDPAU) is used for
  3. * HW decode acceleration for MPEG-1/2, MPEG-4 ASP, H.264 and VC-1.
  4. *
  5. * Copyright (c) 2008 NVIDIA
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <limits.h>
  24. #include "libavutil/avassert.h"
  25. #include "avcodec.h"
  26. #include "internal.h"
  27. #include "h264.h"
  28. #include "vc1.h"
  29. #undef NDEBUG
  30. #include <assert.h>
  31. #include "vdpau.h"
  32. #include "vdpau_internal.h"
  33. /**
  34. * @addtogroup VDPAU_Decoding
  35. *
  36. * @{
  37. */
  38. static int vdpau_error(VdpStatus status)
  39. {
  40. switch (status) {
  41. case VDP_STATUS_OK:
  42. return 0;
  43. case VDP_STATUS_NO_IMPLEMENTATION:
  44. return AVERROR(ENOSYS);
  45. case VDP_STATUS_DISPLAY_PREEMPTED:
  46. return AVERROR(EIO);
  47. case VDP_STATUS_INVALID_HANDLE:
  48. return AVERROR(EBADF);
  49. case VDP_STATUS_INVALID_POINTER:
  50. return AVERROR(EFAULT);
  51. case VDP_STATUS_RESOURCES:
  52. return AVERROR(ENOBUFS);
  53. case VDP_STATUS_HANDLE_DEVICE_MISMATCH:
  54. return AVERROR(EXDEV);
  55. case VDP_STATUS_ERROR:
  56. return AVERROR(EIO);
  57. default:
  58. return AVERROR(EINVAL);
  59. }
  60. }
  61. AVVDPAUContext *av_alloc_vdpaucontext(void)
  62. {
  63. return av_vdpau_alloc_context();
  64. }
  65. MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2)
  66. int ff_vdpau_common_init(AVCodecContext *avctx, VdpDecoderProfile profile,
  67. int level)
  68. {
  69. VDPAUHWContext *hwctx = avctx->hwaccel_context;
  70. VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
  71. VdpDecoderCreate *create;
  72. void *func;
  73. VdpStatus status;
  74. /* See vdpau/vdpau.h for alignment constraints. */
  75. uint32_t width = (avctx->coded_width + 1) & ~1;
  76. uint32_t height = (avctx->coded_height + 3) & ~3;
  77. if (!hwctx) {
  78. vdctx->device = VDP_INVALID_HANDLE;
  79. av_log(avctx, AV_LOG_WARNING, "hwaccel_context has not been setup by the user application, cannot initialize\n");
  80. return 0;
  81. }
  82. if (hwctx->context.decoder != VDP_INVALID_HANDLE) {
  83. vdctx->decoder = hwctx->context.decoder;
  84. vdctx->render = hwctx->context.render;
  85. vdctx->device = VDP_INVALID_HANDLE;
  86. return 0; /* Decoder created by user */
  87. }
  88. vdctx->device = hwctx->device;
  89. vdctx->get_proc_address = hwctx->get_proc_address;
  90. status = vdctx->get_proc_address(vdctx->device, VDP_FUNC_ID_DECODER_CREATE,
  91. &func);
  92. if (status != VDP_STATUS_OK)
  93. return vdpau_error(status);
  94. else
  95. create = func;
  96. status = vdctx->get_proc_address(vdctx->device, VDP_FUNC_ID_DECODER_RENDER,
  97. &func);
  98. if (status != VDP_STATUS_OK)
  99. return vdpau_error(status);
  100. else
  101. vdctx->render = func;
  102. status = create(vdctx->device, profile, width, height, avctx->refs,
  103. &vdctx->decoder);
  104. return vdpau_error(status);
  105. }
  106. int ff_vdpau_common_uninit(AVCodecContext *avctx)
  107. {
  108. VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
  109. VdpDecoderDestroy *destroy;
  110. void *func;
  111. VdpStatus status;
  112. if (vdctx->device == VDP_INVALID_HANDLE)
  113. return 0; /* Decoder created and destroyed by user */
  114. status = vdctx->get_proc_address(vdctx->device,
  115. VDP_FUNC_ID_DECODER_DESTROY, &func);
  116. if (status != VDP_STATUS_OK)
  117. return vdpau_error(status);
  118. else
  119. destroy = func;
  120. status = destroy(vdctx->decoder);
  121. return vdpau_error(status);
  122. }
  123. int ff_vdpau_common_start_frame(struct vdpau_picture_context *pic_ctx,
  124. av_unused const uint8_t *buffer,
  125. av_unused uint32_t size)
  126. {
  127. pic_ctx->bitstream_buffers_allocated = 0;
  128. pic_ctx->bitstream_buffers_used = 0;
  129. pic_ctx->bitstream_buffers = NULL;
  130. return 0;
  131. }
  132. int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
  133. struct vdpau_picture_context *pic_ctx)
  134. {
  135. VDPAUContext *vdctx = avctx->internal->hwaccel_priv_data;
  136. AVVDPAUContext *hwctx = avctx->hwaccel_context;
  137. VdpVideoSurface surf = ff_vdpau_get_surface_id(frame);
  138. VdpStatus status;
  139. #if FF_API_BUFS_VDPAU
  140. FF_DISABLE_DEPRECATION_WARNINGS
  141. hwctx->info = pic_ctx->info;
  142. hwctx->bitstream_buffers = pic_ctx->bitstream_buffers;
  143. hwctx->bitstream_buffers_used = pic_ctx->bitstream_buffers_used;
  144. hwctx->bitstream_buffers_allocated = pic_ctx->bitstream_buffers_allocated;
  145. FF_ENABLE_DEPRECATION_WARNINGS
  146. #endif
  147. if (!hwctx->render) {
  148. status = hwctx->render2(avctx, frame, (void *)&pic_ctx->info,
  149. pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
  150. } else
  151. status = vdctx->render(vdctx->decoder, surf, (void *)&pic_ctx->info,
  152. pic_ctx->bitstream_buffers_used,
  153. pic_ctx->bitstream_buffers);
  154. av_freep(&pic_ctx->bitstream_buffers);
  155. #if FF_API_BUFS_VDPAU
  156. FF_DISABLE_DEPRECATION_WARNINGS
  157. hwctx->bitstream_buffers = NULL;
  158. hwctx->bitstream_buffers_used = 0;
  159. hwctx->bitstream_buffers_allocated = 0;
  160. FF_ENABLE_DEPRECATION_WARNINGS
  161. #endif
  162. return vdpau_error(status);
  163. }
  164. #if CONFIG_H263_VDPAU_HWACCEL || CONFIG_MPEG1_VDPAU_HWACCEL || \
  165. CONFIG_MPEG2_VDPAU_HWACCEL || CONFIG_MPEG4_VDPAU_HWACCEL || \
  166. CONFIG_VC1_VDPAU_HWACCEL || CONFIG_WMV3_VDPAU_HWACCEL
  167. int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
  168. {
  169. MpegEncContext *s = avctx->priv_data;
  170. Picture *pic = s->current_picture_ptr;
  171. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  172. int val;
  173. val = ff_vdpau_common_end_frame(avctx, pic->f, pic_ctx);
  174. if (val < 0)
  175. return val;
  176. ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
  177. return 0;
  178. }
  179. #endif
  180. int ff_vdpau_add_buffer(struct vdpau_picture_context *pic_ctx,
  181. const uint8_t *buf, uint32_t size)
  182. {
  183. VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
  184. buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
  185. (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
  186. if (!buffers)
  187. return AVERROR(ENOMEM);
  188. pic_ctx->bitstream_buffers = buffers;
  189. buffers += pic_ctx->bitstream_buffers_used++;
  190. buffers->struct_version = VDP_BITSTREAM_BUFFER_VERSION;
  191. buffers->bitstream = buf;
  192. buffers->bitstream_bytes = size;
  193. return 0;
  194. }
  195. /* Obsolete non-hwaccel VDPAU support below... */
  196. void ff_vdpau_h264_set_reference_frames(H264Context *h)
  197. {
  198. struct vdpau_render_state *render, *render_ref;
  199. VdpReferenceFrameH264 *rf, *rf2;
  200. H264Picture *pic;
  201. int i, list, pic_frame_idx;
  202. render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
  203. assert(render);
  204. rf = &render->info.h264.referenceFrames[0];
  205. #define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames)
  206. for (list = 0; list < 2; ++list) {
  207. H264Picture **lp = list ? h->long_ref : h->short_ref;
  208. int ls = list ? 16 : h->short_ref_count;
  209. for (i = 0; i < ls; ++i) {
  210. pic = lp[i];
  211. if (!pic || !pic->reference)
  212. continue;
  213. pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
  214. render_ref = (struct vdpau_render_state *)pic->f.data[0];
  215. assert(render_ref);
  216. rf2 = &render->info.h264.referenceFrames[0];
  217. while (rf2 != rf) {
  218. if (
  219. (rf2->surface == render_ref->surface)
  220. && (rf2->is_long_term == pic->long_ref)
  221. && (rf2->frame_idx == pic_frame_idx)
  222. )
  223. break;
  224. ++rf2;
  225. }
  226. if (rf2 != rf) {
  227. rf2->top_is_reference |= (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
  228. rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
  229. continue;
  230. }
  231. if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT])
  232. continue;
  233. rf->surface = render_ref->surface;
  234. rf->is_long_term = pic->long_ref;
  235. rf->top_is_reference = (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE;
  236. rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
  237. rf->field_order_cnt[0] = pic->field_poc[0];
  238. rf->field_order_cnt[1] = pic->field_poc[1];
  239. rf->frame_idx = pic_frame_idx;
  240. ++rf;
  241. }
  242. }
  243. for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
  244. rf->surface = VDP_INVALID_HANDLE;
  245. rf->is_long_term = 0;
  246. rf->top_is_reference = 0;
  247. rf->bottom_is_reference = 0;
  248. rf->field_order_cnt[0] = 0;
  249. rf->field_order_cnt[1] = 0;
  250. rf->frame_idx = 0;
  251. }
  252. }
  253. void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
  254. {
  255. struct vdpau_render_state *render = (struct vdpau_render_state*)data;
  256. assert(render);
  257. render->bitstream_buffers= av_fast_realloc(
  258. render->bitstream_buffers,
  259. &render->bitstream_buffers_allocated,
  260. sizeof(*render->bitstream_buffers)*(render->bitstream_buffers_used + 1)
  261. );
  262. render->bitstream_buffers[render->bitstream_buffers_used].struct_version = VDP_BITSTREAM_BUFFER_VERSION;
  263. render->bitstream_buffers[render->bitstream_buffers_used].bitstream = buf;
  264. render->bitstream_buffers[render->bitstream_buffers_used].bitstream_bytes = buf_size;
  265. render->bitstream_buffers_used++;
  266. }
  267. #if CONFIG_H264_VDPAU_DECODER
  268. void ff_vdpau_h264_picture_start(H264Context *h)
  269. {
  270. struct vdpau_render_state *render;
  271. int i;
  272. render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
  273. assert(render);
  274. for (i = 0; i < 2; ++i) {
  275. int foc = h->cur_pic_ptr->field_poc[i];
  276. if (foc == INT_MAX)
  277. foc = 0;
  278. render->info.h264.field_order_cnt[i] = foc;
  279. }
  280. render->info.h264.frame_num = h->frame_num;
  281. }
  282. void ff_vdpau_h264_picture_complete(H264Context *h)
  283. {
  284. struct vdpau_render_state *render;
  285. render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
  286. assert(render);
  287. render->info.h264.slice_count = h->slice_num;
  288. if (render->info.h264.slice_count < 1)
  289. return;
  290. render->info.h264.is_reference = (h->cur_pic_ptr->reference & 3) ? VDP_TRUE : VDP_FALSE;
  291. render->info.h264.field_pic_flag = h->picture_structure != PICT_FRAME;
  292. render->info.h264.bottom_field_flag = h->picture_structure == PICT_BOTTOM_FIELD;
  293. render->info.h264.num_ref_frames = h->sps.ref_frame_count;
  294. render->info.h264.mb_adaptive_frame_field_flag = h->sps.mb_aff && !render->info.h264.field_pic_flag;
  295. render->info.h264.constrained_intra_pred_flag = h->pps.constrained_intra_pred;
  296. render->info.h264.weighted_pred_flag = h->pps.weighted_pred;
  297. render->info.h264.weighted_bipred_idc = h->pps.weighted_bipred_idc;
  298. render->info.h264.frame_mbs_only_flag = h->sps.frame_mbs_only_flag;
  299. render->info.h264.transform_8x8_mode_flag = h->pps.transform_8x8_mode;
  300. render->info.h264.chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0];
  301. render->info.h264.second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1];
  302. render->info.h264.pic_init_qp_minus26 = h->pps.init_qp - 26;
  303. render->info.h264.num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1;
  304. render->info.h264.num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1;
  305. render->info.h264.log2_max_frame_num_minus4 = h->sps.log2_max_frame_num - 4;
  306. render->info.h264.pic_order_cnt_type = h->sps.poc_type;
  307. render->info.h264.log2_max_pic_order_cnt_lsb_minus4 = h->sps.poc_type ? 0 : h->sps.log2_max_poc_lsb - 4;
  308. render->info.h264.delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag;
  309. render->info.h264.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag;
  310. render->info.h264.entropy_coding_mode_flag = h->pps.cabac;
  311. render->info.h264.pic_order_present_flag = h->pps.pic_order_present;
  312. render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
  313. render->info.h264.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present;
  314. memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4));
  315. memcpy(render->info.h264.scaling_lists_8x8[0], h->pps.scaling_matrix8[0], sizeof(render->info.h264.scaling_lists_8x8[0]));
  316. memcpy(render->info.h264.scaling_lists_8x8[1], h->pps.scaling_matrix8[3], sizeof(render->info.h264.scaling_lists_8x8[0]));
  317. ff_h264_draw_horiz_band(h, 0, h->avctx->height);
  318. render->bitstream_buffers_used = 0;
  319. }
  320. #endif /* CONFIG_H264_VDPAU_DECODER */
  321. #if CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER
  322. void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
  323. int buf_size, int slice_count)
  324. {
  325. struct vdpau_render_state *render, *last, *next;
  326. int i;
  327. if (!s->current_picture_ptr) return;
  328. render = (struct vdpau_render_state *)s->current_picture_ptr->f->data[0];
  329. assert(render);
  330. /* fill VdpPictureInfoMPEG1Or2 struct */
  331. render->info.mpeg.picture_structure = s->picture_structure;
  332. render->info.mpeg.picture_coding_type = s->pict_type;
  333. render->info.mpeg.intra_dc_precision = s->intra_dc_precision;
  334. render->info.mpeg.frame_pred_frame_dct = s->frame_pred_frame_dct;
  335. render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
  336. render->info.mpeg.intra_vlc_format = s->intra_vlc_format;
  337. render->info.mpeg.alternate_scan = s->alternate_scan;
  338. render->info.mpeg.q_scale_type = s->q_scale_type;
  339. render->info.mpeg.top_field_first = s->top_field_first;
  340. render->info.mpeg.full_pel_forward_vector = s->full_pel[0]; // MPEG-1 only. Set 0 for MPEG-2
  341. render->info.mpeg.full_pel_backward_vector = s->full_pel[1]; // MPEG-1 only. Set 0 for MPEG-2
  342. render->info.mpeg.f_code[0][0] = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert.
  343. render->info.mpeg.f_code[0][1] = s->mpeg_f_code[0][1];
  344. render->info.mpeg.f_code[1][0] = s->mpeg_f_code[1][0];
  345. render->info.mpeg.f_code[1][1] = s->mpeg_f_code[1][1];
  346. for (i = 0; i < 64; ++i) {
  347. render->info.mpeg.intra_quantizer_matrix[i] = s->intra_matrix[i];
  348. render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
  349. }
  350. render->info.mpeg.forward_reference = VDP_INVALID_HANDLE;
  351. render->info.mpeg.backward_reference = VDP_INVALID_HANDLE;
  352. switch(s->pict_type){
  353. case AV_PICTURE_TYPE_B:
  354. next = (struct vdpau_render_state *)s->next_picture.f->data[0];
  355. assert(next);
  356. render->info.mpeg.backward_reference = next->surface;
  357. // no return here, going to set forward prediction
  358. case AV_PICTURE_TYPE_P:
  359. last = (struct vdpau_render_state *)s->last_picture.f->data[0];
  360. if (!last) // FIXME: Does this test make sense?
  361. last = render; // predict second field from the first
  362. render->info.mpeg.forward_reference = last->surface;
  363. }
  364. ff_vdpau_add_data_chunk(s->current_picture_ptr->f->data[0], buf, buf_size);
  365. render->info.mpeg.slice_count = slice_count;
  366. if (slice_count)
  367. ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
  368. render->bitstream_buffers_used = 0;
  369. }
  370. #endif /* CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER */
  371. #if CONFIG_VC1_VDPAU_DECODER
  372. void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
  373. int buf_size)
  374. {
  375. VC1Context *v = s->avctx->priv_data;
  376. struct vdpau_render_state *render, *last, *next;
  377. render = (struct vdpau_render_state *)s->current_picture.f->data[0];
  378. assert(render);
  379. /* fill LvPictureInfoVC1 struct */
  380. render->info.vc1.frame_coding_mode = v->fcm ? v->fcm + 1 : 0;
  381. render->info.vc1.postprocflag = v->postprocflag;
  382. render->info.vc1.pulldown = v->broadcast;
  383. render->info.vc1.interlace = v->interlace;
  384. render->info.vc1.tfcntrflag = v->tfcntrflag;
  385. render->info.vc1.finterpflag = v->finterpflag;
  386. render->info.vc1.psf = v->psf;
  387. render->info.vc1.dquant = v->dquant;
  388. render->info.vc1.panscan_flag = v->panscanflag;
  389. render->info.vc1.refdist_flag = v->refdist_flag;
  390. render->info.vc1.quantizer = v->quantizer_mode;
  391. render->info.vc1.extended_mv = v->extended_mv;
  392. render->info.vc1.extended_dmv = v->extended_dmv;
  393. render->info.vc1.overlap = v->overlap;
  394. render->info.vc1.vstransform = v->vstransform;
  395. render->info.vc1.loopfilter = v->s.loop_filter;
  396. render->info.vc1.fastuvmc = v->fastuvmc;
  397. render->info.vc1.range_mapy_flag = v->range_mapy_flag;
  398. render->info.vc1.range_mapy = v->range_mapy;
  399. render->info.vc1.range_mapuv_flag = v->range_mapuv_flag;
  400. render->info.vc1.range_mapuv = v->range_mapuv;
  401. /* Specific to simple/main profile only */
  402. render->info.vc1.multires = v->multires;
  403. render->info.vc1.syncmarker = v->resync_marker;
  404. render->info.vc1.rangered = v->rangered | (v->rangeredfrm << 1);
  405. render->info.vc1.maxbframes = v->s.max_b_frames;
  406. render->info.vc1.deblockEnable = v->postprocflag & 1;
  407. render->info.vc1.pquant = v->pq;
  408. render->info.vc1.forward_reference = VDP_INVALID_HANDLE;
  409. render->info.vc1.backward_reference = VDP_INVALID_HANDLE;
  410. if (v->bi_type)
  411. render->info.vc1.picture_type = 4;
  412. else
  413. render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3;
  414. switch(s->pict_type){
  415. case AV_PICTURE_TYPE_B:
  416. next = (struct vdpau_render_state *)s->next_picture.f->data[0];
  417. assert(next);
  418. render->info.vc1.backward_reference = next->surface;
  419. // no break here, going to set forward prediction
  420. case AV_PICTURE_TYPE_P:
  421. last = (struct vdpau_render_state *)s->last_picture.f->data[0];
  422. if (!last) // FIXME: Does this test make sense?
  423. last = render; // predict second field from the first
  424. render->info.vc1.forward_reference = last->surface;
  425. }
  426. ff_vdpau_add_data_chunk(s->current_picture_ptr->f->data[0], buf, buf_size);
  427. render->info.vc1.slice_count = 1;
  428. ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
  429. render->bitstream_buffers_used = 0;
  430. }
  431. #endif /* (CONFIG_VC1_VDPAU_DECODER */
  432. #if CONFIG_MPEG4_VDPAU_DECODER
  433. void ff_vdpau_mpeg4_decode_picture(Mpeg4DecContext *ctx, const uint8_t *buf,
  434. int buf_size)
  435. {
  436. MpegEncContext *s = &ctx->m;
  437. struct vdpau_render_state *render, *last, *next;
  438. int i;
  439. if (!s->current_picture_ptr) return;
  440. render = (struct vdpau_render_state *)s->current_picture_ptr->f->data[0];
  441. assert(render);
  442. /* fill VdpPictureInfoMPEG4Part2 struct */
  443. render->info.mpeg4.trd[0] = s->pp_time;
  444. render->info.mpeg4.trb[0] = s->pb_time;
  445. render->info.mpeg4.trd[1] = s->pp_field_time >> 1;
  446. render->info.mpeg4.trb[1] = s->pb_field_time >> 1;
  447. render->info.mpeg4.vop_time_increment_resolution = s->avctx->time_base.den;
  448. render->info.mpeg4.vop_coding_type = 0;
  449. render->info.mpeg4.vop_fcode_forward = s->f_code;
  450. render->info.mpeg4.vop_fcode_backward = s->b_code;
  451. render->info.mpeg4.resync_marker_disable = !ctx->resync_marker;
  452. render->info.mpeg4.interlaced = !s->progressive_sequence;
  453. render->info.mpeg4.quant_type = s->mpeg_quant;
  454. render->info.mpeg4.quarter_sample = s->quarter_sample;
  455. render->info.mpeg4.short_video_header = s->avctx->codec->id == AV_CODEC_ID_H263;
  456. render->info.mpeg4.rounding_control = s->no_rounding;
  457. render->info.mpeg4.alternate_vertical_scan_flag = s->alternate_scan;
  458. render->info.mpeg4.top_field_first = s->top_field_first;
  459. for (i = 0; i < 64; ++i) {
  460. render->info.mpeg4.intra_quantizer_matrix[i] = s->intra_matrix[i];
  461. render->info.mpeg4.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
  462. }
  463. render->info.mpeg4.forward_reference = VDP_INVALID_HANDLE;
  464. render->info.mpeg4.backward_reference = VDP_INVALID_HANDLE;
  465. switch (s->pict_type) {
  466. case AV_PICTURE_TYPE_B:
  467. next = (struct vdpau_render_state *)s->next_picture.f->data[0];
  468. assert(next);
  469. render->info.mpeg4.backward_reference = next->surface;
  470. render->info.mpeg4.vop_coding_type = 2;
  471. // no break here, going to set forward prediction
  472. case AV_PICTURE_TYPE_P:
  473. last = (struct vdpau_render_state *)s->last_picture.f->data[0];
  474. assert(last);
  475. render->info.mpeg4.forward_reference = last->surface;
  476. }
  477. ff_vdpau_add_data_chunk(s->current_picture_ptr->f->data[0], buf, buf_size);
  478. ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
  479. render->bitstream_buffers_used = 0;
  480. }
  481. #endif /* CONFIG_MPEG4_VDPAU_DECODER */
  482. int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
  483. {
  484. #define PROFILE(prof) \
  485. do { \
  486. *profile = prof; \
  487. return 0; \
  488. } while (0)
  489. switch (avctx->codec_id) {
  490. case AV_CODEC_ID_MPEG1VIDEO: PROFILE(VDP_DECODER_PROFILE_MPEG1);
  491. case AV_CODEC_ID_MPEG2VIDEO:
  492. switch (avctx->profile) {
  493. case FF_PROFILE_MPEG2_MAIN: PROFILE(VDP_DECODER_PROFILE_MPEG2_MAIN);
  494. case FF_PROFILE_MPEG2_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG2_SIMPLE);
  495. default: return AVERROR(EINVAL);
  496. }
  497. case AV_CODEC_ID_H263: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
  498. case AV_CODEC_ID_MPEG4:
  499. switch (avctx->profile) {
  500. case FF_PROFILE_MPEG4_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_SP);
  501. case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
  502. default: return AVERROR(EINVAL);
  503. }
  504. case AV_CODEC_ID_H264:
  505. switch (avctx->profile & ~FF_PROFILE_H264_INTRA) {
  506. case FF_PROFILE_H264_CONSTRAINED_BASELINE:
  507. case FF_PROFILE_H264_BASELINE: PROFILE(VDP_DECODER_PROFILE_H264_BASELINE);
  508. case FF_PROFILE_H264_MAIN: PROFILE(VDP_DECODER_PROFILE_H264_MAIN);
  509. case FF_PROFILE_H264_HIGH: PROFILE(VDP_DECODER_PROFILE_H264_HIGH);
  510. default: return AVERROR(EINVAL);
  511. }
  512. case AV_CODEC_ID_WMV3:
  513. case AV_CODEC_ID_VC1:
  514. switch (avctx->profile) {
  515. case FF_PROFILE_VC1_SIMPLE: PROFILE(VDP_DECODER_PROFILE_VC1_SIMPLE);
  516. case FF_PROFILE_VC1_MAIN: PROFILE(VDP_DECODER_PROFILE_VC1_MAIN);
  517. case FF_PROFILE_VC1_ADVANCED: PROFILE(VDP_DECODER_PROFILE_VC1_ADVANCED);
  518. default: return AVERROR(EINVAL);
  519. }
  520. }
  521. return AVERROR(EINVAL);
  522. }
  523. AVVDPAUContext *av_vdpau_alloc_context(void)
  524. {
  525. return av_mallocz(sizeof(AVVDPAUContext));
  526. }
  527. /* @}*/