Changeset 5000

Only use the frames both parts can provide.

This should avoid ChanSpy getting so easily out of sync.

Committed by:  karvan
Date:  Jun 27 2008 * 14:38 (6 months ago)

Affected files:

callweaver/branches/karvan/apps/app_chanspy.c (unified diff)

r4997r5000
258258 {
259259
260260 struct chanspy_translation_helper *csth = data;
261 struct cw_frame frame, *f0, *f1;
261 struct cw_frame frame, *f0, *f1, *f;
262 unsigned left, right;
263 unsigned same;
264 unsigned ii;
262265 int len0 = 0;
263266 int len1 = 0;
264267 int samp0 = 0;
------
278281
279282 len = sample * sizeof(int16_t);
280283
281 cw_spy_empty_queues(&csth->spy, &f0, &f1);
284 pthread_mutex_lock(&csth->spy.lock);
285 left = csth->spy.queue[0].count;
286 right = csth->spy.queue[1].count;
287 same = left < right ? left : right;
288 if (same == 0) {
289 pthread_mutex_unlock(&csth->spy.lock);
290 return 0;
291 }
292 ii = 0;
293 for (ii = 0, f0 = csth->spy.queue[0].head, f1 = csth->spy.queue[1].head ; ii < same; ++ii) {
294 f0 = f0->next;
295 f1 = f1->next;
296 }
297 f = csth->spy.queue[0].head;
298 csth->spy.queue[0].head = f0;
299 csth->spy.queue[0].count -= same;
300 if (!csth->spy.queue[0].count)
301 csth->spy.queue[0].tail = NULL;
302 f0 = f;
303 f = csth->spy.queue[1].head;
304 csth->spy.queue[1].head = f1;
305 csth->spy.queue[1].count -= same;
306 if (!csth->spy.queue[1].count)
307 csth->spy.queue[1].tail = NULL;
308 f1 = f;
309 pthread_mutex_unlock(&csth->spy.lock);
282310 while (f0) {
283311 struct cw_frame *f = f0->next;
284312 cw_slinfactory_feed(&csth->slinfactory[0], f0);