UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
capture_filter.cpp File Reference
#include "capture_filter.h"
#include "debug.h"
#include "lib_common.h"
#include "module.h"
#include "utils/color_out.h"
#include "utils/list.h"
#include "video.h"
Include dependency graph for capture_filter.cpp:

Go to the source code of this file.

Classes

struct  capture_filter
 
struct  capture_filter_instance
 

Functions

struct video_frame * capture_filter (struct capture_filter *state, struct video_frame *frame)
 
void capture_filter_destroy (struct capture_filter *state)
 
int capture_filter_init (struct module *parent, const char *cfg, struct capture_filter **state)
 
static int create_filter (struct capture_filter *s, char *cfg)
 
static struct response * process_message (struct capture_filter *s, struct msg_universal *msg)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file capture_filter.cpp.

Function Documentation

◆ capture_filter()

struct video_frame * capture_filter ( struct capture_filter * state,
struct video_frame * frame )

Definition at line 212 of file capture_filter.cpp.

212 {
213 struct capture_filter *s = state;
214
215 struct message *msg;
216 while ((msg = check_message(&s->mod))) {
217 struct response *r = process_message(s, (struct msg_universal *) msg);
218 free_message(msg, r);
219 }
220
221 for(void *it = simple_linked_list_it_init(s->filters);
222 it != NULL;
223 ) {
225 frame = inst->functions->filter(inst->state, frame);
226 if(!frame)
227 return NULL;
228 }
229 return frame;
230}
void ** state
struct video_frame * frame
static struct response * process_message(struct capture_filter *s, struct msg_universal *msg)
void * simple_linked_list_it_next(void **i)
Definition list.cpp:119
void * simple_linked_list_it_init(struct simple_linked_list *l)
Definition list.cpp:108
void free_message(struct message *msg, struct response *r)
struct message * check_message(struct module *mod)
struct msghdr msg
struct video_frame *(* filter)(void *state, struct video_frame *f)
Performs filtering.
const struct capture_filter_info * functions
struct module mod
struct simple_linked_list * filters

References check_message(), capture_filter_info::filter, capture_filter::filters, frame, free_message(), capture_filter_instance::functions, capture_filter::mod, msg, process_message(), simple_linked_list_it_init(), simple_linked_list_it_next(), capture_filter_instance::state, and state.

Referenced by hd_rum_decompress::state_transcoder_decompress::frame_arrived(), and vidcap_grab().

Here is the call graph for this function:

◆ capture_filter_destroy()

void capture_filter_destroy ( struct capture_filter * state)

Definition at line 152 of file capture_filter.cpp.

153{
154 struct capture_filter *s = state;
155
156 while(simple_linked_list_size(s->filters) > 0) {
158 inst->functions->done(inst->state);
159 free(inst);
160 }
161
163
164 module_done(&s->mod);
165
166 free(state);
167}
void module_done(struct module *module_data)
Definition module.c:93
int simple_linked_list_size(struct simple_linked_list *l)
Definition list.cpp:93
void simple_linked_list_destroy(struct simple_linked_list *l)
Definition list.cpp:58
void * simple_linked_list_pop(struct simple_linked_list *l)
Definition list.cpp:82
void(* done)(void *state)

References capture_filter_info::done, capture_filter::filters, capture_filter_instance::functions, capture_filter::mod, module_done(), simple_linked_list_destroy(), simple_linked_list_pop(), simple_linked_list_size(), capture_filter_instance::state, and state.

Referenced by hd_rum_decompress_done(), and vidcap_done().

Here is the call graph for this function:

◆ capture_filter_init()

int capture_filter_init ( struct module * parent,
const char * cfg,
struct capture_filter ** state )
See also
display_init

Definition at line 102 of file capture_filter.cpp.

103{
104 if (cfg && (strcasecmp(cfg, "help") == 0 || strcasecmp(cfg, "fullhelp") == 0)) {
105 printf("Usage:\n");
106 color_printf(TERM_BOLD "\t--capture-filter <filter1>[:opts][,<filter2>[:opts][,<filter3>[:<opts>]]]" TERM_RESET " -t <capture>\n\n");
107 printf("Available capture filters:\n");
108 list_modules(LIBRARY_CLASS_CAPTURE_FILTER, CAPTURE_FILTER_ABI_VERSION, strcasecmp(cfg, "fullhelp") == 0);
109 if (strcasecmp(cfg, "fullhelp") != 0) {
110 printf("(use \"fullhelp\" to show hidden filters)\n");
111 }
112 return 1;
113 }
114
115 struct capture_filter *s = (struct capture_filter *) calloc(1, sizeof(struct capture_filter));
116 char *item, *save_ptr;
117 assert(s);
118 char *filter_list_str = NULL,
119 *tmp = NULL;
120
122
126
127 if(cfg) {
128 filter_list_str = tmp = strdup(cfg);
129
130 while((item = strtok_r(filter_list_str, ",", &save_ptr))) {
131 char filter_name[128];
132 strncpy(filter_name, item, sizeof filter_name - 1);
133
134 int ret = create_filter(s, filter_name);
135 if (ret != 0) {
136 module_done(&s->mod);
137 free(tmp);
138 free(s);
139 return ret;
140 }
141 filter_list_str = NULL;
142 }
143 }
144
145 free(tmp);
146
147 *state = s;
148
149 return 0;
150}
static int create_filter(struct capture_filter *s, char *cfg)
#define CAPTURE_FILTER_ABI_VERSION
int color_printf(const char *format,...)
#define TERM_BOLD
Definition color_out.h:48
#define TERM_RESET
Definition color_out.h:47
void module_init_default(struct module *module_data)
Definition module.c:48
void module_register(struct module *module_data, struct module *parent)
Definition module.c:82
@ MODULE_CLASS_FILTER
Definition module.h:93
void list_modules(enum library_class cls, int abi_version, bool full)
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
struct simple_linked_list * simple_linked_list_init(void)
Definition list.cpp:53
const char * parent
Definition settings.cpp:198
Definition hd-rum.c:27
enum module_class cls
Definition module.h:115

References CAPTURE_FILTER_ABI_VERSION, module::cls, color_printf(), create_filter(), capture_filter::filters, LIBRARY_CLASS_CAPTURE_FILTER, list_modules(), capture_filter::mod, MODULE_CLASS_FILTER, module_done(), module_init_default(), module_register(), parent, simple_linked_list_init(), state, TERM_BOLD, and TERM_RESET.

Referenced by hd_rum_decompress_init(), and initialize_video_capture().

Here is the call graph for this function:

◆ create_filter()

static int create_filter ( struct capture_filter * s,
char * cfg )
static

Definition at line 64 of file capture_filter.cpp.

65{
66 bool found = false;
67 const char *options = "";
68 char *filter_name = cfg;
69 if(strchr(filter_name, ':')) {
70 options = strchr(filter_name, ':') + 1;
71 *strchr(filter_name, ':') = '\0';
72 }
74 for (auto && item : capture_filters) {
75 auto capture_filter_info = static_cast<const struct capture_filter_info*>(item.second);
76 if(strcasecmp(item.first.c_str(), filter_name) == 0) {
78 malloc(sizeof(struct capture_filter_instance));
79 instance->functions = capture_filter_info;
80 int ret = capture_filter_info->init(&s->mod, options, &instance->state);
81 if(ret < 0) {
82 fprintf(stderr, "Unable to initialize capture filter: %s\n",
83 filter_name);
84 }
85 if(ret != 0) {
86 free(instance);
87 return ret;
88 }
90 found = true;
91 break;
92 }
93 }
94 if (!found) {
95 fprintf(stderr, "Unable to find capture filter: %s\n",
96 filter_name);
97 return -1;
98 }
99 return 0;
100}
map< string, const void * > get_libraries_for_class(enum library_class cls, int abi_version, bool include_hidden)
void simple_linked_list_append(struct simple_linked_list *l, void *data)
Definition list.cpp:68
int(* init)(struct module *parent, const char *cfg, void **state)
Initializes capture filter.
Definition rtp.c:253
static class worker_pool instance
Definition worker.cpp:250

References CAPTURE_FILTER_ABI_VERSION, capture_filter::filters, get_libraries_for_class(), capture_filter_info::init, instance, LIBRARY_CLASS_CAPTURE_FILTER, capture_filter::mod, and simple_linked_list_append().

Referenced by capture_filter_init(), and process_message().

Here is the call graph for this function:

◆ process_message()

static struct response * process_message ( struct capture_filter * s,
struct msg_universal * msg )
static

Definition at line 169 of file capture_filter.cpp.

170{
171 if (strncmp("delete ", msg->text, strlen("delete ")) == 0) {
172 int index = atoi(msg->text + strlen("delete "));
173 struct capture_filter_instance *inst = (struct capture_filter_instance *)
175 if (!inst) {
176 fprintf(stderr, "Unable to remove capture filter index %d.\n",
177 index);
179 } else {
180 printf("Capture filter #%d removed successfully.\n", index);
181 inst->functions->done(inst->state);
182 free(inst);
183 }
184 } else if (strcmp("flush", msg->text) == 0) {
185 while(simple_linked_list_size(s->filters) > 0) {
187 inst->functions->done(inst->state);
188 free(inst);
189 }
190 } else if (strcmp("help", msg->text) == 0) {
191 printf("Capture filter control:\n"
192 "\tflush - remove all filters\n"
193 "\tdelete <x> - delete x-th filter\n"
194 "\t<filter> - append a filter named <filter>\n");
195 } else {
196 char *fmt = strdup(msg->text);
197 if (create_filter(s, fmt) != 0) {
198 fprintf(stderr, "Cannot create capture filter: %s.\n",
199 msg->text);
200 free(fmt);
202 } else {
203 printf("Capture filter \"%s\" created successfully.\n",
204 msg->text);
205 }
206 free(fmt);
207 }
208
209 return new_response(RESPONSE_OK, NULL);
210}
const char * fmt
void * simple_linked_list_remove_index(struct simple_linked_list *l, int index)
Definition list.cpp:155
struct response * new_response(int status, const char *text)
#define RESPONSE_OK
Definition messaging.h:57
#define RESPONSE_INT_SERV_ERR
Definition messaging.h:63

References create_filter(), capture_filter_info::done, capture_filter::filters, fmt, capture_filter_instance::functions, new_response(), RESPONSE_INT_SERV_ERR, RESPONSE_OK, simple_linked_list_pop(), simple_linked_list_remove_index(), simple_linked_list_size(), and capture_filter_instance::state.

Referenced by capture_filter().

Here is the call graph for this function: