UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ratelimit.c
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2023 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 "tv.h"
49#include "utils/color_out.h"
50#include "video.h"
51#include "video_codec.h"
52
53struct module;
54
55static int init(struct module *parent, const char *cfg, void **state);
56static void done(void *state);
57static struct video_frame *filter(void *state, struct video_frame *in);
58
63
64static void usage() {
65 color_printf("Filter " TBOLD("ratelimite") " limits frame rate of video stream.\n"
66 "This filter is related to a capture filter " TBOLD("every")".\n\n");
67 printf("ratelimit usage:\n\n");
68 color_printf(TBOLD("\t--capture-filter ratelimit:<fps>") " -t <capture>\n\n");
69}
70
71static int init(struct module *parent, const char *cfg, void **state)
72{
74
75 if (strlen(cfg) == 0 || strcasecmp(cfg, "help") == 0) {
76 usage();
77 return strlen(cfg) == 0 ? -1 : 1;
78 }
79
80 struct state_ratelimit *s = calloc(1, sizeof *s);
81 s->fps = strtod(cfg, NULL);
83 *state = s;
84 return 0;
85}
86
87static void done(void *state)
88{
89 free(state);
90}
91
92static void dispose_frame(struct video_frame *f) {
94 vf_free(f);
95}
96
97static struct video_frame *filter(void *state, struct video_frame *in)
98{
99 struct state_ratelimit *s = state;
100
102
103 if (t < s->next_frame_time) {
105 return NULL;
106 }
107
109 memcpy(frame->tiles, in->tiles, in->tile_count * sizeof(struct tile));
110 frame->fps = s->fps;
111
114
116
117 return frame;
118}
119
121 .init = init,
122 .done = done,
123 .filter = filter,
124};
125
127
#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
@ 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
static struct video_frame * filter(void *state, struct video_frame *in)
Definition ratelimit.c:97
static void usage()
Definition ratelimit.c:64
static const struct capture_filter_info capture_filter_ratelimit
Definition ratelimit.c:120
static void done(void *state)
Definition ratelimit.c:87
static void dispose_frame(struct video_frame *f)
Definition ratelimit.c:92
static int init(struct module *parent, const char *cfg, void **state)
Definition ratelimit.c:71
const char * parent
Definition settings.cpp:198
time_ns_t next_frame_time
Definition ratelimit.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
long long time_ns_t
Definition tv.h:81
#define NS_IN_SEC_DBL
Definition tv.h:93
static time_ns_t get_time_in_ns()
Definition tv.h:101
This is an umbrella header for video functions.
#define VIDEO_FRAME_DISPOSE(frame)
Definition video_frame.h:76