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.

165 lines
5.6KB

  1. /*
  2. * VC-1 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 "vc1.h"
  27. #include "vdpau.h"
  28. #include "vdpau_internal.h"
  29. static int vdpau_vc1_start_frame(AVCodecContext *avctx,
  30. const uint8_t *buffer, uint32_t size)
  31. {
  32. VC1Context * const v = avctx->priv_data;
  33. MpegEncContext * const s = &v->s;
  34. Picture *pic = s->current_picture_ptr;
  35. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  36. VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
  37. VdpVideoSurface ref;
  38. /* fill LvPictureInfoVC1 struct */
  39. info->forward_reference = VDP_INVALID_HANDLE;
  40. info->backward_reference = VDP_INVALID_HANDLE;
  41. switch (s->pict_type) {
  42. case AV_PICTURE_TYPE_B:
  43. ref = ff_vdpau_get_surface_id(s->next_picture.f);
  44. assert(ref != VDP_INVALID_HANDLE);
  45. info->backward_reference = ref;
  46. /* fall-through */
  47. case AV_PICTURE_TYPE_P:
  48. ref = ff_vdpau_get_surface_id(s->last_picture.f);
  49. assert(ref != VDP_INVALID_HANDLE);
  50. info->forward_reference = ref;
  51. }
  52. info->slice_count = 0;
  53. if (v->bi_type)
  54. info->picture_type = 4;
  55. else
  56. info->picture_type = s->pict_type - 1 + s->pict_type / 3;
  57. info->frame_coding_mode = v->fcm ? (v->fcm + 1) : 0;
  58. info->postprocflag = v->postprocflag;
  59. info->pulldown = v->broadcast;
  60. info->interlace = v->interlace;
  61. info->tfcntrflag = v->tfcntrflag;
  62. info->finterpflag = v->finterpflag;
  63. info->psf = v->psf;
  64. info->dquant = v->dquant;
  65. info->panscan_flag = v->panscanflag;
  66. info->refdist_flag = v->refdist_flag;
  67. info->quantizer = v->quantizer_mode;
  68. info->extended_mv = v->extended_mv;
  69. info->extended_dmv = v->extended_dmv;
  70. info->overlap = v->overlap;
  71. info->vstransform = v->vstransform;
  72. info->loopfilter = v->s.loop_filter;
  73. info->fastuvmc = v->fastuvmc;
  74. info->range_mapy_flag = v->range_mapy_flag;
  75. info->range_mapy = v->range_mapy;
  76. info->range_mapuv_flag = v->range_mapuv_flag;
  77. info->range_mapuv = v->range_mapuv;
  78. /* Specific to simple/main profile only */
  79. info->multires = v->multires;
  80. info->syncmarker = v->resync_marker;
  81. info->rangered = v->rangered | (v->rangeredfrm << 1);
  82. info->maxbframes = v->s.max_b_frames;
  83. info->deblockEnable = v->postprocflag & 1;
  84. info->pquant = v->pq;
  85. return ff_vdpau_common_start_frame(pic_ctx, buffer, size);
  86. }
  87. static int vdpau_vc1_decode_slice(AVCodecContext *avctx,
  88. const uint8_t *buffer, uint32_t size)
  89. {
  90. VC1Context * const v = avctx->priv_data;
  91. MpegEncContext * const s = &v->s;
  92. Picture *pic = s->current_picture_ptr;
  93. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  94. int val;
  95. val = ff_vdpau_add_buffer(pic_ctx, buffer, size);
  96. if (val < 0)
  97. return val;
  98. pic_ctx->info.vc1.slice_count++;
  99. return 0;
  100. }
  101. static int vdpau_vc1_init(AVCodecContext *avctx)
  102. {
  103. VdpDecoderProfile profile;
  104. switch (avctx->profile) {
  105. case FF_PROFILE_VC1_SIMPLE:
  106. profile = VDP_DECODER_PROFILE_VC1_SIMPLE;
  107. break;
  108. case FF_PROFILE_VC1_MAIN:
  109. profile = VDP_DECODER_PROFILE_VC1_MAIN;
  110. break;
  111. case FF_PROFILE_VC1_ADVANCED:
  112. profile = VDP_DECODER_PROFILE_VC1_ADVANCED;
  113. break;
  114. default:
  115. return AVERROR(ENOTSUP);
  116. }
  117. return ff_vdpau_common_init(avctx, profile, avctx->level);
  118. }
  119. #if CONFIG_WMV3_VDPAU_HWACCEL
  120. AVHWAccel ff_wmv3_vdpau_hwaccel = {
  121. .name = "wm3_vdpau",
  122. .type = AVMEDIA_TYPE_VIDEO,
  123. .id = AV_CODEC_ID_WMV3,
  124. .pix_fmt = AV_PIX_FMT_VDPAU,
  125. .start_frame = vdpau_vc1_start_frame,
  126. .end_frame = ff_vdpau_mpeg_end_frame,
  127. .decode_slice = vdpau_vc1_decode_slice,
  128. .frame_priv_data_size = sizeof(struct vdpau_picture_context),
  129. .init = vdpau_vc1_init,
  130. .uninit = ff_vdpau_common_uninit,
  131. .priv_data_size = sizeof(VDPAUContext),
  132. .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
  133. };
  134. #endif
  135. AVHWAccel ff_vc1_vdpau_hwaccel = {
  136. .name = "vc1_vdpau",
  137. .type = AVMEDIA_TYPE_VIDEO,
  138. .id = AV_CODEC_ID_VC1,
  139. .pix_fmt = AV_PIX_FMT_VDPAU,
  140. .start_frame = vdpau_vc1_start_frame,
  141. .end_frame = ff_vdpau_mpeg_end_frame,
  142. .decode_slice = vdpau_vc1_decode_slice,
  143. .frame_priv_data_size = sizeof(struct vdpau_picture_context),
  144. .init = vdpau_vc1_init,
  145. .uninit = ff_vdpau_common_uninit,
  146. .priv_data_size = sizeof(VDPAUContext),
  147. .caps_internal = HWACCEL_CAP_ASYNC_SAFE,
  148. };