Index: pjproject/trunk/build/os-darwinos.mak
===================================================================
--- pjproject/trunk/build/os-darwinos.mak	(revision 340)
+++ pjproject/trunk/build/os-darwinos.mak	(revision 341)
@@ -3,5 +3,5 @@
 export OS_CXXFLAGS := 
 
-export OS_LDFLAGS  := $(CC_LIB)pthread$(LIBEXT2) 
+export OS_LDFLAGS  := $(CC_LIB)pthread$(LIBEXT2) -framework CoreAudio
 
 export OS_SOURCES  := 
Index: pjproject/trunk/pjmedia/build/Makefile
===================================================================
--- pjproject/trunk/pjmedia/build/Makefile	(revision 340)
+++ pjproject/trunk/pjmedia/build/Makefile	(revision 341)
@@ -66,5 +66,5 @@
 export PJMEDIA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
 			codec.o conference.o endpoint.o errno.o file_port.o \
-			g711.o jbuf.o null_port.o pasound.o port.o resample.o rtcp.o \
+			g711.o jbuf.o null_port.o port.o resample.o rtcp.o \
 			rtp.o sdp.o sdp_cmp.o sdp_neg.o session.o silencedet.o \
 			sound_port.o stream.o $(SOUND_OBJS) $(NULLSOUND_OBJS)
Index: pjproject/trunk/pjmedia/build/os-darwinos.mak
===================================================================
--- pjproject/trunk/pjmedia/build/os-darwinos.mak	(revision 341)
+++ pjproject/trunk/pjmedia/build/os-darwinos.mak	(revision 341)
@@ -0,0 +1,14 @@
+#
+# OS specific configuration for Darwin/MacOS target. 
+#
+
+#
+# PJMEDIA_OBJS specified here are object files to be included in PJMEDIA
+# (the library) for this specific operating system. Object files common 
+# to all operating systems should go in Makefile instead.
+#
+export PJMEDIA_OBJS += $(PA_DIR)/pa_mac_core.o $(PA_DIR)/pa_mac_hostapis.o \
+		       $(PA_DIR)/pa_unix_util.o
+#		       $(PA_DIR)/ringbuffer.o
+
+export OS_CFLAGS +=  $(CC_DEF)PA_USE_COREAUDIO=1 $(CC_DEF)PA_BIG_ENDIAN=1
Index: pjproject/trunk/pjmedia/build/os-linux.mak
===================================================================
--- pjproject/trunk/pjmedia/build/os-linux.mak	(revision 340)
+++ pjproject/trunk/pjmedia/build/os-linux.mak	(revision 341)
@@ -1,4 +1,4 @@
 #
-# OS specific configuration for Win32 OS target. 
+# OS specific configuration for Linux OS target. 
 #
 
Index: pjproject/trunk/pjmedia/include/pjmedia/wave.h
===================================================================
--- pjproject/trunk/pjmedia/include/pjmedia/wave.h	(revision 340)
+++ pjproject/trunk/pjmedia/include/pjmedia/wave.h	(revision 341)
@@ -30,13 +30,7 @@
 PJ_BEGIN_DECL
 
-#if PJ_IS_BIG_ENDIAN
-#   define PJMEDIA_RIFF_TAG	('R'<<24|'I'<<16|'F'<<8|'F')
-#   define PJMEDIA_WAVE_TAG	('W'<<24|'A'<<16|'V'<<8|'E')
-#   define PJMEDIA_FMT_TAG	('f'<<24|'m'<<16|'t'<<8|' ')
-#else
-#   define PJMEDIA_RIFF_TAG	('F'<<24|'F'<<16|'I'<<8|'R')
-#   define PJMEDIA_WAVE_TAG	('E'<<24|'V'<<16|'A'<<8|'W')
-#   define PJMEDIA_FMT_TAG	(' '<<24|'t'<<16|'m'<<8|'f')
-#endif
+#define PJMEDIA_RIFF_TAG	('F'<<24|'F'<<16|'I'<<8|'R')
+#define PJMEDIA_WAVE_TAG	('E'<<24|'V'<<16|'A'<<8|'W')
+#define PJMEDIA_FMT_TAG		(' '<<24|'t'<<16|'m'<<8|'f')
 
 
@@ -79,2 +73,3 @@
 
 #endif	/* __PJMEDIA_WAVE_H__ */
+
Index: pjproject/trunk/pjmedia/src/pjmedia/file_port.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/file_port.c	(revision 340)
+++ pjproject/trunk/pjmedia/src/pjmedia/file_port.c	(revision 341)
@@ -38,4 +38,45 @@
 #define SIGNATURE	('F'<<24|'I'<<16|'L'<<8|'E')
 
+#if 1
+#   define TRACE_(x)	PJ_LOG(4,x)
+#else
+#   define TRACE_(x)
+#endif
+
+#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
+    PJ_INLINE(pj_int16_t) swap16(pj_int16_t val)
+    {
+	pj_uint8_t *p = (pj_uint8_t*)&val;
+	pj_uint8_t tmp = *p;
+	*p = *(p+1);
+	*(p+1) = tmp;
+	return val;
+    }
+    PJ_INLINE(pj_int32_t) swap32(pj_int32_t val)
+    {
+	pj_uint8_t *p = (pj_uint8_t*)&val;
+	pj_uint8_t tmp = *p;
+	*p = *(p+3);
+	*(p+3) = tmp;
+	tmp = *(p+1);
+	*(p+1) = *(p+2);
+	*(p+2) = tmp;
+	return val;
+    }
+#   define SWAP16(val16)	swap16(val16)
+#   define SWAP32(val32)	swap32(val32)
+    static void samples_to_host(pj_int16_t *samples, unsigned count)
+    {
+	unsigned i;
+	for (i=0; i<count; ++i) {
+	    samples[i] = SWAP16(samples[i]);
+	}
+    }
+#else
+#   define SWAP16(val16)	(val16)
+#   define SWAP32(val32)	(val32)
+#   define samples_to_host(samples,count)
+#endif
+
 struct file_port
 {
@@ -129,6 +170,38 @@
     }
 
+    /* Convert samples to host rep */
+    samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/2);
+
     return PJ_SUCCESS;
 }
+
+
+/*
+ * Change the endianness of WAVE header fields.
+ */
+void pjmedia_wave_hdr_swap_bytes( pjmedia_wave_hdr *hdr )
+{
+    hdr->riff_hdr.riff		    = SWAP32(hdr->riff_hdr.riff);
+    hdr->riff_hdr.file_len	    = SWAP32(hdr->riff_hdr.file_len);
+    hdr->riff_hdr.wave		    = SWAP32(hdr->riff_hdr.wave);
+    
+    hdr->fmt_hdr.fmt		    = SWAP32(hdr->fmt_hdr.fmt);
+    hdr->fmt_hdr.len		    = SWAP32(hdr->fmt_hdr.len);
+    hdr->fmt_hdr.fmt_tag	    = SWAP16(hdr->fmt_hdr.fmt_tag);
+    hdr->fmt_hdr.nchan		    = SWAP16(hdr->fmt_hdr.nchan);
+    hdr->fmt_hdr.sample_rate	    = SWAP32(hdr->fmt_hdr.sample_rate);
+    hdr->fmt_hdr.bytes_per_sec	    = SWAP32(hdr->fmt_hdr.bytes_per_sec);
+    hdr->fmt_hdr.block_align	    = SWAP16(hdr->fmt_hdr.block_align);
+    hdr->fmt_hdr.bits_per_sample    = SWAP16(hdr->fmt_hdr.bits_per_sample);
+    
+    hdr->data_hdr.data		    = SWAP32(hdr->data_hdr.data);
+    hdr->data_hdr.len		    = SWAP32(hdr->data_hdr.len);
+}
+
+
+#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
+#   define normalize_wave_hdr(hdr)  pjmedia_wave_hdr_swap_bytes(hdr)
+#endif
+
 
 /*
@@ -191,4 +264,7 @@
     }
 
+    /* Normalize WAVE header fields value (only used in big-endian hosts) */
+    normalize_wave_hdr(&wave_hdr);
+    
     /* Validate WAVE file. */
     if (wave_hdr.riff_hdr.riff != PJMEDIA_RIFF_TAG ||
@@ -197,4 +273,9 @@
     {
 	pj_file_close(fport->fd);
+	TRACE_((THIS_FILE, 
+		"actual value|expected riff=%x|%x, wave=%x|%x fmt=%x|%x",
+		wave_hdr.riff_hdr.riff, PJMEDIA_RIFF_TAG,
+		wave_hdr.riff_hdr.wave, PJMEDIA_WAVE_TAG,
+		wave_hdr.fmt_hdr.fmt, PJMEDIA_FMT_TAG));
 	return PJMEDIA_ENOTVALIDWAVE;
     }
Index: pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_lib.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_lib.c	(revision 340)
+++ pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_lib.c	(revision 341)
@@ -50,6 +50,10 @@
 
 #include "portaudio.h"
-#include "pa_host.h"
+//#include "pa_host.h"
 #include "pa_trace.h"
+
+typedef PaDeviceIndex PaDeviceID;
+typedef PaStream      PortAudioStream;
+#define DLL_API
 
 /* The reason we might NOT want to validate the rate before opening the stream
Index: pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_mac_core.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_mac_core.c	(revision 340)
+++ pjproject/trunk/pjmedia/src/pjmedia/portaudio/pa_mac_core.c	(revision 341)
@@ -149,6 +149,6 @@
         case kAudioHardwareBadStreamError:
             result = paBadStreamPtr; break;
-        case kAudioHardwareUnsupportedOperationError:
-            result = paInternalError; break;
+//        case kAudioHardwareUnsupportedOperationError:
+//            result = paInternalError; break;
         case kAudioDeviceUnsupportedFormatError:
             result = paSampleFormatNotSupported; break;
@@ -411,4 +411,5 @@
         portAudioBuffer += Pa_GetSampleSize(destination->inputSampleFormat) * channelSpacing;
     }
+    return 0;
 }
 
@@ -440,4 +441,5 @@
         portAudioBuffer += Pa_GetSampleSize(source->outputSampleFormat) * channelSpacing;
     }    
+    return 0;
 }
 
@@ -471,4 +473,5 @@
         Pa_StopStream(clientData->stream);
     }
+    return 0;
 }
 
@@ -495,4 +498,5 @@
     
     PaUtil_EndCpuLoadMeasurement( &clientData->stream->cpuLoadMeasurer, frameCount );
+    return 0;
 }
 
@@ -519,4 +523,5 @@
 
     PaUtil_EndCpuLoadMeasurement( &clientData->stream->cpuLoadMeasurer, frameCount );
+    return 0;
 }
 
