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.

174 lines
5.0KB

  1. /*
  2. * Register all the grabbing devices.
  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. #include "config.h"
  21. #include "libavutil/thread.h"
  22. #include "avdevice.h"
  23. #if FF_API_NEXT
  24. #include "libavformat/internal.h"
  25. #endif
  26. /* devices */
  27. extern AVInputFormat ff_alsa_demuxer;
  28. extern AVOutputFormat ff_alsa_muxer;
  29. extern AVInputFormat ff_avfoundation_demuxer;
  30. extern AVInputFormat ff_bktr_demuxer;
  31. extern AVOutputFormat ff_caca_muxer;
  32. extern AVInputFormat ff_decklink_demuxer;
  33. extern AVOutputFormat ff_decklink_muxer;
  34. extern AVInputFormat ff_libndi_newtek_demuxer;
  35. extern AVOutputFormat ff_libndi_newtek_muxer;
  36. extern AVInputFormat ff_dshow_demuxer;
  37. extern AVInputFormat ff_fbdev_demuxer;
  38. extern AVOutputFormat ff_fbdev_muxer;
  39. extern AVInputFormat ff_gdigrab_demuxer;
  40. extern AVInputFormat ff_iec61883_demuxer;
  41. extern AVInputFormat ff_jack_demuxer;
  42. extern AVInputFormat ff_kmsgrab_demuxer;
  43. extern AVInputFormat ff_lavfi_demuxer;
  44. extern AVInputFormat ff_openal_demuxer;
  45. extern AVOutputFormat ff_opengl_muxer;
  46. extern AVInputFormat ff_oss_demuxer;
  47. extern AVOutputFormat ff_oss_muxer;
  48. extern AVInputFormat ff_pulse_demuxer;
  49. extern AVOutputFormat ff_pulse_muxer;
  50. extern AVOutputFormat ff_sdl2_muxer;
  51. extern AVInputFormat ff_sndio_demuxer;
  52. extern AVOutputFormat ff_sndio_muxer;
  53. extern AVInputFormat ff_v4l2_demuxer;
  54. extern AVOutputFormat ff_v4l2_muxer;
  55. extern AVInputFormat ff_vfwcap_demuxer;
  56. extern AVInputFormat ff_xcbgrab_demuxer;
  57. extern AVOutputFormat ff_xv_muxer;
  58. /* external libraries */
  59. extern AVInputFormat ff_libcdio_demuxer;
  60. extern AVInputFormat ff_libdc1394_demuxer;
  61. #include "libavdevice/outdev_list.c"
  62. #include "libavdevice/indev_list.c"
  63. const AVOutputFormat *av_outdev_iterate(void **opaque)
  64. {
  65. uintptr_t i = (uintptr_t)*opaque;
  66. const AVOutputFormat *f = outdev_list[i];
  67. if (f)
  68. *opaque = (void*)(i + 1);
  69. return f;
  70. }
  71. const AVInputFormat *av_indev_iterate(void **opaque)
  72. {
  73. uintptr_t i = (uintptr_t)*opaque;
  74. const AVInputFormat *f = indev_list[i];
  75. if (f)
  76. *opaque = (void*)(i + 1);
  77. return f;
  78. }
  79. #if FF_API_NEXT
  80. FF_DISABLE_DEPRECATION_WARNINGS
  81. static AVOnce av_device_next_init = AV_ONCE_INIT;
  82. static void av_device_init_next(void)
  83. {
  84. AVOutputFormat *prevout = NULL, *out;
  85. AVInputFormat *previn = NULL, *in;
  86. void *i = 0;
  87. while ((out = (AVOutputFormat*)av_outdev_iterate(&i))) {
  88. if (prevout)
  89. prevout->next = out;
  90. prevout = out;
  91. }
  92. i = 0;
  93. while ((in = (AVInputFormat*)av_indev_iterate(&i))) {
  94. if (previn)
  95. previn->next = in;
  96. previn = in;
  97. }
  98. avpriv_register_devices(outdev_list, indev_list);
  99. }
  100. void avdevice_register_all(void)
  101. {
  102. ff_thread_once(&av_device_next_init, av_device_init_next);
  103. }
  104. static void *device_next(void *prev, int output,
  105. AVClassCategory c1, AVClassCategory c2)
  106. {
  107. const AVClass *pc;
  108. AVClassCategory category = AV_CLASS_CATEGORY_NA;
  109. ff_thread_once(&av_device_next_init, av_device_init_next);
  110. if (!prev && !(prev = (output ? (void*)outdev_list[0] : (void*)indev_list[0])))
  111. return NULL;
  112. do {
  113. if (output) {
  114. if (!(prev = ((AVOutputFormat *)prev)->next))
  115. break;
  116. pc = ((AVOutputFormat *)prev)->priv_class;
  117. } else {
  118. if (!(prev = ((AVInputFormat *)prev)->next))
  119. break;
  120. pc = ((AVInputFormat *)prev)->priv_class;
  121. }
  122. if (!pc)
  123. continue;
  124. category = pc->category;
  125. } while (category != c1 && category != c2);
  126. return prev;
  127. }
  128. AVInputFormat *av_input_audio_device_next(AVInputFormat *d)
  129. {
  130. return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
  131. AV_CLASS_CATEGORY_DEVICE_INPUT);
  132. }
  133. AVInputFormat *av_input_video_device_next(AVInputFormat *d)
  134. {
  135. return device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
  136. AV_CLASS_CATEGORY_DEVICE_INPUT);
  137. }
  138. AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
  139. {
  140. return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
  141. AV_CLASS_CATEGORY_DEVICE_OUTPUT);
  142. }
  143. AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
  144. {
  145. return device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
  146. AV_CLASS_CATEGORY_DEVICE_OUTPUT);
  147. }
  148. FF_DISABLE_DEPRECATION_WARNINGS
  149. #endif