2 * Audio crossconnecting/conferrencing (hardware level).
4 * Copyright 2002 by Andreas Eversberg (jolly@eversberg.eu)
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
12 * The process of adding and removing parties to/from a conference:
14 * There is a chain of struct dsp_conf which has one or more members in a chain
15 * of struct dsp_conf_member.
17 * After a party is added, the conference is checked for hardware capability.
18 * Also if a party is removed, the conference is checked again.
20 * There are 3 different solutions: -1 = software, 0 = hardware-crossconnect
21 * 1-n = hardware-conference. The n will give the conference number.
23 * Depending on the change after removal or insertion of a party, hardware
26 * The current solution is stored within the struct dsp_conf entry.
32 * There are 3 types of interaction: One member is alone, in this case only
33 * data flow from upper to lower layer is done.
34 * Two members will also exchange their data so they are crossconnected.
35 * Three or more members will be added in a conference and will hear each
36 * other but will not receive their own speech (echo) if not enabled.
38 * Features of CMX are:
39 * - Crossconnecting or even conference, if more than two members are together.
40 * - Force mixing of transmit data with other crossconnect/conference members.
41 * - Echo generation to benchmark the delay of audio processing.
42 * - Use hardware to minimize cpu load, disable FIFO load and minimize delay.
43 * - Dejittering and clock generation.
45 * There are 2 buffers:
51 * ----------------+-------------+-------------------
53 * The rx-buffer is a ring buffer used to store the received data for each
54 * individual member. This is only the case if data needs to be dejittered
55 * or in case of a conference where different clocks require reclocking.
56 * The transmit-clock (R) will read the buffer.
57 * If the clock overruns the write-pointer, we will have a buffer underrun.
58 * If the write pointer always has a certain distance from the transmit-
59 * clock, we will have a delay. The delay will dynamically be increased and
66 * -----------------+--------+-----------------------
68 * The tx-buffer is a ring buffer to queue the transmit data from user space
69 * until it will be mixed or sent. There are two pointers, R and W. If the write
70 * pointer W would reach or overrun R, the buffer would overrun. In this case
71 * (some) data is dropped so that it will not overrun.
72 * Additionally a dynamic dejittering can be enabled. this allows data from
73 * user space that have jitter and different clock source.
78 * A Clock is not required, if the data source has exactly one clock. In this
79 * case the data source is forwarded to the destination.
81 * A Clock is required, because the data source
82 * - has multiple clocks.
83 * - has no usable clock due to jitter or packet loss (VoIP).
84 * In this case the system's clock is used. The clock resolution depends on
85 * the jiffie resolution.
87 * If a member joins a conference:
89 * - If a member joins, its rx_buff is set to silence and change read pointer
92 * The procedure of received data from card is explained in cmx_receive.
93 * The procedure of received data from user space is explained in cmx_transmit.
94 * The procedure of transmit data to card is cmx_send.
97 * Interaction with other features:
100 * DTMF decoding is done before the data is crossconnected.
103 * Changing rx-volume is done before the data is crossconnected. The tx-volume
104 * must be changed whenever data is transmitted to the card by the cmx.
107 * If a tone is enabled, it will be processed whenever data is transmitted to
108 * the card. It will replace the tx-data from the user space.
109 * If tones are generated by hardware, this conference member is removed for
113 * If cmx is realized in hardware, rx data will be disabled if requested by
114 * the upper layer. If dtmf decoding is done by software and enabled, rx data
115 * will not be diabled but blocked to the upper layer.
117 * HFC conference engine:
118 * If it is possible to realize all features using hardware, hardware will be
119 * used if not forbidden by control command. Disabling rx-data provides
120 * absolutely traffic free audio processing. (except for the quick 1-frame
121 * upload of a tone loop, only once for a new tone)
125 /* delay.h is required for hw_lock.h */
127 #include <linux/delay.h>
128 #include <linux/mISDNif.h>
129 #include <linux/mISDNdsp.h>
133 * debugging of multi party conference,
134 * by using conference even with two members
137 /* #define CMX_CONF_DEBUG */
139 /*#define CMX_DEBUG * massive read/write pointer output */
140 /*#define CMX_DELAY_DEBUG * gives rx-buffer delay overview */
141 /*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */
144 count_list_member(struct list_head
*head
)
149 list_for_each(m
, head
)
155 * debug cmx memory structure
158 dsp_cmx_debug(struct dsp
*dsp
)
160 struct dsp_conf
*conf
;
161 struct dsp_conf_member
*member
;
164 printk(KERN_DEBUG
"-----Current DSP\n");
165 list_for_each_entry(odsp
, &dsp_ilist
, list
) {
166 printk(KERN_DEBUG
"* %s echo=%d txmix=%d",
167 odsp
->name
, odsp
->echo
, odsp
->tx_mix
);
169 printk(" (Conf %d)", odsp
->conf
->id
);
174 printk(KERN_DEBUG
"-----Current Conf:\n");
175 list_for_each_entry(conf
, &conf_ilist
, list
) {
176 printk(KERN_DEBUG
"* Conf %d (%p)\n", conf
->id
, conf
);
177 list_for_each_entry(member
, &conf
->mlist
, list
) {
179 " - member = %s (slot_tx %d, bank_tx %d, "
180 "slot_rx %d, bank_rx %d hfc_conf %d)%s\n",
181 member
->dsp
->name
, member
->dsp
->pcm_slot_tx
,
182 member
->dsp
->pcm_bank_tx
, member
->dsp
->pcm_slot_rx
,
183 member
->dsp
->pcm_bank_rx
, member
->dsp
->hfc_conf
,
184 (member
->dsp
== dsp
) ? " *this*" : "");
187 printk(KERN_DEBUG
"-----end\n");
193 static struct dsp_conf
*
194 dsp_cmx_search_conf(u32 id
)
196 struct dsp_conf
*conf
;
199 printk(KERN_WARNING
"%s: conference ID is 0.\n", __func__
);
203 /* search conference */
204 list_for_each_entry(conf
, &conf_ilist
, list
)
213 * add member to conference
216 dsp_cmx_add_conf_member(struct dsp
*dsp
, struct dsp_conf
*conf
)
218 struct dsp_conf_member
*member
;
221 printk(KERN_WARNING
"%s: conf or dsp is 0.\n", __func__
);
225 printk(KERN_WARNING
"%s: dsp is already member in a conf.\n",
231 printk(KERN_WARNING
"%s: dsp is already in a conf.\n",
236 member
= kzalloc(sizeof(struct dsp_conf_member
), GFP_ATOMIC
);
238 printk(KERN_ERR
"kmalloc struct dsp_conf_member failed\n");
242 /* clear rx buffer */
243 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
244 dsp
->rx_init
= 1; /* rx_W and rx_R will be adjusted on first frame */
248 list_add_tail(&member
->list
, &conf
->mlist
);
251 dsp
->member
= member
;
258 * del member from conference
261 dsp_cmx_del_conf_member(struct dsp
*dsp
)
263 struct dsp_conf_member
*member
;
266 printk(KERN_WARNING
"%s: dsp is 0.\n",
272 printk(KERN_WARNING
"%s: dsp is not in a conf.\n",
277 if (list_empty(&dsp
->conf
->mlist
)) {
278 printk(KERN_WARNING
"%s: dsp has linked an empty conf.\n",
283 /* find us in conf */
284 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
285 if (member
->dsp
== dsp
) {
286 list_del(&member
->list
);
294 "%s: dsp is not present in its own conf_meber list.\n",
304 static struct dsp_conf
305 *dsp_cmx_new_conf(u32 id
)
307 struct dsp_conf
*conf
;
310 printk(KERN_WARNING
"%s: id is 0.\n",
315 conf
= kzalloc(sizeof(struct dsp_conf
), GFP_ATOMIC
);
317 printk(KERN_ERR
"kmalloc struct dsp_conf failed\n");
320 INIT_LIST_HEAD(&conf
->mlist
);
323 list_add_tail(&conf
->list
, &conf_ilist
);
333 dsp_cmx_del_conf(struct dsp_conf
*conf
)
336 printk(KERN_WARNING
"%s: conf is null.\n",
341 if (!list_empty(&conf
->mlist
)) {
342 printk(KERN_WARNING
"%s: conf not empty.\n",
346 list_del(&conf
->list
);
354 * send HW message to hfc card
357 dsp_cmx_hw_message(struct dsp
*dsp
, u32 message
, u32 param1
, u32 param2
,
358 u32 param3
, u32 param4
)
360 struct mISDN_ctrl_req cq
;
362 memset(&cq
, 0, sizeof(cq
));
364 cq
.p1
= param1
| (param2
<< 8);
365 cq
.p2
= param3
| (param4
<< 8);
367 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
);
372 * do hardware update and set the software/hardware flag
374 * either a conference or a dsp instance can be given
375 * if only dsp instance is given, the instance is not associated with a conf
376 * and therefore removed. if a conference is given, the dsp is expected to
377 * be member of that conference.
380 dsp_cmx_hardware(struct dsp_conf
*conf
, struct dsp
*dsp
)
382 struct dsp_conf_member
*member
, *nextm
;
384 int memb
= 0, i
, ii
, i1
, i2
;
386 u_char freeslots
[256];
387 int same_hfc
= -1, same_pcm
= -1, current_conf
= -1,
390 /* dsp gets updated (no conf) */
394 if (dsp_debug
& DEBUG_DSP_CMX
)
395 printk(KERN_DEBUG
"%s checking dsp %s\n",
396 __func__
, dsp
->name
);
398 /* remove HFC conference if enabled */
399 if (dsp
->hfc_conf
>= 0) {
400 if (dsp_debug
& DEBUG_DSP_CMX
)
402 "%s removing %s from HFC conf %d "
403 "because dsp is split\n", __func__
,
404 dsp
->name
, dsp
->hfc_conf
);
405 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_CONF_SPLIT
,
409 /* process hw echo */
410 if (dsp
->features
.pcm_banks
< 1)
413 /* NO ECHO: remove PCM slot if assigned */
414 if (dsp
->pcm_slot_tx
>= 0 || dsp
->pcm_slot_rx
>= 0) {
415 if (dsp_debug
& DEBUG_DSP_CMX
)
416 printk(KERN_DEBUG
"%s removing %s from"
417 " PCM slot %d (TX) %d (RX) because"
418 " dsp is split (no echo)\n",
420 dsp
->pcm_slot_tx
, dsp
->pcm_slot_rx
);
421 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_DISC
,
423 dsp
->pcm_slot_tx
= -1;
424 dsp
->pcm_bank_tx
= -1;
425 dsp
->pcm_slot_rx
= -1;
426 dsp
->pcm_bank_rx
= -1;
430 /* ECHO: already echo */
431 if (dsp
->pcm_slot_tx
>= 0 && dsp
->pcm_slot_rx
< 0 &&
432 dsp
->pcm_bank_tx
== 2 && dsp
->pcm_bank_rx
== 2)
434 /* ECHO: if slot already assigned */
435 if (dsp
->pcm_slot_tx
>= 0) {
436 dsp
->pcm_slot_rx
= dsp
->pcm_slot_tx
;
437 dsp
->pcm_bank_tx
= 2; /* 2 means loop */
438 dsp
->pcm_bank_rx
= 2;
439 if (dsp_debug
& DEBUG_DSP_CMX
)
441 "%s refresh %s for echo using slot %d\n",
444 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
445 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
448 /* ECHO: find slot */
449 dsp
->pcm_slot_tx
= -1;
450 dsp
->pcm_slot_rx
= -1;
451 memset(freeslots
, 1, sizeof(freeslots
));
452 list_for_each_entry(finddsp
, &dsp_ilist
, list
) {
453 if (finddsp
->features
.pcm_id
== dsp
->features
.pcm_id
) {
454 if (finddsp
->pcm_slot_rx
>= 0 &&
455 finddsp
->pcm_slot_rx
< sizeof(freeslots
))
456 freeslots
[finddsp
->pcm_slot_rx
] = 0;
457 if (finddsp
->pcm_slot_tx
>= 0 &&
458 finddsp
->pcm_slot_tx
< sizeof(freeslots
))
459 freeslots
[finddsp
->pcm_slot_tx
] = 0;
463 ii
= dsp
->features
.pcm_slots
;
470 if (dsp_debug
& DEBUG_DSP_CMX
)
472 "%s no slot available for echo\n",
474 /* no more slots available */
477 /* assign free slot */
478 dsp
->pcm_slot_tx
= i
;
479 dsp
->pcm_slot_rx
= i
;
480 dsp
->pcm_bank_tx
= 2; /* loop */
481 dsp
->pcm_bank_rx
= 2;
482 if (dsp_debug
& DEBUG_DSP_CMX
)
484 "%s assign echo for %s using slot %d\n",
485 __func__
, dsp
->name
, dsp
->pcm_slot_tx
);
486 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
487 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
491 /* conf gets updated (all members) */
492 if (dsp_debug
& DEBUG_DSP_CMX
)
493 printk(KERN_DEBUG
"%s checking conference %d\n",
496 if (list_empty(&conf
->mlist
)) {
497 printk(KERN_ERR
"%s: conference whithout members\n",
501 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
, list
);
502 same_hfc
= member
->dsp
->features
.hfc_id
;
503 same_pcm
= member
->dsp
->features
.pcm_id
;
504 /* check all members in our conference */
505 list_for_each_entry(member
, &conf
->mlist
, list
) {
506 /* check if member uses mixing */
507 if (member
->dsp
->tx_mix
) {
508 if (dsp_debug
& DEBUG_DSP_CMX
)
510 "%s dsp %s cannot form a conf, because "
511 "tx_mix is turned on\n", __func__
,
514 list_for_each_entry(member
, &conf
->mlist
, list
) {
516 /* remove HFC conference if enabled */
517 if (dsp
->hfc_conf
>= 0) {
518 if (dsp_debug
& DEBUG_DSP_CMX
)
520 "%s removing %s from HFC "
521 "conf %d because not "
522 "possible with hardware\n",
526 dsp_cmx_hw_message(dsp
,
527 MISDN_CTRL_HFC_CONF_SPLIT
,
531 /* remove PCM slot if assigned */
532 if (dsp
->pcm_slot_tx
>= 0 ||
533 dsp
->pcm_slot_rx
>= 0) {
534 if (dsp_debug
& DEBUG_DSP_CMX
)
535 printk(KERN_DEBUG
"%s removing "
536 "%s from PCM slot %d (TX)"
537 " slot %d (RX) because not"
538 " possible with hardware\n",
543 dsp_cmx_hw_message(dsp
,
544 MISDN_CTRL_HFC_PCM_DISC
,
546 dsp
->pcm_slot_tx
= -1;
547 dsp
->pcm_bank_tx
= -1;
548 dsp
->pcm_slot_rx
= -1;
549 dsp
->pcm_bank_rx
= -1;
556 /* check if member has echo turned on */
557 if (member
->dsp
->echo
) {
558 if (dsp_debug
& DEBUG_DSP_CMX
)
560 "%s dsp %s cannot form a conf, because "
561 "echo is turned on\n", __func__
,
565 /* check if member has tx_mix turned on */
566 if (member
->dsp
->tx_mix
) {
567 if (dsp_debug
& DEBUG_DSP_CMX
)
569 "%s dsp %s cannot form a conf, because "
570 "tx_mix is turned on\n",
571 __func__
, member
->dsp
->name
);
574 /* check if member changes volume at an not suppoted level */
575 if (member
->dsp
->tx_volume
) {
576 if (dsp_debug
& DEBUG_DSP_CMX
)
578 "%s dsp %s cannot form a conf, because "
579 "tx_volume is changed\n",
580 __func__
, member
->dsp
->name
);
583 if (member
->dsp
->rx_volume
) {
584 if (dsp_debug
& DEBUG_DSP_CMX
)
586 "%s dsp %s cannot form a conf, because "
587 "rx_volume is changed\n",
588 __func__
, member
->dsp
->name
);
591 /* check if tx-data turned on */
592 if (member
->dsp
->tx_data
) {
593 if (dsp_debug
& DEBUG_DSP_CMX
)
595 "%s dsp %s cannot form a conf, because "
596 "tx_data is turned on\n",
597 __func__
, member
->dsp
->name
);
600 /* check if pipeline exists */
601 if (member
->dsp
->pipeline
.inuse
) {
602 if (dsp_debug
& DEBUG_DSP_CMX
)
604 "%s dsp %s cannot form a conf, because "
605 "pipeline exists\n", __func__
,
609 /* check if encryption is enabled */
610 if (member
->dsp
->bf_enable
) {
611 if (dsp_debug
& DEBUG_DSP_CMX
)
612 printk(KERN_DEBUG
"%s dsp %s cannot form a "
613 "conf, because encryption is enabled\n",
614 __func__
, member
->dsp
->name
);
617 /* check if member is on a card with PCM support */
618 if (member
->dsp
->features
.pcm_id
< 0) {
619 if (dsp_debug
& DEBUG_DSP_CMX
)
621 "%s dsp %s cannot form a conf, because "
622 "dsp has no PCM bus\n",
623 __func__
, member
->dsp
->name
);
626 /* check if relations are on the same PCM bus */
627 if (member
->dsp
->features
.pcm_id
!= same_pcm
) {
628 if (dsp_debug
& DEBUG_DSP_CMX
)
630 "%s dsp %s cannot form a conf, because "
631 "dsp is on a different PCM bus than the "
633 __func__
, member
->dsp
->name
);
636 /* determine if members are on the same hfc chip */
637 if (same_hfc
!= member
->dsp
->features
.hfc_id
)
639 /* if there are members already in a conference */
640 if (current_conf
< 0 && member
->dsp
->hfc_conf
>= 0)
641 current_conf
= member
->dsp
->hfc_conf
;
642 /* if any member is not in a conference */
643 if (member
->dsp
->hfc_conf
< 0)
649 /* if no member, this is an error */
655 if (dsp_debug
& DEBUG_DSP_CMX
)
657 "%s conf %d cannot form a HW conference, "
658 "because dsp is alone\n", __func__
, conf
->id
);
661 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
668 * ok, now we are sure that all members are on the same pcm.
669 * now we will see if we have only two members, so we can do
670 * crossconnections, which don't have any limitations.
673 /* if we have only two members */
675 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
677 nextm
= list_entry(member
->list
.next
, struct dsp_conf_member
,
679 /* remove HFC conference if enabled */
680 if (member
->dsp
->hfc_conf
>= 0) {
681 if (dsp_debug
& DEBUG_DSP_CMX
)
683 "%s removing %s from HFC conf %d because "
684 "two parties require only a PCM slot\n",
685 __func__
, member
->dsp
->name
,
686 member
->dsp
->hfc_conf
);
687 dsp_cmx_hw_message(member
->dsp
,
688 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
689 member
->dsp
->hfc_conf
= -1;
691 if (nextm
->dsp
->hfc_conf
>= 0) {
692 if (dsp_debug
& DEBUG_DSP_CMX
)
694 "%s removing %s from HFC conf %d because "
695 "two parties require only a PCM slot\n",
696 __func__
, nextm
->dsp
->name
,
697 nextm
->dsp
->hfc_conf
);
698 dsp_cmx_hw_message(nextm
->dsp
,
699 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
700 nextm
->dsp
->hfc_conf
= -1;
702 /* if members have two banks (and not on the same chip) */
703 if (member
->dsp
->features
.pcm_banks
> 1 &&
704 nextm
->dsp
->features
.pcm_banks
> 1 &&
705 member
->dsp
->features
.hfc_id
!=
706 nextm
->dsp
->features
.hfc_id
) {
707 /* if both members have same slots with crossed banks */
708 if (member
->dsp
->pcm_slot_tx
>= 0 &&
709 member
->dsp
->pcm_slot_rx
>= 0 &&
710 nextm
->dsp
->pcm_slot_tx
>= 0 &&
711 nextm
->dsp
->pcm_slot_rx
>= 0 &&
712 nextm
->dsp
->pcm_slot_tx
==
713 member
->dsp
->pcm_slot_rx
&&
714 nextm
->dsp
->pcm_slot_rx
==
715 member
->dsp
->pcm_slot_tx
&&
716 nextm
->dsp
->pcm_slot_tx
==
717 member
->dsp
->pcm_slot_tx
&&
718 member
->dsp
->pcm_bank_tx
!=
719 member
->dsp
->pcm_bank_rx
&&
720 nextm
->dsp
->pcm_bank_tx
!=
721 nextm
->dsp
->pcm_bank_rx
) {
722 /* all members have same slot */
723 if (dsp_debug
& DEBUG_DSP_CMX
)
725 "%s dsp %s & %s stay joined on "
726 "PCM slot %d bank %d (TX) bank %d "
727 "(RX) (on different chips)\n",
731 member
->dsp
->pcm_slot_tx
,
732 member
->dsp
->pcm_bank_tx
,
733 member
->dsp
->pcm_bank_rx
);
738 /* find a new slot */
739 memset(freeslots
, 1, sizeof(freeslots
));
740 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
741 if (dsp
!= member
->dsp
&&
743 member
->dsp
->features
.pcm_id
==
744 dsp
->features
.pcm_id
) {
745 if (dsp
->pcm_slot_rx
>= 0 &&
748 freeslots
[dsp
->pcm_slot_rx
] = 0;
749 if (dsp
->pcm_slot_tx
>= 0 &&
752 freeslots
[dsp
->pcm_slot_tx
] = 0;
756 ii
= member
->dsp
->features
.pcm_slots
;
763 if (dsp_debug
& DEBUG_DSP_CMX
)
765 "%s no slot available for "
766 "%s & %s\n", __func__
,
769 /* no more slots available */
772 /* assign free slot */
773 member
->dsp
->pcm_slot_tx
= i
;
774 member
->dsp
->pcm_slot_rx
= i
;
775 nextm
->dsp
->pcm_slot_tx
= i
;
776 nextm
->dsp
->pcm_slot_rx
= i
;
777 member
->dsp
->pcm_bank_rx
= 0;
778 member
->dsp
->pcm_bank_tx
= 1;
779 nextm
->dsp
->pcm_bank_rx
= 1;
780 nextm
->dsp
->pcm_bank_tx
= 0;
781 if (dsp_debug
& DEBUG_DSP_CMX
)
783 "%s adding %s & %s to new PCM slot %d "
784 "(TX and RX on different chips) because "
785 "both members have not same slots\n",
789 member
->dsp
->pcm_slot_tx
);
790 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
791 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
792 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
793 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
794 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
795 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
799 /* if members have one bank (or on the same chip) */
801 /* if both members have different crossed slots */
802 if (member
->dsp
->pcm_slot_tx
>= 0 &&
803 member
->dsp
->pcm_slot_rx
>= 0 &&
804 nextm
->dsp
->pcm_slot_tx
>= 0 &&
805 nextm
->dsp
->pcm_slot_rx
>= 0 &&
806 nextm
->dsp
->pcm_slot_tx
==
807 member
->dsp
->pcm_slot_rx
&&
808 nextm
->dsp
->pcm_slot_rx
==
809 member
->dsp
->pcm_slot_tx
&&
810 member
->dsp
->pcm_slot_tx
!=
811 member
->dsp
->pcm_slot_rx
&&
812 member
->dsp
->pcm_bank_tx
== 0 &&
813 member
->dsp
->pcm_bank_rx
== 0 &&
814 nextm
->dsp
->pcm_bank_tx
== 0 &&
815 nextm
->dsp
->pcm_bank_rx
== 0) {
816 /* all members have same slot */
817 if (dsp_debug
& DEBUG_DSP_CMX
)
819 "%s dsp %s & %s stay joined on PCM "
820 "slot %d (TX) %d (RX) on same chip "
821 "or one bank PCM)\n", __func__
,
824 member
->dsp
->pcm_slot_tx
,
825 member
->dsp
->pcm_slot_rx
);
830 /* find two new slot */
831 memset(freeslots
, 1, sizeof(freeslots
));
832 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
833 if (dsp
!= member
->dsp
&&
835 member
->dsp
->features
.pcm_id
==
836 dsp
->features
.pcm_id
) {
837 if (dsp
->pcm_slot_rx
>= 0 &&
840 freeslots
[dsp
->pcm_slot_rx
] = 0;
841 if (dsp
->pcm_slot_tx
>= 0 &&
844 freeslots
[dsp
->pcm_slot_tx
] = 0;
848 ii
= member
->dsp
->features
.pcm_slots
;
855 if (dsp_debug
& DEBUG_DSP_CMX
)
857 "%s no slot available "
858 "for %s & %s\n", __func__
,
861 /* no more slots available */
871 if (dsp_debug
& DEBUG_DSP_CMX
)
873 "%s no slot available "
878 /* no more slots available */
881 /* assign free slots */
882 member
->dsp
->pcm_slot_tx
= i1
;
883 member
->dsp
->pcm_slot_rx
= i2
;
884 nextm
->dsp
->pcm_slot_tx
= i2
;
885 nextm
->dsp
->pcm_slot_rx
= i1
;
886 member
->dsp
->pcm_bank_rx
= 0;
887 member
->dsp
->pcm_bank_tx
= 0;
888 nextm
->dsp
->pcm_bank_rx
= 0;
889 nextm
->dsp
->pcm_bank_tx
= 0;
890 if (dsp_debug
& DEBUG_DSP_CMX
)
892 "%s adding %s & %s to new PCM slot %d "
893 "(TX) %d (RX) on same chip or one bank "
894 "PCM, because both members have not "
895 "crossed slots\n", __func__
,
898 member
->dsp
->pcm_slot_tx
,
899 member
->dsp
->pcm_slot_rx
);
900 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
901 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
902 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
903 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
904 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
905 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
913 * if we have more than two, we may check if we have a conference
914 * unit available on the chip. also all members must be on the same
917 /* if not the same HFC chip */
919 if (dsp_debug
& DEBUG_DSP_CMX
)
921 "%s conference %d cannot be formed, because "
922 "members are on different chips or not "
928 /* for more than two members.. */
930 /* if all members already have the same conference */
935 * if there is an existing conference, but not all members have joined
937 if (current_conf
>= 0) {
939 list_for_each_entry(member
, &conf
->mlist
, list
) {
940 /* in case of hdlc, change to software */
941 if (member
->dsp
->hdlc
)
943 /* join to current conference */
944 if (member
->dsp
->hfc_conf
== current_conf
)
946 /* get a free timeslot first */
947 memset(freeslots
, 1, sizeof(freeslots
));
948 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
950 * not checking current member, because
951 * slot will be overwritten.
954 dsp
!= member
->dsp
&&
955 /* dsp must be on the same PCM */
956 member
->dsp
->features
.pcm_id
==
957 dsp
->features
.pcm_id
) {
958 /* dsp must be on a slot */
959 if (dsp
->pcm_slot_tx
>= 0 &&
962 freeslots
[dsp
->pcm_slot_tx
] = 0;
963 if (dsp
->pcm_slot_rx
>= 0 &&
966 freeslots
[dsp
->pcm_slot_rx
] = 0;
970 ii
= member
->dsp
->features
.pcm_slots
;
977 /* no more slots available */
978 if (dsp_debug
& DEBUG_DSP_CMX
)
980 "%s conference %d cannot be formed,"
981 " because no slot free\n",
985 if (dsp_debug
& DEBUG_DSP_CMX
)
987 "%s changing dsp %s to HW conference "
988 "%d slot %d\n", __func__
,
989 member
->dsp
->name
, current_conf
, i
);
990 /* assign free slot & set PCM & join conf */
991 member
->dsp
->pcm_slot_tx
= i
;
992 member
->dsp
->pcm_slot_rx
= i
;
993 member
->dsp
->pcm_bank_tx
= 2; /* loop */
994 member
->dsp
->pcm_bank_rx
= 2;
995 member
->dsp
->hfc_conf
= current_conf
;
996 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
998 dsp_cmx_hw_message(member
->dsp
,
999 MISDN_CTRL_HFC_CONF_JOIN
, current_conf
, 0, 0, 0);
1005 * no member is in a conference yet, so we find a free one
1007 memset(freeunits
, 1, sizeof(freeunits
));
1008 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1009 /* dsp must be on the same chip */
1010 if (dsp
->features
.hfc_id
== same_hfc
&&
1011 /* dsp must have joined a HW conference */
1012 dsp
->hfc_conf
>= 0 &&
1013 /* slot must be within range */
1015 freeunits
[dsp
->hfc_conf
] = 0;
1025 /* no more conferences available */
1026 if (dsp_debug
& DEBUG_DSP_CMX
)
1028 "%s conference %d cannot be formed, because "
1029 "no conference number free\n",
1030 __func__
, conf
->id
);
1033 /* join all members */
1040 * conf_id != 0: join or change conference
1041 * conf_id == 0: split from conference if not already
1044 dsp_cmx_conf(struct dsp
*dsp
, u32 conf_id
)
1047 struct dsp_conf
*conf
;
1048 struct dsp_conf_member
*member
;
1050 /* if conference doesn't change */
1051 if (dsp
->conf_id
== conf_id
)
1054 /* first remove us from current conf */
1056 if (dsp_debug
& DEBUG_DSP_CMX
)
1057 printk(KERN_DEBUG
"removing us from conference %d\n",
1059 /* remove us from conf */
1061 err
= dsp_cmx_del_conf_member(dsp
);
1066 /* update hardware */
1067 dsp_cmx_hardware(NULL
, dsp
);
1069 /* conf now empty? */
1070 if (list_empty(&conf
->mlist
)) {
1071 if (dsp_debug
& DEBUG_DSP_CMX
)
1073 "conference is empty, so we remove it.\n");
1074 err
= dsp_cmx_del_conf(conf
);
1078 /* update members left on conf */
1079 dsp_cmx_hardware(conf
, NULL
);
1087 /* now add us to conf */
1088 if (dsp_debug
& DEBUG_DSP_CMX
)
1089 printk(KERN_DEBUG
"searching conference %d\n",
1091 conf
= dsp_cmx_search_conf(conf_id
);
1093 if (dsp_debug
& DEBUG_DSP_CMX
)
1095 "conference doesn't exist yet, creating.\n");
1096 /* the conference doesn't exist, so we create */
1097 conf
= dsp_cmx_new_conf(conf_id
);
1100 } else if (!list_empty(&conf
->mlist
)) {
1101 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
1103 if (dsp
->hdlc
&& !member
->dsp
->hdlc
) {
1104 if (dsp_debug
& DEBUG_DSP_CMX
)
1106 "cannot join transparent conference.\n");
1109 if (!dsp
->hdlc
&& member
->dsp
->hdlc
) {
1110 if (dsp_debug
& DEBUG_DSP_CMX
)
1112 "cannot join hdlc conference.\n");
1116 /* add conference member */
1117 err
= dsp_cmx_add_conf_member(dsp
, conf
);
1120 dsp
->conf_id
= conf_id
;
1122 /* if we are alone, we do nothing! */
1123 if (list_empty(&conf
->mlist
)) {
1124 if (dsp_debug
& DEBUG_DSP_CMX
)
1126 "we are alone in this conference, so exit.\n");
1127 /* update hardware */
1128 dsp_cmx_hardware(NULL
, dsp
);
1132 /* update members on conf */
1133 dsp_cmx_hardware(conf
, NULL
);
1138 #ifdef CMX_DELAY_DEBUG
1141 showdelay(struct dsp
*dsp
, int samples
, int delay
)
1143 char bar
[] = "--------------------------------------------------|";
1146 delaycount
+= samples
;
1147 if (delaycount
< 8000)
1151 sdelay
= delay
* 50 / (dsp_poll
<< 2);
1153 printk(KERN_DEBUG
"DELAY (%s) %3d >%s\n", dsp
->name
, delay
,
1154 sdelay
> 50 ? "..." : bar
+ 50 - sdelay
);
1159 * audio data is received from card
1162 dsp_cmx_receive(struct dsp
*dsp
, struct sk_buff
*skb
)
1166 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1169 /* check if we have sompen */
1173 /* half of the buffer should be larger than maximum packet size */
1174 if (len
>= CMX_BUFF_HALF
) {
1176 "%s line %d: packet from card is too large (%d bytes). "
1177 "please make card send smaller packets OR increase "
1178 "CMX_BUFF_SIZE\n", __FILE__
, __LINE__
, len
);
1183 * initialize pointers if not already -
1184 * also add delay if requested by PH_SIGNAL
1188 if (dsp
->features
.unordered
) {
1189 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1191 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1194 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1199 dsp
->rx_W
= dsp
->cmx_delay
;
1201 dsp
->rx_W
= dsp_poll
>> 1;
1204 /* if frame contains time code, write directly */
1205 if (dsp
->features
.unordered
) {
1206 dsp
->rx_W
= (hh
->id
& CMX_BUFF_MASK
);
1207 /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1210 * if we underrun (or maybe overrun),
1211 * we set our new read pointer, and write silence to buffer
1213 if (((dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
) >= CMX_BUFF_HALF
) {
1214 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1216 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1217 "maximum delay), adjusting read pointer! "
1218 "(inst %s)\n", (u_long
)dsp
, dsp
->name
);
1219 /* flush rx buffer and set delay to dsp_poll / 2 */
1220 if (dsp
->features
.unordered
) {
1221 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1223 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1225 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1230 dsp
->rx_W
= dsp
->cmx_delay
;
1232 dsp
->rx_W
= dsp_poll
>> 1;
1234 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1236 /* if we have reached double delay, jump back to middle */
1238 if (((dsp
->rx_W
- dsp
->rx_R
) & CMX_BUFF_MASK
) >=
1239 (dsp
->cmx_delay
<< 1)) {
1240 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1242 "cmx_receive(dsp=%lx): OVERRUN (because "
1243 "twice the delay is reached), adjusting "
1244 "read pointer! (inst %s)\n",
1245 (u_long
)dsp
, dsp
->name
);
1247 if (dsp
->features
.unordered
) {
1248 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1249 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1253 dsp
->rx_W
= dsp
->cmx_delay
;
1255 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1258 /* show where to write */
1261 "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1262 (u_long
)dsp
, dsp
->rx_R
, dsp
->rx_W
, len
, dsp
->name
);
1265 /* write data into rx_buffer */
1272 d
[w
++ & CMX_BUFF_MASK
] = *p
++;
1276 /* increase write-pointer */
1277 dsp
->rx_W
= ((dsp
->rx_W
+len
) & CMX_BUFF_MASK
);
1278 #ifdef CMX_DELAY_DEBUG
1279 showdelay(dsp
, len
, (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
);
1285 * send (mixed) audio data to card and control jitter
1288 dsp_cmx_send_member(struct dsp
*dsp
, int len
, s32
*c
, int members
)
1290 struct dsp_conf
*conf
= dsp
->conf
;
1291 struct dsp
*member
, *other
;
1292 register s32 sample
;
1293 u8
*d
, *p
, *q
, *o_q
;
1294 struct sk_buff
*nskb
, *txskb
;
1295 int r
, rr
, t
, tt
, o_r
, o_rr
;
1297 struct mISDNhead
*hh
, *thh
;
1299 /* don't process if: */
1300 if (!dsp
->b_active
) { /* if not active */
1304 if (dsp
->pcm_slot_tx
>= 0 && /* connected to pcm slot */
1305 dsp
->tx_R
== dsp
->tx_W
&& /* AND no tx-data */
1306 !(dsp
->tone
.tone
&& dsp
->tone
.software
)) { /* AND not soft tones */
1313 "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1314 members
, dsp
->name
, conf
, dsp
->rx_R
, dsp
->rx_W
);
1317 /* preload if we have delay set */
1318 if (dsp
->cmx_delay
&& !dsp
->last_tx
) {
1324 /* PREPARE RESULT */
1325 nskb
= mI_alloc_skb(len
+ preload
, GFP_ATOMIC
);
1328 "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1332 hh
= mISDN_HEAD_P(nskb
);
1333 hh
->prim
= PH_DATA_REQ
;
1337 /* set pointers, indexes and stuff */
1339 p
= dsp
->tx_buff
; /* transmit data */
1340 q
= dsp
->rx_buff
; /* received data */
1341 d
= skb_put(nskb
, preload
+ len
); /* result */
1342 t
= dsp
->tx_R
; /* tx-pointers */
1344 r
= dsp
->rx_R
; /* rx-pointers */
1345 rr
= (r
+ len
) & CMX_BUFF_MASK
;
1347 /* preload with silence, if required */
1349 memset(d
, dsp_silence
, preload
);
1353 /* PROCESS TONES/TX-DATA ONLY */
1354 if (dsp
->tone
.tone
&& dsp
->tone
.software
) {
1356 dsp_tone_copy(dsp
, d
, len
);
1357 dsp
->tx_R
= 0; /* clear tx buffer */
1361 /* if we have tx-data but do not use mixing */
1362 if (!dsp
->tx_mix
&& t
!= tt
) {
1363 /* -> send tx-data and continue when not enough */
1365 sprintf(debugbuf
, "TX sending (%04x-%04x)%p: ", t
, tt
, p
);
1367 while (r
!= rr
&& t
!= tt
) {
1369 if (strlen(debugbuf
) < 48)
1370 sprintf(debugbuf
+strlen(debugbuf
), " %02x", p
[t
]);
1372 *d
++ = p
[t
]; /* write tx_buff */
1373 t
= (t
+1) & CMX_BUFF_MASK
;
1374 r
= (r
+1) & CMX_BUFF_MASK
;
1379 printk(KERN_DEBUG
"%s\n", debugbuf
);
1385 printk(KERN_DEBUG
"%s\n", debugbuf
);
1388 /* PROCESS DATA (one member / no conf) */
1389 if (!conf
|| members
<= 1) {
1390 /* -> if echo is NOT enabled */
1392 /* -> send tx-data if available or use 0-volume */
1393 while (r
!= rr
&& t
!= tt
) {
1394 *d
++ = p
[t
]; /* write tx_buff */
1395 t
= (t
+1) & CMX_BUFF_MASK
;
1396 r
= (r
+1) & CMX_BUFF_MASK
;
1399 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1400 printk(KERN_DEBUG
"%s: RX empty\n",
1402 memset(d
, dsp_silence
, (rr
-r
)&CMX_BUFF_MASK
);
1404 /* -> if echo is enabled */
1407 * -> mix tx-data with echo if available,
1410 while (r
!= rr
&& t
!= tt
) {
1411 *d
++ = dsp_audio_mix_law
[(p
[t
]<<8)|q
[r
]];
1412 t
= (t
+1) & CMX_BUFF_MASK
;
1413 r
= (r
+1) & CMX_BUFF_MASK
;
1416 *d
++ = q
[r
]; /* echo */
1417 r
= (r
+1) & CMX_BUFF_MASK
;
1423 /* PROCESS DATA (two members) */
1424 #ifdef CMX_CONF_DEBUG
1429 /* "other" becomes other party */
1430 other
= (list_entry(conf
->mlist
.next
,
1431 struct dsp_conf_member
, list
))->dsp
;
1432 if (other
== member
)
1433 other
= (list_entry(conf
->mlist
.prev
,
1434 struct dsp_conf_member
, list
))->dsp
;
1435 o_q
= other
->rx_buff
; /* received data */
1436 o_rr
= (other
->rx_R
+ len
) & CMX_BUFF_MASK
;
1437 /* end of rx-pointer */
1438 o_r
= (o_rr
- rr
+ r
) & CMX_BUFF_MASK
;
1439 /* start rx-pointer at current read position*/
1440 /* -> if echo is NOT enabled */
1443 * -> copy other member's rx-data,
1444 * if tx-data is available, mix
1446 while (o_r
!= o_rr
&& t
!= tt
) {
1447 *d
++ = dsp_audio_mix_law
[(p
[t
]<<8)|o_q
[o_r
]];
1448 t
= (t
+1) & CMX_BUFF_MASK
;
1449 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1451 while (o_r
!= o_rr
) {
1453 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1455 /* -> if echo is enabled */
1458 * -> mix other member's rx-data with echo,
1459 * if tx-data is available, mix
1461 while (r
!= rr
&& t
!= tt
) {
1462 sample
= dsp_audio_law_to_s32
[p
[t
]] +
1463 dsp_audio_law_to_s32
[q
[r
]] +
1464 dsp_audio_law_to_s32
[o_q
[o_r
]];
1465 if (sample
< -32768)
1467 else if (sample
> 32767)
1469 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1470 /* tx-data + rx_data + echo */
1471 t
= (t
+1) & CMX_BUFF_MASK
;
1472 r
= (r
+1) & CMX_BUFF_MASK
;
1473 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1476 *d
++ = dsp_audio_mix_law
[(q
[r
]<<8)|o_q
[o_r
]];
1477 r
= (r
+1) & CMX_BUFF_MASK
;
1478 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1484 #ifdef DSP_NEVER_DEFINED
1487 /* PROCESS DATA (three or more members) */
1488 /* -> if echo is NOT enabled */
1491 * -> substract rx-data from conf-data,
1492 * if tx-data is available, mix
1494 while (r
!= rr
&& t
!= tt
) {
1495 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++ -
1496 dsp_audio_law_to_s32
[q
[r
]];
1497 if (sample
< -32768)
1499 else if (sample
> 32767)
1501 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1503 r
= (r
+1) & CMX_BUFF_MASK
;
1504 t
= (t
+1) & CMX_BUFF_MASK
;
1507 sample
= *c
++ - dsp_audio_law_to_s32
[q
[r
]];
1508 if (sample
< -32768)
1510 else if (sample
> 32767)
1512 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1514 r
= (r
+1) & CMX_BUFF_MASK
;
1516 /* -> if echo is enabled */
1519 * -> encode conf-data, if tx-data
1522 while (r
!= rr
&& t
!= tt
) {
1523 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++;
1524 if (sample
< -32768)
1526 else if (sample
> 32767)
1528 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1530 t
= (t
+1) & CMX_BUFF_MASK
;
1531 r
= (r
+1) & CMX_BUFF_MASK
;
1535 if (sample
< -32768)
1537 else if (sample
> 32767)
1539 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1541 r
= (r
+1) & CMX_BUFF_MASK
;
1549 * send tx-data if enabled - don't filter,
1550 * becuase we want what we send, not what we filtered
1553 /* PREPARE RESULT */
1554 txskb
= mI_alloc_skb(len
, GFP_ATOMIC
);
1557 "FATAL ERROR in mISDN_dsp.o: "
1558 "cannot alloc %d bytes\n", len
);
1560 thh
= mISDN_HEAD_P(txskb
);
1561 thh
->prim
= DL_DATA_REQ
;
1563 memcpy(skb_put(txskb
, len
), nskb
->data
+preload
, len
);
1564 /* queue (trigger later) */
1565 skb_queue_tail(&dsp
->sendq
, txskb
);
1570 dsp_change_volume(nskb
, dsp
->tx_volume
);
1572 if (dsp
->pipeline
.inuse
)
1573 dsp_pipeline_process_tx(&dsp
->pipeline
, nskb
->data
, nskb
->len
);
1576 dsp_bf_encrypt(dsp
, nskb
->data
, nskb
->len
);
1577 /* queue and trigger */
1578 skb_queue_tail(&dsp
->sendq
, nskb
);
1579 schedule_work(&dsp
->workq
);
1582 static u32 jittercount
; /* counter for jitter check */
1583 struct timer_list dsp_spl_tl
;
1584 u32 dsp_spl_jiffies
; /* calculate the next time to fire */
1585 static u16 dsp_count
; /* last sample count */
1586 static int dsp_count_valid
; /* if we have last sample count */
1589 dsp_cmx_send(void *arg
)
1591 struct dsp_conf
*conf
;
1592 struct dsp_conf_member
*member
;
1594 int mustmix
, members
;
1595 s32 mixbuffer
[MAX_POLL
+100], *c
;
1598 int jittercheck
= 0, delay
, i
;
1603 spin_lock_irqsave(&dsp_lock
, flags
);
1605 if (!dsp_count_valid
) {
1606 dsp_count
= mISDN_clock_get();
1608 dsp_count_valid
= 1;
1610 count
= mISDN_clock_get();
1611 length
= count
- dsp_count
;
1614 if (length
> MAX_POLL
+ 100)
1615 length
= MAX_POLL
+ 100;
1616 /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
1619 * check if jitter needs to be checked (this is every second)
1621 jittercount
+= length
;
1622 if (jittercount
>= 8000) {
1623 jittercount
-= 8000;
1627 /* loop all members that do not require conference mixing */
1628 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1635 members
= count_list_member(&conf
->mlist
);
1636 #ifdef CMX_CONF_DEBUG
1637 if (conf
->software
&& members
> 1)
1639 if (conf
->software
&& members
> 2)
1644 /* transmission required */
1646 dsp_cmx_send_member(dsp
, length
, mixbuffer
, members
);
1649 * unused mixbuffer is given to prevent a
1650 * potential null-pointer-bug
1655 /* loop all members that require conference mixing */
1656 list_for_each_entry(conf
, &conf_ilist
, list
) {
1657 /* count members and check hardware */
1658 members
= count_list_member(&conf
->mlist
);
1659 #ifdef CMX_CONF_DEBUG
1660 if (conf
->software
&& members
> 1) {
1662 if (conf
->software
&& members
> 2) {
1664 /* check for hdlc conf */
1665 member
= list_entry(conf
->mlist
.next
,
1666 struct dsp_conf_member
, list
);
1667 if (member
->dsp
->hdlc
)
1670 memset(mixbuffer
, 0, length
*sizeof(s32
));
1671 list_for_each_entry(member
, &conf
->mlist
, list
) {
1673 /* get range of data to mix */
1677 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1678 /* add member's data */
1680 *c
++ += dsp_audio_law_to_s32
[q
[r
]];
1681 r
= (r
+1) & CMX_BUFF_MASK
;
1685 /* process each member */
1686 list_for_each_entry(member
, &conf
->mlist
, list
) {
1688 dsp_cmx_send_member(member
->dsp
, length
,
1689 mixbuffer
, members
);
1694 /* delete rx-data, increment buffers, change pointers */
1695 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1701 /* move receive pointer when receiving */
1702 if (!dsp
->rx_is_off
) {
1703 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1704 /* delete rx-data */
1707 r
= (r
+1) & CMX_BUFF_MASK
;
1709 /* increment rx-buffer pointer */
1710 dsp
->rx_R
= r
; /* write incremented read pointer */
1713 /* check current rx_delay */
1714 delay
= (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
;
1715 if (delay
>= CMX_BUFF_HALF
)
1716 delay
= 0; /* will be the delay before next write */
1717 /* check for lower delay */
1718 if (delay
< dsp
->rx_delay
[0])
1719 dsp
->rx_delay
[0] = delay
;
1720 /* check current tx_delay */
1721 delay
= (dsp
->tx_W
-dsp
->tx_R
) & CMX_BUFF_MASK
;
1722 if (delay
>= CMX_BUFF_HALF
)
1723 delay
= 0; /* will be the delay before next write */
1724 /* check for lower delay */
1725 if (delay
< dsp
->tx_delay
[0])
1726 dsp
->tx_delay
[0] = delay
;
1728 /* find the lowest of all rx_delays */
1729 delay
= dsp
->rx_delay
[0];
1731 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1732 if (delay
> dsp
->rx_delay
[i
])
1733 delay
= dsp
->rx_delay
[i
];
1737 * remove rx_delay only if we have delay AND we
1738 * have not preset cmx_delay AND
1739 * the delay is greater dsp_poll
1741 if (delay
> dsp_poll
&& !dsp
->cmx_delay
) {
1742 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1744 "%s lowest rx_delay of %d bytes for"
1745 " dsp %s are now removed.\n",
1749 rr
= (r
+ delay
- (dsp_poll
>> 1))
1751 /* delete rx-data */
1754 r
= (r
+1) & CMX_BUFF_MASK
;
1756 /* increment rx-buffer pointer */
1758 /* write incremented read pointer */
1760 /* find the lowest of all tx_delays */
1761 delay
= dsp
->tx_delay
[0];
1763 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1764 if (delay
> dsp
->tx_delay
[i
])
1765 delay
= dsp
->tx_delay
[i
];
1769 * remove delay only if we have delay AND we
1770 * have enabled tx_dejitter
1772 if (delay
> dsp_poll
&& dsp
->tx_dejitter
) {
1773 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1775 "%s lowest tx_delay of %d bytes for"
1776 " dsp %s are now removed.\n",
1780 rr
= (r
+ delay
- (dsp_poll
>> 1))
1782 /* delete tx-data */
1785 r
= (r
+1) & CMX_BUFF_MASK
;
1787 /* increment rx-buffer pointer */
1789 /* write incremented read pointer */
1791 /* scroll up delays */
1792 i
= MAX_SECONDS_JITTER_CHECK
- 1;
1794 dsp
->rx_delay
[i
] = dsp
->rx_delay
[i
-1];
1795 dsp
->tx_delay
[i
] = dsp
->tx_delay
[i
-1];
1798 dsp
->tx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1799 dsp
->rx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1803 /* if next event would be in the past ... */
1804 if ((s32
)(dsp_spl_jiffies
+dsp_tics
-jiffies
) <= 0)
1805 dsp_spl_jiffies
= jiffies
+ 1;
1807 dsp_spl_jiffies
+= dsp_tics
;
1809 dsp_spl_tl
.expires
= dsp_spl_jiffies
;
1810 add_timer(&dsp_spl_tl
);
1813 spin_unlock_irqrestore(&dsp_lock
, flags
);
1817 * audio data is transmitted from upper layer to the dsp
1820 dsp_cmx_transmit(struct dsp
*dsp
, struct sk_buff
*skb
)
1824 int space
; /* todo: , l = skb->len; */
1826 char debugbuf
[256] = "";
1829 /* check if there is enough space, and then copy */
1834 space
= (ww
- w
- 1) & CMX_BUFF_MASK
;
1835 /* write-pointer should not overrun nor reach read pointer */
1836 if (space
< skb
->len
) {
1837 /* write to the space we have left */
1838 ww
= (ww
- 1) & CMX_BUFF_MASK
; /* end one byte prior tx_R */
1839 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1840 printk(KERN_DEBUG
"%s: TX overflow space=%d skb->len="
1841 "%d, w=0x%04x, ww=0x%04x\n", __func__
, space
,
1844 /* write until all byte are copied */
1845 ww
= (w
+ skb
->len
) & CMX_BUFF_MASK
;
1848 /* show current buffer */
1851 "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1852 (u_long
)dsp
, (ww
-w
)&CMX_BUFF_MASK
, w
, ww
, dsp
->name
);
1855 /* copy transmit data to tx-buffer */
1857 sprintf(debugbuf
, "TX getting (%04x-%04x)%p: ", w
, ww
, p
);
1861 if (strlen(debugbuf
) < 48)
1862 sprintf(debugbuf
+strlen(debugbuf
), " %02x", *d
);
1865 w
= (w
+1) & CMX_BUFF_MASK
;
1868 printk(KERN_DEBUG
"%s\n", debugbuf
);
1874 * hdlc data is received from card and sent to all members.
1877 dsp_cmx_hdlc(struct dsp
*dsp
, struct sk_buff
*skb
)
1879 struct sk_buff
*nskb
= NULL
;
1880 struct dsp_conf_member
*member
;
1881 struct mISDNhead
*hh
;
1883 /* not if not active */
1887 /* check if we have sompen */
1893 /* in case of hardware (echo) */
1894 if (dsp
->pcm_slot_tx
>= 0)
1897 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1899 hh
= mISDN_HEAD_P(nskb
);
1900 hh
->prim
= PH_DATA_REQ
;
1902 skb_queue_tail(&dsp
->sendq
, nskb
);
1903 schedule_work(&dsp
->workq
);
1908 /* in case of hardware conference */
1909 if (dsp
->conf
->hardware
)
1911 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
1912 if (dsp
->echo
|| member
->dsp
!= dsp
) {
1913 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1915 hh
= mISDN_HEAD_P(nskb
);
1916 hh
->prim
= PH_DATA_REQ
;
1918 skb_queue_tail(&member
->dsp
->sendq
, nskb
);
1919 schedule_work(&member
->dsp
->workq
);