enum_options.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2011 Anton Khirnov
  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. /*
  21. * enumerate avoptions and format them in texinfo format
  22. */
  23. #include <string.h>
  24. #include "libavformat/avformat.h"
  25. #include "libavcodec/avcodec.h"
  26. #include "libavutil/log.h"
  27. #include "libavutil/opt.h"
  28. static void print_usage(void)
  29. {
  30. fprintf(stderr, "Usage: enum_options type\n"
  31. "type: format codec\n");
  32. exit(1);
  33. }
  34. static void print_option(const AVClass *class, const AVOption *o)
  35. {
  36. printf("@item -%s @var{", o->name);
  37. switch (o->type) {
  38. case AV_OPT_TYPE_BINARY: printf("hexadecimal string"); break;
  39. case AV_OPT_TYPE_STRING: printf("string"); break;
  40. case AV_OPT_TYPE_INT:
  41. case AV_OPT_TYPE_INT64: printf("integer"); break;
  42. case AV_OPT_TYPE_FLOAT:
  43. case AV_OPT_TYPE_DOUBLE: printf("float"); break;
  44. case AV_OPT_TYPE_RATIONAL: printf("rational number"); break;
  45. case AV_OPT_TYPE_FLAGS: printf("flags"); break;
  46. default: printf("value"); break;
  47. }
  48. printf("} (@emph{");
  49. if (o->flags & AV_OPT_FLAG_ENCODING_PARAM) {
  50. printf("input");
  51. if (o->flags & AV_OPT_FLAG_ENCODING_PARAM)
  52. printf("/");
  53. }
  54. if (o->flags & AV_OPT_FLAG_ENCODING_PARAM)
  55. printf("output");
  56. printf("})\n");
  57. if (o->help)
  58. printf("%s\n", o->help);
  59. if (o->unit) {
  60. const AVOption *u = NULL;
  61. printf("\nPossible values:\n@table @samp\n");
  62. while ((u = av_opt_next(&class, u)))
  63. if (u->type == AV_OPT_TYPE_CONST && u->unit && !strcmp(u->unit, o->unit))
  64. printf("@item %s\n%s\n", u->name, u->help ? u->help : "");
  65. printf("@end table\n");
  66. }
  67. }
  68. static void show_opts(const AVClass *class)
  69. {
  70. const AVOption *o = NULL;
  71. printf("@table @option\n");
  72. while ((o = av_opt_next(&class, o)))
  73. if (o->type != AV_OPT_TYPE_CONST)
  74. print_option(class, o);
  75. printf("@end table\n");
  76. }
  77. static void show_format_opts(void)
  78. {
  79. const AVInputFormat *iformat = NULL;
  80. const AVOutputFormat *oformat = NULL;
  81. void *iformat_opaque = NULL;
  82. void *oformat_opaque = NULL;
  83. printf("@section Generic format AVOptions\n");
  84. show_opts(avformat_get_class());
  85. printf("@section Format-specific AVOptions\n");
  86. while ((iformat = av_demuxer_iterate(&iformat_opaque))) {
  87. if (!iformat->priv_class)
  88. continue;
  89. printf("@subsection %s AVOptions\n", iformat->priv_class->class_name);
  90. show_opts(iformat->priv_class);
  91. }
  92. while ((oformat = av_muxer_iterate(&oformat_opaque))) {
  93. if (!oformat->priv_class)
  94. continue;
  95. printf("@subsection %s AVOptions\n", oformat->priv_class->class_name);
  96. show_opts(oformat->priv_class);
  97. }
  98. }
  99. static void show_codec_opts(void)
  100. {
  101. void *iter = NULL;
  102. const AVCodec *c;
  103. printf("@section Generic codec AVOptions\n");
  104. show_opts(avcodec_get_class());
  105. printf("@section Codec-specific AVOptions\n");
  106. while ((c = av_codec_iterate(&iter))) {
  107. if (!c->priv_class)
  108. continue;
  109. printf("@subsection %s AVOptions\n", c->priv_class->class_name);
  110. show_opts(c->priv_class);
  111. }
  112. }
  113. int main(int argc, char **argv)
  114. {
  115. if (argc < 2)
  116. print_usage();
  117. if (!strcmp(argv[1], "format"))
  118. show_format_opts();
  119. else if (!strcmp(argv[1], "codec"))
  120. show_codec_opts();
  121. else
  122. print_usage();
  123. return 0;
  124. }