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.

80 lines
1.9KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include "libavutil/mem.h"
  20. #include "vda.h"
  21. #include "vda_internal.h"
  22. #if CONFIG_H264_VDA_HWACCEL
  23. AVVDAContext *av_vda_alloc_context(void)
  24. {
  25. AVVDAContext *ret = av_mallocz(sizeof(*ret));
  26. if (ret) {
  27. ret->output_callback = ff_vda_output_callback;
  28. ret->cv_pix_fmt_type = kCVPixelFormatType_422YpCbCr8;
  29. }
  30. return ret;
  31. }
  32. int av_vda_default_init(AVCodecContext *avctx)
  33. {
  34. return av_vda_default_init2(avctx, NULL);
  35. }
  36. int av_vda_default_init2(AVCodecContext *avctx, AVVDAContext *vdactx)
  37. {
  38. avctx->hwaccel_context = vdactx ?: av_vda_alloc_context();
  39. if (!avctx->hwaccel_context)
  40. return AVERROR(ENOMEM);
  41. return ff_vda_default_init(avctx);
  42. }
  43. void av_vda_default_free(AVCodecContext *avctx)
  44. {
  45. ff_vda_default_free(avctx);
  46. av_freep(&avctx->hwaccel_context);
  47. }
  48. void ff_vda_default_free(AVCodecContext *avctx)
  49. {
  50. AVVDAContext *vda = avctx->hwaccel_context;
  51. if (vda && vda->decoder)
  52. VDADecoderDestroy(vda->decoder);
  53. }
  54. #else
  55. AVVDAContext *av_vda_alloc_context(void)
  56. {
  57. return NULL;
  58. }
  59. int av_vda_default_init(AVCodecContext *avctx)
  60. {
  61. return AVERROR(ENOSYS);
  62. }
  63. void av_vda_default_free(AVCodecContext *ctx)
  64. {
  65. }
  66. #endif