mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-06 10:26:41 +00:00
add non-blocking reads to mod_sangoma_codec
This commit is contained in:
parent
aa0751366a
commit
bfe2f22b38
@ -126,6 +126,9 @@ struct codec_data {
|
|||||||
long lastrxseqno;
|
long lastrxseqno;
|
||||||
unsigned long rxlost;
|
unsigned long rxlost;
|
||||||
|
|
||||||
|
/* discarded silence packets */
|
||||||
|
unsigned long rxdiscarded;
|
||||||
|
|
||||||
/* avg Rx time */
|
/* avg Rx time */
|
||||||
switch_time_t avgrxus;
|
switch_time_t avgrxus;
|
||||||
switch_time_t last_rx_time;
|
switch_time_t last_rx_time;
|
||||||
@ -400,26 +403,31 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
|||||||
sess->encoder.tx++;
|
sess->encoder.tx++;
|
||||||
|
|
||||||
/* do the reading */
|
/* do the reading */
|
||||||
memset(&encoded_frame, 0, sizeof(encoded_frame));
|
for ( ; ; ) {
|
||||||
sres = switch_rtp_zerocopy_read_frame(sess->encoder.rxrtp, &encoded_frame, SWITCH_IO_FLAG_NOBLOCK);
|
sres = switch_rtp_zerocopy_read_frame(sess->encoder.rxrtp, &encoded_frame, SWITCH_IO_FLAG_NOBLOCK);
|
||||||
if (sres == SWITCH_STATUS_GENERR) {
|
if (sres == SWITCH_STATUS_GENERR) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to read on Sangoma encoder RTP session: %d\n", sres);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to read on Sangoma encoder RTP session: %d\n", sres);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == encoded_frame.datalen) {
|
if (0 == encoded_frame.datalen) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on Sangoma encoder RTP session.\n");
|
break;
|
||||||
return SWITCH_STATUS_SUCCESS;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (encoded_frame.payload != codec->implementation->ianacode
|
if (encoded_frame.payload != codec->implementation->ianacode
|
||||||
&& encoded_frame.payload != IANACODE_CN) {
|
&& encoded_frame.payload != IANACODE_CN) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read unexpected payload %d in Sangoma encoder RTP session, expecting %d\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read unexpected payload %d in Sangoma encoder RTP session, expecting %d\n",
|
||||||
encoded_frame.payload, codec->implementation->ianacode);
|
encoded_frame.payload, codec->implementation->ianacode);
|
||||||
return SWITCH_STATUS_FALSE;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*encoded_data_len) {
|
||||||
|
sess->encoder.rxdiscarded++;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(encoded_data, encoded_frame.data, encoded_frame.datalen);
|
||||||
|
*encoded_data_len = encoded_frame.datalen;
|
||||||
}
|
}
|
||||||
memcpy(encoded_data, encoded_frame.data, encoded_frame.datalen);
|
|
||||||
*encoded_data_len = encoded_frame.datalen;
|
|
||||||
|
|
||||||
/* update encoding stats */
|
/* update encoding stats */
|
||||||
sess->encoder.rx++;
|
sess->encoder.rx++;
|
||||||
@ -513,30 +521,34 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses
|
|||||||
sess->decoder.tx++;
|
sess->decoder.tx++;
|
||||||
|
|
||||||
/* do the reading */
|
/* do the reading */
|
||||||
memset(&ulaw_frame, 0, sizeof(ulaw_frame));
|
for ( ; ; ) {
|
||||||
sres = switch_rtp_zerocopy_read_frame(sess->decoder.rxrtp, &ulaw_frame, SWITCH_IO_FLAG_NOBLOCK);
|
sres = switch_rtp_zerocopy_read_frame(sess->decoder.rxrtp, &ulaw_frame, SWITCH_IO_FLAG_NOBLOCK);
|
||||||
if (sres == SWITCH_STATUS_GENERR) {
|
if (sres == SWITCH_STATUS_GENERR) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to read on Sangoma decoder RTP session: %d\n", sres);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to read on Sangoma decoder RTP session: %d\n", sres);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == ulaw_frame.datalen) {
|
if (0 == ulaw_frame.datalen) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No output on Sangoma decoder RTP session.\n");
|
break;
|
||||||
return SWITCH_STATUS_SUCCESS;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ulaw_frame.payload != IANA_ULAW
|
if (ulaw_frame.payload != IANA_ULAW
|
||||||
&& ulaw_frame.payload != IANACODE_CN) {
|
&& ulaw_frame.payload != IANACODE_CN) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read unexpected payload %d in Sangoma decoder RTP session, expecting %d\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read unexpected payload %d in Sangoma decoder RTP session, expecting %d\n",
|
||||||
ulaw_frame.payload, IANA_ULAW);
|
ulaw_frame.payload, IANA_ULAW);
|
||||||
return SWITCH_STATUS_FALSE;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* transcode to linear */
|
if (*decoded_data_len) {
|
||||||
for (i = 0; i < ulaw_frame.datalen; i++) {
|
sess->decoder.rxdiscarded++;
|
||||||
dbuf_linear[i] = ulaw_to_linear(((char *)ulaw_frame.data)[i]);
|
}
|
||||||
|
|
||||||
|
/* transcode to linear */
|
||||||
|
for (i = 0; i < ulaw_frame.datalen; i++) {
|
||||||
|
dbuf_linear[i] = ulaw_to_linear(((char *)ulaw_frame.data)[i]);
|
||||||
|
}
|
||||||
|
*decoded_data_len = i * 2;
|
||||||
}
|
}
|
||||||
*decoded_data_len = i * 2;
|
|
||||||
|
|
||||||
/* update decoding stats */
|
/* update decoding stats */
|
||||||
sess->decoder.rx++;
|
sess->decoder.rx++;
|
||||||
@ -708,6 +720,7 @@ SWITCH_STANDARD_API(sangoma_function)
|
|||||||
if (sess->encoder.rxrtp) {
|
if (sess->encoder.rxrtp) {
|
||||||
stats = switch_rtp_get_stats(sess->encoder.rxrtp, NULL);
|
stats = switch_rtp_get_stats(sess->encoder.rxrtp, NULL);
|
||||||
stream->write_function(stream, "-- Encoder Inbound Stats --\n");
|
stream->write_function(stream, "-- Encoder Inbound Stats --\n");
|
||||||
|
stream->write_function(stream, "Rx Discarded: %lu\n", sess->encoder.rxdiscarded);
|
||||||
sangoma_print_stats(stream, &stats->inbound);
|
sangoma_print_stats(stream, &stats->inbound);
|
||||||
|
|
||||||
|
|
||||||
@ -719,6 +732,7 @@ SWITCH_STANDARD_API(sangoma_function)
|
|||||||
if (sess->decoder.rxrtp) {
|
if (sess->decoder.rxrtp) {
|
||||||
stats = switch_rtp_get_stats(sess->decoder.rxrtp, NULL);
|
stats = switch_rtp_get_stats(sess->decoder.rxrtp, NULL);
|
||||||
stream->write_function(stream, "-- Decoder Inbound Stats --\n");
|
stream->write_function(stream, "-- Decoder Inbound Stats --\n");
|
||||||
|
stream->write_function(stream, "Rx Discarded: %lu\n", sess->decoder.rxdiscarded);
|
||||||
sangoma_print_stats(stream, &stats->inbound);
|
sangoma_print_stats(stream, &stats->inbound);
|
||||||
|
|
||||||
stats = switch_rtp_get_stats(sess->decoder.txrtp, NULL);
|
stats = switch_rtp_get_stats(sess->decoder.txrtp, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user