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.

135 lines
4.7KB

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