diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-03-20 16:58:43 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-03-20 16:58:43 +0000 |
commit | aedb6add962bf31cd191fbc80985063cb17c9098 (patch) | |
tree | c68fe4cdb1d9349de5dea419eda685b627e4aaa9 | |
parent | a6bf727493002d528bafca90c0c97b4a42068f4b (diff) |
Ported PJMEDIA to Darwin/MacOSX
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@341 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | build/os-darwinos.mak | 2 | ||||
-rw-r--r-- | pjmedia/build/Makefile | 2 | ||||
-rw-r--r-- | pjmedia/build/os-darwinos.mak | 14 | ||||
-rw-r--r-- | pjmedia/build/os-linux.mak | 2 | ||||
-rw-r--r-- | pjmedia/include/pjmedia/wave.h | 13 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/file_port.c | 81 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/portaudio/pa_lib.c | 6 | ||||
-rw-r--r-- | pjmedia/src/pjmedia/portaudio/pa_mac_core.c | 11 |
8 files changed, 115 insertions, 16 deletions
diff --git a/build/os-darwinos.mak b/build/os-darwinos.mak index c9ab026f..22e80516 100644 --- a/build/os-darwinos.mak +++ b/build/os-darwinos.mak @@ -2,7 +2,7 @@ export OS_CFLAGS := $(CC_DEF)PJ_DARWINOS=1 export OS_CXXFLAGS := -export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2) +export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2) -framework CoreAudio export OS_SOURCES := diff --git a/pjmedia/build/Makefile b/pjmedia/build/Makefile index 94adba10..9b347edb 100644 --- a/pjmedia/build/Makefile +++ b/pjmedia/build/Makefile @@ -65,7 +65,7 @@ export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJMEDIA_LIB)) \ export PJMEDIA_SRCDIR = ../src/pjmedia 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) diff --git a/pjmedia/build/os-darwinos.mak b/pjmedia/build/os-darwinos.mak new file mode 100644 index 00000000..15154209 --- /dev/null +++ b/pjmedia/build/os-darwinos.mak @@ -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 diff --git a/pjmedia/build/os-linux.mak b/pjmedia/build/os-linux.mak index 2e6d1e98..adc1936b 100644 --- a/pjmedia/build/os-linux.mak +++ b/pjmedia/build/os-linux.mak @@ -1,5 +1,5 @@ # -# OS specific configuration for Win32 OS target. +# OS specific configuration for Linux OS target. # # diff --git a/pjmedia/include/pjmedia/wave.h b/pjmedia/include/pjmedia/wave.h index b42206fa..cd4c3e61 100644 --- a/pjmedia/include/pjmedia/wave.h +++ b/pjmedia/include/pjmedia/wave.h @@ -29,15 +29,9 @@ 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') /** @@ -78,3 +72,4 @@ typedef struct pjmedia_wave_hdr pjmedia_wave_hdr; PJ_END_DECL #endif /* __PJMEDIA_WAVE_H__ */ + diff --git a/pjmedia/src/pjmedia/file_port.c b/pjmedia/src/pjmedia/file_port.c index 11e59eec..62fe02aa 100644 --- a/pjmedia/src/pjmedia/file_port.c +++ b/pjmedia/src/pjmedia/file_port.c @@ -37,6 +37,47 @@ #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 { pjmedia_port base; @@ -128,9 +169,41 @@ static pj_status_t fill_buffer(struct file_port *fport) } } + /* 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 + + /* * Create WAVE player port. */ @@ -190,12 +263,20 @@ PJ_DEF(pj_status_t) pjmedia_file_player_port_create( pj_pool_t *pool, return PJMEDIA_ENOTVALIDWAVE; } + /* 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 || wave_hdr.riff_hdr.wave != PJMEDIA_WAVE_TAG || wave_hdr.fmt_hdr.fmt != PJMEDIA_FMT_TAG) { 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; } diff --git a/pjmedia/src/pjmedia/portaudio/pa_lib.c b/pjmedia/src/pjmedia/portaudio/pa_lib.c index 86601592..8dfdb590 100644 --- a/pjmedia/src/pjmedia/portaudio/pa_lib.c +++ b/pjmedia/src/pjmedia/portaudio/pa_lib.c @@ -49,9 +49,13 @@ #endif /* _WIN32 */ #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 * is because many DirectSound drivers lie about the rates they actually support. */ diff --git a/pjmedia/src/pjmedia/portaudio/pa_mac_core.c b/pjmedia/src/pjmedia/portaudio/pa_mac_core.c index 020b5aeb..ce55b477 100644 --- a/pjmedia/src/pjmedia/portaudio/pa_mac_core.c +++ b/pjmedia/src/pjmedia/portaudio/pa_mac_core.c @@ -148,8 +148,8 @@ static PaError conv_err(OSStatus error) result = paInvalidDevice; break; case kAudioHardwareBadStreamError: result = paBadStreamPtr; break; - case kAudioHardwareUnsupportedOperationError: - result = paInternalError; break; +// case kAudioHardwareUnsupportedOperationError: +// result = paInternalError; break; case kAudioDeviceUnsupportedFormatError: result = paSampleFormatNotSupported; break; case kAudioDevicePermissionsError: @@ -410,6 +410,7 @@ static OSStatus CopyInputData(PaMacClientData* destination, const AudioBufferLis coreAudioBuffer += sizeof(Float32); portAudioBuffer += Pa_GetSampleSize(destination->inputSampleFormat) * channelSpacing; } + return 0; } static OSStatus CopyOutputData(AudioBufferList* destination, PaMacClientData *source, unsigned long frameCount) @@ -439,6 +440,7 @@ static OSStatus CopyOutputData(AudioBufferList* destination, PaMacClientData *so coreAudioBuffer += sizeof(Float32); portAudioBuffer += Pa_GetSampleSize(source->outputSampleFormat) * channelSpacing; } + return 0; } static OSStatus AudioIOProc( AudioDeviceID inDevice, @@ -470,6 +472,7 @@ static OSStatus AudioIOProc( AudioDeviceID inDevice, if (result == paComplete || result == paAbort) { Pa_StopStream(clientData->stream); } + return 0; } // This is not for input-only streams, this is for streams where the input device is different from the output device @@ -494,6 +497,7 @@ static OSStatus AudioInputProc( AudioDeviceID inDevice, clientData->callback(clientData->inputBuffer, NULL, frameCount, timeInfo, paNoFlag, clientData->userData); PaUtil_EndCpuLoadMeasurement( &clientData->stream->cpuLoadMeasurer, frameCount ); + return 0; } // This is not for output-only streams, this is for streams where the input device is different from the output device @@ -518,6 +522,7 @@ static OSStatus AudioOutputProc( AudioDeviceID inDevice, CopyOutputData(outOutputData, clientData, frameCount); PaUtil_EndCpuLoadMeasurement( &clientData->stream->cpuLoadMeasurer, frameCount ); + return 0; } static PaError SetSampleRate(AudioDeviceID device, double sampleRate, int isInput) @@ -893,4 +898,4 @@ error: } return result; -}
\ No newline at end of file +} |