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.

111 lines
3.6KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <limits.h>
  19. #include <stdio.h>
  20. #include "libavutil/common.h"
  21. #include "libavutil/error.h"
  22. #include "libavutil/log.h"
  23. #include "libavutil/mem.h"
  24. #include "libavutil/rational.h"
  25. #include "libavutil/opt.h"
  26. typedef struct TestContext {
  27. const AVClass *class;
  28. int num;
  29. int toggle;
  30. char *string;
  31. int flags;
  32. AVRational rational;
  33. } TestContext;
  34. #define OFFSET(x) offsetof(TestContext, x)
  35. #define TEST_FLAG_COOL 01
  36. #define TEST_FLAG_LAME 02
  37. #define TEST_FLAG_MU 04
  38. static const AVOption test_options[] = {
  39. { "num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 100 },
  40. { "toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1 },
  41. { "rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 0 }, 0, 10 },
  42. { "string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { 0 }, CHAR_MIN, CHAR_MAX },
  43. { "flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX, 0, "flags"},
  44. { "cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 0, "flags"},
  45. { "lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 0, "flags"},
  46. { "mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 0, "flags"},
  47. { NULL },
  48. };
  49. static const char *test_get_name(void *ctx)
  50. {
  51. return "test";
  52. }
  53. static const AVClass test_class = {
  54. "TestContext",
  55. test_get_name,
  56. test_options
  57. };
  58. int main(void)
  59. {
  60. int i;
  61. TestContext test_ctx = { .class = &test_class };
  62. static const char *options[] = {
  63. "",
  64. ":",
  65. "=",
  66. "foo=:",
  67. ":=foo",
  68. "=foo",
  69. "foo=",
  70. "foo",
  71. "foo=val",
  72. "foo==val",
  73. "toggle=:",
  74. "string=:",
  75. "toggle=1 : foo",
  76. "toggle=100",
  77. "toggle==1",
  78. "flags=+mu-lame : num=42: toggle=0",
  79. "num=42 : string=blahblah",
  80. "rational=0 : rational=1/2 : rational=1/-1",
  81. "rational=-1/0",
  82. };
  83. printf("\nTesting av_set_options_string()\n");
  84. av_opt_set_defaults(&test_ctx);
  85. test_ctx.string = av_strdup("default");
  86. if (!test_ctx.string)
  87. return AVERROR(ENOMEM);
  88. av_log_set_level(AV_LOG_DEBUG);
  89. for (i = 0; i < FF_ARRAY_ELEMS(options); i++) {
  90. av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
  91. if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
  92. av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
  93. printf("\n");
  94. }
  95. return 0;
  96. }