--- ./kopete/protocols/jabber/jingle/libjingle/talk/base/criticalsection.h.orig	Mon Mar 20 23:18:37 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/base/criticalsection.h	Thu Apr 20 02:38:21 2006
@@ -83,8 +83,10 @@
 public:
   CriticalSection() {
     pthread_mutexattr_t mutex_attribute;
+    pthread_mutexattr_init(&mutex_attribute);
     pthread_mutexattr_settype(&mutex_attribute, PTHREAD_MUTEX_RECURSIVE);
     pthread_mutex_init(&mutex_, &mutex_attribute);
+    pthread_mutexattr_destroy(&mutex_attribute);
   }
   ~CriticalSection() {
     pthread_mutex_destroy(&mutex_);
--- kopete/protocols/jabber/jingle/libjingle/talk/base/thread.cc.orig	Tue May  2 11:43:09 2006
+++ kopete/protocols/jabber/jingle/libjingle/talk/base/thread.cc	Tue May  2 11:43:21 2006
@@ -113,6 +113,7 @@
   pthread_attr_t attr;
   pthread_attr_init(&attr);
   pthread_create(&thread_, &attr, PreLoop, this);
+  pthread_attr_destroy(&attr);
   started_ = true;
 }
 
--- kopete/protocols/jabber/jingle/libjingle/talk/p2p/base/Makefile.in.orig	Thu Apr 20 10:32:14 2006
+++ kopete/protocols/jabber/jingle/libjingle/talk/p2p/base/Makefile.in	Thu Apr 20 10:33:01 2006
@@ -699,7 +699,7 @@
 	for dir in "$(DESTDIR)$(bindir)"; do \
 	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
 	done
-install: install-am
+install:
 install-exec: install-exec-am
 install-data: install-data-am
 uninstall: uninstall-am
--- kopete/protocols/jabber/jingle/libjingle/talk/session/phone/linphonemediaengine.cc.orig	Wed Feb 22 16:32:44 2006
+++ kopete/protocols/jabber/jingle/libjingle/talk/session/phone/linphonemediaengine.cc	Wed Feb 22 16:41:45 2006
@@ -65,6 +65,7 @@
   
   pthread_attr_init(&attr);
   pthread_create(&thread_, &attr, &thread_function, this);
+  pthread_attr_destroy(&attr);
 }
 
 LinphoneMediaChannel::~LinphoneMediaChannel() {
@@ -118,8 +119,8 @@
   mute_ = !send;
 }
 
-float LinphoneMediaChannel::GetCurrentQuality() {}
-int LinphoneMediaChannel::GetOutputLevel() {}
+float LinphoneMediaChannel::GetCurrentQuality() { return 0; }
+int LinphoneMediaChannel::GetOutputLevel() { return 0; }
 
 LinphoneMediaEngine::LinphoneMediaEngine() {}
 LinphoneMediaEngine::~LinphoneMediaEngine() {}
@@ -139,7 +140,7 @@
  
 #ifdef HAVE_SPEEX
   ms_speex_codec_init();
-  rtp_profile_set_payload(&av_profile, 110, &speex_wb);
+  rtp_profile_set_payload(&av_profile, 110, &payload_type_speex_wb);
   codecs_.push_back(Codec(110, "speex", 8));
 #endif
 
@@ -149,7 +150,7 @@
   codecs_.push_back(Codec(102, "iLBC", 4));
 #endif
 
-  rtp_profile_set_payload(&av_profile, 0, &pcmu8000);
+  rtp_profile_set_payload(&av_profile, 0, &payload_type_pcmu8000);
   codecs_.push_back(Codec(0, "PCMU", 2));
   
 return true;
@@ -163,8 +164,8 @@
   return new LinphoneMediaChannel();
 }
 
-int LinphoneMediaEngine::SetAudioOptions(int options) {}
-int LinphoneMediaEngine::SetSoundDevices(int wave_in_device, int wave_out_device) {}
+int LinphoneMediaEngine::SetAudioOptions(int options) { return 0; }
+int LinphoneMediaEngine::SetSoundDevices(int wave_in_device, int wave_out_device) { return 0; }
 
-float LinphoneMediaEngine::GetCurrentQuality() {}
-int LinphoneMediaEngine::GetInputLevel() {}
+float LinphoneMediaEngine::GetCurrentQuality() { return 0; }
+int LinphoneMediaEngine::GetInputLevel() { return 0; }
--- ./kopete/protocols/jabber/jingle/libjingle/talk/session/phone/portaudiomediaengine.cc.orig	Mon Mar 20 23:18:35 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/session/phone/portaudiomediaengine.cc	Thu Apr 20 02:38:21 2006
@@ -30,6 +30,7 @@
 // ORTP settings
 #define MAX_RTP_SIZE 1500 // From mediastreamer
 
+#define rtp_session_max_buf_size_set(session, bufsize)	(rtp_session_set_recv_buf_size(session, bufsize))
 
 // -----------------------------------------------------------------------------
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/audiostream.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/audiostream.c	Thu Apr 20 02:38:21 2006
@@ -29,6 +29,8 @@
 
 #define MAX_RTP_SIZE	1500
 
+#define rtp_session_max_buf_size_set(session, bufsize)	(rtp_session_set_recv_buf_size(session, bufsize))
+
 /* this code is not part of the library itself, it is part of the mediastream program */
 void audio_stream_free(AudioStream *stream)
 {
@@ -118,7 +120,8 @@
 	if (remport>0) rtp_session_set_remote_addr(rtpr,remip,remport);
 	rtp_session_set_scheduling_mode(rtpr,0);
 	rtp_session_set_blocking_mode(rtpr,0);
-	rtp_session_set_payload_type(rtpr,payload);
+	rtp_session_set_send_payload_type(rtpr,payload);
+	rtp_session_set_recv_payload_type(rtpr,payload);
 	rtp_session_set_jitter_compensation(rtpr,jitt_comp);
 	rtp_session_enable_adaptive_jitter_compensation(rtpr,TRUE);
 	/*rtp_session_signal_connect(rtpr,"timestamp_jump",(RtpCallback)on_timestamp_jump,NULL);*/
@@ -143,7 +146,8 @@
 	rtp_session_set_remote_addr(rtps,remip,remport);
 	rtp_session_set_scheduling_mode(rtps,0);
 	rtp_session_set_blocking_mode(rtps,0);
-	rtp_session_set_payload_type(rtps,payload);
+	rtp_session_set_send_payload_type(rtps,payload);
+	rtp_session_set_recv_payload_type(rtps,payload);
 	rtp_session_set_jitter_compensation(rtps,jitt_comp);
 	
 	rtpr=rtp_session_new(RTP_SESSION_RECVONLY);
@@ -158,7 +162,6 @@
 	rtp_session_set_blocking_mode(rtpr,0);
 	rtp_session_set_payload_type(rtpr,payload);
 	rtp_session_set_jitter_compensation(rtpr,jitt_comp);
-	rtp_session_signal_connect(rtpr,"telephone-event",(RtpCallback)on_dtmf_received,NULL);
 	rtp_session_signal_connect(rtpr,"timestamp_jump",(RtpCallback)on_timestamp_jump,NULL);
 	*recv=rtpr;
 	*send=rtps;
@@ -179,8 +182,6 @@
 	rtp_session_signal_connect(rtpr,"telephone-event",(RtpCallback)on_dtmf_received,(gpointer)stream);
 	rtps=rtpr;
 	
-	stream->recv_session = rtpr;
-	stream->send_session = rtps;
 	stream->rtpsend=ms_rtp_send_new();
 	ms_rtp_send_set_session(MS_RTP_SEND(stream->rtpsend),rtps);
 	stream->rtprecv=ms_rtp_recv_new();
@@ -192,7 +193,13 @@
 	else stream->soundread=ms_read_new(infile);
 	if (outfile==NULL) stream->soundwrite=snd_card_create_write_filter(playcard);
 	else stream->soundwrite=ms_write_new(outfile);
-	
+
+	if ((stream->soundread==NULL) || (stream->soundwrite==NULL)){
+		/* big problem: we do not have valid sound input/output */
+		g_error("mediastream.c: No soundcard input/output available.");
+		return NULL;
+	}
+
 	/* creates the couple of encoder/decoder */
 	pt=rtp_profile_get_payload(profile,payload);
 	if (pt==NULL){
@@ -217,8 +224,8 @@
 	ms_filter_set_property(stream->decoder,MS_FILTER_PROPERTY_FREQ,&pt->clock_rate);
 	ms_filter_set_property(stream->decoder,MS_FILTER_PROPERTY_BITRATE,&pt->normal_bitrate);
 	
-	ms_filter_set_property(stream->encoder,MS_FILTER_PROPERTY_FMTP, (void*)pt->fmtp);
-	ms_filter_set_property(stream->decoder,MS_FILTER_PROPERTY_FMTP,(void*)pt->fmtp);
+	ms_filter_set_property(stream->encoder,MS_FILTER_PROPERTY_FMTP,(void*)pt->send_fmtp);
+	ms_filter_set_property(stream->decoder,MS_FILTER_PROPERTY_FMTP,(void*)pt->recv_fmtp);
 	/* create the synchronisation source */
 	stream->timer=ms_timer_new();
 	
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msGSMdecoder.h.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msGSMdecoder.h	Thu Apr 20 02:38:21 2006
@@ -36,7 +36,7 @@
     /* the MSGSMDecoder derivates from MSFilter, so the MSFilter object MUST be the first of the MSGSMDecoder object
        in order to the object mechanism to work*/
     MSFilter filter;
-    MSFifo *f_inputs[MSGSMDECODER_MAX_INPUTS];
+    MSQueue *q_inputs[MSGSMDECODER_MAX_INPUTS];
     MSFifo *f_outputs[MSGSMDECODER_MAX_INPUTS];
     gsm gsm_handle;
 } MSGSMDecoder;
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msGSMencoder.h.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msGSMencoder.h	Thu Apr 20 02:38:21 2006
@@ -36,7 +36,7 @@
        in order to the object mechanism to work*/
     MSFilter filter;
     MSFifo *f_inputs[MSGSMENCODER_MAX_INPUTS];
-    MSFifo *f_outputs[MSGSMENCODER_MAX_INPUTS];
+    MSQueue *q_outputs[MSGSMENCODER_MAX_INPUTS];
     gsm gsm_handle;
 } MSGSMEncoder;
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msbuffer.h.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msbuffer.h	Thu Apr 20 02:38:21 2006
@@ -48,11 +48,12 @@
 struct _MSMessage
 {
    MSBuffer *buffer; /* points to a MSBuffer */
-   void *data;          /*points to buffer->buffer  */
+   char *data;          /*points to buffer->buffer  */
    guint32 size;   /* the size of the buffer to read in data. It may not be the
    								physical size (I mean buffer->buffer->size */
    struct _MSMessage *next;
    struct _MSMessage *prev;  /* MSMessage are queued into MSQueues */
+   gboolean markbit;
 };
 
 typedef struct _MSMessage MSMessage;
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msfifo.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msfifo.c	Thu Apr 20 02:38:21 2006
@@ -123,7 +123,7 @@
 	/* fix readsize and writesize */
 	fifo->readsize-=unwritten;
 	fifo->writesize+=unwritten;
-	fifo->wr_ptr+=written;
+	fifo->wr_ptr=fifo->prev_wr_ptr+written;
 }
 
 gint ms_fifo_get_write_ptr(MSFifo *fifo, gint bsize, void **ret_ptr)
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msqueue.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msqueue.c	Thu Apr 20 02:38:21 2006
@@ -53,4 +53,7 @@
    q->size++;
 }
 
+MSMessage *ms_queue_peek_last(MSQueue *q){
+   return q->last;
+}
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msqueue.h.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msqueue.h	Thu Apr 20 02:38:21 2006
@@ -41,6 +41,8 @@
 
 void ms_queue_put(MSQueue *q, MSMessage *m);
 
+MSMessage *ms_queue_peek_last(MSQueue *q);
+
 #define ms_queue_can_get(q) ( (q)->size!=0 )
 
 #define ms_queue_destroy(q) g_free(q)

--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtprecv.h.orig	Thu Mar 16 18:43:05 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtprecv.h	Fri Apr 21 10:56:34 2006
@@ -34,7 +34,7 @@
 
 #define MSRTPRECV_MAX_OUTPUTS  1 /* max output per filter*/
 
-#define MSRTPRECV_DEF_GRAN 4096 /* the default granularity*/
+#define MSRTPRECV_DEF_GRAN 320	/* the default granularity*/
 
 struct _MSRtpRecv
 {
@@ -47,6 +47,8 @@
 	RtpSession *rtpsession;
 	guint32 prev_ts;
 	gint stream_started;
+	gint payload_expected;
+	gboolean ignore;
 };
 
 typedef struct _MSRtpRecv MSRtpRecv;
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtpsend.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtpsend.c	Thu Apr 20 02:38:21 2006
@@ -85,7 +85,7 @@
 {
 	guint32 clockts;
 	/* use the sync system time to compute a timestamp */
-	PayloadType *pt=rtp_profile_get_payload(r->rtpsession->profile,r->rtpsession->payload_type);
+	PayloadType *pt=rtp_profile_get_payload(r->rtpsession->rcv.profile,r->rtpsession->rcv.pt);
 	g_return_val_if_fail(pt!=NULL,0);
 	clockts=(guint32)(((double)synctime * (double)pt->clock_rate)/1000.0);
 	ms_trace("ms_rtp_send_process: sync->time=%i clock=%i",synctime,clockts);
@@ -139,8 +139,9 @@
 			ts=get_new_timestamp(r,synctime);
 			if (!skip) {
 				/*g_message("Sending packet with ts=%u",ts);*/
-				rtp_session_send_with_ts(r->rtpsession,msg->data,msg->size,ts);
-				
+				mblk_t *packet=rtp_session_create_packet_with_data(r->rtpsession,msg->data,msg->size,NULL);
+				rtp_set_markbit(packet,msg->markbit);
+				rtp_session_sendm_with_ts(r->rtpsession,packet,ts);
 			}
 			ms_message_destroy(msg);
 		}
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtpsend.h.orig	Fri May  5 23:32:24 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtpsend.h	Fri May  5 23:32:42 2006
@@ -34,7 +34,7 @@
 
 #define MSRTPSEND_MAX_INPUTS  1 /* max input per filter*/
 
-#define MSRTPSEND_DEF_GRAN  4096/* the default granularity*/
+#define MSRTPSEND_DEF_GRAN 160	/* the default granularity*/
 
 struct _MSRtpSend
 {
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msspeexdec.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msspeexdec.c	Thu Apr 20 02:38:22 2006
@@ -171,6 +171,7 @@
 void ms_speex_dec_uninit_core(MSSpeexDec *obj)
 {
 	speex_decoder_destroy(obj->speex_state);
+	speex_bits_destroy(&obj->bits);
 	obj->initialized=0;
 }
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msspeexenc.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msspeexenc.c	Thu Apr 20 02:38:22 2006
@@ -157,6 +157,7 @@
 {
 	if (obj->initialized){
 		speex_encoder_destroy(obj->speex_state);
+		speex_bits_destroy(&obj->bits);
 		obj->initialized=0;
 	}
 }
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/mssync.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/mssync.c	Thu Apr 20 02:38:22 2006
@@ -189,5 +189,6 @@
 	g_mutex_free(sync->lock);
 	g_cond_free(sync->thread_cond);
 	g_cond_free(sync->stop_cond);
+	return 0;
 }
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/mstimer.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/mstimer.c	Thu Apr 20 02:38:22 2006
@@ -66,6 +66,8 @@
 	else {
 		gint32 diff,time;
 		struct timeval tv,cur;
+
+		timer->sync.time+=timer->milisec;
 	
 		gettimeofday(&cur,NULL);
 		time=((cur.tv_usec-timer->orig.tv_usec)/1000 ) + ((cur.tv_sec-timer->orig.tv_sec)*1000 );
@@ -74,14 +76,13 @@
 		}
 		while((diff = timer->sync.time-time) > 0)
 		{
-			tv.tv_sec = diff/1000;
-			tv.tv_usec = (diff%1000)*1000;
+			tv.tv_sec = timer->milisec/1000;
+			tv.tv_usec = (timer->milisec%1000)*1000;
 			select(0,NULL,NULL,NULL,&tv);
 			gettimeofday(&cur,NULL);
 			time=((cur.tv_usec-timer->orig.tv_usec)/1000 ) + ((cur.tv_sec-timer->orig.tv_sec)*1000 );
 		}
 	}
-	timer->sync.time+=timer->milisec;
 	return;
 }
 
--- ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/osscard.c.orig	Mon Mar 20 23:18:36 2006
+++ ./kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/osscard.c	Thu Apr 20 02:38:22 2006
@@ -342,7 +342,7 @@
 {
 	int p=0,mix_fd;
 	int osscmd;
-	g_return_if_fail(obj->mixdev_name!=NULL);
+	g_return_val_if_fail(obj->mixdev_name!=NULL,-1);
 #ifdef HAVE_SYS_SOUNDCARD_H
 	switch(way){
 		case SND_CARD_LEVEL_GENERAL:
--- kopete/protocols/jabber/jingle/libjingle/talk/xmpp/saslplainmechanism.h.orig	Wed May 10 07:43:35 2006
+++ kopete/protocols/jabber/jingle/libjingle/talk/xmpp/saslplainmechanism.h	Wed May 10 07:44:01 2006
@@ -48,7 +48,7 @@
 
     FormatXmppPassword credential;
     credential.Append("\0", 1);
-    credential.Append(user_jid_.Str());
+    credential.Append(user_jid_.node());
     credential.Append("\0", 1);
     credential.Append(&password_);
     el->AddText(Base64EncodeFromArray(credential.GetData(), credential.GetLength()));
--- kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtprecv.c.orig	Sun Oct  1 19:26:45 2006
+++ kopete/protocols/jabber/jingle/libjingle/talk/third_party/mediastreamer/msrtprecv.c	Mon Dec 18 16:26:36 2006
@@ -26,7 +26,7 @@
 MSMessage *msgb_2_ms_message(mblk_t* mp){
 	MSMessage *msg;
 	MSBuffer *msbuf;
-	if (mp->b_datap->ref_count!=1) return NULL; /* cannot handle properly non-unique buffers*/
+	if (mp->b_datap->db_ref!=1) return NULL; /* cannot handle properly non-unique buffers*/
 	/* create a MSBuffer using the mblk_t buffer */
 	msg=ms_message_alloc();
 	msbuf=ms_buffer_alloc(0);
@@ -70,6 +70,8 @@
 	memset(r->q_outputs,0,sizeof(MSFifo*)*MSRTPRECV_MAX_OUTPUTS);
 	r->rtpsession=NULL;
 	r->stream_started=0;
+	r->ignore=FALSE;
+	r->payload_expected=0;
 }
 
 void ms_rtp_recv_class_init(MSRtpRecvClass *klass)
@@ -120,7 +122,7 @@
 		gint got=0;
 		/* we are connected with queues (surely for video)*/
 		/* use the sync system time to compute a timestamp */
-		PayloadType *pt=rtp_profile_get_payload(r->rtpsession->profile,r->rtpsession->payload_type);
+		PayloadType *pt=rtp_profile_get_payload(r->rtpsession->snd.profile,r->rtpsession->snd.pt);
 		if (pt==NULL) {
 			ms_warning("ms_rtp_recv_process(): NULL RtpPayload- skipping.");
 			return;
@@ -134,10 +136,16 @@
 			/*g_message("Got packet with timestamp %u",clock);*/
 			got++;
 			r->stream_started=1;
-			mdata=mp->b_cont;
-			freeb(mp);
-			msg=msgb_2_ms_message(mdata);
-			ms_queue_put(qo,msg);
+			if (!r->ignore){
+				gboolean markbit=((rtp_header_t*)mp->b_rptr)->markbit;
+				mdata=mp->b_cont;
+				freeb(mp);
+				msg=msgb_2_ms_message(mdata);
+				msg->markbit=markbit;   
+				ms_queue_put(qo,msg);
+			}else{
+				freemsg(mp);
+			}
 		}
 	}
 }
@@ -147,10 +155,24 @@
 	g_free(obj);
 }
 
+static void __payload_type_changed(RtpSession *session,MSRtpRecv *obj){
+	int pt_num=rtp_session_get_recv_payload_type(session);
+	PayloadType *pt=rtp_profile_get_payload(rtp_session_get_profile(session),pt_num);
+	if (pt==NULL){
+		/* sip phone should ignore payload types they don't understand */
+		g_warning("Ignoring payload type %i",pt_num);
+		obj->ignore=TRUE;
+	}else{
+		if (obj->ignore) g_warning("payload type is coming back to something known");
+		obj->ignore=FALSE;
+	}
+}
+
 RtpSession * ms_rtp_recv_set_session(MSRtpRecv *obj,RtpSession *session)
 {
 	RtpSession *old=obj->rtpsession;
 	obj->rtpsession=session;
+	rtp_session_signal_connect(session,"payload_type_changed",(RtpCallback)__payload_type_changed,(unsigned long)obj);
 	obj->prev_ts=0;
 	return old;
 }
