options.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "libavutil/opt.h"
  22. /**
  23. * @file
  24. * Options definition for AVFormatContext.
  25. */
  26. static const char* format_to_name(void* ptr)
  27. {
  28. AVFormatContext* fc = (AVFormatContext*) ptr;
  29. if(fc->iformat) return fc->iformat->name;
  30. else if(fc->oformat) return fc->oformat->name;
  31. else return "NULL";
  32. }
  33. static const AVOption *opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
  34. {
  35. AVFormatContext *s = obj;
  36. AVInputFormat *ifmt = NULL;
  37. AVOutputFormat *ofmt = NULL;
  38. if (s->priv_data) {
  39. if ((s->iformat && !s->iformat->priv_class) ||
  40. (s->oformat && !s->oformat->priv_class))
  41. return NULL;
  42. return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags);
  43. }
  44. while ((ifmt = av_iformat_next(ifmt))) {
  45. const AVOption *o;
  46. if (ifmt->priv_class && (o = av_opt_find(&ifmt->priv_class, name, unit, opt_flags, search_flags)))
  47. return o;
  48. }
  49. while ((ofmt = av_oformat_next(ofmt))) {
  50. const AVOption *o;
  51. if (ofmt->priv_class && (o = av_opt_find(&ofmt->priv_class, name, unit, opt_flags, search_flags)))
  52. return o;
  53. }
  54. return NULL;
  55. }
  56. #define OFFSET(x) offsetof(AVFormatContext,x)
  57. #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C
  58. //these names are too long to be readable
  59. #define E AV_OPT_FLAG_ENCODING_PARAM
  60. #define D AV_OPT_FLAG_DECODING_PARAM
  61. static const AVOption options[]={
  62. {"probesize", "set probing size", OFFSET(probesize), FF_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D},
  63. {"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
  64. {"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E},
  65. {"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
  66. {"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
  67. {"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
  68. {"nofillin", "do not fill in missing values that can be exactly calculated", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},
  69. {"noparse", "disable AVParsers, this needs nofillin too", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"},
  70. {"igndts", "ignore dts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"},
  71. #if FF_API_FLAG_RTP_HINT
  72. {"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"},
  73. #endif
  74. {"discardcorrupt", "discard corrupted frames", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"},
  75. {"sortdts", "try to interleave outputted packets by dts", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"},
  76. {"keepside", "dont merge side data", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"},
  77. {"latm", "enable RTP MP4A-LATM payload", 0, FF_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"},
  78. {"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D},
  79. {"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D},
  80. {"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D},
  81. {"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */
  82. {"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
  83. {"ts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
  84. {"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
  85. {"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), FF_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D},
  86. {NULL},
  87. };
  88. #undef E
  89. #undef D
  90. #undef DEFAULT
  91. static const AVClass av_format_context_class = {
  92. .class_name = "AVFormatContext",
  93. .item_name = format_to_name,
  94. .option = options,
  95. .version = LIBAVUTIL_VERSION_INT,
  96. .opt_find = opt_find,
  97. };
  98. static void avformat_get_context_defaults(AVFormatContext *s)
  99. {
  100. memset(s, 0, sizeof(AVFormatContext));
  101. s->av_class = &av_format_context_class;
  102. av_opt_set_defaults(s);
  103. }
  104. AVFormatContext *avformat_alloc_context(void)
  105. {
  106. AVFormatContext *ic;
  107. ic = av_malloc(sizeof(AVFormatContext));
  108. if (!ic) return ic;
  109. avformat_get_context_defaults(ic);
  110. return ic;
  111. }
  112. #if FF_API_ALLOC_FORMAT_CONTEXT
  113. AVFormatContext *av_alloc_format_context(void)
  114. {
  115. return avformat_alloc_context();
  116. }
  117. #endif