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.

122 lines
4.4KB

  1. /*
  2. * MPEG-1/2 HW 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 "vdpau.h"
  26. #include "vdpau_internal.h"
  27. static int vdpau_mpeg_start_frame(AVCodecContext *avctx,
  28. const uint8_t *buffer, uint32_t size)
  29. {
  30. MpegEncContext * const s = avctx->priv_data;
  31. Picture *pic = s->current_picture_ptr;
  32. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  33. VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
  34. VdpVideoSurface ref;
  35. int i;
  36. /* fill VdpPictureInfoMPEG1Or2 struct */
  37. info->forward_reference = VDP_INVALID_HANDLE;
  38. info->backward_reference = VDP_INVALID_HANDLE;
  39. switch (s->pict_type) {
  40. case AV_PICTURE_TYPE_B:
  41. ref = ff_vdpau_get_surface_id(&s->next_picture);
  42. assert(ref != VDP_INVALID_HANDLE);
  43. info->backward_reference = ref;
  44. /* fall through to forward prediction */
  45. case AV_PICTURE_TYPE_P:
  46. ref = ff_vdpau_get_surface_id(&s->last_picture);
  47. info->forward_reference = ref;
  48. }
  49. info->slice_count = 0;
  50. info->picture_structure = s->picture_structure;
  51. info->picture_coding_type = s->pict_type;
  52. info->intra_dc_precision = s->intra_dc_precision;
  53. info->frame_pred_frame_dct = s->frame_pred_frame_dct;
  54. info->concealment_motion_vectors = s->concealment_motion_vectors;
  55. info->intra_vlc_format = s->intra_vlc_format;
  56. info->alternate_scan = s->alternate_scan;
  57. info->q_scale_type = s->q_scale_type;
  58. info->top_field_first = s->top_field_first;
  59. // Both for MPEG-1 only, zero for MPEG-2:
  60. info->full_pel_forward_vector = s->full_pel[0];
  61. info->full_pel_backward_vector = s->full_pel[1];
  62. // For MPEG-1 fill both horizontal & vertical:
  63. info->f_code[0][0] = s->mpeg_f_code[0][0];
  64. info->f_code[0][1] = s->mpeg_f_code[0][1];
  65. info->f_code[1][0] = s->mpeg_f_code[1][0];
  66. info->f_code[1][1] = s->mpeg_f_code[1][1];
  67. for (i = 0; i < 64; ++i) {
  68. info->intra_quantizer_matrix[i] = s->intra_matrix[i];
  69. info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
  70. }
  71. return ff_vdpau_common_start_frame(pic, buffer, size);
  72. }
  73. static int vdpau_mpeg_decode_slice(AVCodecContext *avctx,
  74. const uint8_t *buffer, uint32_t size)
  75. {
  76. MpegEncContext * const s = avctx->priv_data;
  77. Picture *pic = s->current_picture_ptr;
  78. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  79. int val;
  80. val = ff_vdpau_add_buffer(pic, buffer, size);
  81. if (val < 0)
  82. return val;
  83. pic_ctx->info.mpeg.slice_count++;
  84. return 0;
  85. }
  86. #if CONFIG_MPEG1_VDPAU_HWACCEL
  87. AVHWAccel ff_mpeg1_vdpau_hwaccel = {
  88. .name = "mpeg1_vdpau",
  89. .type = AVMEDIA_TYPE_VIDEO,
  90. .id = AV_CODEC_ID_MPEG1VIDEO,
  91. .pix_fmt = AV_PIX_FMT_VDPAU,
  92. .start_frame = vdpau_mpeg_start_frame,
  93. .end_frame = ff_vdpau_mpeg_end_frame,
  94. .decode_slice = vdpau_mpeg_decode_slice,
  95. .priv_data_size = sizeof(struct vdpau_picture_context),
  96. };
  97. #endif
  98. #if CONFIG_MPEG2_VDPAU_HWACCEL
  99. AVHWAccel ff_mpeg2_vdpau_hwaccel = {
  100. .name = "mpeg2_vdpau",
  101. .type = AVMEDIA_TYPE_VIDEO,
  102. .id = AV_CODEC_ID_MPEG2VIDEO,
  103. .pix_fmt = AV_PIX_FMT_VDPAU,
  104. .start_frame = vdpau_mpeg_start_frame,
  105. .end_frame = ff_vdpau_mpeg_end_frame,
  106. .decode_slice = vdpau_mpeg_decode_slice,
  107. .priv_data_size = sizeof(struct vdpau_picture_context),
  108. };
  109. #endif