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 hardecho=%d softecho=%d txmix=%d",
167 odsp
->name
, odsp
->echo
.hardware
, odsp
->echo
.software
,
170 printk(" (Conf %d)", odsp
->conf
->id
);
175 printk(KERN_DEBUG
"-----Current Conf:\n");
176 list_for_each_entry(conf
, &conf_ilist
, list
) {
177 printk(KERN_DEBUG
"* Conf %d (%p)\n", conf
->id
, conf
);
178 list_for_each_entry(member
, &conf
->mlist
, list
) {
180 " - member = %s (slot_tx %d, bank_tx %d, "
181 "slot_rx %d, bank_rx %d hfc_conf %d "
182 "tx_data %d rx_is_off %d)%s\n",
183 member
->dsp
->name
, member
->dsp
->pcm_slot_tx
,
184 member
->dsp
->pcm_bank_tx
, member
->dsp
->pcm_slot_rx
,
185 member
->dsp
->pcm_bank_rx
, member
->dsp
->hfc_conf
,
186 member
->dsp
->tx_data
, member
->dsp
->rx_is_off
,
187 (member
->dsp
== dsp
) ? " *this*" : "");
190 printk(KERN_DEBUG
"-----end\n");
196 static struct dsp_conf
*
197 dsp_cmx_search_conf(u32 id
)
199 struct dsp_conf
*conf
;
202 printk(KERN_WARNING
"%s: conference ID is 0.\n", __func__
);
206 /* search conference */
207 list_for_each_entry(conf
, &conf_ilist
, list
)
216 * add member to conference
219 dsp_cmx_add_conf_member(struct dsp
*dsp
, struct dsp_conf
*conf
)
221 struct dsp_conf_member
*member
;
224 printk(KERN_WARNING
"%s: conf or dsp is 0.\n", __func__
);
228 printk(KERN_WARNING
"%s: dsp is already member in a conf.\n",
234 printk(KERN_WARNING
"%s: dsp is already in a conf.\n",
239 member
= kzalloc(sizeof(struct dsp_conf_member
), GFP_ATOMIC
);
241 printk(KERN_ERR
"kzalloc struct dsp_conf_member failed\n");
245 /* clear rx buffer */
246 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
247 dsp
->rx_init
= 1; /* rx_W and rx_R will be adjusted on first frame */
251 list_add_tail(&member
->list
, &conf
->mlist
);
254 dsp
->member
= member
;
261 * del member from conference
264 dsp_cmx_del_conf_member(struct dsp
*dsp
)
266 struct dsp_conf_member
*member
;
269 printk(KERN_WARNING
"%s: dsp is 0.\n",
275 printk(KERN_WARNING
"%s: dsp is not in a conf.\n",
280 if (list_empty(&dsp
->conf
->mlist
)) {
281 printk(KERN_WARNING
"%s: dsp has linked an empty conf.\n",
286 /* find us in conf */
287 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
288 if (member
->dsp
== dsp
) {
289 list_del(&member
->list
);
297 "%s: dsp is not present in its own conf_meber list.\n",
307 static struct dsp_conf
308 *dsp_cmx_new_conf(u32 id
)
310 struct dsp_conf
*conf
;
313 printk(KERN_WARNING
"%s: id is 0.\n",
318 conf
= kzalloc(sizeof(struct dsp_conf
), GFP_ATOMIC
);
320 printk(KERN_ERR
"kzalloc struct dsp_conf failed\n");
323 INIT_LIST_HEAD(&conf
->mlist
);
326 list_add_tail(&conf
->list
, &conf_ilist
);
336 dsp_cmx_del_conf(struct dsp_conf
*conf
)
339 printk(KERN_WARNING
"%s: conf is null.\n",
344 if (!list_empty(&conf
->mlist
)) {
345 printk(KERN_WARNING
"%s: conf not empty.\n",
349 list_del(&conf
->list
);
357 * send HW message to hfc card
360 dsp_cmx_hw_message(struct dsp
*dsp
, u32 message
, u32 param1
, u32 param2
,
361 u32 param3
, u32 param4
)
363 struct mISDN_ctrl_req cq
;
365 memset(&cq
, 0, sizeof(cq
));
367 cq
.p1
= param1
| (param2
<< 8);
368 cq
.p2
= param3
| (param4
<< 8);
370 dsp
->ch
.peer
->ctrl(dsp
->ch
.peer
, CONTROL_CHANNEL
, &cq
);
375 * do hardware update and set the software/hardware flag
377 * either a conference or a dsp instance can be given
378 * if only dsp instance is given, the instance is not associated with a conf
379 * and therefore removed. if a conference is given, the dsp is expected to
380 * be member of that conference.
383 dsp_cmx_hardware(struct dsp_conf
*conf
, struct dsp
*dsp
)
385 struct dsp_conf_member
*member
, *nextm
;
387 int memb
= 0, i
, ii
, i1
, i2
;
389 u_char freeslots
[256];
390 int same_hfc
= -1, same_pcm
= -1, current_conf
= -1,
391 all_conf
= 1, tx_data
= 0;
393 /* dsp gets updated (no conf) */
397 if (dsp_debug
& DEBUG_DSP_CMX
)
398 printk(KERN_DEBUG
"%s checking dsp %s\n",
399 __func__
, dsp
->name
);
401 /* remove HFC conference if enabled */
402 if (dsp
->hfc_conf
>= 0) {
403 if (dsp_debug
& DEBUG_DSP_CMX
)
405 "%s removing %s from HFC conf %d "
406 "because dsp is split\n", __func__
,
407 dsp
->name
, dsp
->hfc_conf
);
408 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_CONF_SPLIT
,
412 /* process hw echo */
413 if (dsp
->features
.pcm_banks
< 1)
415 if (!dsp
->echo
.software
&& !dsp
->echo
.hardware
) {
416 /* NO ECHO: remove PCM slot if assigned */
417 if (dsp
->pcm_slot_tx
>= 0 || dsp
->pcm_slot_rx
>= 0) {
418 if (dsp_debug
& DEBUG_DSP_CMX
)
419 printk(KERN_DEBUG
"%s removing %s from"
420 " PCM slot %d (TX) %d (RX) because"
421 " dsp is split (no echo)\n",
423 dsp
->pcm_slot_tx
, dsp
->pcm_slot_rx
);
424 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_DISC
,
426 dsp
->pcm_slot_tx
= -1;
427 dsp
->pcm_bank_tx
= -1;
428 dsp
->pcm_slot_rx
= -1;
429 dsp
->pcm_bank_rx
= -1;
433 /* echo is enabled, find out if we use soft or hardware */
434 dsp
->echo
.software
= dsp
->tx_data
;
435 dsp
->echo
.hardware
= 0;
436 /* ECHO: already echo */
437 if (dsp
->pcm_slot_tx
>= 0 && dsp
->pcm_slot_rx
< 0 &&
438 dsp
->pcm_bank_tx
== 2 && dsp
->pcm_bank_rx
== 2) {
439 dsp
->echo
.hardware
= 1;
442 /* ECHO: if slot already assigned */
443 if (dsp
->pcm_slot_tx
>= 0) {
444 dsp
->pcm_slot_rx
= dsp
->pcm_slot_tx
;
445 dsp
->pcm_bank_tx
= 2; /* 2 means loop */
446 dsp
->pcm_bank_rx
= 2;
447 if (dsp_debug
& DEBUG_DSP_CMX
)
449 "%s refresh %s for echo using slot %d\n",
452 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
453 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
454 dsp
->echo
.hardware
= 1;
457 /* ECHO: find slot */
458 dsp
->pcm_slot_tx
= -1;
459 dsp
->pcm_slot_rx
= -1;
460 memset(freeslots
, 1, sizeof(freeslots
));
461 list_for_each_entry(finddsp
, &dsp_ilist
, list
) {
462 if (finddsp
->features
.pcm_id
== dsp
->features
.pcm_id
) {
463 if (finddsp
->pcm_slot_rx
>= 0 &&
464 finddsp
->pcm_slot_rx
< sizeof(freeslots
))
465 freeslots
[finddsp
->pcm_slot_rx
] = 0;
466 if (finddsp
->pcm_slot_tx
>= 0 &&
467 finddsp
->pcm_slot_tx
< sizeof(freeslots
))
468 freeslots
[finddsp
->pcm_slot_tx
] = 0;
472 ii
= dsp
->features
.pcm_slots
;
479 if (dsp_debug
& DEBUG_DSP_CMX
)
481 "%s no slot available for echo\n",
483 /* no more slots available */
484 dsp
->echo
.software
= 1;
487 /* assign free slot */
488 dsp
->pcm_slot_tx
= i
;
489 dsp
->pcm_slot_rx
= i
;
490 dsp
->pcm_bank_tx
= 2; /* loop */
491 dsp
->pcm_bank_rx
= 2;
492 if (dsp_debug
& DEBUG_DSP_CMX
)
494 "%s assign echo for %s using slot %d\n",
495 __func__
, dsp
->name
, dsp
->pcm_slot_tx
);
496 dsp_cmx_hw_message(dsp
, MISDN_CTRL_HFC_PCM_CONN
,
497 dsp
->pcm_slot_tx
, 2, dsp
->pcm_slot_rx
, 2);
498 dsp
->echo
.hardware
= 1;
502 /* conf gets updated (all members) */
503 if (dsp_debug
& DEBUG_DSP_CMX
)
504 printk(KERN_DEBUG
"%s checking conference %d\n",
507 if (list_empty(&conf
->mlist
)) {
508 printk(KERN_ERR
"%s: conference whithout members\n",
512 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
, list
);
513 same_hfc
= member
->dsp
->features
.hfc_id
;
514 same_pcm
= member
->dsp
->features
.pcm_id
;
515 /* check all members in our conference */
516 list_for_each_entry(member
, &conf
->mlist
, list
) {
517 /* check if member uses mixing */
518 if (member
->dsp
->tx_mix
) {
519 if (dsp_debug
& DEBUG_DSP_CMX
)
521 "%s dsp %s cannot form a conf, because "
522 "tx_mix is turned on\n", __func__
,
525 list_for_each_entry(member
, &conf
->mlist
, list
) {
527 /* remove HFC conference if enabled */
528 if (dsp
->hfc_conf
>= 0) {
529 if (dsp_debug
& DEBUG_DSP_CMX
)
531 "%s removing %s from HFC "
532 "conf %d because not "
533 "possible with hardware\n",
537 dsp_cmx_hw_message(dsp
,
538 MISDN_CTRL_HFC_CONF_SPLIT
,
542 /* remove PCM slot if assigned */
543 if (dsp
->pcm_slot_tx
>= 0 ||
544 dsp
->pcm_slot_rx
>= 0) {
545 if (dsp_debug
& DEBUG_DSP_CMX
)
546 printk(KERN_DEBUG
"%s removing "
547 "%s from PCM slot %d (TX)"
548 " slot %d (RX) because not"
549 " possible with hardware\n",
554 dsp_cmx_hw_message(dsp
,
555 MISDN_CTRL_HFC_PCM_DISC
,
557 dsp
->pcm_slot_tx
= -1;
558 dsp
->pcm_bank_tx
= -1;
559 dsp
->pcm_slot_rx
= -1;
560 dsp
->pcm_bank_rx
= -1;
567 /* check if member has echo turned on */
568 if (member
->dsp
->echo
.hardware
|| member
->dsp
->echo
.software
) {
569 if (dsp_debug
& DEBUG_DSP_CMX
)
571 "%s dsp %s cannot form a conf, because "
572 "echo is turned on\n", __func__
,
576 /* check if member has tx_mix turned on */
577 if (member
->dsp
->tx_mix
) {
578 if (dsp_debug
& DEBUG_DSP_CMX
)
580 "%s dsp %s cannot form a conf, because "
581 "tx_mix is turned on\n",
582 __func__
, member
->dsp
->name
);
585 /* check if member changes volume at an not suppoted level */
586 if (member
->dsp
->tx_volume
) {
587 if (dsp_debug
& DEBUG_DSP_CMX
)
589 "%s dsp %s cannot form a conf, because "
590 "tx_volume is changed\n",
591 __func__
, member
->dsp
->name
);
594 if (member
->dsp
->rx_volume
) {
595 if (dsp_debug
& DEBUG_DSP_CMX
)
597 "%s dsp %s cannot form a conf, because "
598 "rx_volume is changed\n",
599 __func__
, member
->dsp
->name
);
602 /* check if tx-data turned on */
603 if (member
->dsp
->tx_data
) {
604 if (dsp_debug
& DEBUG_DSP_CMX
)
606 "%s dsp %s tx_data is turned on\n",
607 __func__
, member
->dsp
->name
);
610 /* check if pipeline exists */
611 if (member
->dsp
->pipeline
.inuse
) {
612 if (dsp_debug
& DEBUG_DSP_CMX
)
614 "%s dsp %s cannot form a conf, because "
615 "pipeline exists\n", __func__
,
619 /* check if encryption is enabled */
620 if (member
->dsp
->bf_enable
) {
621 if (dsp_debug
& DEBUG_DSP_CMX
)
622 printk(KERN_DEBUG
"%s dsp %s cannot form a "
623 "conf, because encryption is enabled\n",
624 __func__
, member
->dsp
->name
);
627 /* check if member is on a card with PCM support */
628 if (member
->dsp
->features
.pcm_id
< 0) {
629 if (dsp_debug
& DEBUG_DSP_CMX
)
631 "%s dsp %s cannot form a conf, because "
632 "dsp has no PCM bus\n",
633 __func__
, member
->dsp
->name
);
636 /* check if relations are on the same PCM bus */
637 if (member
->dsp
->features
.pcm_id
!= same_pcm
) {
638 if (dsp_debug
& DEBUG_DSP_CMX
)
640 "%s dsp %s cannot form a conf, because "
641 "dsp is on a different PCM bus than the "
643 __func__
, member
->dsp
->name
);
646 /* determine if members are on the same hfc chip */
647 if (same_hfc
!= member
->dsp
->features
.hfc_id
)
649 /* if there are members already in a conference */
650 if (current_conf
< 0 && member
->dsp
->hfc_conf
>= 0)
651 current_conf
= member
->dsp
->hfc_conf
;
652 /* if any member is not in a conference */
653 if (member
->dsp
->hfc_conf
< 0)
659 /* if no member, this is an error */
665 if (dsp_debug
& DEBUG_DSP_CMX
)
667 "%s conf %d cannot form a HW conference, "
668 "because dsp is alone\n", __func__
, conf
->id
);
671 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
678 * ok, now we are sure that all members are on the same pcm.
679 * now we will see if we have only two members, so we can do
680 * crossconnections, which don't have any limitations.
683 /* if we have only two members */
685 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
687 nextm
= list_entry(member
->list
.next
, struct dsp_conf_member
,
689 /* remove HFC conference if enabled */
690 if (member
->dsp
->hfc_conf
>= 0) {
691 if (dsp_debug
& DEBUG_DSP_CMX
)
693 "%s removing %s from HFC conf %d because "
694 "two parties require only a PCM slot\n",
695 __func__
, member
->dsp
->name
,
696 member
->dsp
->hfc_conf
);
697 dsp_cmx_hw_message(member
->dsp
,
698 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
699 member
->dsp
->hfc_conf
= -1;
701 if (nextm
->dsp
->hfc_conf
>= 0) {
702 if (dsp_debug
& DEBUG_DSP_CMX
)
704 "%s removing %s from HFC conf %d because "
705 "two parties require only a PCM slot\n",
706 __func__
, nextm
->dsp
->name
,
707 nextm
->dsp
->hfc_conf
);
708 dsp_cmx_hw_message(nextm
->dsp
,
709 MISDN_CTRL_HFC_CONF_SPLIT
, 0, 0, 0, 0);
710 nextm
->dsp
->hfc_conf
= -1;
712 /* if members have two banks (and not on the same chip) */
713 if (member
->dsp
->features
.pcm_banks
> 1 &&
714 nextm
->dsp
->features
.pcm_banks
> 1 &&
715 member
->dsp
->features
.hfc_id
!=
716 nextm
->dsp
->features
.hfc_id
) {
717 /* if both members have same slots with crossed banks */
718 if (member
->dsp
->pcm_slot_tx
>= 0 &&
719 member
->dsp
->pcm_slot_rx
>= 0 &&
720 nextm
->dsp
->pcm_slot_tx
>= 0 &&
721 nextm
->dsp
->pcm_slot_rx
>= 0 &&
722 nextm
->dsp
->pcm_slot_tx
==
723 member
->dsp
->pcm_slot_rx
&&
724 nextm
->dsp
->pcm_slot_rx
==
725 member
->dsp
->pcm_slot_tx
&&
726 nextm
->dsp
->pcm_slot_tx
==
727 member
->dsp
->pcm_slot_tx
&&
728 member
->dsp
->pcm_bank_tx
!=
729 member
->dsp
->pcm_bank_rx
&&
730 nextm
->dsp
->pcm_bank_tx
!=
731 nextm
->dsp
->pcm_bank_rx
) {
732 /* all members have same slot */
733 if (dsp_debug
& DEBUG_DSP_CMX
)
735 "%s dsp %s & %s stay joined on "
736 "PCM slot %d bank %d (TX) bank %d "
737 "(RX) (on different chips)\n",
741 member
->dsp
->pcm_slot_tx
,
742 member
->dsp
->pcm_bank_tx
,
743 member
->dsp
->pcm_bank_rx
);
748 /* find a new slot */
749 memset(freeslots
, 1, sizeof(freeslots
));
750 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
751 if (dsp
!= member
->dsp
&&
753 member
->dsp
->features
.pcm_id
==
754 dsp
->features
.pcm_id
) {
755 if (dsp
->pcm_slot_rx
>= 0 &&
758 freeslots
[dsp
->pcm_slot_rx
] = 0;
759 if (dsp
->pcm_slot_tx
>= 0 &&
762 freeslots
[dsp
->pcm_slot_tx
] = 0;
766 ii
= member
->dsp
->features
.pcm_slots
;
773 if (dsp_debug
& DEBUG_DSP_CMX
)
775 "%s no slot available for "
776 "%s & %s\n", __func__
,
779 /* no more slots available */
782 /* assign free slot */
783 member
->dsp
->pcm_slot_tx
= i
;
784 member
->dsp
->pcm_slot_rx
= i
;
785 nextm
->dsp
->pcm_slot_tx
= i
;
786 nextm
->dsp
->pcm_slot_rx
= i
;
787 member
->dsp
->pcm_bank_rx
= 0;
788 member
->dsp
->pcm_bank_tx
= 1;
789 nextm
->dsp
->pcm_bank_rx
= 1;
790 nextm
->dsp
->pcm_bank_tx
= 0;
791 if (dsp_debug
& DEBUG_DSP_CMX
)
793 "%s adding %s & %s to new PCM slot %d "
794 "(TX and RX on different chips) because "
795 "both members have not same slots\n",
799 member
->dsp
->pcm_slot_tx
);
800 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
801 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
802 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
803 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
804 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
805 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
807 conf
->software
= tx_data
;
809 /* if members have one bank (or on the same chip) */
811 /* if both members have different crossed slots */
812 if (member
->dsp
->pcm_slot_tx
>= 0 &&
813 member
->dsp
->pcm_slot_rx
>= 0 &&
814 nextm
->dsp
->pcm_slot_tx
>= 0 &&
815 nextm
->dsp
->pcm_slot_rx
>= 0 &&
816 nextm
->dsp
->pcm_slot_tx
==
817 member
->dsp
->pcm_slot_rx
&&
818 nextm
->dsp
->pcm_slot_rx
==
819 member
->dsp
->pcm_slot_tx
&&
820 member
->dsp
->pcm_slot_tx
!=
821 member
->dsp
->pcm_slot_rx
&&
822 member
->dsp
->pcm_bank_tx
== 0 &&
823 member
->dsp
->pcm_bank_rx
== 0 &&
824 nextm
->dsp
->pcm_bank_tx
== 0 &&
825 nextm
->dsp
->pcm_bank_rx
== 0) {
826 /* all members have same slot */
827 if (dsp_debug
& DEBUG_DSP_CMX
)
829 "%s dsp %s & %s stay joined on PCM "
830 "slot %d (TX) %d (RX) on same chip "
831 "or one bank PCM)\n", __func__
,
834 member
->dsp
->pcm_slot_tx
,
835 member
->dsp
->pcm_slot_rx
);
840 /* find two new slot */
841 memset(freeslots
, 1, sizeof(freeslots
));
842 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
843 if (dsp
!= member
->dsp
&&
845 member
->dsp
->features
.pcm_id
==
846 dsp
->features
.pcm_id
) {
847 if (dsp
->pcm_slot_rx
>= 0 &&
850 freeslots
[dsp
->pcm_slot_rx
] = 0;
851 if (dsp
->pcm_slot_tx
>= 0 &&
854 freeslots
[dsp
->pcm_slot_tx
] = 0;
858 ii
= member
->dsp
->features
.pcm_slots
;
865 if (dsp_debug
& DEBUG_DSP_CMX
)
867 "%s no slot available "
868 "for %s & %s\n", __func__
,
871 /* no more slots available */
881 if (dsp_debug
& DEBUG_DSP_CMX
)
883 "%s no slot available "
888 /* no more slots available */
891 /* assign free slots */
892 member
->dsp
->pcm_slot_tx
= i1
;
893 member
->dsp
->pcm_slot_rx
= i2
;
894 nextm
->dsp
->pcm_slot_tx
= i2
;
895 nextm
->dsp
->pcm_slot_rx
= i1
;
896 member
->dsp
->pcm_bank_rx
= 0;
897 member
->dsp
->pcm_bank_tx
= 0;
898 nextm
->dsp
->pcm_bank_rx
= 0;
899 nextm
->dsp
->pcm_bank_tx
= 0;
900 if (dsp_debug
& DEBUG_DSP_CMX
)
902 "%s adding %s & %s to new PCM slot %d "
903 "(TX) %d (RX) on same chip or one bank "
904 "PCM, because both members have not "
905 "crossed slots\n", __func__
,
908 member
->dsp
->pcm_slot_tx
,
909 member
->dsp
->pcm_slot_rx
);
910 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
911 member
->dsp
->pcm_slot_tx
, member
->dsp
->pcm_bank_tx
,
912 member
->dsp
->pcm_slot_rx
, member
->dsp
->pcm_bank_rx
);
913 dsp_cmx_hw_message(nextm
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
914 nextm
->dsp
->pcm_slot_tx
, nextm
->dsp
->pcm_bank_tx
,
915 nextm
->dsp
->pcm_slot_rx
, nextm
->dsp
->pcm_bank_rx
);
917 conf
->software
= tx_data
;
923 * if we have more than two, we may check if we have a conference
924 * unit available on the chip. also all members must be on the same
927 /* if not the same HFC chip */
929 if (dsp_debug
& DEBUG_DSP_CMX
)
931 "%s conference %d cannot be formed, because "
932 "members are on different chips or not "
938 /* for more than two members.. */
940 /* if all members already have the same conference */
945 * if there is an existing conference, but not all members have joined
947 if (current_conf
>= 0) {
949 list_for_each_entry(member
, &conf
->mlist
, list
) {
950 /* if no conference engine on our chip, change to
952 if (!member
->dsp
->features
.hfc_conf
)
954 /* in case of hdlc, change to software */
955 if (member
->dsp
->hdlc
)
957 /* join to current conference */
958 if (member
->dsp
->hfc_conf
== current_conf
)
960 /* get a free timeslot first */
961 memset(freeslots
, 1, sizeof(freeslots
));
962 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
964 * not checking current member, because
965 * slot will be overwritten.
968 dsp
!= member
->dsp
&&
969 /* dsp must be on the same PCM */
970 member
->dsp
->features
.pcm_id
==
971 dsp
->features
.pcm_id
) {
972 /* dsp must be on a slot */
973 if (dsp
->pcm_slot_tx
>= 0 &&
976 freeslots
[dsp
->pcm_slot_tx
] = 0;
977 if (dsp
->pcm_slot_rx
>= 0 &&
980 freeslots
[dsp
->pcm_slot_rx
] = 0;
984 ii
= member
->dsp
->features
.pcm_slots
;
991 /* no more slots available */
992 if (dsp_debug
& DEBUG_DSP_CMX
)
994 "%s conference %d cannot be formed,"
995 " because no slot free\n",
999 if (dsp_debug
& DEBUG_DSP_CMX
)
1001 "%s changing dsp %s to HW conference "
1002 "%d slot %d\n", __func__
,
1003 member
->dsp
->name
, current_conf
, i
);
1004 /* assign free slot & set PCM & join conf */
1005 member
->dsp
->pcm_slot_tx
= i
;
1006 member
->dsp
->pcm_slot_rx
= i
;
1007 member
->dsp
->pcm_bank_tx
= 2; /* loop */
1008 member
->dsp
->pcm_bank_rx
= 2;
1009 member
->dsp
->hfc_conf
= current_conf
;
1010 dsp_cmx_hw_message(member
->dsp
, MISDN_CTRL_HFC_PCM_CONN
,
1012 dsp_cmx_hw_message(member
->dsp
,
1013 MISDN_CTRL_HFC_CONF_JOIN
, current_conf
, 0, 0, 0);
1019 * no member is in a conference yet, so we find a free one
1021 memset(freeunits
, 1, sizeof(freeunits
));
1022 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1023 /* dsp must be on the same chip */
1024 if (dsp
->features
.hfc_id
== same_hfc
&&
1025 /* dsp must have joined a HW conference */
1026 dsp
->hfc_conf
>= 0 &&
1027 /* slot must be within range */
1029 freeunits
[dsp
->hfc_conf
] = 0;
1039 /* no more conferences available */
1040 if (dsp_debug
& DEBUG_DSP_CMX
)
1042 "%s conference %d cannot be formed, because "
1043 "no conference number free\n",
1044 __func__
, conf
->id
);
1047 /* join all members */
1054 * conf_id != 0: join or change conference
1055 * conf_id == 0: split from conference if not already
1058 dsp_cmx_conf(struct dsp
*dsp
, u32 conf_id
)
1061 struct dsp_conf
*conf
;
1062 struct dsp_conf_member
*member
;
1064 /* if conference doesn't change */
1065 if (dsp
->conf_id
== conf_id
)
1068 /* first remove us from current conf */
1070 if (dsp_debug
& DEBUG_DSP_CMX
)
1071 printk(KERN_DEBUG
"removing us from conference %d\n",
1073 /* remove us from conf */
1075 err
= dsp_cmx_del_conf_member(dsp
);
1080 /* update hardware */
1081 dsp_cmx_hardware(NULL
, dsp
);
1083 /* conf now empty? */
1084 if (list_empty(&conf
->mlist
)) {
1085 if (dsp_debug
& DEBUG_DSP_CMX
)
1087 "conference is empty, so we remove it.\n");
1088 err
= dsp_cmx_del_conf(conf
);
1092 /* update members left on conf */
1093 dsp_cmx_hardware(conf
, NULL
);
1101 /* now add us to conf */
1102 if (dsp_debug
& DEBUG_DSP_CMX
)
1103 printk(KERN_DEBUG
"searching conference %d\n",
1105 conf
= dsp_cmx_search_conf(conf_id
);
1107 if (dsp_debug
& DEBUG_DSP_CMX
)
1109 "conference doesn't exist yet, creating.\n");
1110 /* the conference doesn't exist, so we create */
1111 conf
= dsp_cmx_new_conf(conf_id
);
1114 } else if (!list_empty(&conf
->mlist
)) {
1115 member
= list_entry(conf
->mlist
.next
, struct dsp_conf_member
,
1117 if (dsp
->hdlc
&& !member
->dsp
->hdlc
) {
1118 if (dsp_debug
& DEBUG_DSP_CMX
)
1120 "cannot join transparent conference.\n");
1123 if (!dsp
->hdlc
&& member
->dsp
->hdlc
) {
1124 if (dsp_debug
& DEBUG_DSP_CMX
)
1126 "cannot join hdlc conference.\n");
1130 /* add conference member */
1131 err
= dsp_cmx_add_conf_member(dsp
, conf
);
1134 dsp
->conf_id
= conf_id
;
1136 /* if we are alone, we do nothing! */
1137 if (list_empty(&conf
->mlist
)) {
1138 if (dsp_debug
& DEBUG_DSP_CMX
)
1140 "we are alone in this conference, so exit.\n");
1141 /* update hardware */
1142 dsp_cmx_hardware(NULL
, dsp
);
1146 /* update members on conf */
1147 dsp_cmx_hardware(conf
, NULL
);
1152 #ifdef CMX_DELAY_DEBUG
1155 showdelay(struct dsp
*dsp
, int samples
, int delay
)
1157 char bar
[] = "--------------------------------------------------|";
1160 delaycount
+= samples
;
1161 if (delaycount
< 8000)
1165 sdelay
= delay
* 50 / (dsp_poll
<< 2);
1167 printk(KERN_DEBUG
"DELAY (%s) %3d >%s\n", dsp
->name
, delay
,
1168 sdelay
> 50 ? "..." : bar
+ 50 - sdelay
);
1173 * audio data is received from card
1176 dsp_cmx_receive(struct dsp
*dsp
, struct sk_buff
*skb
)
1180 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1183 /* check if we have sompen */
1187 /* half of the buffer should be larger than maximum packet size */
1188 if (len
>= CMX_BUFF_HALF
) {
1190 "%s line %d: packet from card is too large (%d bytes). "
1191 "please make card send smaller packets OR increase "
1192 "CMX_BUFF_SIZE\n", __FILE__
, __LINE__
, len
);
1197 * initialize pointers if not already -
1198 * also add delay if requested by PH_SIGNAL
1202 if (dsp
->features
.unordered
) {
1203 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1205 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1208 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1213 dsp
->rx_W
= dsp
->cmx_delay
;
1215 dsp
->rx_W
= dsp_poll
>> 1;
1218 /* if frame contains time code, write directly */
1219 if (dsp
->features
.unordered
) {
1220 dsp
->rx_W
= (hh
->id
& CMX_BUFF_MASK
);
1221 /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1224 * if we underrun (or maybe overrun),
1225 * we set our new read pointer, and write silence to buffer
1227 if (((dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
) >= CMX_BUFF_HALF
) {
1228 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1230 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1231 "maximum delay), adjusting read pointer! "
1232 "(inst %s)\n", (u_long
)dsp
, dsp
->name
);
1233 /* flush rx buffer and set delay to dsp_poll / 2 */
1234 if (dsp
->features
.unordered
) {
1235 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1237 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1239 dsp
->rx_W
= (dsp
->rx_R
+ (dsp_poll
>> 1))
1244 dsp
->rx_W
= dsp
->cmx_delay
;
1246 dsp
->rx_W
= dsp_poll
>> 1;
1248 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1250 /* if we have reached double delay, jump back to middle */
1252 if (((dsp
->rx_W
- dsp
->rx_R
) & CMX_BUFF_MASK
) >=
1253 (dsp
->cmx_delay
<< 1)) {
1254 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1256 "cmx_receive(dsp=%lx): OVERRUN (because "
1257 "twice the delay is reached), adjusting "
1258 "read pointer! (inst %s)\n",
1259 (u_long
)dsp
, dsp
->name
);
1261 if (dsp
->features
.unordered
) {
1262 dsp
->rx_R
= (hh
->id
& CMX_BUFF_MASK
);
1263 dsp
->rx_W
= (dsp
->rx_R
+ dsp
->cmx_delay
)
1267 dsp
->rx_W
= dsp
->cmx_delay
;
1269 memset(dsp
->rx_buff
, dsp_silence
, sizeof(dsp
->rx_buff
));
1272 /* show where to write */
1275 "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1276 (u_long
)dsp
, dsp
->rx_R
, dsp
->rx_W
, len
, dsp
->name
);
1279 /* write data into rx_buffer */
1286 d
[w
++ & CMX_BUFF_MASK
] = *p
++;
1290 /* increase write-pointer */
1291 dsp
->rx_W
= ((dsp
->rx_W
+len
) & CMX_BUFF_MASK
);
1292 #ifdef CMX_DELAY_DEBUG
1293 showdelay(dsp
, len
, (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
);
1299 * send (mixed) audio data to card and control jitter
1302 dsp_cmx_send_member(struct dsp
*dsp
, int len
, s32
*c
, int members
)
1304 struct dsp_conf
*conf
= dsp
->conf
;
1305 struct dsp
*member
, *other
;
1306 register s32 sample
;
1307 u8
*d
, *p
, *q
, *o_q
;
1308 struct sk_buff
*nskb
, *txskb
;
1309 int r
, rr
, t
, tt
, o_r
, o_rr
;
1311 struct mISDNhead
*hh
, *thh
;
1312 int tx_data_only
= 0;
1314 /* don't process if: */
1315 if (!dsp
->b_active
) { /* if not active */
1319 if (((dsp
->conf
&& dsp
->conf
->hardware
) || /* hardware conf */
1320 dsp
->echo
.hardware
) && /* OR hardware echo */
1321 dsp
->tx_R
== dsp
->tx_W
&& /* AND no tx-data */
1322 !(dsp
->tone
.tone
&& dsp
->tone
.software
)) { /* AND not soft tones */
1323 if (!dsp
->tx_data
) { /* no tx_data for user space required */
1327 if (dsp
->conf
&& dsp
->conf
->software
&& dsp
->conf
->hardware
)
1329 if (dsp
->conf
->software
&& dsp
->echo
.hardware
)
1335 "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1336 members
, dsp
->name
, conf
, dsp
->rx_R
, dsp
->rx_W
);
1339 /* preload if we have delay set */
1340 if (dsp
->cmx_delay
&& !dsp
->last_tx
) {
1346 /* PREPARE RESULT */
1347 nskb
= mI_alloc_skb(len
+ preload
, GFP_ATOMIC
);
1350 "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1354 hh
= mISDN_HEAD_P(nskb
);
1355 hh
->prim
= PH_DATA_REQ
;
1359 /* set pointers, indexes and stuff */
1361 p
= dsp
->tx_buff
; /* transmit data */
1362 q
= dsp
->rx_buff
; /* received data */
1363 d
= skb_put(nskb
, preload
+ len
); /* result */
1364 t
= dsp
->tx_R
; /* tx-pointers */
1366 r
= dsp
->rx_R
; /* rx-pointers */
1367 rr
= (r
+ len
) & CMX_BUFF_MASK
;
1369 /* preload with silence, if required */
1371 memset(d
, dsp_silence
, preload
);
1375 /* PROCESS TONES/TX-DATA ONLY */
1376 if (dsp
->tone
.tone
&& dsp
->tone
.software
) {
1378 dsp_tone_copy(dsp
, d
, len
);
1379 dsp
->tx_R
= 0; /* clear tx buffer */
1383 /* if we have tx-data but do not use mixing */
1384 if (!dsp
->tx_mix
&& t
!= tt
) {
1385 /* -> send tx-data and continue when not enough */
1387 sprintf(debugbuf
, "TX sending (%04x-%04x)%p: ", t
, tt
, p
);
1389 while (r
!= rr
&& t
!= tt
) {
1391 if (strlen(debugbuf
) < 48)
1392 sprintf(debugbuf
+strlen(debugbuf
), " %02x",
1395 *d
++ = p
[t
]; /* write tx_buff */
1396 t
= (t
+1) & CMX_BUFF_MASK
;
1397 r
= (r
+1) & CMX_BUFF_MASK
;
1402 printk(KERN_DEBUG
"%s\n", debugbuf
);
1408 printk(KERN_DEBUG
"%s\n", debugbuf
);
1411 /* PROCESS DATA (one member / no conf) */
1412 if (!conf
|| members
<= 1) {
1413 /* -> if echo is NOT enabled */
1414 if (!dsp
->echo
.software
) {
1415 /* -> send tx-data if available or use 0-volume */
1416 while (r
!= rr
&& t
!= tt
) {
1417 *d
++ = p
[t
]; /* write tx_buff */
1418 t
= (t
+1) & CMX_BUFF_MASK
;
1419 r
= (r
+1) & CMX_BUFF_MASK
;
1422 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1423 printk(KERN_DEBUG
"%s: RX empty\n",
1425 memset(d
, dsp_silence
, (rr
-r
)&CMX_BUFF_MASK
);
1427 /* -> if echo is enabled */
1430 * -> mix tx-data with echo if available,
1433 while (r
!= rr
&& t
!= tt
) {
1434 *d
++ = dsp_audio_mix_law
[(p
[t
]<<8)|q
[r
]];
1435 t
= (t
+1) & CMX_BUFF_MASK
;
1436 r
= (r
+1) & CMX_BUFF_MASK
;
1439 *d
++ = q
[r
]; /* echo */
1440 r
= (r
+1) & CMX_BUFF_MASK
;
1446 /* PROCESS DATA (two members) */
1447 #ifdef CMX_CONF_DEBUG
1452 /* "other" becomes other party */
1453 other
= (list_entry(conf
->mlist
.next
,
1454 struct dsp_conf_member
, list
))->dsp
;
1455 if (other
== member
)
1456 other
= (list_entry(conf
->mlist
.prev
,
1457 struct dsp_conf_member
, list
))->dsp
;
1458 o_q
= other
->rx_buff
; /* received data */
1459 o_rr
= (other
->rx_R
+ len
) & CMX_BUFF_MASK
;
1460 /* end of rx-pointer */
1461 o_r
= (o_rr
- rr
+ r
) & CMX_BUFF_MASK
;
1462 /* start rx-pointer at current read position*/
1463 /* -> if echo is NOT enabled */
1464 if (!dsp
->echo
.software
) {
1466 * -> copy other member's rx-data,
1467 * if tx-data is available, mix
1469 while (o_r
!= o_rr
&& t
!= tt
) {
1470 *d
++ = dsp_audio_mix_law
[(p
[t
]<<8)|o_q
[o_r
]];
1471 t
= (t
+1) & CMX_BUFF_MASK
;
1472 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1474 while (o_r
!= o_rr
) {
1476 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1478 /* -> if echo is enabled */
1481 * -> mix other member's rx-data with echo,
1482 * if tx-data is available, mix
1484 while (r
!= rr
&& t
!= tt
) {
1485 sample
= dsp_audio_law_to_s32
[p
[t
]] +
1486 dsp_audio_law_to_s32
[q
[r
]] +
1487 dsp_audio_law_to_s32
[o_q
[o_r
]];
1488 if (sample
< -32768)
1490 else if (sample
> 32767)
1492 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1493 /* tx-data + rx_data + echo */
1494 t
= (t
+1) & CMX_BUFF_MASK
;
1495 r
= (r
+1) & CMX_BUFF_MASK
;
1496 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1499 *d
++ = dsp_audio_mix_law
[(q
[r
]<<8)|o_q
[o_r
]];
1500 r
= (r
+1) & CMX_BUFF_MASK
;
1501 o_r
= (o_r
+1) & CMX_BUFF_MASK
;
1507 #ifdef DSP_NEVER_DEFINED
1510 /* PROCESS DATA (three or more members) */
1511 /* -> if echo is NOT enabled */
1512 if (!dsp
->echo
.software
) {
1514 * -> substract rx-data from conf-data,
1515 * if tx-data is available, mix
1517 while (r
!= rr
&& t
!= tt
) {
1518 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++ -
1519 dsp_audio_law_to_s32
[q
[r
]];
1520 if (sample
< -32768)
1522 else if (sample
> 32767)
1524 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1526 r
= (r
+1) & CMX_BUFF_MASK
;
1527 t
= (t
+1) & CMX_BUFF_MASK
;
1530 sample
= *c
++ - dsp_audio_law_to_s32
[q
[r
]];
1531 if (sample
< -32768)
1533 else if (sample
> 32767)
1535 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1537 r
= (r
+1) & CMX_BUFF_MASK
;
1539 /* -> if echo is enabled */
1542 * -> encode conf-data, if tx-data
1545 while (r
!= rr
&& t
!= tt
) {
1546 sample
= dsp_audio_law_to_s32
[p
[t
]] + *c
++;
1547 if (sample
< -32768)
1549 else if (sample
> 32767)
1551 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1553 t
= (t
+1) & CMX_BUFF_MASK
;
1554 r
= (r
+1) & CMX_BUFF_MASK
;
1558 if (sample
< -32768)
1560 else if (sample
> 32767)
1562 *d
++ = dsp_audio_s16_to_law
[sample
& 0xffff];
1564 r
= (r
+1) & CMX_BUFF_MASK
;
1572 * send tx-data if enabled - don't filter,
1573 * becuase we want what we send, not what we filtered
1577 hh
->prim
= DL_DATA_REQ
;
1579 /* queue and trigger */
1580 skb_queue_tail(&dsp
->sendq
, nskb
);
1581 schedule_work(&dsp
->workq
);
1582 /* exit because only tx_data is used */
1585 txskb
= mI_alloc_skb(len
, GFP_ATOMIC
);
1588 "FATAL ERROR in mISDN_dsp.o: "
1589 "cannot alloc %d bytes\n", len
);
1591 thh
= mISDN_HEAD_P(txskb
);
1592 thh
->prim
= DL_DATA_REQ
;
1594 memcpy(skb_put(txskb
, len
), nskb
->data
+preload
,
1596 /* queue (trigger later) */
1597 skb_queue_tail(&dsp
->sendq
, txskb
);
1602 /* send data only to card, if we don't just calculated tx_data */
1605 dsp_change_volume(nskb
, dsp
->tx_volume
);
1607 if (dsp
->pipeline
.inuse
)
1608 dsp_pipeline_process_tx(&dsp
->pipeline
, nskb
->data
,
1612 dsp_bf_encrypt(dsp
, nskb
->data
, nskb
->len
);
1613 /* queue and trigger */
1614 skb_queue_tail(&dsp
->sendq
, nskb
);
1615 schedule_work(&dsp
->workq
);
1618 static u32 jittercount
; /* counter for jitter check */
1619 struct timer_list dsp_spl_tl
;
1620 u32 dsp_spl_jiffies
; /* calculate the next time to fire */
1621 static u16 dsp_count
; /* last sample count */
1622 static int dsp_count_valid
; /* if we have last sample count */
1625 dsp_cmx_send(void *arg
)
1627 struct dsp_conf
*conf
;
1628 struct dsp_conf_member
*member
;
1630 int mustmix
, members
;
1631 static s32 mixbuffer
[MAX_POLL
+100];
1635 int jittercheck
= 0, delay
, i
;
1640 spin_lock_irqsave(&dsp_lock
, flags
);
1642 if (!dsp_count_valid
) {
1643 dsp_count
= mISDN_clock_get();
1645 dsp_count_valid
= 1;
1647 count
= mISDN_clock_get();
1648 length
= count
- dsp_count
;
1651 if (length
> MAX_POLL
+ 100)
1652 length
= MAX_POLL
+ 100;
1653 /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
1656 * check if jitter needs to be checked (this is every second)
1658 jittercount
+= length
;
1659 if (jittercount
>= 8000) {
1660 jittercount
-= 8000;
1664 /* loop all members that do not require conference mixing */
1665 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1672 members
= count_list_member(&conf
->mlist
);
1673 #ifdef CMX_CONF_DEBUG
1674 if (conf
->software
&& members
> 1)
1676 if (conf
->software
&& members
> 2)
1681 /* transmission required */
1683 dsp_cmx_send_member(dsp
, length
, mixbuffer
, members
);
1686 * unused mixbuffer is given to prevent a
1687 * potential null-pointer-bug
1692 /* loop all members that require conference mixing */
1693 list_for_each_entry(conf
, &conf_ilist
, list
) {
1694 /* count members and check hardware */
1695 members
= count_list_member(&conf
->mlist
);
1696 #ifdef CMX_CONF_DEBUG
1697 if (conf
->software
&& members
> 1) {
1699 if (conf
->software
&& members
> 2) {
1701 /* check for hdlc conf */
1702 member
= list_entry(conf
->mlist
.next
,
1703 struct dsp_conf_member
, list
);
1704 if (member
->dsp
->hdlc
)
1707 memset(mixbuffer
, 0, length
*sizeof(s32
));
1708 list_for_each_entry(member
, &conf
->mlist
, list
) {
1710 /* get range of data to mix */
1714 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1715 /* add member's data */
1717 *c
++ += dsp_audio_law_to_s32
[q
[r
]];
1718 r
= (r
+1) & CMX_BUFF_MASK
;
1722 /* process each member */
1723 list_for_each_entry(member
, &conf
->mlist
, list
) {
1725 dsp_cmx_send_member(member
->dsp
, length
,
1726 mixbuffer
, members
);
1731 /* delete rx-data, increment buffers, change pointers */
1732 list_for_each_entry(dsp
, &dsp_ilist
, list
) {
1738 /* move receive pointer when receiving */
1739 if (!dsp
->rx_is_off
) {
1740 rr
= (r
+ length
) & CMX_BUFF_MASK
;
1741 /* delete rx-data */
1744 r
= (r
+1) & CMX_BUFF_MASK
;
1746 /* increment rx-buffer pointer */
1747 dsp
->rx_R
= r
; /* write incremented read pointer */
1750 /* check current rx_delay */
1751 delay
= (dsp
->rx_W
-dsp
->rx_R
) & CMX_BUFF_MASK
;
1752 if (delay
>= CMX_BUFF_HALF
)
1753 delay
= 0; /* will be the delay before next write */
1754 /* check for lower delay */
1755 if (delay
< dsp
->rx_delay
[0])
1756 dsp
->rx_delay
[0] = delay
;
1757 /* check current tx_delay */
1758 delay
= (dsp
->tx_W
-dsp
->tx_R
) & CMX_BUFF_MASK
;
1759 if (delay
>= CMX_BUFF_HALF
)
1760 delay
= 0; /* will be the delay before next write */
1761 /* check for lower delay */
1762 if (delay
< dsp
->tx_delay
[0])
1763 dsp
->tx_delay
[0] = delay
;
1765 /* find the lowest of all rx_delays */
1766 delay
= dsp
->rx_delay
[0];
1768 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1769 if (delay
> dsp
->rx_delay
[i
])
1770 delay
= dsp
->rx_delay
[i
];
1774 * remove rx_delay only if we have delay AND we
1775 * have not preset cmx_delay AND
1776 * the delay is greater dsp_poll
1778 if (delay
> dsp_poll
&& !dsp
->cmx_delay
) {
1779 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1781 "%s lowest rx_delay of %d bytes for"
1782 " dsp %s are now removed.\n",
1786 rr
= (r
+ delay
- (dsp_poll
>> 1))
1788 /* delete rx-data */
1791 r
= (r
+1) & CMX_BUFF_MASK
;
1793 /* increment rx-buffer pointer */
1795 /* write incremented read pointer */
1797 /* find the lowest of all tx_delays */
1798 delay
= dsp
->tx_delay
[0];
1800 while (i
< MAX_SECONDS_JITTER_CHECK
) {
1801 if (delay
> dsp
->tx_delay
[i
])
1802 delay
= dsp
->tx_delay
[i
];
1806 * remove delay only if we have delay AND we
1807 * have enabled tx_dejitter
1809 if (delay
> dsp_poll
&& dsp
->tx_dejitter
) {
1810 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1812 "%s lowest tx_delay of %d bytes for"
1813 " dsp %s are now removed.\n",
1817 rr
= (r
+ delay
- (dsp_poll
>> 1))
1819 /* delete tx-data */
1822 r
= (r
+1) & CMX_BUFF_MASK
;
1824 /* increment rx-buffer pointer */
1826 /* write incremented read pointer */
1828 /* scroll up delays */
1829 i
= MAX_SECONDS_JITTER_CHECK
- 1;
1831 dsp
->rx_delay
[i
] = dsp
->rx_delay
[i
-1];
1832 dsp
->tx_delay
[i
] = dsp
->tx_delay
[i
-1];
1835 dsp
->tx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1836 dsp
->rx_delay
[0] = CMX_BUFF_HALF
; /* (infinite) delay */
1840 /* if next event would be in the past ... */
1841 if ((s32
)(dsp_spl_jiffies
+dsp_tics
-jiffies
) <= 0)
1842 dsp_spl_jiffies
= jiffies
+ 1;
1844 dsp_spl_jiffies
+= dsp_tics
;
1846 dsp_spl_tl
.expires
= dsp_spl_jiffies
;
1847 add_timer(&dsp_spl_tl
);
1850 spin_unlock_irqrestore(&dsp_lock
, flags
);
1854 * audio data is transmitted from upper layer to the dsp
1857 dsp_cmx_transmit(struct dsp
*dsp
, struct sk_buff
*skb
)
1861 int space
; /* todo: , l = skb->len; */
1863 char debugbuf
[256] = "";
1866 /* check if there is enough space, and then copy */
1871 space
= (ww
- w
- 1) & CMX_BUFF_MASK
;
1872 /* write-pointer should not overrun nor reach read pointer */
1873 if (space
< skb
->len
) {
1874 /* write to the space we have left */
1875 ww
= (ww
- 1) & CMX_BUFF_MASK
; /* end one byte prior tx_R */
1876 if (dsp_debug
& DEBUG_DSP_CLOCK
)
1877 printk(KERN_DEBUG
"%s: TX overflow space=%d skb->len="
1878 "%d, w=0x%04x, ww=0x%04x\n", __func__
, space
,
1881 /* write until all byte are copied */
1882 ww
= (w
+ skb
->len
) & CMX_BUFF_MASK
;
1885 /* show current buffer */
1888 "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1889 (u_long
)dsp
, (ww
-w
)&CMX_BUFF_MASK
, w
, ww
, dsp
->name
);
1892 /* copy transmit data to tx-buffer */
1894 sprintf(debugbuf
, "TX getting (%04x-%04x)%p: ", w
, ww
, p
);
1898 if (strlen(debugbuf
) < 48)
1899 sprintf(debugbuf
+strlen(debugbuf
), " %02x", *d
);
1902 w
= (w
+1) & CMX_BUFF_MASK
;
1905 printk(KERN_DEBUG
"%s\n", debugbuf
);
1911 * hdlc data is received from card and sent to all members.
1914 dsp_cmx_hdlc(struct dsp
*dsp
, struct sk_buff
*skb
)
1916 struct sk_buff
*nskb
= NULL
;
1917 struct dsp_conf_member
*member
;
1918 struct mISDNhead
*hh
;
1920 /* not if not active */
1924 /* check if we have sompen */
1930 /* in case of software echo */
1931 if (dsp
->echo
.software
) {
1932 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1934 hh
= mISDN_HEAD_P(nskb
);
1935 hh
->prim
= PH_DATA_REQ
;
1937 skb_queue_tail(&dsp
->sendq
, nskb
);
1938 schedule_work(&dsp
->workq
);
1943 /* in case of hardware conference */
1944 if (dsp
->conf
->hardware
)
1946 list_for_each_entry(member
, &dsp
->conf
->mlist
, list
) {
1947 if (dsp
->echo
.software
|| member
->dsp
!= dsp
) {
1948 nskb
= skb_clone(skb
, GFP_ATOMIC
);
1950 hh
= mISDN_HEAD_P(nskb
);
1951 hh
->prim
= PH_DATA_REQ
;
1953 skb_queue_tail(&member
->dsp
->sendq
, nskb
);
1954 schedule_work(&member
->dsp
->workq
);