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.

124 lines
4.5KB

  1. /*
  2. * MPEG-4 Part 2 / H.263 decode acceleration through VDPAU
  3. *
  4. * Copyright (c) 2008 NVIDIA
  5. * Copyright (c) 2013 Rémi Denis-Courmont
  6. *
  7. * This file is part of Libav.
  8. *
  9. * Libav 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. * Libav 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 Libav; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <vdpau/vdpau.h>
  24. #include "avcodec.h"
  25. #include "hwaccel.h"
  26. #include "mpeg4video.h"
  27. #include "vdpau.h"
  28. #include "vdpau_internal.h"
  29. static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
  30. const uint8_t *buffer, uint32_t size)
  31. {
  32. Mpeg4DecContext *ctx = avctx->priv_data;
  33. MpegEncContext * const s = &ctx->m;
  34. Picture *pic = s->current_picture_ptr;
  35. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  36. VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
  37. VdpVideoSurface ref;
  38. int i;
  39. /* fill VdpPictureInfoMPEG4Part2 struct */
  40. info->forward_reference = VDP_INVALID_HANDLE;
  41. info->backward_reference = VDP_INVALID_HANDLE;
  42. info->vop_coding_type = 0;
  43. switch (s->pict_type) {
  44. case AV_PICTURE_TYPE_B:
  45. ref = ff_vdpau_get_surface_id(s->next_picture.f);
  46. assert(ref != VDP_INVALID_HANDLE);
  47. info->backward_reference = ref;
  48. info->vop_coding_type = 2;
  49. /* fall-through */
  50. case AV_PICTURE_TYPE_P:
  51. ref = ff_vdpau_get_surface_id(s->last_picture.f);
  52. assert(ref != VDP_INVALID_HANDLE);
  53. info->forward_reference = ref;
  54. }
  55. info->trd[0] = s->pp_time;
  56. info->trb[0] = s->pb_time;
  57. info->trd[1] = s->pp_field_time >> 1;
  58. info->trb[1] = s->pb_field_time >> 1;
  59. info->vop_time_increment_resolution = s->avctx->framerate.num;
  60. info->vop_fcode_forward = s->f_code;
  61. info->vop_fcode_backward = s->b_code;
  62. info->resync_marker_disable = !ctx->resync_marker;
  63. info->interlaced = !s->progressive_sequence;
  64. info->quant_type = s->mpeg_quant;
  65. info->quarter_sample = s->quarter_sample;
  66. info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
  67. info->rounding_control = s->no_rounding;
  68. info->alternate_vertical_scan_flag = s->alternate_scan;
  69. info->top_field_first = s->top_field_first;
  70. for (i = 0; i < 64; ++i) {
  71. info->intra_quantizer_matrix[i] = s->intra_matrix[i];
  72. info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
  73. }
  74. ff_vdpau_common_start_frame(pic_ctx, buffer, size);
  75. return ff_vdpau_add_buffer(pic_ctx, buffer, size);
  76. }
  77. static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx,
  78. av_unused const uint8_t *buffer,
  79. av_unused uint32_t size)
  80. {
  81. return 0;
  82. }
  83. static int vdpau_mpeg4_init(AVCodecContext *avctx)
  84. {
  85. VdpDecoderProfile profile;
  86. switch (avctx->profile) {
  87. case FF_PROFILE_MPEG4_SIMPLE:
  88. profile = VDP_DECODER_PROFILE_MPEG4_PART2_SP;
  89. break;
  90. case FF_PROFILE_MPEG4_ADVANCED_SIMPLE:
  91. profile = VDP_DECODER_PROFILE_MPEG4_PART2_ASP;
  92. break;
  93. default:
  94. return AVERROR(ENOTSUP);
  95. }
  96. return ff_vdpau_common_init(avctx, profile, avctx->level);
  97. }
  98. AVHWAccel ff_mpeg4_vdpau_hwaccel = {
  99. .name = "mpeg4_vdpau",
  100. .type = AVMEDIA_TYPE_VIDEO,
  101. .id = AV_CODEC_ID_MPEG4,
  102. .pix_fmt = AV_PIX_FMT_VDPAU,
  103. .start_frame = vdpau_mpeg4_start_frame,
  104. .end_frame = ff_vdpau_mpeg_end_frame,
  105. .decode_slice = vdpau_mpeg4_decode_slice,
  106. .frame_priv_data_size = sizeof(struct vdpau_picture_context),
  107. .init = vdpau_mpeg4_init,
  108. .uninit = ff_vdpau_common_uninit,
  109. .priv_data_size = sizeof(VDPAUContext),
  110. .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
  111. };