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.

121 lines
3.1KB

  1. /*
  2. * Video processing hooks
  3. * Copyright (c) 2000, 2001 Fabrice Bellard.
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <errno.h>
  22. #include "config.h"
  23. #include "avformat.h"
  24. #include "framehook.h"
  25. #ifdef HAVE_DLFCN_H
  26. #include <dlfcn.h>
  27. #endif
  28. typedef struct _FrameHookEntry {
  29. struct _FrameHookEntry *next;
  30. FrameHookConfigureFn Configure;
  31. FrameHookProcessFn Process;
  32. FrameHookReleaseFn Release;
  33. void *ctx;
  34. } FrameHookEntry;
  35. static FrameHookEntry *first_hook;
  36. /* Returns 0 on OK */
  37. int frame_hook_add(int argc, char *argv[])
  38. {
  39. #ifdef CONFIG_VHOOK
  40. void *loaded;
  41. FrameHookEntry *fhe, **fhep;
  42. if (argc < 1) {
  43. return ENOENT;
  44. }
  45. loaded = dlopen(argv[0], RTLD_NOW);
  46. if (!loaded) {
  47. av_log(NULL, AV_LOG_ERROR, "%s\n", dlerror());
  48. return -1;
  49. }
  50. fhe = av_mallocz(sizeof(*fhe));
  51. if (!fhe) {
  52. return AVERROR(ENOMEM);
  53. }
  54. fhe->Configure = dlsym(loaded, "Configure");
  55. fhe->Process = dlsym(loaded, "Process");
  56. fhe->Release = dlsym(loaded, "Release"); /* Optional */
  57. if (!fhe->Process) {
  58. av_log(NULL, AV_LOG_ERROR, "Failed to find Process entrypoint in %s\n", argv[0]);
  59. return AVERROR(ENOENT);
  60. }
  61. if (!fhe->Configure && argc > 1) {
  62. av_log(NULL, AV_LOG_ERROR, "Failed to find Configure entrypoint in %s\n", argv[0]);
  63. return AVERROR(ENOENT);
  64. }
  65. if (argc > 1 || fhe->Configure) {
  66. if (fhe->Configure(&fhe->ctx, argc, argv)) {
  67. av_log(NULL, AV_LOG_ERROR, "Failed to Configure %s\n", argv[0]);
  68. return AVERROR(EINVAL);
  69. }
  70. }
  71. for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
  72. }
  73. *fhep = fhe;
  74. return 0;
  75. #else
  76. av_log(NULL, AV_LOG_ERROR, "Video hooking not compiled into this version\n");
  77. return 1;
  78. #endif
  79. }
  80. void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts)
  81. {
  82. if (first_hook) {
  83. FrameHookEntry *fhe;
  84. for (fhe = first_hook; fhe; fhe = fhe->next) {
  85. fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
  86. }
  87. }
  88. }
  89. void frame_hook_release(void)
  90. {
  91. FrameHookEntry *fhe;
  92. FrameHookEntry *fhenext;
  93. for (fhe = first_hook; fhe; fhe = fhenext) {
  94. fhenext = fhe->next;
  95. if (fhe->Release)
  96. fhe->Release(fhe->ctx);
  97. av_free(fhe);
  98. }
  99. first_hook = NULL;
  100. }