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.

147 lines
4.4KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/avassert.h"
  19. #include "avdevice.h"
  20. #include "config.h"
  21. unsigned avdevice_version(void)
  22. {
  23. av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100);
  24. return LIBAVDEVICE_VERSION_INT;
  25. }
  26. const char * avdevice_configuration(void)
  27. {
  28. return FFMPEG_CONFIGURATION;
  29. }
  30. const char * avdevice_license(void)
  31. {
  32. #define LICENSE_PREFIX "libavdevice license: "
  33. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  34. }
  35. static void *av_device_next(void *prev, int output,
  36. AVClassCategory c1, AVClassCategory c2)
  37. {
  38. const AVClass *pc;
  39. AVClassCategory category = AV_CLASS_CATEGORY_NA;
  40. do {
  41. if (output) {
  42. if (!(prev = av_oformat_next(prev)))
  43. break;
  44. pc = ((AVOutputFormat *)prev)->priv_class;
  45. } else {
  46. if (!(prev = av_iformat_next(prev)))
  47. break;
  48. pc = ((AVInputFormat *)prev)->priv_class;
  49. }
  50. if (!pc)
  51. continue;
  52. category = pc->category;
  53. } while (category != c1 && category != c2);
  54. return prev;
  55. }
  56. AVInputFormat *av_input_audio_device_next(AVInputFormat *d)
  57. {
  58. return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT,
  59. AV_CLASS_CATEGORY_DEVICE_INPUT);
  60. }
  61. AVInputFormat *av_input_video_device_next(AVInputFormat *d)
  62. {
  63. return av_device_next(d, 0, AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT,
  64. AV_CLASS_CATEGORY_DEVICE_INPUT);
  65. }
  66. AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d)
  67. {
  68. return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT,
  69. AV_CLASS_CATEGORY_DEVICE_OUTPUT);
  70. }
  71. AVOutputFormat *av_output_video_device_next(AVOutputFormat *d)
  72. {
  73. return av_device_next(d, 1, AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT,
  74. AV_CLASS_CATEGORY_DEVICE_OUTPUT);
  75. }
  76. int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type,
  77. void *data, size_t data_size)
  78. {
  79. if (!s->oformat || !s->oformat->control_message)
  80. return AVERROR(ENOSYS);
  81. return s->oformat->control_message(s, type, data, data_size);
  82. }
  83. int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type,
  84. void *data, size_t data_size)
  85. {
  86. if (!s->control_message_cb)
  87. return AVERROR(ENOSYS);
  88. return s->control_message_cb(s, type, data, data_size);
  89. }
  90. int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
  91. {
  92. int ret;
  93. av_assert0(s);
  94. av_assert0(device_list);
  95. av_assert0(s->oformat || s->iformat);
  96. if ((s->oformat && !s->oformat->get_device_list) ||
  97. (s->iformat && !s->iformat->get_device_list)) {
  98. *device_list = NULL;
  99. return AVERROR(ENOSYS);
  100. }
  101. *device_list = av_mallocz(sizeof(AVDeviceInfoList));
  102. if (!(*device_list))
  103. return AVERROR(ENOMEM);
  104. if (s->oformat)
  105. ret = s->oformat->get_device_list(s, *device_list);
  106. else
  107. ret = s->iformat->get_device_list(s, *device_list);
  108. if (ret < 0)
  109. avdevice_free_list_devices(device_list);
  110. return ret;
  111. }
  112. void avdevice_free_list_devices(AVDeviceInfoList **device_list)
  113. {
  114. AVDeviceInfoList *list;
  115. AVDeviceInfo *dev;
  116. int i;
  117. av_assert0(device_list);
  118. list = *device_list;
  119. if (!list)
  120. return;
  121. for (i = 0; i < list->nb_devices; i++) {
  122. dev = list->devices[i];
  123. if (dev) {
  124. av_free(dev->device_name);
  125. av_free(dev->device_description);
  126. av_free(dev);
  127. }
  128. }
  129. av_free(list->devices);
  130. av_freep(device_list);
  131. }