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.

157 lines
4.1KB

  1. /*
  2. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "avformat.h"
  21. #include "avio_internal.h"
  22. #include "internal.h"
  23. #include "url.h"
  24. #include "libavutil/internal.h"
  25. #include "libavutil/opt.h"
  26. /**
  27. * @file
  28. * Options definition for AVFormatContext.
  29. */
  30. FF_DISABLE_DEPRECATION_WARNINGS
  31. #include "options_table.h"
  32. FF_ENABLE_DEPRECATION_WARNINGS
  33. static const char* format_to_name(void* ptr)
  34. {
  35. AVFormatContext* fc = (AVFormatContext*) ptr;
  36. if(fc->iformat) return fc->iformat->name;
  37. else if(fc->oformat) return fc->oformat->name;
  38. else return "NULL";
  39. }
  40. static void *format_child_next(void *obj, void *prev)
  41. {
  42. AVFormatContext *s = obj;
  43. if (!prev && s->priv_data &&
  44. ((s->iformat && s->iformat->priv_class) ||
  45. s->oformat && s->oformat->priv_class))
  46. return s->priv_data;
  47. if (s->pb && s->pb->av_class && prev != s->pb)
  48. return s->pb;
  49. return NULL;
  50. }
  51. static const AVClass *format_child_class_next(const AVClass *prev)
  52. {
  53. AVInputFormat *ifmt = NULL;
  54. AVOutputFormat *ofmt = NULL;
  55. if (!prev)
  56. return &ff_avio_class;
  57. while ((ifmt = av_iformat_next(ifmt)))
  58. if (ifmt->priv_class == prev)
  59. break;
  60. if (!ifmt)
  61. while ((ofmt = av_oformat_next(ofmt)))
  62. if (ofmt->priv_class == prev)
  63. break;
  64. if (!ofmt)
  65. while (ifmt = av_iformat_next(ifmt))
  66. if (ifmt->priv_class)
  67. return ifmt->priv_class;
  68. while (ofmt = av_oformat_next(ofmt))
  69. if (ofmt->priv_class)
  70. return ofmt->priv_class;
  71. return NULL;
  72. }
  73. static const AVClass av_format_context_class = {
  74. .class_name = "AVFormatContext",
  75. .item_name = format_to_name,
  76. .option = avformat_options,
  77. .version = LIBAVUTIL_VERSION_INT,
  78. .child_next = format_child_next,
  79. .child_class_next = format_child_class_next,
  80. };
  81. static int io_open_default(AVFormatContext *s, AVIOContext **pb,
  82. const char *url, int flags, AVDictionary **options)
  83. {
  84. AVDictionary *opts_local = NULL;
  85. int ret;
  86. if (!options)
  87. options = &opts_local;
  88. if (s->protocol_whitelist) {
  89. ret = av_dict_set(options, "protocol_whitelist", s->protocol_whitelist, 0);
  90. if (ret < 0)
  91. goto finish;
  92. }
  93. if (s->protocol_blacklist) {
  94. ret = av_dict_set(options, "protocol_blacklist", s->protocol_blacklist, 0);
  95. if (ret < 0)
  96. goto finish;
  97. }
  98. ret = avio_open2(pb, url, flags, &s->interrupt_callback, options);
  99. finish:
  100. av_dict_free(&opts_local);
  101. return ret;
  102. }
  103. static void io_close_default(AVFormatContext *s, AVIOContext *pb)
  104. {
  105. avio_close(pb);
  106. }
  107. static void avformat_get_context_defaults(AVFormatContext *s)
  108. {
  109. memset(s, 0, sizeof(AVFormatContext));
  110. s->av_class = &av_format_context_class;
  111. s->io_open = io_open_default;
  112. s->io_close = io_close_default;
  113. av_opt_set_defaults(s);
  114. }
  115. AVFormatContext *avformat_alloc_context(void)
  116. {
  117. AVFormatContext *ic;
  118. ic = av_malloc(sizeof(AVFormatContext));
  119. if (!ic) return ic;
  120. avformat_get_context_defaults(ic);
  121. ic->internal = av_mallocz(sizeof(*ic->internal));
  122. if (!ic->internal) {
  123. avformat_free_context(ic);
  124. return NULL;
  125. }
  126. ic->internal->offset = AV_NOPTS_VALUE;
  127. return ic;
  128. }
  129. const AVClass *avformat_get_class(void)
  130. {
  131. return &av_format_context_class;
  132. }