Commit f7e6ccfb authored by Ghislain MARY's avatar Ghislain MARY

Factorize payload type change callback.

parent e003e8c6
......@@ -163,44 +163,6 @@ bool_t audio_stream_alive(AudioStream * stream, int timeout){
return TRUE;
}
/*this function must be called from the MSTicker thread:
it replaces one filter by another one.
This is a dirty hack that works anyway.
It would be interesting to have something that does the job
simplier within the MSTicker api
*/
void audio_stream_change_decoder(AudioStream *stream, int payload){
RtpSession *session=stream->ms.session;
RtpProfile *prof=rtp_session_get_profile(session);
PayloadType *pt=rtp_profile_get_payload(prof,payload);
if (pt!=NULL){
MSFilter *dec=ms_filter_create_decoder(pt->mime_type);
if (dec!=NULL){
MSFilter *nextFilter = stream->ms.decoder->outputs[0]->next.filter;
ms_filter_unlink(stream->ms.rtprecv, 0, stream->ms.decoder, 0);
ms_filter_unlink(stream->ms.decoder, 0, nextFilter, 0);
ms_filter_postprocess(stream->ms.decoder);
ms_filter_destroy(stream->ms.decoder);
stream->ms.decoder=dec;
if (pt->recv_fmtp!=NULL)
ms_filter_call_method(stream->ms.decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);
ms_filter_link(stream->ms.rtprecv, 0, stream->ms.decoder, 0);
ms_filter_link(stream->ms.decoder, 0, nextFilter, 0);
ms_filter_preprocess(stream->ms.decoder,stream->ms.ticker);
}else{
ms_warning("No decoder found for %s",pt->mime_type);
}
}else{
ms_warning("No payload defined with number %i",payload);
}
}
static void payload_type_changed(RtpSession *session, unsigned long data){
AudioStream *stream=(AudioStream*)data;
int pt=rtp_session_get_recv_payload_type(stream->ms.session);
audio_stream_change_decoder(stream,pt);
}
/*invoked from FEC capable filters*/
static mblk_t* audio_stream_payload_picker(MSRtpPayloadPickerContext* context,unsigned int sequence_number) {
return rtp_session_pick_with_cseq(((AudioStream*)(context->filter_graph_manager))->ms.session, sequence_number);
......@@ -290,7 +252,7 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
else
stream->dtmfgen=NULL;
rtp_session_signal_connect(rtps,"telephone-event",(RtpCallback)on_dtmf_received,(unsigned long)stream);
rtp_session_signal_connect(rtps,"payload_type_changed",(RtpCallback)payload_type_changed,(unsigned long)stream);
rtp_session_signal_connect(rtps,"payload_type_changed",(RtpCallback)payload_type_changed,(unsigned long)&stream->ms);
/* creates the local part */
if (captcard!=NULL){
if (stream->soundread==NULL)
......
......@@ -49,6 +49,48 @@ static void disable_checksums(ortp_socket_t sock) {
#endif
}
/**
* This function must be called from the MSTicker thread:
* it replaces one filter by another one.
* This is a dirty hack that works anyway.
* It would be interesting to have something that does the job
* more easily within the MSTicker API.
*/
static void media_stream_change_decoder(MediaStream *stream, int payload) {
RtpSession *session = stream->session;
RtpProfile *prof = rtp_session_get_profile(session);
PayloadType *pt = rtp_profile_get_payload(prof, payload);
if (pt != NULL){
MSFilter *dec;
if ((stream->type == VideoStreamType)
&& (stream->decoder != NULL) && (stream->decoder->desc->enc_fmt != NULL)
&& (strcasecmp(pt->mime_type, stream->decoder->desc->enc_fmt) == 0)) {
/* Same formats behind different numbers, nothing to do. */
return;
}
dec = ms_filter_create_decoder(pt->mime_type);
if (dec != NULL) {
MSFilter *nextFilter = stream->decoder->outputs[0]->next.filter;
ms_filter_unlink(stream->rtprecv, 0, stream->decoder, 0);
ms_filter_unlink(stream->decoder, 0, nextFilter, 0);
ms_filter_postprocess(stream->decoder);
ms_filter_destroy(stream->decoder);
stream->decoder = dec;
if (pt->recv_fmtp != NULL)
ms_filter_call_method(stream->decoder, MS_FILTER_ADD_FMTP, (void *)pt->recv_fmtp);
ms_filter_link(stream->rtprecv, 0, stream->decoder, 0);
ms_filter_link(stream->decoder, 0, nextFilter, 0);
ms_filter_preprocess(stream->decoder,stream->ticker);
} else {
ms_warning("No decoder found for %s", pt->mime_type);
}
} else {
ms_warning("No payload defined with number %i", payload);
}
}
MSTickerPrio __ms_get_default_prio(bool_t is_video) {
const char *penv;
......@@ -197,3 +239,9 @@ bool_t ms_is_ipv6(const char *remote) {
#endif
return ret;
}
void payload_type_changed(RtpSession *session, unsigned long data) {
MediaStream *stream = (MediaStream *)data;
int pt = rtp_session_get_recv_payload_type(stream->session);
media_stream_change_decoder(stream, pt);
}
......@@ -33,6 +33,8 @@ RtpSession * create_duplex_rtpsession(int loc_rtp_port, int loc_rtcp_port, bool_
void start_ticker(MediaStream *stream);
void payload_type_changed(RtpSession *session, unsigned long data);
const char * const media_stream_type_str(MediaStream *stream);
void media_stream_free(MediaStream *stream);
......
......@@ -65,51 +65,6 @@ static void event_cb(void *ud, MSFilter* f, unsigned int event, void *eventdata)
}
}
/*this function must be called from the MSTicker thread:
it replaces one filter by another one.
This is a dirty hack that works anyway.
It would be interesting to have something that does the job
simplier within the MSTicker api
*/
void video_stream_change_decoder(VideoStream *stream, int payload){
RtpSession *session=stream->ms.session;
RtpProfile *prof=rtp_session_get_profile(session);
PayloadType *pt=rtp_profile_get_payload(prof,payload);
if (pt!=NULL){
MSFilter *dec;
if (stream->ms.decoder!=NULL && stream->ms.decoder->desc->enc_fmt!=NULL &&
strcasecmp(pt->mime_type,stream->ms.decoder->desc->enc_fmt)==0){
/* same formats behind different numbers, nothing to do */
return;
}
dec=ms_filter_create_decoder(pt->mime_type);
if (dec!=NULL){
ms_filter_unlink(stream->ms.rtprecv, 0, stream->ms.decoder, 0);
if (stream->tee2)
ms_filter_unlink(stream->ms.decoder,0,stream->tee2,0);
else if(stream->output)
ms_filter_unlink(stream->ms.decoder,0,stream->output,0);
ms_filter_postprocess(stream->ms.decoder);
ms_filter_destroy(stream->ms.decoder);
stream->ms.decoder=dec;
if (pt->recv_fmtp!=NULL)
ms_filter_call_method(stream->ms.decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);
ms_filter_link (stream->ms.rtprecv, 0, stream->ms.decoder, 0);
if (stream->tee2)
ms_filter_link(stream->ms.decoder,0,stream->tee2,0);
else if(stream->output)
ms_filter_link (stream->ms.decoder,0 , stream->output, 0);
ms_filter_preprocess(stream->ms.decoder,stream->ms.ticker);
ms_filter_set_notify_callback(dec, event_cb, stream);
}else{
ms_warning("No decoder found for %s",pt->mime_type);
}
}else{
ms_warning("No payload defined with number %i",payload);
}
}
static void video_steam_process_rtcp(VideoStream *stream, mblk_t *m){
do{
if (rtcp_is_SR(m)){
......@@ -161,12 +116,6 @@ void video_stream_iterate(VideoStream *stream){
if (stream->ms.ice_check_list) ice_check_list_process(stream->ms.ice_check_list,stream->ms.session);
}
static void payload_type_changed(RtpSession *session, unsigned long data){
VideoStream *stream=(VideoStream*)data;
int pt=rtp_session_get_recv_payload_type(stream->ms.session);
video_stream_change_decoder(stream,pt);
}
static void choose_display_name(VideoStream *stream){
#ifdef WIN32
stream->display_name=ms_strdup("MSDrawDibDisplay");
......@@ -367,7 +316,7 @@ int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *re
rtp_session_set_jitter_compensation(rtps,jitt_comp);
rtp_session_signal_connect(stream->ms.session,"payload_type_changed",
(RtpCallback)payload_type_changed,(unsigned long)stream);
(RtpCallback)payload_type_changed,(unsigned long)&stream->ms);
rtp_session_get_jitter_buffer_params(stream->ms.session,&jbp);
jbp.max_packets=1000;//needed for high resolution video
......
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