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 "h264.h"
  23. #include "vda_internal.h"
  24. static int start_frame(AVCodecContext *avctx,
  25. av_unused const uint8_t *buffer,
  26. av_unused uint32_t size)
  27. {
  28. struct vda_context *vda_ctx = avctx->hwaccel_context;
  29. if (!vda_ctx->decoder)
  30. return -1;
  31. vda_ctx->bitstream_size = 0;
  32. return 0;
  33. }
  34. static int decode_slice(AVCodecContext *avctx,
  35. const uint8_t *buffer,
  36. uint32_t size)
  37. {
  38. struct vda_context *vda_ctx = avctx->hwaccel_context;
  39. void *tmp;
  40. if (!vda_ctx->decoder)
  41. return -1;
  42. tmp = av_fast_realloc(vda_ctx->bitstream, &vda_ctx->ref_size, vda_ctx->bitstream_size+size+4);
  43. if (!tmp)
  44. return AVERROR(ENOMEM);
  45. vda_ctx->bitstream = tmp;
  46. AV_WB32(vda_ctx->bitstream+vda_ctx->bitstream_size, size);
  47. memcpy(vda_ctx->bitstream+vda_ctx->bitstream_size+4, buffer, size);
  48. vda_ctx->bitstream_size += size + 4;
  49. return 0;
  50. }
  51. static int end_frame(AVCodecContext *avctx)
  52. {
  53. H264Context *h = avctx->priv_data;
  54. struct vda_context *vda_ctx = avctx->hwaccel_context;
  55. AVFrame *frame = &h->s.current_picture_ptr->f;
  56. int status;
  57. if (!vda_ctx->decoder || !vda_ctx->bitstream)
  58. return -1;
  59. status = ff_vda_decoder_decode(vda_ctx, vda_ctx->bitstream,
  60. vda_ctx->bitstream_size,
  61. frame->reordered_opaque);
  62. if (status)
  63. av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status);
  64. return status;
  65. }
  66. AVHWAccel ff_h264_vda_hwaccel = {
  67. .name = "h264_vda",
  68. .type = AVMEDIA_TYPE_VIDEO,
  69. .id = CODEC_ID_H264,
  70. .pix_fmt = PIX_FMT_VDA_VLD,
  71. .start_frame = start_frame,
  72. .decode_slice = decode_slice,
  73. .end_frame = end_frame,
  74. .priv_data_size = 0,
  75. };