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.

69 lines
2.0KB

  1. /*
  2. * Tee common code
  3. * Copyright (c) 2012 Nicolas George
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/avutil.h"
  22. #include "libavutil/avstring.h"
  23. #include "libavutil/opt.h"
  24. #include "tee_common.h"
  25. static const char *const slave_opt_open = "[";
  26. static const char *const slave_opt_close = "]";
  27. static const char *const slave_opt_delim = ":]"; /* must have the close too */
  28. int ff_tee_parse_slave_options(void *log, char *slave,
  29. AVDictionary **options, char **filename)
  30. {
  31. const char *p;
  32. char *key, *val;
  33. int ret;
  34. if (!strspn(slave, slave_opt_open)) {
  35. *filename = slave;
  36. return 0;
  37. }
  38. p = slave + 1;
  39. if (strspn(p, slave_opt_close)) {
  40. *filename = (char *)p + 1;
  41. return 0;
  42. }
  43. while (1) {
  44. ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
  45. if (ret < 0) {
  46. av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
  47. goto fail;
  48. }
  49. ret = av_dict_set(options, key, val,
  50. AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);
  51. if (ret < 0)
  52. goto fail;
  53. if (strspn(p, slave_opt_close))
  54. break;
  55. p++;
  56. }
  57. *filename = (char *)p + 1;
  58. return 0;
  59. fail:
  60. av_dict_free(options);
  61. return ret;
  62. }