Commit 20a79213 authored by Simon Morlat's avatar Simon Morlat

pump the event queue just before destroying the filters

parent 812d6dcb
......@@ -139,9 +139,10 @@ struct _MediaStream {
int target_bitrate;
media_stream_process_rtcp_callback_t process_rtcp;
OrtpEvDispatcher *evd;
MSFactory *factory;
};
MS2_PUBLIC void media_stream_init(MediaStream *stream);
MS2_PUBLIC void media_stream_init(MediaStream *stream, MSFactory *factory);
/**
......
......@@ -51,7 +51,7 @@ extern "C" {
MS2_PUBLIC MSFactory *ms_factory_new(void);
/**
* Create the factory default callback.
* Create the fallback factory (for compatibility with applications not using MSFactory to create ms2 object)
**/
MS2_PUBLIC MSFactory *ms_factory_create_fallback(void);
......
......@@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msitc.h"
#include "mediastreamer2/msvaddtx.h"
#include "mediastreamer2/msgenericplc.h"
#include "mediastreamer2/mseventqueue.h"
#include "private.h"
#ifdef ANDROID
......@@ -510,7 +511,7 @@ static int open_av_player(AudioStream *stream, const char *filename){
int channels=1;
ms_filter_call_method(player->player,MS_FILTER_GET_SAMPLE_RATE,&sr);
ms_filter_call_method(player->player,MS_FILTER_GET_NCHANNELS,&channels);
fmt1.fmt=ms_factory_get_audio_format(ms_factory_get_fallback(),"pcm", sr, channels, NULL);
fmt1.fmt=ms_factory_get_audio_format(stream->ms.factory, "pcm", sr, channels, NULL);
audiofmt=&fmt1;
}else{
if (fmt1.fmt && fmt1.fmt->type==MSAudio) {
......@@ -590,7 +591,7 @@ static void setup_av_recorder(AudioStream *stream, int sample_rate, int nchannel
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&g711_rate);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_NCHANNELS,&nchannels);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&g711_nchannels);
pinfmt.fmt=ms_factory_get_audio_format(ms_factory_get_fallback(),"pcmu",g711_rate,g711_nchannels,NULL);
pinfmt.fmt=ms_factory_get_audio_format(stream->ms.factory, "pcmu",g711_rate,g711_nchannels,NULL);
}else{
int got_sr=0;
......@@ -601,7 +602,7 @@ static void setup_av_recorder(AudioStream *stream, int sample_rate, int nchannel
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&got_sr);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_NCHANNELS,&nchannels);
ms_filter_call_method(stream->av_recorder.resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&nchannels);
pinfmt.fmt=ms_factory_get_audio_format(ms_factory_get_fallback(),"opus",48000,nchannels,NULL);
pinfmt.fmt=ms_factory_get_audio_format(stream->ms.factory,"opus",48000,nchannels,NULL);
}
pinfmt.pin=1;
ms_message("Configuring av recorder with audio format %s",ms_fmt_descriptor_to_string(pinfmt.fmt));
......@@ -1334,7 +1335,7 @@ AudioStream *audio_stream_new_with_sessions(const MSMediaStreamSessions *session
stream->ms.type = MSAudio;
stream->ms.sessions = *sessions;
media_stream_init(&stream->ms);
media_stream_init(&stream->ms, ms_factory_get_fallback());
ms_filter_enable_statistics(TRUE);
ms_filter_reset_statistics();
......@@ -1611,6 +1612,9 @@ void audio_stream_stop(AudioStream * stream){
rtp_session_set_rtcp_xr_media_callbacks(stream->ms.sessions.rtp_session, NULL);
rtp_session_signal_disconnect_by_callback(stream->ms.sessions.rtp_session,"telephone-event",(RtpCallback)on_dtmf_received);
rtp_session_signal_disconnect_by_callback(stream->ms.sessions.rtp_session,"payload_type_changed",(RtpCallback)audio_stream_payload_type_changed);
/*before destroying the filters, pump the event queue so that pending events have a chance to reach their listeners.
* When the filter are destroyed, all their pending events in the event queue will be cancelled*/
ms_event_queue_pump(ms_factory_get_event_queue(stream->ms.factory));
audio_stream_free(stream);
ms_filter_log_statistics();
}
......
......@@ -100,9 +100,10 @@ MSTickerPrio __ms_get_default_prio(bool_t is_video) {
}
}
void media_stream_init(MediaStream *stream) {
void media_stream_init(MediaStream *stream, MSFactory *factory) {
stream->evd = ortp_ev_dispatcher_new(stream->sessions.rtp_session);
stream->evq = ortp_ev_queue_new();
stream->factory = factory; /*the factory is used later to instanciate everything in mediastreamer2.*/
rtp_session_register_event_queue(stream->sessions.rtp_session, stream->evq);
}
......
......@@ -211,7 +211,7 @@ TextStream *text_stream_new_with_sessions(const MSMediaStreamSessions *sessions)
stream->ms.type = MSText;
stream->ms.sessions = *sessions;
media_stream_init(&stream->ms);
media_stream_init(&stream->ms, ms_factory_get_fallback());
ms_filter_enable_statistics(TRUE);
ms_filter_reset_statistics();
......
......@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msitc.h"
#include "mediastreamer2/zrtp.h"
#include "mediastreamer2/msvideopresets.h"
#include "mediastreamer2/mseventqueue.h"
#include "private.h"
......@@ -278,7 +279,7 @@ VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *session
stream->ms.type = MSVideo;
stream->ms.sessions=*sessions;
media_stream_init(&stream->ms);
media_stream_init(&stream->ms, ms_factory_get_fallback());
if (sessions->zrtp_context != NULL) {
ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions));
......@@ -303,7 +304,7 @@ VideoStream *video_stream_new_with_sessions(const MSMediaStreamSessions *session
/*
* In practice, these filters are needed only for audio+video recording.
*/
if (ms_factory_lookup_filter_by_id(ms_factory_get_fallback(), MS_MKV_RECORDER_ID)){
if (ms_factory_lookup_filter_by_id(stream->ms.factory, MS_MKV_RECORDER_ID)){
stream->tee3=ms_filter_new(MS_TEE_ID);
stream->recorder_output=ms_filter_new(MS_ITC_SINK_ID);
}
......@@ -472,7 +473,7 @@ static void configure_video_source(VideoStream *stream){
MSVideoSize vsize={640,480};
ms_error("Player does not give its format correctly [%s]",ms_fmt_descriptor_to_string(pf.fmt));
/*put a default format as the error handling is complicated here*/
pf.fmt=ms_factory_get_video_format(ms_factory_get_fallback(),"VP8",vsize,0,NULL);
pf.fmt=ms_factory_get_video_format(stream->ms.factory,"VP8",vsize,0,NULL);
}
cam_vsize=pf.fmt->vsize;
}else{
......@@ -584,7 +585,7 @@ static void configure_recorder_output(VideoStream *stream){
tmp.encoding=pt->mime_type;
tmp.rate=pt->clock_rate;
pinfmt.pin=0;
pinfmt.fmt=ms_factory_get_format(ms_factory_get_fallback(),&tmp);
pinfmt.fmt=ms_factory_get_format(stream->ms.factory,&tmp);
ms_filter_call_method(stream->recorder_output,MS_FILTER_SET_INPUT_FMT,&pinfmt);
ms_message("configure_itc(): format set to %s",ms_fmt_descriptor_to_string(pinfmt.fmt));
}
......@@ -750,7 +751,7 @@ bool_t video_stream_started(VideoStream *stream) {
}
static void apply_video_preset(VideoStream *stream, PayloadType *pt) {
MSVideoPresetsManager *vpm = ms_factory_get_video_presets_manager(ms_factory_get_fallback());
MSVideoPresetsManager *vpm = ms_factory_get_video_presets_manager(stream->ms.factory);
MSVideoPresetConfiguration *vpc = NULL;
MSVideoConfiguration *conf = NULL;
MSList *codec_tags = NULL;
......@@ -1406,6 +1407,10 @@ static MSFilter* _video_stream_stop(VideoStream * stream, bool_t keep_source)
source = stream->source;
stream->source = NULL; // will prevent video_stream_free() from destroying the source
}
/*before destroying the filters, pump the event queue so that pending events have a chance to reach their listeners.
* When the filter are destroyed, all their pending events in the event queue will be cancelled*/
ms_event_queue_pump(ms_factory_get_event_queue(stream->ms.factory));
video_stream_free(stream);
return 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