if (!conf || !dsp) {
printk(KERN_WARNING "%s: conf or dsp is 0.\n", __func__); return -EINVAL;
} if (dsp->member) {
printk(KERN_WARNING "%s: dsp is already member in a conf.\n",
__func__); return -EINVAL;
}
if (dsp->conf) {
printk(KERN_WARNING "%s: dsp is already in a conf.\n",
__func__); return -EINVAL;
}
member = kzalloc(sizeof(struct dsp_conf_member), GFP_ATOMIC); if (!member) {
printk(KERN_ERR "kzalloc struct dsp_conf_member failed\n"); return -ENOMEM;
}
member->dsp = dsp; /* clear rx buffer */
memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
dsp->rx_init = 1; /* rx_W and rx_R will be adjusted on first frame */
dsp->rx_W = 0;
dsp->rx_R = 0;
if (!dsp) {
printk(KERN_WARNING "%s: dsp is 0.\n",
__func__); return -EINVAL;
}
if (!dsp->conf) {
printk(KERN_WARNING "%s: dsp is not in a conf.\n",
__func__); return -EINVAL;
}
if (list_empty(&dsp->conf->mlist)) {
printk(KERN_WARNING "%s: dsp has linked an empty conf.\n",
__func__); return -EINVAL;
}
/* find us in conf */
list_for_each_entry(member, &dsp->conf->mlist, list) { if (member->dsp == dsp) {
list_del(&member->list);
dsp->conf = NULL;
dsp->member = NULL;
kfree(member); return0;
}
}
printk(KERN_WARNING "%s: dsp is not present in its own conf_member list.\n",
__func__);
if (list_empty(&conf->mlist)) {
printk(KERN_ERR "%s: conference without members\n",
__func__); return;
}
member = list_entry(conf->mlist.next, struct dsp_conf_member, list);
same_hfc = member->dsp->features.hfc_id;
same_pcm = member->dsp->features.pcm_id; /* check all members in our conference */
list_for_each_entry(member, &conf->mlist, list) { /* check if member uses mixing */ if (member->dsp->tx_mix) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "tx_mix is turned on\n", __func__,
member->dsp->name);
conf_software:
list_for_each_entry(member, &conf->mlist, list) {
dsp = member->dsp; /* remove HFC conference if enabled */ if (dsp->hfc_conf >= 0) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s removing %s from HFC " "conf %d because not " "possible with hardware\n",
__func__,
dsp->name,
dsp->hfc_conf);
dsp_cmx_hw_message(dsp,
MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
dsp->hfc_conf = -1;
} /* remove PCM slot if assigned */ if (dsp->pcm_slot_tx >= 0 ||
dsp->pcm_slot_rx >= 0) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s removing " "%s from PCM slot %d (TX)" " slot %d (RX) because not" " possible with hardware\n",
__func__,
dsp->name,
dsp->pcm_slot_tx,
dsp->pcm_slot_rx);
dsp_cmx_hw_message(dsp,
MISDN_CTRL_HFC_PCM_DISC, 0, 0, 0, 0);
dsp->pcm_slot_tx = -1;
dsp->pcm_bank_tx = -1;
dsp->pcm_slot_rx = -1;
dsp->pcm_bank_rx = -1;
}
}
conf->hardware = 0;
conf->software = 1; return;
} /* check if member has echo turned on */ if (member->dsp->echo.hardware || member->dsp->echo.software) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "echo is turned on\n", __func__,
member->dsp->name); goto conf_software;
} /* check if member has tx_mix turned on */ if (member->dsp->tx_mix) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "tx_mix is turned on\n",
__func__, member->dsp->name); goto conf_software;
} /* check if member changes volume at an not suppoted level */ if (member->dsp->tx_volume) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "tx_volume is changed\n",
__func__, member->dsp->name); goto conf_software;
} if (member->dsp->rx_volume) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "rx_volume is changed\n",
__func__, member->dsp->name); goto conf_software;
} /* check if tx-data turned on */ if (member->dsp->tx_data) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s tx_data is turned on\n",
__func__, member->dsp->name);
tx_data = 1;
} /* check if pipeline exists */ if (member->dsp->pipeline.inuse) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "pipeline exists\n", __func__,
member->dsp->name); goto conf_software;
} /* check if encryption is enabled */ if (member->dsp->bf_enable) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a " "conf, because encryption is enabled\n",
__func__, member->dsp->name); goto conf_software;
} /* check if member is on a card with PCM support */ if (member->dsp->features.pcm_id < 0) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "dsp has no PCM bus\n",
__func__, member->dsp->name); goto conf_software;
} /* check if relations are on the same PCM bus */ if (member->dsp->features.pcm_id != same_pcm) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s dsp %s cannot form a conf, because " "dsp is on a different PCM bus than the " "first dsp\n",
__func__, member->dsp->name); goto conf_software;
} /* determine if members are on the same hfc chip */ if (same_hfc != member->dsp->features.hfc_id)
same_hfc = -1; /* if there are members already in a conference */ if (current_conf < 0 && member->dsp->hfc_conf >= 0)
current_conf = member->dsp->hfc_conf; /* if any member is not in a conference */ if (member->dsp->hfc_conf < 0)
all_conf = 0;
memb++;
}
/* if no member, this is an error */ if (memb < 1) return;
/* one member */ if (memb == 1) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s conf %d cannot form a HW conference, " "because dsp is alone\n", __func__, conf->id);
conf->hardware = 0;
conf->software = 0;
member = list_entry(conf->mlist.next, struct dsp_conf_member,
list);
dsp = member->dsp; goto one_member;
}
/* if not the same HFC chip */ if (same_hfc < 0) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s conference %d cannot be formed, because " "members are on different chips or not " "on HFC chip\n",
__func__, conf->id); goto conf_software;
}
/* for more than two members.. */
/* if all members already have the same conference */ if (all_conf) {
conf->hardware = 1;
conf->software = tx_data; return;
}
/* *ifthereisanexistingconference,butnotallmembershavejoined
*/ if (current_conf >= 0) {
join_members:
list_for_each_entry(member, &conf->mlist, list) { /* if no conference engine on our chip, change to
* software */ if (!member->dsp->features.hfc_conf) goto conf_software; /* in case of hdlc, change to software */ if (member->dsp->hdlc) goto conf_software; /* join to current conference */ if (member->dsp->hfc_conf == current_conf) continue; /* get a free timeslot first */
memset(freeslots, 1, sizeof(freeslots));
list_for_each_entry(dsp, &dsp_ilist, list) { /* *notcheckingcurrentmember,because *slotwillbeoverwritten.
*/ if (
dsp != member->dsp && /* dsp must be on the same PCM */
member->dsp->features.pcm_id ==
dsp->features.pcm_id) { /* dsp must be on a slot */ if (dsp->pcm_slot_tx >= 0 &&
dsp->pcm_slot_tx < sizeof(freeslots))
freeslots[dsp->pcm_slot_tx] = 0; if (dsp->pcm_slot_rx >= 0 &&
dsp->pcm_slot_rx < sizeof(freeslots))
freeslots[dsp->pcm_slot_rx] = 0;
}
}
i = 0;
ii = member->dsp->features.pcm_slots; while (i < ii) { if (freeslots[i]) break;
i++;
} if (i == ii) { /* no more slots available */ if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s conference %d cannot be formed," " because no slot free\n",
__func__, conf->id); goto conf_software;
} if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s changing dsp %s to HW conference " "%d slot %d\n", __func__,
member->dsp->name, current_conf, i); /* assign free slot & set PCM & join conf */
member->dsp->pcm_slot_tx = i;
member->dsp->pcm_slot_rx = i;
member->dsp->pcm_bank_tx = 2; /* loop */
member->dsp->pcm_bank_rx = 2;
member->dsp->hfc_conf = current_conf;
dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
i, 2, i, 2);
dsp_cmx_hw_message(member->dsp,
MISDN_CTRL_HFC_CONF_JOIN, current_conf, 0, 0, 0);
}
conf->hardware = 1;
conf->software = tx_data; return;
}
/* *nomemberisinaconferenceyet,sowefindafreeone
*/
memset(freeunits, 1, sizeof(freeunits));
list_for_each_entry(dsp, &dsp_ilist, list) { /* dsp must be on the same chip */ if (dsp->features.hfc_id == same_hfc && /* dsp must have joined a HW conference */
dsp->hfc_conf >= 0 && /* slot must be within range */
dsp->hfc_conf < 8)
freeunits[dsp->hfc_conf] = 0;
}
i = 0;
ii = 8; while (i < ii) { if (freeunits[i]) break;
i++;
} if (i == ii) { /* no more conferences available */ if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "%s conference %d cannot be formed, because " "no conference number free\n",
__func__, conf->id); goto conf_software;
} /* join all members */
current_conf = i; goto join_members;
}
/* *conf_id!=0:joinorchangeconference *conf_id==0:splitfromconferenceifnotalready
*/ int
dsp_cmx_conf(struct dsp *dsp, u32 conf_id)
{ int err; struct dsp_conf *conf; struct dsp_conf_member *member;
/* if conference doesn't change */ if (dsp->conf_id == conf_id) return0;
/* first remove us from current conf */ if (dsp->conf_id) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "removing us from conference %d\n",
dsp->conf->id); /* remove us from conf */
conf = dsp->conf;
err = dsp_cmx_del_conf_member(dsp); if (err) return err;
dsp->conf_id = 0;
/* conf now empty? */ if (list_empty(&conf->mlist)) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "conference is empty, so we remove it.\n");
err = dsp_cmx_del_conf(conf); if (err) return err;
} else { /* update members left on conf */
dsp_cmx_hardware(conf, NULL);
}
}
/* if split */ if (!conf_id) return0;
/* now add us to conf */ if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "searching conference %d\n",
conf_id);
conf = dsp_cmx_search_conf(conf_id); if (!conf) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "conference doesn't exist yet, creating.\n"); /* the conference doesn't exist, so we create */
conf = dsp_cmx_new_conf(conf_id); if (!conf) return -EINVAL;
} elseif (!list_empty(&conf->mlist)) {
member = list_entry(conf->mlist.next, struct dsp_conf_member,
list); if (dsp->hdlc && !member->dsp->hdlc) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "cannot join transparent conference.\n"); return -EINVAL;
} if (!dsp->hdlc && member->dsp->hdlc) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "cannot join hdlc conference.\n"); return -EINVAL;
}
} /* add conference member */
err = dsp_cmx_add_conf_member(dsp, conf); if (err) return err;
dsp->conf_id = conf_id;
/* if we are alone, we do nothing! */ if (list_empty(&conf->mlist)) { if (dsp_debug & DEBUG_DSP_CMX)
printk(KERN_DEBUG "we are alone in this conference, so exit.\n"); /* update hardware */
dsp_cmx_hardware(NULL, dsp); return0;
}
/* update members on conf */
dsp_cmx_hardware(conf, NULL);
return0;
}
#ifdef CMX_DELAY_DEBUG int delaycount; staticvoid
showdelay(struct dsp *dsp, int samples, int delay)
{ char bar[] = "--------------------------------------------------|"; int sdelay;
/* *audiodataisreceivedfromcard
*/ void
dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb)
{
u8 *d, *p; int len = skb->len; struct mISDNhead *hh = mISDN_HEAD_P(skb); int w, i, ii;
/* check if we have sompen */ if (len < 1) return;
/* half of the buffer should be larger than maximum packet size */ if (len >= CMX_BUFF_HALF) {
printk(KERN_ERR "%s line %d: packet from card is too large (%d bytes). " "please make card send smaller packets OR increase " "CMX_BUFF_SIZE\n", __FILE__, __LINE__, len); return;
}
/* *initializepointersifnotalready- *alsoadddelayifrequestedbyPH_SIGNAL
*/ if (dsp->rx_init) {
dsp->rx_init = 0; if (dsp->features.unordered) {
dsp->rx_R = (hh->id & CMX_BUFF_MASK); if (dsp->cmx_delay)
dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
& CMX_BUFF_MASK; else
dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
& CMX_BUFF_MASK;
} else {
dsp->rx_R = 0; if (dsp->cmx_delay)
dsp->rx_W = dsp->cmx_delay; else
dsp->rx_W = dsp_poll >> 1;
}
} /* if frame contains time code, write directly */ if (dsp->features.unordered) {
dsp->rx_W = (hh->id & CMX_BUFF_MASK); /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
} /* *ifweunderrun(ormaybeoverrun), *wesetournewreadpointer,andwritesilencetobuffer
*/ if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) { if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "cmx_receive(dsp=%lx): UNDERRUN (or overrun the " "maximum delay), adjusting read pointer! " "(inst %s)\n", (u_long)dsp, dsp->name); /* flush rx buffer and set delay to dsp_poll / 2 */ if (dsp->features.unordered) {
dsp->rx_R = (hh->id & CMX_BUFF_MASK); if (dsp->cmx_delay)
dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
& CMX_BUFF_MASK; else
dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
& CMX_BUFF_MASK;
} else {
dsp->rx_R = 0; if (dsp->cmx_delay)
dsp->rx_W = dsp->cmx_delay; else
dsp->rx_W = dsp_poll >> 1;
}
memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
} /* if we have reached double delay, jump back to middle */ if (dsp->cmx_delay) if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
(dsp->cmx_delay << 1)) { if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "cmx_receive(dsp=%lx): OVERRUN (because " "twice the delay is reached), adjusting " "read pointer! (inst %s)\n",
(u_long)dsp, dsp->name); /* flush buffer */ if (dsp->features.unordered) {
dsp->rx_R = (hh->id & CMX_BUFF_MASK);
dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
& CMX_BUFF_MASK;
} else {
dsp->rx_R = 0;
dsp->rx_W = dsp->cmx_delay;
}
memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
}
/* show where to write */ #ifdef CMX_DEBUG
printk(KERN_DEBUG "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
(u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name); #endif
/* write data into rx_buffer */
p = skb->data;
d = dsp->rx_buff;
w = dsp->rx_W;
i = 0;
ii = len; while (i < ii) {
d[w++ & CMX_BUFF_MASK] = *p++;
i++;
}
/* don't process if: */ if (!dsp->b_active) { /* if not active */
dsp->last_tx = 0; return;
} if (((dsp->conf && dsp->conf->hardware) || /* hardware conf */
dsp->echo.hardware) && /* OR hardware echo */
dsp->tx_R == dsp->tx_W && /* AND no tx-data */
!(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */ if (!dsp->tx_data) { /* no tx_data for user space required */
dsp->last_tx = 0; return;
} if (dsp->conf && dsp->conf->software && dsp->conf->hardware)
tx_data_only = 1; if (dsp->echo.software && dsp->echo.hardware)
tx_data_only = 1;
}
/* preload if we have delay set */ if (dsp->cmx_delay && !dsp->last_tx) {
preload = len; if (preload < 128)
preload = 128;
}
/* PREPARE RESULT */
nskb = mI_alloc_skb(len + preload, GFP_ATOMIC); if (!nskb) {
printk(KERN_ERR "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
len + preload); return;
}
hh = mISDN_HEAD_P(nskb);
hh->prim = PH_DATA_REQ;
hh->id = 0;
dsp->last_tx = 1;
/* set pointers, indexes and stuff */
member = dsp;
p = dsp->tx_buff; /* transmit data */
q = dsp->rx_buff; /* received data */
d = skb_put(nskb, preload + len); /* result */
t = dsp->tx_R; /* tx-pointers */
tt = dsp->tx_W;
r = dsp->rx_R; /* rx-pointers */
rr = (r + len) & CMX_BUFF_MASK;
/* preload with silence, if required */ if (preload) {
memset(d, dsp_silence, preload);
d += preload;
}
/* PROCESS TONES/TX-DATA ONLY */ if (dsp->tone.tone && dsp->tone.software) { /* -> copy tone */
dsp_tone_copy(dsp, d, len);
dsp->tx_R = 0; /* clear tx buffer */
dsp->tx_W = 0; goto send_packet;
} /* if we have tx-data but do not use mixing */ if (!dsp->tx_mix && t != tt) { /* -> send tx-data and continue when not enough */ #ifdef CMX_TX_DEBUG
sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p); #endif while (r != rr && t != tt) { #ifdef CMX_TX_DEBUG if (strlen(debugbuf) < 48)
sprintf(debugbuf + strlen(debugbuf), " %02x",
p[t]); #endif
*d++ = p[t]; /* write tx_buff */
t = (t + 1) & CMX_BUFF_MASK;
r = (r + 1) & CMX_BUFF_MASK;
} if (r == rr) {
dsp->tx_R = t; #ifdef CMX_TX_DEBUG
printk(KERN_DEBUG "%s\n", debugbuf); #endif goto send_packet;
}
} #ifdef CMX_TX_DEBUG
printk(KERN_DEBUG "%s\n", debugbuf); #endif
/* PROCESS DATA (one member / no conf) */ if (!conf || members <= 1) { /* -> if echo is NOT enabled */ if (!dsp->echo.software) { /* -> send tx-data if available or use 0-volume */ while (r != rr && t != tt) {
*d++ = p[t]; /* write tx_buff */
t = (t + 1) & CMX_BUFF_MASK;
r = (r + 1) & CMX_BUFF_MASK;
} if (r != rr) { if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "%s: RX empty\n",
__func__);
memset(d, dsp_silence, (rr - r) & CMX_BUFF_MASK);
} /* -> if echo is enabled */
} else { /* *->mixtx-datawithechoifavailable, *oruseechoonly
*/ while (r != rr && t != tt) {
*d++ = dsp_audio_mix_law[(p[t] << 8) | q[r]];
t = (t + 1) & CMX_BUFF_MASK;
r = (r + 1) & CMX_BUFF_MASK;
} while (r != rr) {
*d++ = q[r]; /* echo */
r = (r + 1) & CMX_BUFF_MASK;
}
}
dsp->tx_R = t; goto send_packet;
} /* PROCESS DATA (two members) */ #ifdef CMX_CONF_DEBUG if (0) { #else if (members == 2) { #endif /* "other" becomes other party */
other = (list_entry(conf->mlist.next, struct dsp_conf_member, list))->dsp; if (other == member)
other = (list_entry(conf->mlist.prev, struct dsp_conf_member, list))->dsp;
o_q = other->rx_buff; /* received data */
o_rr = (other->rx_R + len) & CMX_BUFF_MASK; /* end of rx-pointer */
o_r = (o_rr - rr + r) & CMX_BUFF_MASK; /* start rx-pointer at current read position*/ /* -> if echo is NOT enabled */ if (!dsp->echo.software) { /* *->copyothermember'srx-data, *iftx-dataisavailable,mix
*/ while (o_r != o_rr && t != tt) {
*d++ = dsp_audio_mix_law[(p[t] << 8) | o_q[o_r]];
t = (t + 1) & CMX_BUFF_MASK;
o_r = (o_r + 1) & CMX_BUFF_MASK;
} while (o_r != o_rr) {
*d++ = o_q[o_r];
o_r = (o_r + 1) & CMX_BUFF_MASK;
} /* -> if echo is enabled */
} else { /* *->mixothermember'srx-datawithecho, *iftx-dataisavailable,mix
*/ while (r != rr && t != tt) {
sample = dsp_audio_law_to_s32[p[t]] +
dsp_audio_law_to_s32[q[r]] +
dsp_audio_law_to_s32[o_q[o_r]]; if (sample < -32768)
sample = -32768; elseif (sample > 32767)
sample = 32767;
*d++ = dsp_audio_s16_to_law[sample & 0xffff]; /* tx-data + rx_data + echo */
t = (t + 1) & CMX_BUFF_MASK;
r = (r + 1) & CMX_BUFF_MASK;
o_r = (o_r + 1) & CMX_BUFF_MASK;
} while (r != rr) {
*d++ = dsp_audio_mix_law[(q[r] << 8) | o_q[o_r]];
r = (r + 1) & CMX_BUFF_MASK;
o_r = (o_r + 1) & CMX_BUFF_MASK;
}
}
dsp->tx_R = t; goto send_packet;
} /* PROCESS DATA (three or more members) */ /* -> if echo is NOT enabled */ if (!dsp->echo.software) { /* *->subtractrx-datafromconf-data, *iftx-dataisavailable,mix
*/ while (r != rr && t != tt) {
sample = dsp_audio_law_to_s32[p[t]] + *c++ -
dsp_audio_law_to_s32[q[r]]; if (sample < -32768)
sample = -32768; elseif (sample > 32767)
sample = 32767;
*d++ = dsp_audio_s16_to_law[sample & 0xffff]; /* conf-rx+tx */
r = (r + 1) & CMX_BUFF_MASK;
t = (t + 1) & CMX_BUFF_MASK;
} while (r != rr) {
sample = *c++ - dsp_audio_law_to_s32[q[r]]; if (sample < -32768)
sample = -32768; elseif (sample > 32767)
sample = 32767;
*d++ = dsp_audio_s16_to_law[sample & 0xffff]; /* conf-rx */
r = (r + 1) & CMX_BUFF_MASK;
} /* -> if echo is enabled */
} else { /* *->encodeconf-data,iftx-data *isavailable,mix
*/ while (r != rr && t != tt) {
sample = dsp_audio_law_to_s32[p[t]] + *c++; if (sample < -32768)
sample = -32768; elseif (sample > 32767)
sample = 32767;
*d++ = dsp_audio_s16_to_law[sample & 0xffff]; /* conf(echo)+tx */
t = (t + 1) & CMX_BUFF_MASK;
r = (r + 1) & CMX_BUFF_MASK;
} while (r != rr) {
sample = *c++; if (sample < -32768)
sample = -32768; elseif (sample > 32767)
sample = 32767;
*d++ = dsp_audio_s16_to_law[sample & 0xffff]; /* conf(echo) */
r = (r + 1) & CMX_BUFF_MASK;
}
}
dsp->tx_R = t; goto send_packet;
send_packet: /* *sendtx-dataifenabled-don'tfilter, *becausewewantwhatwesend,notwhatwefiltered
*/ if (dsp->tx_data) { if (tx_data_only) {
hh->prim = DL_DATA_REQ;
hh->id = 0; /* queue and trigger */
skb_queue_tail(&dsp->sendq, nskb);
schedule_work(&dsp->workq); /* exit because only tx_data is used */ return;
} else {
txskb = mI_alloc_skb(len, GFP_ATOMIC); if (!txskb) {
printk(KERN_ERR "FATAL ERROR in mISDN_dsp.o: " "cannot alloc %d bytes\n", len);
} else {
thh = mISDN_HEAD_P(txskb);
thh->prim = DL_DATA_REQ;
thh->id = 0;
skb_put_data(txskb, nskb->data + preload, len); /* queue (trigger later) */
skb_queue_tail(&dsp->sendq, txskb);
}
}
}
/* send data only to card, if we don't just calculated tx_data */ /* adjust volume */ if (dsp->tx_volume)
dsp_change_volume(nskb, dsp->tx_volume); /* pipeline */ if (dsp->pipeline.inuse)
dsp_pipeline_process_tx(&dsp->pipeline, nskb->data,
nskb->len); /* crypt */ if (dsp->bf_enable)
dsp_bf_encrypt(dsp, nskb->data, nskb->len); /* queue and trigger */
skb_queue_tail(&dsp->sendq, nskb);
schedule_work(&dsp->workq);
}
static u32 jittercount; /* counter for jitter check */ struct timer_list dsp_spl_tl; unsignedlong dsp_spl_jiffies; /* calculate the next time to fire */ static u16 dsp_count; /* last sample count */ staticint dsp_count_valid; /* if we have last sample count */
/* loop all members that do not require conference mixing */
list_for_each_entry(dsp, &dsp_ilist, list) { if (dsp->hdlc) continue;
conf = dsp->conf;
mustmix = 0;
members = 0; if (conf) {
members = list_count_nodes(&conf->mlist); #ifdef CMX_CONF_DEBUG if (conf->software && members > 1) #else if (conf->software && members > 2) #endif
mustmix = 1;
}
/* loop all members that require conference mixing */
list_for_each_entry(conf, &conf_ilist, list) { /* count members and check hardware */
members = list_count_nodes(&conf->mlist); #ifdef CMX_CONF_DEBUG if (conf->software && members > 1) { #else if (conf->software && members > 2) { #endif /* check for hdlc conf */
member = list_entry(conf->mlist.next, struct dsp_conf_member, list); if (member->dsp->hdlc) continue; /* mix all data */
memset(mixbuffer, 0, length * sizeof(s32));
list_for_each_entry(member, &conf->mlist, list) {
dsp = member->dsp; /* get range of data to mix */
c = mixbuffer;
q = dsp->rx_buff;
r = dsp->rx_R;
rr = (r + length) & CMX_BUFF_MASK; /* add member's data */ while (r != rr) {
*c++ += dsp_audio_law_to_s32[q[r]];
r = (r + 1) & CMX_BUFF_MASK;
}
}
/* process each member */
list_for_each_entry(member, &conf->mlist, list) { /* transmission */
dsp_cmx_send_member(member->dsp, length,
mixbuffer, members);
}
}
}
/* check current rx_delay */
delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK; if (delay >= CMX_BUFF_HALF)
delay = 0; /* will be the delay before next write */ /* check for lower delay */ if (delay < dsp->rx_delay[0])
dsp->rx_delay[0] = delay; /* check current tx_delay */
delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK; if (delay >= CMX_BUFF_HALF)
delay = 0; /* will be the delay before next write */ /* check for lower delay */ if (delay < dsp->tx_delay[0])
dsp->tx_delay[0] = delay; if (jittercheck) { /* find the lowest of all rx_delays */
delay = dsp->rx_delay[0];
i = 1; while (i < MAX_SECONDS_JITTER_CHECK) { if (delay > dsp->rx_delay[i])
delay = dsp->rx_delay[i];
i++;
} /* *removerx_delayonlyifwehavedelayANDwe *havenotpresetcmx_delayAND *thedelayisgreaterdsp_poll
*/ if (delay > dsp_poll && !dsp->cmx_delay) { if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "%s lowest rx_delay of %d bytes for" " dsp %s are now removed.\n",
__func__, delay,
dsp->name);
r = dsp->rx_R;
rr = (r + delay - (dsp_poll >> 1))
& CMX_BUFF_MASK; /* delete rx-data */ while (r != rr) {
p[r] = dsp_silence;
r = (r + 1) & CMX_BUFF_MASK;
} /* increment rx-buffer pointer */
dsp->rx_R = r; /* write incremented read pointer */
} /* find the lowest of all tx_delays */
delay = dsp->tx_delay[0];
i = 1; while (i < MAX_SECONDS_JITTER_CHECK) { if (delay > dsp->tx_delay[i])
delay = dsp->tx_delay[i];
i++;
} /* *removedelayonlyifwehavedelayANDwe *haveenabledtx_dejitter
*/ if (delay > dsp_poll && dsp->tx_dejitter) { if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "%s lowest tx_delay of %d bytes for" " dsp %s are now removed.\n",
__func__, delay,
dsp->name);
r = dsp->tx_R;
rr = (r + delay - (dsp_poll >> 1))
& CMX_BUFF_MASK; /* delete tx-data */ while (r != rr) {
q[r] = dsp_silence;
r = (r + 1) & CMX_BUFF_MASK;
} /* increment rx-buffer pointer */
dsp->tx_R = r; /* write incremented read pointer */
} /* scroll up delays */
i = MAX_SECONDS_JITTER_CHECK - 1; while (i) {
dsp->rx_delay[i] = dsp->rx_delay[i - 1];
dsp->tx_delay[i] = dsp->tx_delay[i - 1];
i--;
}
dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
}
}
/* if next event would be in the past ... */ if ((s32)(dsp_spl_jiffies + dsp_tics-jiffies) <= 0)
dsp_spl_jiffies = jiffies + 1; else
dsp_spl_jiffies += dsp_tics;
/* check if there is enough space, and then copy */
w = dsp->tx_W;
ww = dsp->tx_R;
p = dsp->tx_buff;
d = skb->data;
space = (ww - w - 1) & CMX_BUFF_MASK; /* write-pointer should not overrun nor reach read pointer */ if (space < skb->len) { /* write to the space we have left */
ww = (ww - 1) & CMX_BUFF_MASK; /* end one byte prior tx_R */ if (dsp_debug & DEBUG_DSP_CLOCK)
printk(KERN_DEBUG "%s: TX overflow space=%d skb->len=" "%d, w=0x%04x, ww=0x%04x\n", __func__, space,
skb->len, w, ww);
} else /* write until all byte are copied */
ww = (w + skb->len) & CMX_BUFF_MASK;
dsp->tx_W = ww; /* show current buffer */ #ifdef CMX_DEBUG
printk(KERN_DEBUG "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
(u_long)dsp, (ww - w) & CMX_BUFF_MASK, w, ww, dsp->name); #endif
/* copy transmit data to tx-buffer */ #ifdef CMX_TX_DEBUG
sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p); #endif while (w != ww) { #ifdef CMX_TX_DEBUG if (strlen(debugbuf) < 48)
sprintf(debugbuf + strlen(debugbuf), " %02x", *d); #endif
p[w] = *d++;
w = (w + 1) & CMX_BUFF_MASK;
} #ifdef CMX_TX_DEBUG
printk(KERN_DEBUG "%s\n", debugbuf); #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.