options.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "libavutil/opt.h"
  23. /**
  24. * @file
  25. * Options definition for AVFormatContext.
  26. */
  27. #include "options_table.h"
  28. static const char* format_to_name(void* ptr)
  29. {
  30. AVFormatContext* fc = (AVFormatContext*) ptr;
  31. if(fc->iformat) return fc->iformat->name;
  32. else if(fc->oformat) return fc->oformat->name;
  33. else return "NULL";
  34. }
  35. static void *format_child_next(void *obj, void *prev)
  36. {
  37. AVFormatContext *s = obj;
  38. if (!prev && s->priv_data &&
  39. ((s->iformat && s->iformat->priv_class) ||
  40. s->oformat && s->oformat->priv_class))
  41. return s->priv_data;
  42. if (s->pb && s->pb->av_class && prev != s->pb)
  43. return s->pb;
  44. return NULL;
  45. }
  46. static const AVClass *format_child_class_next(const AVClass *prev)
  47. {
  48. AVInputFormat *ifmt = NULL;
  49. AVOutputFormat *ofmt = NULL;
  50. if (!prev)
  51. return &ffio_url_class;
  52. while ((ifmt = av_iformat_next(ifmt)))
  53. if (ifmt->priv_class == prev)
  54. break;
  55. if (!ifmt)
  56. while ((ofmt = av_oformat_next(ofmt)))
  57. if (ofmt->priv_class == prev)
  58. break;
  59. if (!ofmt)
  60. while (ifmt = av_iformat_next(ifmt))
  61. if (ifmt->priv_class)
  62. return ifmt->priv_class;
  63. while (ofmt = av_oformat_next(ofmt))
  64. if (ofmt->priv_class)
  65. return ofmt->priv_class;
  66. return NULL;
  67. }
  68. static AVClassCategory get_category(void *ptr)
  69. {
  70. AVFormatContext* s = ptr;
  71. if(s->iformat) return AV_CLASS_CATEGORY_DEMUXER;
  72. else return AV_CLASS_CATEGORY_MUXER;
  73. }
  74. static const AVClass av_format_context_class = {
  75. .class_name = "AVFormatContext",
  76. .item_name = format_to_name,
  77. .option = options,
  78. .version = LIBAVUTIL_VERSION_INT,
  79. .child_next = format_child_next,
  80. .child_class_next = format_child_class_next,
  81. .category = AV_CLASS_CATEGORY_MUXER,
  82. .get_category = get_category,
  83. };
  84. static void avformat_get_context_defaults(AVFormatContext *s)
  85. {
  86. memset(s, 0, sizeof(AVFormatContext));
  87. s->av_class = &av_format_context_class;
  88. av_opt_set_defaults(s);
  89. }
  90. AVFormatContext *avformat_alloc_context(void)
  91. {
  92. AVFormatContext *ic;
  93. ic = av_malloc(sizeof(AVFormatContext));
  94. if (!ic) return ic;
  95. avformat_get_context_defaults(ic);
  96. return ic;
  97. }
  98. enum AVDurationEstimationMethod av_fmt_ctx_get_duration_estimation_method(const AVFormatContext* ctx)
  99. {
  100. return ctx->duration_estimation_method;
  101. }
  102. const AVClass *avformat_get_class(void)
  103. {
  104. return &av_format_context_class;
  105. }