UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
discard.cpp
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2022 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 <memory>
45#include <string_view>
46
47#include "debug.h"
48#include "module.h"
49#include "audio/audio_filter.h"
50#include "audio/types.h"
51#include "audio/utils.h"
52#include "lib_common.h"
53
56 {
57 }
58
60
61 int bps = 0;
62 int ch_count = 0;
63 int sample_rate = 0;
64};
65
66static void usage(){
67 printf("discard:\n");
68 printf("Discards all audio frames\n");
69}
70
71static af_result_code init(struct module *parent, const char *cfg, void **state){
72 auto s = std::make_unique<state_discard>(parent);
73
74 if(strcmp(cfg, "help") == 0){
75 usage();
76 return AF_HELP_SHOWN;
77 }
78
79 *state = s.release();
80 return AF_OK;
81};
82
84 int in_bps, int in_ch_count, int in_sample_rate)
85{
86 auto s = static_cast<state_discard *>(state);
87
88 s->bps = in_bps;
89 s->ch_count = in_ch_count;
90 s->sample_rate = in_sample_rate;
91
92 return AF_OK;
93}
94
95static void done(void *state){
96 auto s = static_cast<state_discard *>(state);
97
98 delete s;
99}
100
101static void get_configured(void *state,
102 int *bps, int *ch_count, int *sample_rate)
103{
104 auto s = static_cast<state_discard *>(state);
105
106 if(bps) *bps = s->bps;
107 if(ch_count) *ch_count = s->ch_count;
108 if(sample_rate) *sample_rate = s->sample_rate;
109}
110
112 auto s = static_cast<state_discard *>(state);
113
114 auto f = *frame;
115
116 if(f->bps != s->bps || f->ch_count != s->ch_count){
117 if(configure(state, f->bps, f->ch_count, f->sample_rate) != AF_OK){
118 return AF_MISCONFIGURED;
119 }
120 }
121
122 *frame = nullptr;
123
124 return AF_OK;
125}
126
128 .name = "discard",
129 .init = init,
130 .done = done,
131 .configure = configure,
132 .get_configured_in = get_configured,
133 .get_configured_out = get_configured,
134 .filter = filter,
135};
136
void ** state
int int int sample_rate
struct video_frame * frame
This file contains definition of some common audio types.
#define AUDIO_FILTER_ABI_VERSION
af_result_code
@ AF_MISCONFIGURED
@ AF_HELP_SHOWN
@ AF_OK
static af_result_code filter(void *state, struct audio_frame **frame)
Definition discard.cpp:111
static void usage()
Definition discard.cpp:66
static void get_configured(void *state, int *bps, int *ch_count, int *sample_rate)
Definition discard.cpp:101
static af_result_code init(struct module *parent, const char *cfg, void **state)
Definition discard.cpp:71
static af_result_code configure(void *state, int in_bps, int in_ch_count, int in_sample_rate)
Definition discard.cpp:83
static void done(void *state)
Definition discard.cpp:95
static const struct audio_filter_info audio_filter_discard
Definition discard.cpp:127
@ MODULE_CLASS_DATA
Definition module.h:86
@ LIBRARY_CLASS_AUDIO_FILTER
Definition lib_common.h:85
#define REGISTER_HIDDEN_MODULE(name, info, lclass, abi)
Definition lib_common.h:156
const char * parent
Definition settings.cpp:198
struct used to comunicate with audio capture/playback device
Definition types.h:99
module_raii mod
Definition discard.cpp:59
state_discard(struct module *mod)
Definition discard.cpp:55