Skip to content

Commit fe9e939

Browse files
committed
delay initialization of lame until after config parsing is complete
1 parent d7095db commit fe9e939

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/config.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ using namespace std;
3434
static int parse_outputs(libconfig::Setting& outs, channel_t* channel, int i, int j, bool parsing_mixers) {
3535
int oo = 0;
3636
for (int o = 0; o < channel->output_count; o++) {
37+
channel->outputs[oo].has_mp3_output = false;
3738
channel->outputs[oo].lame = NULL;
3839
channel->outputs[oo].lamebuf = NULL;
3940

@@ -95,8 +96,7 @@ static int parse_outputs(libconfig::Setting& outs, channel_t* channel, int i, in
9596
}
9697
#endif /* LIBSHOUT_HAS_TLS */
9798

98-
channel->outputs[oo].lame = airlame_init(channel->mode, channel->highpass, channel->lowpass);
99-
channel->outputs[oo].lamebuf = (unsigned char*)malloc(sizeof(unsigned char) * LAMEBUF_SIZE);
99+
channel->outputs[oo].has_mp3_output = true;
100100
} else if (!strncmp(outs[o]["type"], "file", 4)) {
101101
channel->outputs[oo].data = XCALLOC(1, sizeof(struct file_data));
102102
channel->outputs[oo].type = O_FILE;
@@ -122,8 +122,7 @@ static int parse_outputs(libconfig::Setting& outs, channel_t* channel, int i, in
122122
fdata->split_on_transmission = outs[o].exists("split_on_transmission") ? (bool)(outs[o]["split_on_transmission"]) : false;
123123
fdata->include_freq = outs[o].exists("include_freq") ? (bool)(outs[o]["include_freq"]) : false;
124124

125-
channel->outputs[oo].lame = airlame_init(channel->mode, channel->highpass, channel->lowpass);
126-
channel->outputs[oo].lamebuf = (unsigned char*)malloc(sizeof(unsigned char) * LAMEBUF_SIZE);
125+
channel->outputs[oo].has_mp3_output = true;
127126

128127
if (fdata->split_on_transmission) {
129128
if (parsing_mixers) {

src/rtl_airband.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ void init_demod(demod_params_t* params, Signal* signal, int device_start, int de
266266
}
267267

268268
bool init_output(channel_t* channel, output_t* output) {
269+
if (output->has_mp3_output) {
270+
output->lame = airlame_init(channel->mode, channel->highpass, channel->lowpass);
271+
output->lamebuf = (unsigned char*)malloc(sizeof(unsigned char) * LAMEBUF_SIZE);
272+
}
269273
if (output->type == O_ICECAST) {
270274
shout_setup((icecast_data*)(output->data), channel->mode);
271275
} else if (output->type == O_UDP_STREAM) {

src/rtl_airband.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ struct output_t {
184184
bool active;
185185
void* data;
186186

187-
// set if this output performs mp3 encoding
187+
// set to true in order to initialize `lame` and `lamebuf` after config parsing
188+
// is complete
189+
bool has_mp3_output;
190+
191+
// lame encoder and buffer for mp3 output. initialized after config parsing
192+
// if `uses_mp3_output` is true
188193
lame_t lame;
189-
unsigned char* lamebuf; // temporary buffer used for lame encoding
194+
unsigned char* lamebuf;
190195
};
191196

192197
struct freq_tag {

0 commit comments

Comments
 (0)