UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
filter_chain.cpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2021 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#ifdef HAVE_CONFIG_H
38#include "config.h"
39#include "config_unix.h"
40#include "config_win32.h"
41#endif /* HAVE_CONFIG_H */
42
43#include "debug.h"
44#include "audio/types.h"
45#include "filter_chain.hpp"
47
50
54
56 filters.push_back(filter);
57}
58
59bool Filter_chain::emplace_new(std::string_view cfg){
60 std::string filter_name(tokenize(cfg, ':'));
61 if(!cfg.empty() && cfg[0] == ':')
62 cfg.remove_prefix(1);
63 std::string config(cfg);
64
65 struct audio_filter afilter;
67 filter_name.c_str(),
68 config.c_str(),
69 &afilter) != AF_OK)
70 {
71 return false;
72 }
73
74 push_back(afilter);
75 return true;
76}
77
79 for(auto& i : filters){
81 }
82}
83
85 struct message *msg;
86 while ((msg = check_message(mod.get()))) {
87 std::string_view text = ((msg_universal *) msg)->text;
88
89 if(!emplace_new(text)) {
90 log_msg(LOG_LEVEL_ERROR, "Failed to init audio filter\n");
92 continue;
93 }
94
96 }
97
98 auto f = *frame;
99 af_result_code res = reconfigure(f->bps, f->ch_count, f->sample_rate);
100 if(res != AF_OK)
101 return AF_MISCONFIGURED;
102
103 for(auto& i : filters){
104 res = audio_filter(&i, frame);
105 if(res != AF_OK)
106 return res;
107 }
108
109 return res;
110}
111
113 if(this->bps == bps
114 && this->ch_count == ch_count
115 && this->sample_rate == sample_rate)
116 {
117 return AF_OK;
118 }
119
120 this->bps = bps;
121 this->ch_count = ch_count;
122 this->sample_rate = sample_rate;
123
124 af_result_code res = AF_OK;
125 for(auto& i : filters){
127 if(res != AF_OK)
128 return res;
129
131 }
132
133 return res;
134}
int int int sample_rate
struct video_frame * frame
This file contains definition of some common audio types.
af_result_code audio_filter_configure(struct audio_filter *state, int bps, int ch_count, int sample_rate)
void audio_filter_get_configured_out(struct audio_filter *state, int *bps, int *ch_count, int *sample_rate)
af_result_code audio_filter(struct audio_filter *state, struct audio_frame **frame)
void audio_filter_destroy(struct audio_filter *state)
af_result_code audio_filter_init(struct module *parent, const char *name, const char *cfg, struct audio_filter *filter)
af_result_code
@ AF_MISCONFIGURED
@ AF_OK
static af_result_code filter(void *state, struct audio_frame **frame)
bool emplace_new(std::string_view cfg)
struct module * get_module()
af_result_code filter(struct audio_frame **frame)
std::vector< struct audio_filter > filters
module_raii mod
af_result_code reconfigure(int bps, int ch_count, int sample_rate)
Filter_chain(struct module *parent)
void push_back(struct audio_filter filter)
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
@ MODULE_CLASS_FILTER
Definition module.h:93
void free_message(struct message *msg, struct response *r)
struct response * new_response(int status, const char *text)
struct message * check_message(struct module *mod)
#define RESPONSE_OK
Definition messaging.h:57
#define RESPONSE_INT_SERV_ERR
Definition messaging.h:63
struct msghdr msg
const char * parent
Definition settings.cpp:198
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.
struct used to comunicate with audio capture/playback device
Definition types.h:99