UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
every.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2013-2019 CESNET, z. s. p. o.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, is permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of CESNET nor the names of its contributors may be
21 * used to endorse or promote products derived from this software without
22 * specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
26 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
28 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#include "config_unix.h"
41#include "config_win32.h"
42#endif /* HAVE_CONFIG_H */
43
44#include "capture_filter.h"
45
46#include "debug.h"
47#include "lib_common.h"
48#include "utils/color_out.h"
49#include "video.h"
50#include "video_codec.h"
51
52struct module;
53
54static int init(struct module *parent, const char *cfg, void **state);
55static void done(void *state);
56static struct video_frame *filter(void *state, struct video_frame *in);
57
59 int num;
60 int denom;
62};
63
64static void usage() {
65 color_printf("Passes only every n-th frame.\n"
66 "See also capture filter " TBOLD("ratelimit") ".\n\n");
67 color_printf(TBOLD("every") " usage:\n");
68 printf("\tevery:numerator[/denominator]\n\n");
69 printf("Example: every:2 - every second frame will be dropped\n");
70 printf("The special case every:0 can be used to discard all frames\n");
71}
72
73static int init(struct module *parent, const char *cfg, void **state)
74{
76
77 int n;
78 int denom = 1;;
79 if (strlen(cfg) == 0) {
80 usage();
81 return -1;
82 }
83 if(strcasecmp(cfg, "help") == 0) {
84 usage();
85 return 1;
86 }
87 n = atoi(cfg);
88 if(strchr(cfg, '/')) {
89 denom = atoi(strchr(cfg, '/') + 1);
90 }
91 if (denom > n && n != 0) {
92 log_msg(LOG_LEVEL_ERROR, "Currently, numerator has to be greater "
93 "(or equal, which, however, has a little use) than denominator.\n");
94 return -1;
95 }
96
97 struct state_every *s = calloc(1, sizeof(struct state_every));
98 s->num = n;
99 s->denom = denom;
100
101 s->current = -1;
102
103 *state = s;
104 return 0;
105}
106
107static void done(void *state)
108{
109 free(state);
110}
111
112static void dispose_frame(struct video_frame *f) {
114 vf_free(f);
115}
116
117static struct video_frame *filter(void *state, struct video_frame *in)
118{
119 struct state_every *s = state;
120
121 if (s->num == 0) {
123 return NULL;
124 }
125
126 s->current = (s->current + 1) % s->num;
127
128 if (s->current >= s->denom) {
130 return NULL;
131 }
132
134 memcpy(frame->tiles, in->tiles, in->tile_count * sizeof(struct tile));
135 frame->fps /= (double) s->num / s->denom;
136
139
140 return frame;
141}
142
144 .init = init,
145 .done = done,
146 .filter = filter,
147};
148
150
#define UNUSED(x)
void ** state
struct video_frame * frame
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
#define CAPTURE_FILTER_ABI_VERSION
int color_printf(const char *format,...)
#define TBOLD(x)
Definition color_out.h:70
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
static struct video_frame * filter(void *state, struct video_frame *in)
Definition every.c:117
static void usage()
Definition every.c:64
static const struct capture_filter_info capture_filter_every
Definition every.c:143
static void done(void *state)
Definition every.c:107
static void dispose_frame(struct video_frame *f)
Definition every.c:112
static int init(struct module *parent, const char *cfg, void **state)
Definition every.c:73
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
const char * parent
Definition settings.cpp:198
int num
Definition every.c:59
int current
Definition every.c:61
int denom
Definition every.c:60
Struct tile is an area of video_frame.
Definition types.h:279
void(* dispose)(struct video_frame *)
Definition types.h:245
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
double fps
Definition types.h:308
unsigned int tile_count
Definition types.h:344
struct video_frame_callbacks callbacks
Definition types.h:324
This is an umbrella header for video functions.
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76