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.

87 lines
2.7KB

  1. /*
  2. * MJPEG HW decode acceleration through NVDEC
  3. *
  4. * Copyright (c) 2017 Philip Langdale
  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 "avcodec.h"
  23. #include "internal.h"
  24. #include "mjpegdec.h"
  25. #include "nvdec.h"
  26. #include "decode.h"
  27. static int nvdec_mjpeg_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
  28. {
  29. MJpegDecodeContext *s = avctx->priv_data;
  30. NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
  31. CUVIDPICPARAMS *pp = &ctx->pic_params;
  32. FrameDecodeData *fdd;
  33. NVDECFrame *cf;
  34. AVFrame *cur_frame = s->picture;
  35. int ret;
  36. ret = ff_nvdec_start_frame(avctx, cur_frame);
  37. if (ret < 0)
  38. return ret;
  39. fdd = (FrameDecodeData*)cur_frame->private_ref->data;
  40. cf = (NVDECFrame*)fdd->hwaccel_priv;
  41. *pp = (CUVIDPICPARAMS) {
  42. .PicWidthInMbs = (cur_frame->width + 15) / 16,
  43. .FrameHeightInMbs = (cur_frame->height + 15) / 16,
  44. .CurrPicIdx = cf->idx,
  45. .intra_pic_flag = 1,
  46. .ref_pic_flag = 0,
  47. };
  48. return ff_nvdec_simple_decode_slice(avctx, buffer, size);
  49. }
  50. static int nvdec_mjpeg_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
  51. {
  52. return 0;
  53. }
  54. static int nvdec_mjpeg_frame_params(AVCodecContext *avctx,
  55. AVBufferRef *hw_frames_ctx)
  56. {
  57. // Only need storage for the current frame
  58. return ff_nvdec_frame_params(avctx, hw_frames_ctx, 1, 0);
  59. }
  60. #if CONFIG_MJPEG_NVDEC_HWACCEL
  61. AVHWAccel ff_mjpeg_nvdec_hwaccel = {
  62. .name = "mjpeg_nvdec",
  63. .type = AVMEDIA_TYPE_VIDEO,
  64. .id = AV_CODEC_ID_MJPEG,
  65. .pix_fmt = AV_PIX_FMT_CUDA,
  66. .start_frame = nvdec_mjpeg_start_frame,
  67. .end_frame = ff_nvdec_simple_end_frame,
  68. .decode_slice = nvdec_mjpeg_decode_slice,
  69. .frame_params = nvdec_mjpeg_frame_params,
  70. .init = ff_nvdec_decode_init,
  71. .uninit = ff_nvdec_decode_uninit,
  72. .priv_data_size = sizeof(NVDECContext),
  73. };
  74. #endif