Index: pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 66)
+++ pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 121)
@@ -25,5 +25,10 @@
 #include <pj/string.h>	    /* memcpy() */
 #include <pj/pool.h>
+#include <pj/assert.h>
+#include <pj/compat/socket.h>
+#include <pj/sock_select.h>
+#include <pj/errno.h>
 #include <stdlib.h>
+
 
 #define THISFILE    "stream.c"
@@ -92,5 +97,5 @@
     struct pj_audio_frame frame_in, frame_out;
 
-    PJ_UNUSED_ARG(timestamp)
+    PJ_UNUSED_ARG(timestamp);
 
     /* Lock mutex */
@@ -153,10 +158,10 @@
     void *rtphdr;
     int rtphdrlen;
-    int sent;
+    pj_ssize_t sent;
 #if 0
     static FILE *fhnd = NULL;
 #endif
 
-    PJ_UNUSED_ARG(timestamp)
+    PJ_UNUSED_ARG(timestamp);
 
     /* Start locking channel mutex */
@@ -203,12 +208,9 @@
 
     /* Send. */
-    sent = pj_sock_sendto (channel->rtp_sock, channel->out_pkt, frame_out.size+sizeof(pj_rtp_hdr), 0, 
+    sent = frame_out.size+sizeof(pj_rtp_hdr);
+    status = pj_sock_sendto (channel->rtp_sock, channel->out_pkt, &sent, 0, 
 			   &channel->dst_addr, sizeof(channel->dst_addr));
-    if (sent != (int)frame_out.size + (int)sizeof(pj_rtp_hdr))  {
-	pj_perror(THISFILE, "Error sending RTP packet to %s:%d", 
-		  pj_sockaddr_get_str_addr(&channel->dst_addr),
-		  pj_sockaddr_get_port(&channel->dst_addr));
+    if (status != PJ_SUCCESS)
 	goto on_return;
-    }
 
     /* Update stat */
@@ -232,10 +234,10 @@
 
 
-static void* PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg)
+static int PJ_THREAD_FUNC stream_decoder_transport_thread (void*arg)
 {
     pj_media_stream_t *channel = arg;
 
     while (!channel->thread_quit_flag) {
-	int len, size;
+	pj_ssize_t len, size;
 	const pj_rtp_hdr *hdr;
 	const void *payload;
@@ -245,5 +247,5 @@
 
 	/* Wait for packet. */
-	fd_set fds;
+	pj_fd_set_t fds;
 	pj_time_val timeout;
 
@@ -259,7 +261,8 @@
 
 	/* Get packet from socket. */
-	len = pj_sock_recv (channel->rtp_sock, channel->in_pkt, channel->in_pkt_size, 0);
-	if (len < 1) {
-	    if (pj_getlasterror() == PJ_ECONNRESET) {
+	len = channel->in_pkt_size;
+	status = pj_sock_recv (channel->rtp_sock, channel->in_pkt, &len, 0);
+	if (len < 1 || status != PJ_SUCCESS) {
+	    if (pj_get_netos_error() == PJ_STATUS_FROM_OS(OSERR_ECONNRESET)) {
 		/* On Win2K SP2 (or above) and WinXP, recv() will get WSAECONNRESET
 		   when the sending side receives ICMP port unreachable.
@@ -267,5 +270,5 @@
 		continue;
 	    }
-	    pj_perror(THISFILE, "Error receiving packet from socket (len=%d)", len);
+	    //pj_perror(THISFILE, "Error receiving packet from socket (len=%d)", len);
 	    pj_thread_sleep(1);
 	    continue;
@@ -326,5 +329,5 @@
     }
 
-    return NULL;
+    return 0;
 }
 
@@ -349,5 +352,5 @@
     void *ptr;
     unsigned size;
-    int status;
+    pj_status_t status;
     
     /* Allocate memory for channel descriptor */
@@ -370,6 +373,6 @@
 
     /* Create mutex for the channel. */
-    channel->mutex = pj_mutex_create(pool, NULL, PJ_MUTEX_SIMPLE);
-    if (channel->mutex == NULL)
+    status = pj_mutex_create_simple(pool, NULL, &channel->mutex);
+    if (status != PJ_SUCCESS)
 	goto err_cleanup;
 
@@ -485,9 +488,9 @@
 	}
 
-	channel->transport_thread = pj_thread_create(pool, "decode", 
-						     &stream_decoder_transport_thread, channel,
-						     0, NULL, 0);
-	if (!channel->transport_thread) {
-	    pj_perror(THISFILE, "Unable to create transport thread");
+	status = pj_thread_create(pool, "decode", 
+				  &stream_decoder_transport_thread, channel,
+				  0, 0, &channel->transport_thread);
+	if (status != PJ_SUCCESS) {
+	    //pj_perror(THISFILE, "Unable to create transport thread");
 	    goto err_cleanup;
 	}
@@ -574,5 +577,5 @@
 PJ_DEF(pj_status_t) pj_media_stream_pause (pj_media_stream_t *channel)
 {
-    PJ_UNUSED_ARG(channel)
+    PJ_UNUSED_ARG(channel);
     return -1;
 }
@@ -580,5 +583,5 @@
 PJ_DEF(pj_status_t) pj_media_stream_resume (pj_media_stream_t *channel)
 {
-    PJ_UNUSED_ARG(channel)
+    PJ_UNUSED_ARG(channel);
     return -1;
 }
