Commit 941b3444 authored by Simon Morlat's avatar Simon Morlat

robustize event queue (was not able to receive events from multiple MSTickers)

various other fixes
parent 7b19568e
......@@ -191,11 +191,11 @@ typedef enum _MSRecorderState MSRecorderState;
/** retrieve echo canceller internal state, as a base64 encoded string */
#define MS_ECHO_CANCELLER_GET_STATE_STRING \
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,5,char **)
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,5,char *)
/** restore a previous state suppling the echo canceller config as base64 encoded string */
#define MS_ECHO_CANCELLER_SET_STATE_STRING \
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,6, const char *)
MS_FILTER_METHOD(MSFilterEchoCancellerInterface,6, const char)
......@@ -207,15 +207,15 @@ typedef enum _MSRecorderState MSRecorderState;
#define MS_VIDEO_DECODER_SEND_PLI \
MS_FILTER_EVENT_NO_ARG(MSFilterVideoDecoderInterface, 2)
#define MS_VIDEO_DECODER_SEND_SLI \
MS_FILTER_EVENT(MSFilterVideoDecoderInterface, 3, const MSVideoCodecSLI *)
MS_FILTER_EVENT(MSFilterVideoDecoderInterface, 3, MSVideoCodecSLI)
#define MS_VIDEO_DECODER_SEND_RPSI \
MS_FILTER_EVENT(MSFilterVideoDecoderInterface, 4, const MSVideoCodecRPSI *)
MS_FILTER_EVENT(MSFilterVideoDecoderInterface, 4, MSVideoCodecRPSI)
#define MS_VIDEO_DECODER_RESET_FIRST_IMAGE_NOTIFICATION \
MS_FILTER_METHOD_NO_ARG(MSFilterVideoDecoderInterface, 5)
#define MS_VIDEO_DECODER_ENABLE_AVPF \
MS_FILTER_METHOD(MSFilterVideoDecoderInterface, 6, bool_t)
#define MS_VIDEO_DECODER_SUPPORT_RENDERING \
MS_FILTER_METHOD(MSFilterVideoDecoderInterface, 7, MSVideoDisplayDecodingSupport*)
MS_FILTER_METHOD(MSFilterVideoDecoderInterface, 7, MSVideoDisplayDecodingSupport)
#define MS_VIDEO_DECODER_FREEZE_ON_ERROR \
MS_FILTER_METHOD(MSFilterVideoDecoderInterface, 8, bool_t)
#define MS_VIDEO_DECODER_RECOVERED_FROM_ERRORS \
......@@ -235,29 +235,29 @@ typedef enum _MSRecorderState MSRecorderState;
#define MS_DECODER_HAVE_PLC MS_AUDIO_DECODER_HAVE_PLC /*for backward compatibility*/
#define MS_AUDIO_DECODER_SET_RTP_PAYLOAD_PICKER \
MS_FILTER_METHOD(MSFilterAudioDecoderInterface,1,MSRtpPayloadPickerContext*)
MS_FILTER_METHOD(MSFilterAudioDecoderInterface,1,MSRtpPayloadPickerContext)
/**
* Interface definition for video encoders.
**/
#define MS_VIDEO_ENCODER_SUPPORTS_PIXFMT \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 0, MSVideoEncoderPixFmt*)
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 0, MSVideoEncoderPixFmt)
/* request a video-fast-update (=I frame for H263,MP4V-ES) to a video encoder*/
#define MS_VIDEO_ENCODER_REQ_VFU \
MS_FILTER_METHOD_NO_ARG(MSFilterVideoEncoderInterface, 1)
#define MS_VIDEO_ENCODER_GET_CONFIGURATION_LIST \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 2, const MSVideoConfiguration **)
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 2, const MSVideoConfiguration *)
#define MS_VIDEO_ENCODER_SET_CONFIGURATION \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 3, const MSVideoConfiguration *)
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 3, const MSVideoConfiguration )
#define MS_VIDEO_ENCODER_NOTIFY_PLI \
MS_FILTER_METHOD_NO_ARG(MSFilterVideoEncoderInterface, 4)
#define MS_VIDEO_ENCODER_NOTIFY_FIR \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 5, uint8_t *)
#define MS_VIDEO_ENCODER_NOTIFY_SLI \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 6, const MSVideoCodecSLI *)
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 6, MSVideoCodecSLI)
#define MS_VIDEO_ENCODER_NOTIFY_RPSI \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 7, const MSVideoCodecRPSI *)
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 7, MSVideoCodecRPSI)
#define MS_VIDEO_ENCODER_ENABLE_AVPF \
MS_FILTER_METHOD(MSFilterVideoEncoderInterface, 8, bool_t)
......
......@@ -56,9 +56,13 @@ struct _MSEventQueue{
static void write_event(MSEventQueue *q, MSFilter *f, unsigned int ev_id, void *arg){
int argsize=ev_id & 0xff;
int size=argsize+16;
uint8_t *nextpos=q->wptr+size;
uint8_t *nextpos;
ms_mutex_lock(&q->mutex);
nextpos=q->wptr+size;
if (q->freeroom<size){
ms_mutex_unlock(&q->mutex);
ms_error("Dropped event, no more free space in event buffer !");
return;
}
......@@ -73,7 +77,7 @@ static void write_event(MSEventQueue *q, MSFilter *f, unsigned int ev_id, void *
*(long*)(q->wptr+8)=(long)ev_id;
if (argsize>0) memcpy(q->wptr+16,arg,argsize);
q->wptr=nextpos;
ms_mutex_lock(&q->mutex);
q->freeroom-=size;
ms_mutex_unlock(&q->mutex);
}
......
......@@ -77,15 +77,16 @@ static void disable_checksums(ortp_socket_t sock) {
* 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.
* return TRUE if the decoder was changed, FALSE otherwise.
*/
static void media_stream_change_decoder(MediaStream *stream, int payload) {
static bool_t media_stream_change_decoder(MediaStream *stream, int payload) {
RtpSession *session = stream->sessions.rtp_session;
RtpProfile *prof = rtp_session_get_profile(session);
PayloadType *pt = rtp_profile_get_payload(prof, payload);
if (stream->decoder == NULL){
ms_message("media_stream_change_decoder(): ignored, no decoder.");
return;
return FALSE;
}
if (pt != NULL){
......@@ -96,7 +97,7 @@ static void media_stream_change_decoder(MediaStream *stream, int payload) {
if ((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;
return FALSE;
}
}
......@@ -113,12 +114,14 @@ static void media_stream_change_decoder(MediaStream *stream, int payload) {
ms_filter_link(stream->rtprecv, 0, stream->decoder, 0);
ms_filter_link(stream->decoder, 0, nextFilter, 0);
ms_filter_preprocess(stream->decoder,stream->sessions.ticker);
return TRUE;
} else {
ms_warning("No decoder found for %s", pt->mime_type);
}
} else {
ms_warning("No payload defined with number %i", payload);
}
return FALSE;
}
MSTickerPrio __ms_get_default_prio(bool_t is_video) {
......@@ -455,10 +458,10 @@ bool_t ms_is_ipv6(const char *remote) {
return ret;
}
void mediastream_payload_type_changed(RtpSession *session, unsigned long data) {
bool_t mediastream_payload_type_changed(RtpSession *session, unsigned long data) {
MediaStream *stream = (MediaStream *)data;
int pt = rtp_session_get_recv_payload_type(stream->sessions.rtp_session);
media_stream_change_decoder(stream, pt);
return media_stream_change_decoder(stream, pt);
}
static void media_stream_process_rtcp(MediaStream *stream, mblk_t *m, time_t curtime){
......
......@@ -52,7 +52,7 @@ MEDIASTREAMER2_INTERNAL_EXPORT RtpSession * create_duplex_rtpsession(int loc_rtp
void media_stream_start_ticker(MediaStream *stream);
void mediastream_payload_type_changed(RtpSession *session, unsigned long data);
bool_t mediastream_payload_type_changed(RtpSession *session, unsigned long data);
const char * media_stream_type_str(MediaStream *stream);
......
......@@ -477,10 +477,21 @@ static void configure_itc(VideoStream *stream){
}
}
static void configure_decoder(VideoStream *stream, PayloadType *pt){
bool_t avpf_enabled=!!(pt->flags & PAYLOAD_TYPE_RTCP_FEEDBACK_ENABLED);
ms_filter_call_method(stream->ms.decoder, MS_VIDEO_DECODER_ENABLE_AVPF, &avpf_enabled);
ms_filter_call_method(stream->ms.decoder, MS_VIDEO_DECODER_FREEZE_ON_ERROR, &stream->freeze_on_error);
ms_filter_add_notify_callback(stream->ms.decoder, event_cb, stream, FALSE);
/* It is important that the internal_event_cb is called synchronously! */
ms_filter_add_notify_callback(stream->ms.decoder, internal_event_cb, stream, TRUE);
}
static void video_stream_payload_type_changed(RtpSession *session, unsigned long data){
VideoStream *stream = (VideoStream *)data;
mediastream_payload_type_changed(session,data);
RtpProfile *prof = rtp_session_get_profile(session);
PayloadType *pt = rtp_profile_get_payload(prof, rtp_session_get_recv_payload_type(session));
if (mediastream_payload_type_changed(session,data) && pt)
configure_decoder(stream,pt);
configure_itc(stream);
}
......@@ -642,9 +653,6 @@ int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *re
ms_fatal("No video display filter could be instantiated. Please check build-time configuration");
}
ms_filter_add_notify_callback(stream->ms.decoder, event_cb, stream, FALSE);
/* It is important that the internal_event_cb is called synchronously! */
ms_filter_add_notify_callback(stream->ms.decoder, internal_event_cb, stream, TRUE);
stream->ms.rtprecv = ms_filter_new (MS_RTP_RECV_ID);
ms_filter_call_method(stream->ms.rtprecv,MS_RTP_RECV_SET_SESSION,stream->ms.sessions.rtp_session);
......@@ -667,8 +675,7 @@ int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *re
}
if (pt->recv_fmtp!=NULL)
ms_filter_call_method(stream->ms.decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);
ms_filter_call_method(stream->ms.decoder, MS_VIDEO_DECODER_ENABLE_AVPF, &avpf_enabled);
ms_filter_call_method(stream->ms.decoder, MS_VIDEO_DECODER_FREEZE_ON_ERROR, &stream->freeze_on_error);
configure_decoder(stream,pt);
/*force the decoder to output YUV420P */
format=MS_YUV420P;
......
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