Ignore:
Timestamp:
Mar 20, 2006 4:58:43 PM (18 years ago)
Author:
bennylp
Message:

Ported PJMEDIA to Darwin/MacOSX

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/file_port.c

    r334 r341  
    3838#define SIGNATURE       ('F'<<24|'I'<<16|'L'<<8|'E') 
    3939 
     40#if 1 
     41#   define TRACE_(x)    PJ_LOG(4,x) 
     42#else 
     43#   define TRACE_(x) 
     44#endif 
     45 
     46#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
     47    PJ_INLINE(pj_int16_t) swap16(pj_int16_t val) 
     48    { 
     49        pj_uint8_t *p = (pj_uint8_t*)&val; 
     50        pj_uint8_t tmp = *p; 
     51        *p = *(p+1); 
     52        *(p+1) = tmp; 
     53        return val; 
     54    } 
     55    PJ_INLINE(pj_int32_t) swap32(pj_int32_t val) 
     56    { 
     57        pj_uint8_t *p = (pj_uint8_t*)&val; 
     58        pj_uint8_t tmp = *p; 
     59        *p = *(p+3); 
     60        *(p+3) = tmp; 
     61        tmp = *(p+1); 
     62        *(p+1) = *(p+2); 
     63        *(p+2) = tmp; 
     64        return val; 
     65    } 
     66#   define SWAP16(val16)        swap16(val16) 
     67#   define SWAP32(val32)        swap32(val32) 
     68    static void samples_to_host(pj_int16_t *samples, unsigned count) 
     69    { 
     70        unsigned i; 
     71        for (i=0; i<count; ++i) { 
     72            samples[i] = SWAP16(samples[i]); 
     73        } 
     74    } 
     75#else 
     76#   define SWAP16(val16)        (val16) 
     77#   define SWAP32(val32)        (val32) 
     78#   define samples_to_host(samples,count) 
     79#endif 
     80 
    4081struct file_port 
    4182{ 
     
    129170    } 
    130171 
     172    /* Convert samples to host rep */ 
     173    samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/2); 
     174 
    131175    return PJ_SUCCESS; 
    132176} 
     177 
     178 
     179/* 
     180 * Change the endianness of WAVE header fields. 
     181 */ 
     182void pjmedia_wave_hdr_swap_bytes( pjmedia_wave_hdr *hdr ) 
     183{ 
     184    hdr->riff_hdr.riff              = SWAP32(hdr->riff_hdr.riff); 
     185    hdr->riff_hdr.file_len          = SWAP32(hdr->riff_hdr.file_len); 
     186    hdr->riff_hdr.wave              = SWAP32(hdr->riff_hdr.wave); 
     187     
     188    hdr->fmt_hdr.fmt                = SWAP32(hdr->fmt_hdr.fmt); 
     189    hdr->fmt_hdr.len                = SWAP32(hdr->fmt_hdr.len); 
     190    hdr->fmt_hdr.fmt_tag            = SWAP16(hdr->fmt_hdr.fmt_tag); 
     191    hdr->fmt_hdr.nchan              = SWAP16(hdr->fmt_hdr.nchan); 
     192    hdr->fmt_hdr.sample_rate        = SWAP32(hdr->fmt_hdr.sample_rate); 
     193    hdr->fmt_hdr.bytes_per_sec      = SWAP32(hdr->fmt_hdr.bytes_per_sec); 
     194    hdr->fmt_hdr.block_align        = SWAP16(hdr->fmt_hdr.block_align); 
     195    hdr->fmt_hdr.bits_per_sample    = SWAP16(hdr->fmt_hdr.bits_per_sample); 
     196     
     197    hdr->data_hdr.data              = SWAP32(hdr->data_hdr.data); 
     198    hdr->data_hdr.len               = SWAP32(hdr->data_hdr.len); 
     199} 
     200 
     201 
     202#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
     203#   define normalize_wave_hdr(hdr)  pjmedia_wave_hdr_swap_bytes(hdr) 
     204#endif 
     205 
    133206 
    134207/* 
     
    191264    } 
    192265 
     266    /* Normalize WAVE header fields value (only used in big-endian hosts) */ 
     267    normalize_wave_hdr(&wave_hdr); 
     268     
    193269    /* Validate WAVE file. */ 
    194270    if (wave_hdr.riff_hdr.riff != PJMEDIA_RIFF_TAG || 
     
    197273    { 
    198274        pj_file_close(fport->fd); 
     275        TRACE_((THIS_FILE,  
     276                "actual value|expected riff=%x|%x, wave=%x|%x fmt=%x|%x", 
     277                wave_hdr.riff_hdr.riff, PJMEDIA_RIFF_TAG, 
     278                wave_hdr.riff_hdr.wave, PJMEDIA_WAVE_TAG, 
     279                wave_hdr.fmt_hdr.fmt, PJMEDIA_FMT_TAG)); 
    199280        return PJMEDIA_ENOTVALIDWAVE; 
    200281    } 
Note: See TracChangeset for help on using the changeset viewer.