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.

120 lines
3.0KB

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