Changeset 358 for pjproject/trunk/pjmedia/src/pjmedia/file_player.c
- Timestamp:
- Mar 24, 2006 8:41:20 PM (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/file_player.c
r357 r358 31 31 32 32 33 #ifndef PJMEDIA_FILE_PORT_BUFSIZE 34 # define PJMEDIA_FILE_PORT_BUFSIZE 4000 35 #endif 36 37 38 #define SIGNATURE ('F'<<24|'I'<<16|'L'<<8|'E') 33 #define SIGNATURE ('F'<<24|'P'<<16|'L'<<8|'Y') 34 #define BYTES_PER_SAMPLE 2 35 39 36 40 37 #if 1 … … 45 42 46 43 #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 44 static void samples_to_host(pj_int16_t *samples, unsigned count) 69 45 { 70 46 unsigned i; 71 47 for (i=0; i<count; ++i) { 72 samples[i] = SWAP16(samples[i]);48 samples[i] = pj_swap16(samples[i]); 73 49 } 74 50 } 75 51 #else 76 # define SWAP16(val16) (val16)77 # define SWAP32(val32) (val32)78 52 # define samples_to_host(samples,count) 79 53 #endif … … 171 145 172 146 /* Convert samples to host rep */ 173 samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/ 2);147 samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/BYTES_PER_SAMPLE); 174 148 175 149 return PJ_SUCCESS; 176 150 } 177 178 179 /*180 * Change the endianness of WAVE header fields.181 */182 void 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!=0203 # define normalize_wave_hdr(hdr) pjmedia_wave_hdr_swap_bytes(hdr)204 #else205 # define normalize_wave_hdr(hdr)206 #endif207 151 208 152 … … 224 168 225 169 PJ_UNUSED_ARG(flags); 226 PJ_UNUSED_ARG(buff_size);227 170 228 171 /* Check arguments. */ … … 266 209 } 267 210 268 /* Normalize WAVE header fields value (only used in big-endian hosts) */ 269 normalize_wave_hdr(&wave_hdr); 211 /* Normalize WAVE header fields values from little-endian to host 212 * byte order. 213 */ 214 pjmedia_wave_hdr_file_to_host(&wave_hdr); 270 215 271 216 /* Validate WAVE file. */ … … 292 237 293 238 /* Block align must be 2*nchannels */ 294 if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan* 2) {239 if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan*BYTES_PER_SAMPLE) { 295 240 pj_file_close(fport->fd); 296 241 return PJMEDIA_EWAVEUNSUPP; … … 327 272 /* Create file buffer. 328 273 */ 329 fport->bufsize = PJMEDIA_FILE_PORT_BUFSIZE; 274 if (buff_size < 1) buff_size = PJMEDIA_FILE_PORT_BUFSIZE; 275 fport->bufsize = buff_size; 330 276 331 277 … … 355 301 356 302 PJ_LOG(4,(THIS_FILE, 357 "File p ort '%.*s' created: clock=%dKHz, bufsize=%uKB, "303 "File player '%.*s' created: samp.rate=%d, ch=%d, bufsize=%uKB, " 358 304 "filesize=%luKB", 359 305 (int)fport->base.info.name.slen, 360 306 fport->base.info.name.ptr, 361 fport->base.info.sample_rate/1000, 307 fport->base.info.sample_rate, 308 fport->base.info.channel_count, 362 309 fport->bufsize / 1000, 363 310 (unsigned long)(fport->fsize / 1000))); … … 390 337 pj_assert(fport->base.info.signature == SIGNATURE); 391 338 392 frame_size = fport->base.info.bytes_per_frame; 393 pj_assert(frame->size == frame_size); 339 //frame_size = fport->base.info.bytes_per_frame; 340 //pj_assert(frame->size == frame_size); 341 frame_size = frame->size; 394 342 395 343 /* Copy frame from buffer. */
Note: See TracChangeset
for help on using the changeset viewer.