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.

111 lines
4.1KB

  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 "vdpau.h"
  26. #include "vdpau_internal.h"
  27. static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
  28. const uint8_t *buffer, uint32_t size)
  29. {
  30. MpegEncContext * const s = avctx->priv_data;
  31. AVVDPAUContext *hwctx = avctx->hwaccel_context;
  32. VdpPictureInfoMPEG4Part2 *info = &hwctx->info.mpeg4;
  33. VdpVideoSurface ref;
  34. int i;
  35. /* fill VdpPictureInfoMPEG4Part2 struct */
  36. info->forward_reference = VDP_INVALID_HANDLE;
  37. info->backward_reference = VDP_INVALID_HANDLE;
  38. info->vop_coding_type = 0;
  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. info->vop_coding_type = 2;
  45. /* fall-through */
  46. case AV_PICTURE_TYPE_P:
  47. ref = ff_vdpau_get_surface_id(&s->last_picture);
  48. assert(ref != VDP_INVALID_HANDLE);
  49. info->forward_reference = ref;
  50. }
  51. info->trd[0] = s->pp_time;
  52. info->trb[0] = s->pb_time;
  53. info->trd[1] = s->pp_field_time >> 1;
  54. info->trb[1] = s->pb_field_time >> 1;
  55. info->vop_time_increment_resolution = s->avctx->time_base.den;
  56. info->vop_fcode_forward = s->f_code;
  57. info->vop_fcode_backward = s->b_code;
  58. info->resync_marker_disable = !s->resync_marker;
  59. info->interlaced = !s->progressive_sequence;
  60. info->quant_type = s->mpeg_quant;
  61. info->quarter_sample = s->quarter_sample;
  62. info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
  63. info->rounding_control = s->no_rounding;
  64. info->alternate_vertical_scan_flag = s->alternate_scan;
  65. info->top_field_first = s->top_field_first;
  66. for (i = 0; i < 64; ++i) {
  67. info->intra_quantizer_matrix[i] = s->intra_matrix[i];
  68. info->non_intra_quantizer_matrix[i] = s->inter_matrix[i];
  69. }
  70. ff_vdpau_common_start_frame(avctx, buffer, size);
  71. return ff_vdpau_add_buffer(avctx, buffer, size);
  72. }
  73. static int vdpau_mpeg4_decode_slice(av_unused AVCodecContext *avctx,
  74. av_unused const uint8_t *buffer,
  75. av_unused uint32_t size)
  76. {
  77. return 0;
  78. }
  79. #if CONFIG_H263_VDPAU_HWACCEL
  80. AVHWAccel ff_h263_vdpau_hwaccel = {
  81. .name = "h263_vdpau",
  82. .type = AVMEDIA_TYPE_VIDEO,
  83. .id = AV_CODEC_ID_H263,
  84. .pix_fmt = AV_PIX_FMT_VDPAU,
  85. .start_frame = vdpau_mpeg4_start_frame,
  86. .end_frame = ff_vdpau_mpeg_end_frame,
  87. .decode_slice = vdpau_mpeg4_decode_slice,
  88. };
  89. #endif
  90. #if CONFIG_MPEG4_VDPAU_HWACCEL
  91. AVHWAccel ff_mpeg4_vdpau_hwaccel = {
  92. .name = "mpeg4_vdpau",
  93. .type = AVMEDIA_TYPE_VIDEO,
  94. .id = AV_CODEC_ID_MPEG4,
  95. .pix_fmt = AV_PIX_FMT_VDPAU,
  96. .start_frame = vdpau_mpeg4_start_frame,
  97. .end_frame = ff_vdpau_mpeg_end_frame,
  98. .decode_slice = vdpau_mpeg4_decode_slice,
  99. };
  100. #endif