executor.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (C) 2023 Nuo Mi
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_EXECUTOR_H
  21. #define AVUTIL_EXECUTOR_H
  22. typedef struct AVExecutor AVExecutor;
  23. typedef struct AVTask AVTask;
  24. struct AVTask {
  25. AVTask *next;
  26. };
  27. typedef struct AVTaskCallbacks {
  28. void *user_data;
  29. int local_context_size;
  30. // return 1 if a's priority > b's priority
  31. int (*priority_higher)(const AVTask *a, const AVTask *b);
  32. // task is ready for run
  33. int (*ready)(const AVTask *t, void *user_data);
  34. // run the task
  35. int (*run)(AVTask *t, void *local_context, void *user_data);
  36. } AVTaskCallbacks;
  37. /**
  38. * Alloc executor
  39. * @param callbacks callback structure for executor
  40. * @param thread_count worker thread number
  41. * @return return the executor
  42. */
  43. AVExecutor* av_executor_alloc(const AVTaskCallbacks *callbacks, int thread_count);
  44. /**
  45. * Free executor
  46. * @param e pointer to executor
  47. */
  48. void av_executor_free(AVExecutor **e);
  49. /**
  50. * Add task to executor
  51. * @param e pointer to executor
  52. * @param t pointer to task. If NULL, it will wakeup one work thread
  53. */
  54. void av_executor_execute(AVExecutor *e, AVTask *t);
  55. #endif //AVUTIL_EXECUTOR_H