mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-22 00:40:25 +00:00
handle audio resampler init exception gracefully
Catch the exception. Can occur mainly if wrong '--param resampler=' option is given.
This commit is contained in:
@@ -56,6 +56,7 @@
|
||||
#include <cinttypes>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
@@ -88,6 +89,7 @@
|
||||
#include "tv.h"
|
||||
#include "transmit.h"
|
||||
#include "pdb.h"
|
||||
#include "ug_runtime_error.hpp"
|
||||
#include "utils/color_out.h"
|
||||
#include "utils/net.h"
|
||||
#include "utils/thread.h"
|
||||
@@ -695,6 +697,10 @@ static void *audio_receiver_thread(void *arg)
|
||||
cp->decoder_state = dec_state;
|
||||
dec_state->enabled = true;
|
||||
dec_state->pbuf_data.decoder = (struct state_audio_decoder *) audio_decoder_init(s->audio_channel_map, s->audio_scale, s->requested_encryption, (audio_playback_ctl_t) audio_playback_ctl, s->audio_playback_device, s->audio_receiver_module.get());
|
||||
if (!dec_state->pbuf_data.decoder) {
|
||||
exit_uv(1);
|
||||
break;
|
||||
}
|
||||
audio_decoder_set_volume(dec_state->pbuf_data.decoder, s->muted_receiver ? 0.0 : s->volume);
|
||||
assert(dec_state->pbuf_data.decoder != NULL);
|
||||
cp->decoder_state_deleter = audio_decoder_state_deleter;
|
||||
@@ -982,7 +988,14 @@ static void *audio_sender_thread(void *arg)
|
||||
set_thread_name(__func__);
|
||||
struct state_audio *s = (struct state_audio *) arg;
|
||||
struct audio_frame *buffer = NULL;
|
||||
audio_frame2_resampler resampler_state;
|
||||
unique_ptr<audio_frame2_resampler> resampler_state;
|
||||
try {
|
||||
resampler_state = unique_ptr<audio_frame2_resampler>(new audio_frame2_resampler);
|
||||
} catch (ug_runtime_error &e) {
|
||||
log_msg(LOG_LEVEL_ERROR, MOD_NAME "%s\n", e.what());
|
||||
exit_uv(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf("Audio sending started.\n");
|
||||
|
||||
@@ -1039,7 +1052,7 @@ static void *audio_sender_thread(void *arg)
|
||||
bf_n.change_bps(2);
|
||||
}
|
||||
|
||||
bf_n.resample(resampler_state, resample_to);
|
||||
bf_n.resample(*resampler_state, resample_to);
|
||||
}
|
||||
// COMPRESS
|
||||
process_statistics(s, &bf_n);
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include "crypto/crc.h"
|
||||
#include "crypto/openssl_decrypt.h"
|
||||
#include "rang.hpp"
|
||||
#include "ug_runtime_error.hpp"
|
||||
#include "utils/color_out.h"
|
||||
#include "utils/macros.h"
|
||||
#include "utils/packet_counter.h"
|
||||
@@ -279,14 +280,20 @@ ADD_TO_PARAM("soft-resample", "* soft-resample=<num>/<den>\n"
|
||||
|
||||
void *audio_decoder_init(char *audio_channel_map, const char *audio_scale, const char *encryption, audio_playback_ctl_t c, void *p_state, struct module *parent)
|
||||
{
|
||||
struct state_audio_decoder *s;
|
||||
struct state_audio_decoder *s = NULL;
|
||||
bool scale_auto = false;
|
||||
double scale_factor = 1.0;
|
||||
char *tmp = nullptr;
|
||||
|
||||
assert(audio_scale != NULL);
|
||||
|
||||
s = new struct state_audio_decoder();
|
||||
try {
|
||||
s = new struct state_audio_decoder();
|
||||
} catch (ug_runtime_error &e) {
|
||||
log_msg(LOG_LEVEL_ERROR, MOD_NAME "%s\n", e.what());
|
||||
goto error;
|
||||
}
|
||||
|
||||
s->magic = AUDIO_DECODER_MAGIC;
|
||||
s->audio_playback_ctl_func = c;
|
||||
s->audio_playback_state = p_state;
|
||||
@@ -422,7 +429,9 @@ void *audio_decoder_init(char *audio_channel_map, const char *audio_scale, const
|
||||
|
||||
error:
|
||||
free(tmp);
|
||||
audio_decoder_destroy(s);
|
||||
if (s) {
|
||||
audio_decoder_destroy(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user