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.

103 lines
2.6KB

  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <errno.h>
  20. #include "config.h"
  21. #include "framehook.h"
  22. #include "avformat.h"
  23. #ifdef HAVE_VHOOK
  24. #include <dlfcn.h>
  25. #endif
  26. typedef struct _FrameHookEntry {
  27. struct _FrameHookEntry *next;
  28. FrameHookConfigureFn Configure;
  29. FrameHookProcessFn Process;
  30. void *ctx;
  31. } FrameHookEntry;
  32. static FrameHookEntry *first_hook;
  33. /* Returns 0 on OK */
  34. int frame_hook_add(int argc, char *argv[])
  35. {
  36. #ifdef HAVE_VHOOK
  37. void *loaded;
  38. FrameHookEntry *fhe, **fhep;
  39. if (argc < 1) {
  40. return ENOENT;
  41. }
  42. loaded = dlopen(argv[0], RTLD_NOW);
  43. if (!loaded) {
  44. fprintf(stderr, "%s\n", dlerror());
  45. return -1;
  46. }
  47. fhe = av_mallocz(sizeof(*fhe));
  48. if (!fhe) {
  49. return errno;
  50. }
  51. fhe->Configure = dlsym(loaded, "Configure");
  52. fhe->Process = dlsym(loaded, "Process");
  53. if (!fhe->Process) {
  54. fprintf(stderr, "Failed to find Process entrypoint in %s\n", argv[0]);
  55. return -1;
  56. }
  57. if (!fhe->Configure && argc > 1) {
  58. fprintf(stderr, "Failed to find Configure entrypoint in %s\n", argv[0]);
  59. return -1;
  60. }
  61. if (argc > 1 || fhe->Configure) {
  62. if (fhe->Configure(&fhe->ctx, argc, argv)) {
  63. fprintf(stderr, "Failed to Configure %s\n", argv[0]);
  64. return -1;
  65. }
  66. }
  67. for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
  68. }
  69. *fhep = fhe;
  70. return 0;
  71. #else
  72. fprintf(stderr, "Video hooking not compiled into this version\n");
  73. return 1;
  74. #endif
  75. }
  76. void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height)
  77. {
  78. if (first_hook) {
  79. FrameHookEntry *fhe;
  80. INT64 pts = av_gettime();
  81. for (fhe = first_hook; fhe; fhe = fhe->next) {
  82. fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
  83. }
  84. }
  85. }