Changeset 1919
- Timestamp:
- Apr 10, 2008 10:15:05 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/pasound.c
r1918 r1919 85 85 */ 86 86 pj_int16_t *rec_buf; 87 unsigned rec_buf_ size;87 unsigned rec_buf_count; 88 88 89 89 /* Sometime the player callback does not request framesize as configured … … 92 92 */ 93 93 pj_int16_t *play_buf; 94 unsigned play_buf_ size;94 unsigned play_buf_count; 95 95 }; 96 96 … … 134 134 135 135 /* Calculate number of samples we've got */ 136 nsamples = frameCount * stream->channel_count + stream->rec_buf_ size;136 nsamples = frameCount * stream->channel_count + stream->rec_buf_count; 137 137 138 138 if (nsamples >= stream->samples_per_frame) … … 141 141 * samples, then call put_frame. 142 142 */ 143 if (stream->rec_buf_ size) {144 unsigned chunk_ size= 0;143 if (stream->rec_buf_count) { 144 unsigned chunk_count = 0; 145 145 146 chunk_size = stream->samples_per_frame - stream->rec_buf_size; 147 pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_size, 148 (pj_int16_t*)input, chunk_size); 149 status = (*stream->rec_cb)(stream->user_data, stream->rec_timestamp, 146 chunk_count = stream->samples_per_frame - stream->rec_buf_count; 147 pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_count, 148 (pj_int16_t*)input, chunk_count); 149 status = (*stream->rec_cb)(stream->user_data, 150 stream->rec_timestamp, 150 151 (void*) stream->rec_buf, 151 152 stream->samples_per_frame * 152 153 stream->bytes_per_sample); 153 154 154 input = (pj_int16_t*) input + chunk_ size;155 input = (pj_int16_t*) input + chunk_count; 155 156 nsamples -= stream->samples_per_frame; 156 stream->rec_buf_ size= 0;157 stream->rec_buf_count = 0; 157 158 } 158 159 159 160 /* Give all frames we have */ 160 161 while (nsamples >= stream->samples_per_frame && status == 0) { 161 status = (*stream->rec_cb)(stream->user_data, stream->rec_timestamp, 162 status = (*stream->rec_cb)(stream->user_data, 163 stream->rec_timestamp, 162 164 (void*) input, 163 165 stream->samples_per_frame * … … 169 171 /* Store the remaining samples into the buffer */ 170 172 if (nsamples && status == 0) { 171 stream->rec_buf_ size= nsamples;172 pjmedia_copy_samples( (pj_int16_t*)stream->rec_buf,173 (pj_int16_t*)input,nsamples);173 stream->rec_buf_count = nsamples; 174 pjmedia_copy_samples(stream->rec_buf, (pj_int16_t*)input, 175 nsamples); 174 176 } 175 177 176 178 } else { 177 179 /* Not enough samples, let's just store them in the buffer */ 178 pjmedia_copy_samples((pj_int16_t*)(stream->rec_buf + 179 stream->rec_buf_size), 180 (pj_int16_t*)input, 181 frameCount * stream->channel_count); 182 stream->rec_buf_size += frameCount * stream->channel_count; 180 pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_count, 181 (pj_int16_t*)input, 182 frameCount * stream->channel_count); 183 stream->rec_buf_count += frameCount * stream->channel_count; 183 184 } 184 185 … … 229 230 230 231 /* Check if any buffered samples */ 231 if (stream->play_buf_ size) {232 if (stream->play_buf_count) { 232 233 /* samples buffered >= requested by sound device */ 233 if (stream->play_buf_ size>= nsamples_req) {234 if (stream->play_buf_count >= nsamples_req) { 234 235 pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf, 235 236 nsamples_req); 236 stream->play_buf_ size-= nsamples_req;237 stream->play_buf_count -= nsamples_req; 237 238 pjmedia_move_samples(stream->play_buf, 238 239 stream->play_buf + nsamples_req, 239 stream->play_buf_ size);240 stream->play_buf_count); 240 241 nsamples_req = 0; 241 242 … … 245 246 /* samples buffered < requested by sound device */ 246 247 pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf, 247 stream->play_buf_ size);248 nsamples_req -= stream->play_buf_ size;249 output = (pj_int16_t*)output + stream->play_buf_ size;250 stream->play_buf_ size= 0;248 stream->play_buf_count); 249 nsamples_req -= stream->play_buf_count; 250 output = (pj_int16_t*)output + stream->play_buf_count; 251 stream->play_buf_count = 0; 251 252 } 252 253 … … 269 270 pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf, 270 271 nsamples_req); 271 stream->play_buf_size = stream->samples_per_frame - nsamples_req; 272 pjmedia_move_samples(stream->play_buf, stream->play_buf+nsamples_req, 273 stream->play_buf_size); 272 stream->play_buf_count = stream->samples_per_frame - nsamples_req; 273 pjmedia_move_samples(stream->play_buf, 274 stream->play_buf+nsamples_req, 275 stream->play_buf_count); 274 276 nsamples_req = 0; 275 277 } … … 553 555 stream->rec_buf = (pj_int16_t*)pj_pool_alloc(pool, 554 556 stream->samples_per_frame * stream->bytes_per_sample); 555 stream->rec_buf_ size= 0;557 stream->rec_buf_count = 0; 556 558 557 559 pj_bzero(&inputParam, sizeof(inputParam)); … … 655 657 stream->play_buf = (pj_int16_t*)pj_pool_alloc(pool, 656 658 stream->samples_per_frame * stream->bytes_per_sample); 657 stream->play_buf_ size= 0;659 stream->play_buf_count = 0; 658 660 659 661 pj_bzero(&outputParam, sizeof(outputParam)); … … 782 784 stream->rec_buf = (pj_int16_t*)pj_pool_alloc(pool, 783 785 stream->samples_per_frame * stream->bytes_per_sample); 784 stream->rec_buf_ size= 0;786 stream->rec_buf_count = 0; 785 787 786 788 stream->play_buf = (pj_int16_t*)pj_pool_alloc(pool, 787 789 stream->samples_per_frame * stream->bytes_per_sample); 788 stream->play_buf_ size= 0;790 stream->play_buf_count = 0; 789 791 790 792 pj_bzero(&inputParam, sizeof(inputParam));
Note: See TracChangeset
for help on using the changeset viewer.