FFmpeg
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 <string.h>
23 
24 #include "libavutil/log.h"
25 #include "libavutil/opt.h"
26 
27 #include "tee_common.h"
28 
29 static const char *const slave_opt_open = "[";
30 static const char *const slave_opt_close = "]";
31 static const char *const slave_opt_delim = ":]"; /* must have the close too */
32 
33 int ff_tee_parse_slave_options(void *log, char *slave,
34  AVDictionary **options, char **filename)
35 {
36  const char *p;
37  char *key, *val;
38  int ret;
39 
40  if (!strspn(slave, slave_opt_open)) {
41  *filename = slave;
42  return 0;
43  }
44  p = slave + 1;
45  if (strspn(p, slave_opt_close)) {
46  *filename = (char *)p + 1;
47  return 0;
48  }
49  while (1) {
50  ret = av_opt_get_key_value(&p, "=", slave_opt_delim, 0, &key, &val);
51  if (ret < 0) {
52  av_log(log, AV_LOG_ERROR, "No option found near \"%s\"\n", p);
53  goto fail;
54  }
57  if (ret < 0)
58  goto fail;
59  if (strspn(p, slave_opt_close))
60  break;
61  p++;
62  }
63  *filename = (char *)p + 1;
64  return 0;
65 
66 fail:
68  return ret;
69 }
opt.h
slave_opt_delim
static const char *const slave_opt_delim
Definition: tee_common.c:31
normalize.log
log
Definition: normalize.py:21
slave_opt_close
static const char *const slave_opt_close
Definition: tee_common.c:30
ff_tee_parse_slave_options
int ff_tee_parse_slave_options(void *log, char *slave, AVDictionary **options, char **filename)
Definition: tee_common.c:33
AVDictionary
Definition: dict.c:34
slave_opt_open
static const char *const slave_opt_open
Definition: tee_common.c:29
tee_common.h
fail
#define fail()
Definition: checkasm.h:179
av_opt_get_key_value
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:1834
val
static double val(void *priv, double ch)
Definition: aeval.c:78
AV_DICT_DONT_STRDUP_VAL
#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:79
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
key
const char * key
Definition: hwcontext_opencl.c:189
options
const OptionDef options[]
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
log.h
ret
ret
Definition: filter_design.txt:187
av_dict_set
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:88
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_DICT_DONT_STRDUP_KEY
#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:77