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.

117 lines
3.7KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVFILTER_OPENCL_H
  19. #define AVFILTER_OPENCL_H
  20. // The intended target is OpenCL 1.2, so disable warnings for APIs
  21. // deprecated after that. This primarily applies to clCreateCommandQueue(),
  22. // we can't use the replacement clCreateCommandQueueWithProperties() because
  23. // it was introduced in OpenCL 2.0.
  24. #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
  25. #include "libavutil/buffer.h"
  26. #include "libavutil/hwcontext.h"
  27. #include "libavutil/hwcontext_opencl.h"
  28. #include "libavutil/pixfmt.h"
  29. #include "avfilter.h"
  30. typedef struct OpenCLFilterContext {
  31. const AVClass *class;
  32. AVBufferRef *device_ref;
  33. AVHWDeviceContext *device;
  34. AVOpenCLDeviceContext *hwctx;
  35. cl_program program;
  36. enum AVPixelFormat output_format;
  37. int output_width;
  38. int output_height;
  39. } OpenCLFilterContext;
  40. /**
  41. * set argument to specific Kernel.
  42. * This macro relies on usage of local label "fail" and variables:
  43. * avctx, cle and err.
  44. */
  45. #define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg) \
  46. cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg); \
  47. if (cle != CL_SUCCESS) { \
  48. av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
  49. "argument %d: error %d.\n", arg_num, cle); \
  50. err = AVERROR(EIO); \
  51. goto fail; \
  52. }
  53. /**
  54. * Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
  55. */
  56. int ff_opencl_filter_query_formats(AVFilterContext *avctx);
  57. /**
  58. * Check that the input link contains a suitable hardware frames
  59. * context and extract the device from it.
  60. */
  61. int ff_opencl_filter_config_input(AVFilterLink *inlink);
  62. /**
  63. * Create a suitable hardware frames context for the output.
  64. */
  65. int ff_opencl_filter_config_output(AVFilterLink *outlink);
  66. /**
  67. * Initialise an OpenCL filter context.
  68. */
  69. int ff_opencl_filter_init(AVFilterContext *avctx);
  70. /**
  71. * Uninitialise an OpenCL filter context.
  72. */
  73. void ff_opencl_filter_uninit(AVFilterContext *avctx);
  74. /**
  75. * Load a new OpenCL program from strings in memory.
  76. *
  77. * Creates a new program and compiles it for the current device.
  78. * Will log any build errors if compilation fails.
  79. */
  80. int ff_opencl_filter_load_program(AVFilterContext *avctx,
  81. const char **program_source_array,
  82. int nb_strings);
  83. /**
  84. * Load a new OpenCL program from a file.
  85. *
  86. * Same as ff_opencl_filter_load_program(), but from a file.
  87. */
  88. int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx,
  89. const char *filename);
  90. /**
  91. * Find the work size needed needed for a given plane of an image.
  92. */
  93. int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx,
  94. size_t *work_size,
  95. AVFrame *frame, int plane,
  96. int block_alignment);
  97. #endif /* AVFILTER_OPENCL_H */