From aedb6add962bf31cd191fbc80985063cb17c9098 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 20 Mar 2006 16:58:43 +0000 Subject: Ported PJMEDIA to Darwin/MacOSX git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@341 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/src/pjmedia/file_port.c | 81 +++++++++++++++++++++++++++++ pjmedia/src/pjmedia/portaudio/pa_lib.c | 6 ++- pjmedia/src/pjmedia/portaudio/pa_mac_core.c | 11 ++-- 3 files changed, 94 insertions(+), 4 deletions(-) (limited to 'pjmedia/src') 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; ibuf, 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 +} -- cgit v1.2.3