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.

142 lines
5.0KB

  1. /*
  2. * Video Decode and Presentation API for UNIX (VDPAU) is used for
  3. * HW decode acceleration for MPEG-1/2, MPEG-4 ASP, H.264 and VC-1.
  4. *
  5. * Copyright (c) 2008 NVIDIA
  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
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <limits.h>
  24. #include "avcodec.h"
  25. #include "h264.h"
  26. #include "vc1.h"
  27. #undef NDEBUG
  28. #include <assert.h>
  29. #include "vdpau.h"
  30. #include "vdpau_internal.h"
  31. /**
  32. * @addtogroup VDPAU_Decoding
  33. *
  34. * @{
  35. */
  36. int ff_vdpau_common_start_frame(Picture *pic,
  37. av_unused const uint8_t *buffer,
  38. av_unused uint32_t size)
  39. {
  40. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  41. pic_ctx->bitstream_buffers_allocated = 0;
  42. pic_ctx->bitstream_buffers_used = 0;
  43. pic_ctx->bitstream_buffers = NULL;
  44. return 0;
  45. }
  46. #if CONFIG_H263_VDPAU_HWACCEL || CONFIG_MPEG1_VDPAU_HWACCEL || \
  47. CONFIG_MPEG2_VDPAU_HWACCEL || CONFIG_MPEG4_VDPAU_HWACCEL || \
  48. CONFIG_VC1_VDPAU_HWACCEL || CONFIG_WMV3_VDPAU_HWACCEL
  49. int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
  50. {
  51. AVVDPAUContext *hwctx = avctx->hwaccel_context;
  52. MpegEncContext *s = avctx->priv_data;
  53. Picture *pic = s->current_picture_ptr;
  54. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  55. VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
  56. hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
  57. pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
  58. ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
  59. av_freep(&pic_ctx->bitstream_buffers);
  60. return 0;
  61. }
  62. #endif
  63. int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t size)
  64. {
  65. struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
  66. VdpBitstreamBuffer *buffers = pic_ctx->bitstream_buffers;
  67. buffers = av_fast_realloc(buffers, &pic_ctx->bitstream_buffers_allocated,
  68. (pic_ctx->bitstream_buffers_used + 1) * sizeof(*buffers));
  69. if (!buffers)
  70. return AVERROR(ENOMEM);
  71. pic_ctx->bitstream_buffers = buffers;
  72. buffers += pic_ctx->bitstream_buffers_used++;
  73. buffers->struct_version = VDP_BITSTREAM_BUFFER_VERSION;
  74. buffers->bitstream = buf;
  75. buffers->bitstream_bytes = size;
  76. return 0;
  77. }
  78. int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
  79. {
  80. #define PROFILE(prof) \
  81. do { \
  82. *profile = prof; \
  83. return 0; \
  84. } while (0)
  85. switch (avctx->codec_id) {
  86. case AV_CODEC_ID_MPEG1VIDEO: PROFILE(VDP_DECODER_PROFILE_MPEG1);
  87. case AV_CODEC_ID_MPEG2VIDEO:
  88. switch (avctx->profile) {
  89. case FF_PROFILE_MPEG2_MAIN: PROFILE(VDP_DECODER_PROFILE_MPEG2_MAIN);
  90. case FF_PROFILE_MPEG2_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG2_SIMPLE);
  91. default: return AVERROR(EINVAL);
  92. }
  93. case AV_CODEC_ID_H263: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
  94. case AV_CODEC_ID_MPEG4:
  95. switch (avctx->profile) {
  96. case FF_PROFILE_MPEG4_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_SP);
  97. case FF_PROFILE_MPEG4_ADVANCED_SIMPLE: PROFILE(VDP_DECODER_PROFILE_MPEG4_PART2_ASP);
  98. default: return AVERROR(EINVAL);
  99. }
  100. case AV_CODEC_ID_H264:
  101. switch (avctx->profile & ~FF_PROFILE_H264_INTRA) {
  102. case FF_PROFILE_H264_CONSTRAINED_BASELINE:
  103. case FF_PROFILE_H264_BASELINE: PROFILE(VDP_DECODER_PROFILE_H264_BASELINE);
  104. case FF_PROFILE_H264_MAIN: PROFILE(VDP_DECODER_PROFILE_H264_MAIN);
  105. case FF_PROFILE_H264_HIGH: PROFILE(VDP_DECODER_PROFILE_H264_HIGH);
  106. default: return AVERROR(EINVAL);
  107. }
  108. case AV_CODEC_ID_WMV3:
  109. case AV_CODEC_ID_VC1:
  110. switch (avctx->profile) {
  111. case FF_PROFILE_VC1_SIMPLE: PROFILE(VDP_DECODER_PROFILE_VC1_SIMPLE);
  112. case FF_PROFILE_VC1_MAIN: PROFILE(VDP_DECODER_PROFILE_VC1_MAIN);
  113. case FF_PROFILE_VC1_ADVANCED: PROFILE(VDP_DECODER_PROFILE_VC1_ADVANCED);
  114. default: return AVERROR(EINVAL);
  115. }
  116. }
  117. return AVERROR(EINVAL);
  118. }
  119. AVVDPAUContext *av_vdpau_alloc_context(void)
  120. {
  121. return av_mallocz(sizeof(AVVDPAUContext));
  122. }
  123. /* @}*/