UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_capture_params.cpp
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2013-2023 CESNET z.s.p.o.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, is permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * 3. Neither the name of CESNET nor the names of its contributors may be
23 * used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
28 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#include "config_unix.h"
43#include "config_win32.h"
44#endif
45
46#include <string>
47
48#include "utils/config_file.h"
50
51using namespace std;
52
57 char *driver;
58 char *fmt;
59 unsigned int flags;
60
62 char *name;
65 struct module *parent;
66};
67
76{
77 bool ret;
78 char buf[1024];
79 string real_capture;
80 struct config_file *conf =
82 sizeof(buf)));
83 if (conf == NULL)
84 return false;
85 real_capture = config_file_get_alias(conf, "capture", params->name);
86 if (real_capture.empty()) {
87 ret = false;
88 } else {
89 params->driver = strdup(real_capture.c_str());
90 if (strchr(params->driver, ':')) {
91 char *delim = strchr(params->driver, ':');
92 params->fmt = strdup(delim + 1);
93 *delim = '\0';
94 } else {
95 params->fmt = strdup("");
96 }
97 ret = true;
98 }
99
100
101 if (params->requested_capture_filter == NULL) {
102 string matched_cap_filter = config_file_get_capture_filter_for_alias(conf,
103 params->name);
104 if (!matched_cap_filter.empty())
105 params->requested_capture_filter = strdup(matched_cap_filter.c_str());
106 }
107
108 config_file_close(conf);
109
110 return ret;
111}
112
113
118{
119 return (struct vidcap_params *) calloc(1, sizeof(struct vidcap_params));
120}
121
130{
132 return curr->next;
133}
134
139{
140 return curr->next;
141}
142
146struct vidcap_params *vidcap_params_get_nth(struct vidcap_params *curr, int index)
147{
148 struct vidcap_params *ret = curr;
149 for (int i = 0; i < index; i++) {
150 ret = ret->next;
151 if (ret == NULL) {
152 return NULL;
153 }
154 }
155 if (ret->driver == NULL) {
156 // this is just the stopper of the list...
157 return NULL;
158 }
159 return ret;
160}
161
166void vidcap_params_set_device(struct vidcap_params *params, const char *config)
167{
168 free(params->name);
169 free(params->driver);
170 free(params->fmt);
171
172 params->name = strdup(config);
173
175 params->driver = strdup(config);
176 if (strchr(params->driver, ':')) {
177 char *delim = strchr(params->driver, ':');
178 *delim = '\0';
179 params->fmt = strdup(delim + 1);
180 } else {
181 params->fmt = strdup("");
182 }
183 }
184}
185
187{
188 free(params->driver);
189 params->driver = strdup(driver);
190}
191
193 const char *req_capture_filter)
194{
195 params->requested_capture_filter = strdup(req_capture_filter);
196}
197
199{
200 return params->requested_capture_filter;
201}
202
204{
205 params->flags = flags;
206}
207
209{
210 params->flags |= flags;
211}
212
217{
218 return params->driver;
219}
220
225{
226 return params->fmt;
227}
228
230{
231 return params->flags;
232}
233
239{
240 return params->name;
241}
242
244{
245 return params->parent;
246}
247
249 params->parent = mod;
250}
251
256{
257 if (!params)
258 return NULL;
259
260 struct vidcap_params *ret = (struct vidcap_params *) calloc(1, sizeof(struct vidcap_params));
261
262 if (params->driver)
263 ret->driver = strdup(params->driver);
264 if (params->fmt)
265 ret->fmt = strdup(params->fmt);
266 if (params->requested_capture_filter)
268 strdup(params->requested_capture_filter);
269 if (params->name)
270 ret->name = strdup(params->name);
271 if (params->flags)
272 ret->flags = params->flags;
273
274 ret->next = NULL; // there is high probability that the pointer will be invalid
275
276 return ret;
277}
278
285{
286 if (!buf)
287 return;
288
289 free(buf->driver);
290 free(buf->fmt);
291 free(buf->requested_capture_filter);
292 free(buf->name);
293
294 free(buf);
295}
296
const char unsigned int flags
struct config_file * config_file_open(const char *name)
void config_file_close(struct config_file *s)
string config_file_get_capture_filter_for_alias(struct config_file *s, const char *alias)
char * default_config_file(char *buf, int buf_len)
string config_file_get_alias(struct config_file *s, const char *req_item_class, const char *requested_name)
char * driver
driver name
struct module * parent
struct vidcap_params * next
char * fmt
driver options
char * name
input name (capture alias in config file or complete config if not alias)
unsigned int flags
one of vidcap_flags
struct module * vidcap_params_get_parent(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_allocate_next(struct vidcap_params *curr)
void vidcap_params_set_parent(struct vidcap_params *params, struct module *mod)
const char * vidcap_params_get_capture_filter(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_get_next(const struct vidcap_params *curr)
void vidcap_params_add_flags(struct vidcap_params *params, unsigned int flags)
void vidcap_params_set_driver(struct vidcap_params *params, const char *driver)
void vidcap_params_free_struct(struct vidcap_params *buf)
struct vidcap_params * vidcap_params_copy(const struct vidcap_params *params)
const char * vidcap_params_get_name(const struct vidcap_params *params)
const char * vidcap_params_get_driver(const struct vidcap_params *params)
void vidcap_params_set_flags(struct vidcap_params *params, unsigned int flags)
void vidcap_params_set_capture_filter(struct vidcap_params *params, const char *req_capture_filter)
const char * vidcap_params_get_fmt(const struct vidcap_params *params)
unsigned int vidcap_params_get_flags(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_allocate(void)
struct vidcap_params * vidcap_params_get_nth(struct vidcap_params *curr, int index)
void vidcap_params_set_device(struct vidcap_params *params, const char *config)
static bool vidcap_dispatch_alias(struct vidcap_params *params)