enum_options.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2011 Anton Khirnov
  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. /*
  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 FF_OPT_TYPE_BINARY: printf("hexadecimal string"); break;
  39. case FF_OPT_TYPE_STRING: printf("string"); break;
  40. case FF_OPT_TYPE_INT:
  41. case FF_OPT_TYPE_INT64: printf("integer"); break;
  42. case FF_OPT_TYPE_FLOAT:
  43. case FF_OPT_TYPE_DOUBLE: printf("float"); break;
  44. case FF_OPT_TYPE_RATIONAL: printf("rational number"); break;
  45. case FF_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_next_option(&class, u)))
  63. if (u->type == FF_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_next_option(&class, o)))
  73. if (o->type != FF_OPT_TYPE_CONST)
  74. print_option(class, o);
  75. printf("@end table\n");
  76. }
  77. static void show_format_opts(void)
  78. {
  79. AVInputFormat *iformat = NULL;
  80. AVOutputFormat *oformat = NULL;
  81. printf("@section Generic format AVOptions\n");
  82. show_opts(avformat_get_class());
  83. printf("@section Format-specific AVOptions\n");
  84. while ((iformat = av_iformat_next(iformat))) {
  85. if (!iformat->priv_class)
  86. continue;
  87. printf("@subsection %s AVOptions\n", iformat->priv_class->class_name);
  88. show_opts(iformat->priv_class);
  89. }
  90. while ((oformat = av_oformat_next(oformat))) {
  91. if (!oformat->priv_class)
  92. continue;
  93. printf("@subsection %s AVOptions\n", oformat->priv_class->class_name);
  94. show_opts(oformat->priv_class);
  95. }
  96. }
  97. static void show_codec_opts(void)
  98. {
  99. AVCodec *c = NULL;
  100. printf("@section Generic codec AVOptions\n");
  101. show_opts(avcodec_get_class());
  102. printf("@section Codec-specific AVOptions\n");
  103. while ((c = av_codec_next(c))) {
  104. if (!c->priv_class)
  105. continue;
  106. printf("@subsection %s AVOptions\n", c->priv_class->class_name);
  107. show_opts(c->priv_class);
  108. }
  109. }
  110. int main(int argc, char **argv)
  111. {
  112. if (argc < 2)
  113. print_usage();
  114. av_register_all();
  115. if (!strcmp(argv[1], "format"))
  116. show_format_opts();
  117. else if (!strcmp(argv[1], "codec"))
  118. show_codec_opts();
  119. else
  120. print_usage();
  121. return 0;
  122. }