UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
disrupt.c
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2021 CESNET, z. s. p. o.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, is permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * 3. Neither the name of CESNET nor the names of its contributors may be
24 * used to endorse or promote products derived from this software without
25 * specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
29 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
30 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
31 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
32 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifdef HAVE_CONFIG_H
42#include "config.h"
43#include "config_unix.h"
44#include "config_win32.h"
45#endif /* HAVE_CONFIG_H */
46
47#include "capture_filter.h"
48
49#include "compat/usleep.h"
50#include "debug.h"
51#include "lib_common.h"
52#include "utils/color_out.h"
53#include "utils/random.h"
54#include "video.h"
55#include "video_codec.h"
56
57#define MOD_NAME "[disrupt c. f.] "
58
59struct module;
60
61static int init(struct module *parent, const char *cfg, void **state);
62static void done(void *state);
63static struct video_frame *filter(void *state, struct video_frame *in);
64
66 double jitter_ms;
67};
68
69static void usage() {
70 printf("Disrupts video frame flow\n\n");
71 printf("disrupt usage:\n");
72 printf("\tdisrupt:jitter[=<ms>]\n");
73 printf("where:\n");
74 printf("\tjitter - add random jitter to frame timing (value in ms - maximal delay)\n");
75}
76
77static int init(struct module *parent, const char *cfg, void **state)
78{
80
81 if (cfg == NULL || strlen(cfg) == 0 || strcmp(cfg, "help") == 0) {
82 usage();
83 return cfg && strcmp(cfg, "help") == 0 ? 1 : -1;
84 }
85
86 struct state_disrupt *s = calloc(1, sizeof *s);
87
88 if (strstr(cfg, "jitter") == cfg) {
89 if (strchr(cfg, '=') != NULL) {
90 s->jitter_ms = atof(strchr(cfg, '=') + 1);
91 }
92 } else {
93 usage();
94 color_printf(TERM_FG_RED MOD_NAME "Currently only supported filter is jitter\n" TERM_FG_RESET);
95 free(s);
96 return -1;
97 }
98
99 *state = s;
100
101 return 0;
102}
103
104static void done(void *state)
105{
106 free(state);
107}
108
109
110static struct video_frame *filter(void *state, struct video_frame *in)
111{
112 struct state_disrupt *s = state;
113
114 usleep(1000.0 * ug_drand() * s->jitter_ms);
115
116 return in;
117}
118
120 .init = init,
121 .done = done,
122 .filter = filter,
123};
124
126
#define UNUSED(x)
void ** state
#define CAPTURE_FILTER_ABI_VERSION
int color_printf(const char *format,...)
#define TERM_FG_RED
Definition color_out.h:50
#define TERM_FG_RESET
Definition color_out.h:59
static struct video_frame * filter(void *state, struct video_frame *in)
Definition disrupt.c:110
static void usage()
Definition disrupt.c:69
static const struct capture_filter_info capture_filter_disrupt
Definition disrupt.c:119
#define MOD_NAME
Definition disrupt.c:57
static void done(void *state)
Definition disrupt.c:104
static int init(struct module *parent, const char *cfg, void **state)
Definition disrupt.c:77
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
#define REGISTER_HIDDEN_MODULE(name, info, lclass, abi)
Definition lib_common.h:156
const char * parent
Definition settings.cpp:198
double jitter_ms
Definition disrupt.c:66
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
int usleep(unsigned int usec)
Definition usleep.c:47
double ug_drand()
Definition random.c:111
This is an umbrella header for video functions.