Commit ce59013a authored by Simon Morlat's avatar Simon Morlat

fix sample rate logic again, to be robust to filters not implementing MS_FILTER_GET_SAMPLE_RATE

parent a99d6b0d
......@@ -435,6 +435,15 @@ MS2_PUBLIC int ms_filter_call_method_noarg(MSFilter *f, unsigned int id);
*/
MS2_PUBLIC bool_t ms_filter_has_method(MSFilter *f, unsigned int id);
/**
* Returns whether a filter implements a given interface.
* @param f a MSFilter object
* @param id an interface id.
*
* Returns TRUE if interface is implemented, FALSE, otherwise.
**/
bool_t ms_filter_implements_interface(MSFilter *f, MSFilterInterfaceId id);
/**
* Set a callback on filter's to be informed of private filter's event.
* This callback is called from the filter's MSTicker, unless a global event queue
......
......@@ -211,6 +211,10 @@ bool_t ms_filter_desc_implements_interface(MSFilterDesc *desc, MSFilterInterface
return FALSE;
}
bool_t ms_filter_implements_interface(MSFilter *f, MSFilterInterfaceId id){
return ms_filter_desc_implements_interface(f->desc,id);
}
MSList *ms_filter_lookup_by_interface(MSFilterInterfaceId id){
MSList *ret=NULL;
MSList *elem;
......
......@@ -105,7 +105,9 @@ static void cut_audio_stream_graph(MSAudioEndpoint *ep, bool_t is_remote){
if (ms_filter_has_method(st->ms.encoder,MS_FILTER_GET_SAMPLE_RATE)){
ms_filter_call_method(st->ms.encoder,MS_FILTER_GET_SAMPLE_RATE,&ep->samplerate);
}else ms_warning("MSAudioConference: filter %s does not implement MS_FILTER_GET_SAMPLE_RATE, assuming 8khz",st->ms.encoder->desc->name);
}else{
ms_filter_call_method(st->ms.rtpsend,MS_FILTER_GET_SAMPLE_RATE,&ep->samplerate);
}
if (is_remote){
ep->mixer_in.filter=ep->in_cut_point_prev.filter;
......
......@@ -86,7 +86,11 @@ static void on_dtmf_received(RtpSession *s, int dtmf, void * user_data)
}
}
static void audio_stream_configure_resampler(MSFilter *resampler,MSFilter *from,MSFilter *to) {
/*
* note: since not all filters implement MS_FILTER_GET_SAMPLE_RATE, fallback_from_rate and fallback_to_rate are expected to provide sample rates
* obtained by another context, such as the RTP clock rate for example.
*/
static void audio_stream_configure_resampler(MSFilter *resampler,MSFilter *from, MSFilter *to, int fallback_from_rate, int fallback_to_rate) {
int from_rate=0, to_rate=0;
int from_channels = 0, to_channels = 0;
ms_filter_call_method(from,MS_FILTER_GET_SAMPLE_RATE,&from_rate);
......@@ -102,12 +106,12 @@ static void audio_stream_configure_resampler(MSFilter *resampler,MSFilter *from,
ms_error("Filter %s does not implement the MS_FILTER_GET_NCHANNELS method", to->desc->name);
}
if (from_rate == 0){
ms_error("Filter %s does not implement the MS_FILTER_GET_SAMPLE_RATE method, assuming 8000hz", from->desc->name);
from_rate=8000;
ms_error("Filter %s does not implement the MS_FILTER_GET_SAMPLE_RATE method", from->desc->name);
from_rate=fallback_from_rate;
}
if (to_rate == 0){
ms_error("Filter %s does not implement the MS_FILTER_GET_SAMPLE_RATE method, assuming 8000hz", to->desc->name);
to_rate=8000;
ms_error("Filter %s does not implement the MS_FILTER_GET_SAMPLE_RATE method", to->desc->name);
to_rate=fallback_to_rate;
}
ms_filter_call_method(resampler,MS_FILTER_SET_SAMPLE_RATE,&from_rate);
ms_filter_call_method(resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&to_rate);
......@@ -360,14 +364,12 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
}else {
stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID);
stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID);
if (infile!=NULL) audio_stream_play(stream,infile);
}
if (playcard!=NULL) {
if (stream->soundwrite==NULL)
stream->soundwrite=ms_snd_card_create_writer(playcard);
}else {
stream->soundwrite=ms_filter_new(MS_FILE_REC_ID);
if (outfile!=NULL) audio_stream_record(stream,outfile);
}
/* creates the couple of encoder/decoder */
......@@ -444,6 +446,13 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
stream->volrecv=NULL;
audio_stream_enable_echo_limiter(stream,stream->el_type);
audio_stream_enable_noise_gate(stream,stream->use_ng);
if (ms_filter_implements_interface(stream->soundread,MSFilterPlayerInterface) && infile){
audio_stream_play(stream,infile);
}
if (ms_filter_implements_interface(stream->soundwrite,MSFilterPlayerInterface) && outfile){
audio_stream_record(stream,outfile);
}
if (stream->use_agc){
int tmp=1;
......@@ -542,11 +551,11 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
/*configure resamplers if needed*/
if (stream->read_resampler){
audio_stream_configure_resampler(stream->read_resampler,stream->soundread,stream->ms.encoder);
audio_stream_configure_resampler(stream->read_resampler,stream->soundread,stream->ms.encoder,8000,pt->clock_rate);
}
if (stream->write_resampler){
audio_stream_configure_resampler(stream->write_resampler,stream->ms.decoder,stream->soundwrite);
audio_stream_configure_resampler(stream->write_resampler,stream->ms.decoder,stream->soundwrite,pt->clock_rate,8000);
}
if (stream->ms.use_rc){
......@@ -698,7 +707,9 @@ void audio_stream_play(AudioStream *st, const char *name){
if (name != NULL) {
ms_filter_call_method(st->soundread,MS_FILE_PLAYER_OPEN,(void*)name);
if (st->read_resampler){
audio_stream_configure_resampler(st->read_resampler,st->soundread,st->ms.rtpsend);
int fallback_to_rate=8000;
ms_filter_call_method(st->ms.rtpsend,MS_FILTER_GET_SAMPLE_RATE,&fallback_to_rate);
audio_stream_configure_resampler(st->read_resampler,st->soundread,st->ms.encoder, 8000, fallback_to_rate);
}
ms_filter_call_method_noarg(st->soundread,MS_FILE_PLAYER_START);
}
......
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