Changeset 3405 for pjproject/trunk/pjmedia/src/pjmedia/wav_player.c
- Timestamp:
- Jan 19, 2011 10:23:58 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/wav_player.c
r2394 r3405 68 68 pj_off_t fsize; 69 69 unsigned start_data; 70 unsigned data_len; 71 unsigned data_left; 70 72 pj_off_t fpos; 71 73 pj_oshandle_t fd; … … 106 108 static pj_status_t fill_buffer(struct file_reader_port *fport) 107 109 { 108 pj_ssize_t size_left = fport->bufsize; 110 pj_size_t data_left = fport->data_left; 111 pj_ssize_t bufsize = (fport->bufsize > data_left) ? data_left : fport->bufsize; 112 pj_ssize_t size_left = bufsize; 109 113 unsigned size_to_read; 110 114 pj_ssize_t size; … … 118 122 size = size_to_read = size_left; 119 123 status = pj_file_read(fport->fd, 120 &fport->buf[fport->bufsize-size_left], 124 //&fport->buf[fport->bufsize-size_left], 125 &fport->buf[bufsize-size_left], 121 126 &size); 122 127 if (status != PJ_SUCCESS) … … 128 133 129 134 size_left -= size; 135 fport->data_left -= size; 130 136 fport->fpos += size; 131 137 … … 133 139 * encountered EOF. Rewind the file. 134 140 */ 135 if (size < (pj_ssize_t)size_to_read) { 136 fport->eof = PJ_TRUE; 137 fport->eofpos = fport->buf + fport->bufsize - size_left; 138 139 if (fport->options & PJMEDIA_FILE_NO_LOOP) { 140 /* Zero remaining buffer */ 141 pj_bzero(fport->eofpos, size_left); 142 } 141 if (size < (pj_ssize_t)size_to_read || fport->data_left <= 0) { 142 fport->eof = PJ_TRUE; 143 //fport->eofpos = fport->buf + fport->bufsize - size_left; 144 fport->eofpos = fport->buf + bufsize - size_left; 145 146 if (fport->options & PJMEDIA_FILE_NO_LOOP) { 147 /* Zero remaining buffer */ 148 if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) { 149 pj_bzero(fport->eofpos, size_left + 150 (fport->bufsize - data_left)); 151 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) { 152 int val = pjmedia_linear2ulaw(0); 153 pj_memset(fport->eofpos, val, size_left + 154 (fport->bufsize - data_left)); 155 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) { 156 int val = pjmedia_linear2alaw(0); 157 pj_memset(fport->eofpos, val, size_left + 158 (fport->bufsize - data_left)); 159 } 160 } 143 161 144 162 /* Rewind file */ 145 163 fport->fpos = fport->start_data; 146 164 pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET); 165 fport->data_left = fport->data_len; 147 166 } 148 167 } … … 313 332 status = pj_file_getpos(fport->fd, &pos); 314 333 fport->start_data = (unsigned)pos; 315 316 /* Validate length. */ 334 fport->data_len = wave_hdr.data_hdr.len; 335 fport->data_left = wave_hdr.data_hdr.len; 336 337 /* Validate length. This is unnecessary since we only play data chunks. */ 338 /* 317 339 if (wave_hdr.data_hdr.len != fport->fsize - fport->start_data) { 318 340 pj_file_close(fport->fd); 319 341 return PJMEDIA_EWAVEUNSUPP; 320 342 } 343 */ 321 344 if (wave_hdr.data_hdr.len < ptime * wave_hdr.fmt_hdr.sample_rate * 322 345 wave_hdr.fmt_hdr.nchan / 1000) … … 592 615 if (fport->eof && (fport->options & PJMEDIA_FILE_NO_LOOP)) { 593 616 fport->readpos += endread; 594 pj_bzero((char*)frame->buf + endread, frame_size - endread); 617 618 if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) { 619 pj_bzero((char*)frame->buf + endread, frame_size - endread); 620 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) { 621 int val = pjmedia_linear2ulaw(0); 622 pj_memset((char*)frame->buf + endread, val, 623 frame_size - endread); 624 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) { 625 int val = pjmedia_linear2alaw(0); 626 pj_memset((char*)frame->buf + endread, val, 627 frame_size - endread); 628 } 629 595 630 return PJ_SUCCESS; 596 631 }
Note: See TracChangeset
for help on using the changeset viewer.