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.

160 lines
4.4KB

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