Commit 321a3f9d authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix resampler configuration in media player.

parent ef599c81
......@@ -110,7 +110,7 @@ bool_t ms_media_player_open(MSMediaPlayer *obj, const char *filepath) {
wave_header_t header;
int fd;
char *tmp;
ms_message("Openning %s", filepath);
ms_message("Opening %s", filepath);
if(access(filepath, F_OK) != 0) {
ms_error("Cannot open %s. File does not exist", filepath);
return FALSE;
......@@ -341,19 +341,29 @@ static void _create_decoders(MSMediaPlayer *obj) {
}
static void _create_sinks(MSMediaPlayer *obj) {
int sink_sample_rate, sample_rate, nchannels;
int sink_sample_rate, sample_rate, sink_nchannels, nchannels;
bool_t need_resampler = FALSE;
if(obj->audio_pin_fmt.fmt && obj->snd_card) {
sample_rate = obj->audio_pin_fmt.fmt->rate;
nchannels = obj->audio_pin_fmt.fmt->nchannels;
if((obj->audio_sink = ms_snd_card_create_writer(obj->snd_card))) {
if(ms_filter_call_method(obj->audio_sink, MS_FILTER_SET_SAMPLE_RATE, &sample_rate) == -1) {
if (ms_filter_call_method(obj->audio_sink, MS_FILTER_SET_SAMPLE_RATE, &sample_rate) == -1) {
ms_warning("The sound card (%s) does not support %dHz", obj->snd_card->name, sample_rate);
ms_filter_call_method(obj->audio_sink, MS_FILTER_GET_SAMPLE_RATE, &sink_sample_rate);
need_resampler = TRUE;
}
if (ms_filter_call_method(obj->audio_sink, MS_FILTER_SET_NCHANNELS, &nchannels) == -1) {
ms_warning("The sound card (%s) does not support %d channels", obj->snd_card->name, nchannels);
ms_filter_call_method(obj->audio_sink, MS_FILTER_GET_NCHANNELS, &sink_nchannels);
need_resampler = TRUE;
}
if (need_resampler == TRUE) {
ms_message("Resampling to %dHz", sink_sample_rate);
obj->resampler = ms_filter_new(MS_RESAMPLE_ID);
ms_filter_call_method(obj->resampler, MS_FILTER_SET_SAMPLE_RATE, &sample_rate);
ms_filter_call_method(obj->resampler, MS_FILTER_SET_OUTPUT_SAMPLE_RATE, &sink_sample_rate);
ms_filter_call_method(obj->resampler, MS_FILTER_SET_NCHANNELS, &nchannels);
ms_filter_call_method(obj->resampler, MS_FILTER_SET_OUTPUT_NCHANNELS, &sink_nchannels);
}
ms_filter_call_method(obj->audio_sink, MS_FILTER_SET_NCHANNELS, &nchannels);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment