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.

167 lines
4.9KB

  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 "libavutil/samplefmt.h"
  20. #include "libavutil/pixfmt.h"
  21. #include "libavcodec/avcodec.h"
  22. #include "avdevice.h"
  23. #include "internal.h"
  24. #include "config.h"
  25. #include "libavutil/ffversion.h"
  26. const char av_device_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
  27. #if FF_API_DEVICE_CAPABILITIES
  28. const AVOption av_device_capabilities[] = {
  29. { NULL }
  30. };
  31. #endif
  32. unsigned avdevice_version(void)
  33. {
  34. av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100);
  35. return LIBAVDEVICE_VERSION_INT;
  36. }
  37. const char * avdevice_configuration(void)
  38. {
  39. return FFMPEG_CONFIGURATION;
  40. }
  41. const char * avdevice_license(void)
  42. {
  43. #define LICENSE_PREFIX "libavdevice license: "
  44. return &LICENSE_PREFIX FFMPEG_LICENSE[sizeof(LICENSE_PREFIX) - 1];
  45. }
  46. int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type,
  47. void *data, size_t data_size)
  48. {
  49. if (!s->oformat || !s->oformat->control_message)
  50. return AVERROR(ENOSYS);
  51. return s->oformat->control_message(s, type, data, data_size);
  52. }
  53. int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type,
  54. void *data, size_t data_size)
  55. {
  56. if (!s->control_message_cb)
  57. return AVERROR(ENOSYS);
  58. return s->control_message_cb(s, type, data, data_size);
  59. }
  60. #if FF_API_DEVICE_CAPABILITIES
  61. int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
  62. AVDictionary **device_options)
  63. {
  64. return AVERROR(ENOSYS);
  65. }
  66. void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
  67. {
  68. return;
  69. }
  70. #endif
  71. int avdevice_list_devices(AVFormatContext *s, AVDeviceInfoList **device_list)
  72. {
  73. int ret;
  74. av_assert0(s);
  75. av_assert0(device_list);
  76. av_assert0(s->oformat || s->iformat);
  77. if ((s->oformat && !s->oformat->get_device_list) ||
  78. (s->iformat && !s->iformat->get_device_list)) {
  79. *device_list = NULL;
  80. return AVERROR(ENOSYS);
  81. }
  82. *device_list = av_mallocz(sizeof(AVDeviceInfoList));
  83. if (!(*device_list))
  84. return AVERROR(ENOMEM);
  85. /* no default device by default */
  86. (*device_list)->default_device = -1;
  87. if (s->oformat)
  88. ret = s->oformat->get_device_list(s, *device_list);
  89. else
  90. ret = s->iformat->get_device_list(s, *device_list);
  91. if (ret < 0)
  92. avdevice_free_list_devices(device_list);
  93. return ret;
  94. }
  95. static int list_devices_for_context(AVFormatContext *s, AVDictionary *options,
  96. AVDeviceInfoList **device_list)
  97. {
  98. AVDictionary *tmp = NULL;
  99. int ret;
  100. av_dict_copy(&tmp, options, 0);
  101. if ((ret = av_opt_set_dict2(s, &tmp, AV_OPT_SEARCH_CHILDREN)) < 0)
  102. goto fail;
  103. ret = avdevice_list_devices(s, device_list);
  104. fail:
  105. av_dict_free(&tmp);
  106. avformat_free_context(s);
  107. return ret;
  108. }
  109. int avdevice_list_input_sources(AVInputFormat *device, const char *device_name,
  110. AVDictionary *device_options, AVDeviceInfoList **device_list)
  111. {
  112. AVFormatContext *s = NULL;
  113. int ret;
  114. if ((ret = ff_alloc_input_device_context(&s, device, device_name)) < 0)
  115. return ret;
  116. return list_devices_for_context(s, device_options, device_list);
  117. }
  118. int avdevice_list_output_sinks(AVOutputFormat *device, const char *device_name,
  119. AVDictionary *device_options, AVDeviceInfoList **device_list)
  120. {
  121. AVFormatContext *s = NULL;
  122. int ret;
  123. if ((ret = avformat_alloc_output_context2(&s, device, device_name, NULL)) < 0)
  124. return ret;
  125. return list_devices_for_context(s, device_options, device_list);
  126. }
  127. void avdevice_free_list_devices(AVDeviceInfoList **device_list)
  128. {
  129. AVDeviceInfoList *list;
  130. AVDeviceInfo *dev;
  131. int i;
  132. av_assert0(device_list);
  133. list = *device_list;
  134. if (!list)
  135. return;
  136. for (i = 0; i < list->nb_devices; i++) {
  137. dev = list->devices[i];
  138. if (dev) {
  139. av_freep(&dev->device_name);
  140. av_freep(&dev->device_description);
  141. av_free(dev);
  142. }
  143. }
  144. av_freep(&list->devices);
  145. av_freep(device_list);
  146. }