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.

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