ringstream.c: returns NULL if fileplayer failed to open the input file instead...

ringstream.c: returns NULL if fileplayer failed to open the input file instead of creating a silent player
parent 853609fc
......@@ -35,7 +35,7 @@ static void ring_player_event_handler(void *ud, MSFilter *f, unsigned int evid,
pinfmt.pin = 1;
ms_filter_call_method(stream->source, MS_FILTER_GET_OUTPUT_FMT, &pinfmt);
}
if (stream->write_resampler){
ms_message("Configuring resampler input with rate=[%i], nchannels=[%i]",pinfmt.fmt->rate, pinfmt.fmt->nchannels);
ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_NCHANNELS,(void*)&pinfmt.fmt->nchannels);
......@@ -64,8 +64,8 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
stream->source=_ms_create_av_player(file);
if (stream->source == NULL){
ms_error("ring_start_with_cb(): could not create player for playing '%s'", file);
file = NULL;
stream->source=ms_filter_new(MS_FILE_PLAYER_ID);
ms_free(stream);
return NULL;
}
} else {
/*create dummy source*/
......@@ -77,13 +77,17 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
stream->gendtmf=ms_filter_new(MS_DTMF_GEN_ID);
stream->sndwrite=ms_snd_card_create_writer(sndcard);
stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID);
if (file){
ms_filter_call_method(stream->source,MS_PLAYER_OPEN,(void*)file);
/*in we failed to open the file, we must release the stream*/
if (ms_filter_call_method(stream->source,MS_PLAYER_OPEN,(void*)file) != 0) {
ring_stop(stream);
return NULL;
}
ms_filter_call_method(stream->source,MS_PLAYER_SET_LOOP,&interval);
ms_filter_call_method_noarg(stream->source,MS_PLAYER_START);
}
/*configure sound output filter*/
ms_filter_call_method(stream->source, MS_FILTER_GET_OUTPUT_FMT, &pinfmt);
if (pinfmt.fmt == NULL){
......@@ -101,7 +105,7 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
ms_filter_call_method(stream->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&dstrate);
ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_NCHANNELS,&srcchannels);
ms_filter_call_method(stream->sndwrite,MS_FILTER_GET_NCHANNELS,&dstchannels);
/*eventually create a decoder*/
if (strcasecmp(pinfmt.fmt->encoding, "pcm") != 0){
stream->decoder = ms_filter_create_decoder(pinfmt.fmt->encoding);
......@@ -111,17 +115,17 @@ RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard
return NULL;
}
}
/*configure output of resampler*/
if (stream->write_resampler){
ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&dstrate);
ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&dstchannels);
/*the input of the resampler, as well as dtmf generator are configured within the ring_player_event_handler()
* callback triggered during the open of the file player*/
ms_message("configuring resampler output to rate=[%i], nchannels=[%i]",dstrate,dstchannels);
}
params.name="Ring MSTicker";
params.prio=MS_TICKER_PRIO_HIGH;
stream->ticker=ms_ticker_new_with_params(&params);
......@@ -154,7 +158,7 @@ void ring_stop_dtmf(RingStream *stream){
void ring_stop(RingStream *stream){
MSConnectionHelper h;
if (stream->ticker){
ms_ticker_detach(stream->ticker,stream->source);
......
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