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.

94 lines
2.7KB

  1. /*
  2. * VDA H264 HW acceleration.
  3. *
  4. * copyright (c) 2011 Sebastien Zwickert
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "vda_internal.h"
  23. static int start_frame(AVCodecContext *avctx,
  24. av_unused const uint8_t *buffer,
  25. av_unused uint32_t size)
  26. {
  27. struct vda_context *vda_ctx = avctx->hwaccel_context;
  28. if (!vda_ctx->decoder)
  29. return -1;
  30. vda_ctx->bitstream_size = 0;
  31. return 0;
  32. }
  33. static int decode_slice(AVCodecContext *avctx,
  34. const uint8_t *buffer,
  35. uint32_t size)
  36. {
  37. struct vda_context *vda_ctx = avctx->hwaccel_context;
  38. void *tmp;
  39. if (!vda_ctx->decoder)
  40. return -1;
  41. tmp = av_fast_realloc(vda_ctx->bitstream, &vda_ctx->ref_size, vda_ctx->bitstream_size+size+4);
  42. if (!tmp)
  43. return AVERROR(ENOMEM);
  44. vda_ctx->bitstream = tmp;
  45. AV_WB32(vda_ctx->bitstream+vda_ctx->bitstream_size, size);
  46. memcpy(vda_ctx->bitstream+vda_ctx->bitstream_size+4, buffer, size);
  47. vda_ctx->bitstream_size += size + 4;
  48. return 0;
  49. }
  50. static int end_frame(AVCodecContext *avctx)
  51. {
  52. H264Context *h = avctx->priv_data;
  53. struct vda_context *vda_ctx = avctx->hwaccel_context;
  54. AVFrame *frame = (AVFrame*)h->s.current_picture_ptr;
  55. int status;
  56. if (!vda_ctx->decoder || !vda_ctx->bitstream)
  57. return -1;
  58. status = ff_vda_decoder_decode(vda_ctx, vda_ctx->bitstream,
  59. vda_ctx->bitstream_size,
  60. frame->reordered_opaque);
  61. if (status)
  62. av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
  63. return status;
  64. }
  65. AVHWAccel ff_h264_vda_hwaccel = {
  66. .name = "h264_vda",
  67. .type = AVMEDIA_TYPE_VIDEO,
  68. .id = CODEC_ID_H264,
  69. .pix_fmt = PIX_FMT_VDA_VLD,
  70. .capabilities = 0,
  71. .start_frame = start_frame,
  72. .decode_slice = decode_slice,
  73. .end_frame = end_frame,
  74. .priv_data_size = 0,
  75. };