FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tee_common.c
Go to the documentation of this file.
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 
22 #include "libavutil/avutil.h"
23 #include "libavutil/avstring.h"
24 #include "libavutil/opt.h"
25 
26 #include "tee_common.h"
27 
28 static const char *const slave_opt_open = "[";
29 static const char *const slave_opt_close = "]";
30 static const char *const slave_opt_delim = ":]"; /* must have the close too */
31 
32 int ff_tee_parse_slave_options(void *log, char *slave,
33  AVDictionary **options, char **filename)
34 {
35  const char *p;
36  char *key, *val;
37  int ret;
38 
39  if (!strspn(slave, slave_opt_open)) {
40  *filename = slave;
41  return 0;
42  }
43  p = slave + 1;
44  if (strspn(p, slave_opt_close)) {
45  *filename = (char *)p + 1;
46  return 0;
47  }
48  while (1) {
49  ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
50  if (ret < 0) {
51  av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
52  goto fail;
53  }
54  ret = av_dict_set(options, key, val,
56  if (ret < 0)
57  goto fail;
58  if (strspn(p, slave_opt_close))
59  break;
60  p++;
61  }
62  *filename = (char *)p + 1;
63  return 0;
64 
65 fail:
66  av_dict_free(options);
67  return ret;
68 }
const char const char void * val
Definition: avisynth_c.h:771
Convenience header that includes libavutil's core.
static const char *const slave_opt_close
Definition: tee_common.c:29
#define AV_DICT_DONT_STRDUP_KEY
Take ownership of a key that's been allocated with av_malloc() or another memory allocation function...
Definition: dict.h:73
AVOptions.
static const char *const slave_opt_open
Definition: tee_common.c:28
static const char *const slave_opt_delim
Definition: tee_common.c:30
const OptionDef options[]
Definition: ffserver.c:3969
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
#define fail()
Definition: checkasm.h:83
int ff_tee_parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee_common.c:32
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:76
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition: opt.c:1442