lib_LTLIBRARIES = libfreeswitch.la
libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g
libfreeswitch_la_LDFLAGS = -version-info 1:0:0
-libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3 -ljitterbuffer
+libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3
nodist_libfreeswitch_la_SOURCES = src/include/switch_version.h
bin_PROGRAMS = freeswitch
lib_LTLIBRARIES = libfreeswitch.la
libfreeswitch_la_CFLAGS = $(AM_CFLAGS) -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g
libfreeswitch_la_LDFLAGS = -version-info 1:0:0
-libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3 -ljitterbuffer
+libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3
nodist_libfreeswitch_la_SOURCES = src/include/switch_version.h
freeswitch_SOURCES = src/switch.c\
src/include/switch_version.h
*/
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts, switch_frame_flag *flags);
+/*!
+ \brief Write data to a given RTP session
+ \param rtp_session the RTP session to write to
+ \param frame the frame to write
+ \param ts then number of bytes to increment the timestamp by
+ \return the number of bytes written
+*/
+SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp *rtp_session, switch_frame *frame, uint32_t ts);
+
/*!
\brief Write data with a specified payload and sequence number to a given RTP session
\param rtp_session the RTP session to write to
tech_pvt->read_codec.codec_interface->ianacode,
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
ms,
- 0,
+ SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE,
key,
&err, switch_core_session_get_pool(tech_pvt->session));
return SWITCH_STATUS_TIMEOUT;
}
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_IO)) {
+ switch_status status;
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
return SWITCH_STATUS_GENERR;
tech_pvt->read_frame.datalen = 0;
- while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
- && tech_pvt->read_frame.datalen == 0) {
+ while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
now = switch_time_now();
tech_pvt->read_frame.flags = 0;
- if (switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame) != SWITCH_STATUS_SUCCESS) {
+
+ status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame);
+ if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
return SWITCH_STATUS_FALSE;
}
-
+
payload = tech_pvt->read_frame.payload;
+
if (timeout > -1) {
elapsed = (unsigned int)((switch_time_now() - started) / 1000);
if (elapsed >= (unsigned int)timeout) {
for (x = 0; x < loops; x++) {
+ frame->flags = 0;
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq, &frame->flags);
printf("Send %s packet for [%c] ts=%d sofar=%u dur=%d\n",
loops == 1 ? "middle" : "end",
ts = tech_pvt->timestamp_dtmf += samples;
tech_pvt->out_digit_seq++;
for (x = 0; x < 3; x++) {
+ frame->flags = 0;
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq, &frame->flags);
printf("Send start packet for [%c] ts=%d sofar=%u dur=%d\n", tech_pvt->out_digit, ts,
tech_pvt->out_digit_sofar, 0);
- //printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
+ //printf("%s %s->%s send %d bytes %d samples in %d frames ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, tech_pvt->timestamp_send);
-
- switch_rtp_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples, &frame->flags);
+ switch_rtp_write_frame(tech_pvt->rtp_session, frame, samples);
+
tech_pvt->timestamp_send += (int) samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
TFLAG_DTMF = (1 << 3),
TFLAG_VOICE = (1 << 4),
TFLAG_HANGUP = (1 << 5),
- TFLAG_LINEAR = (1 << 6)
+ TFLAG_LINEAR = (1 << 6),
+ TFLAG_CODEC = (1 << 7)
} TFLAGS;
typedef enum {
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
+ switch_set_flag(tech_pvt, TFLAG_CODEC);
}
tech_pvt->codec = chosen;
tech_pvt->codecs = local_cap;
static void iax_out_cb(const char *s)
{
- if (globals.debug) {
+ if (globals.debug > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_DEBUG, "IAX INFO: %s", s);
}
}
return SWITCH_STATUS_TERM;
}
- if (globals.debug) {
+ if (globals.debug > 1) {
iax_enable_debug();
}
if (iax_init(globals.ip, globals.port) < 0) {
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n",
- iaxevent->etype, IAXNAMES[iaxevent->etype]);
+ iaxevent->etype, IAXNAMES[iaxevent->etype]);
}
+
switch (iaxevent->etype) {
case IAX_EVENT_REGACK:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Registration completed successfully.\n");
if (tech_pvt) {
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
-
+
if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET) !=
SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "WTF? %u %u\n", iaxevent->ies.format,
if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n",
- switch_channel_get_name(channel));
+ switch_channel_get_name(channel));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n",
switch_channel_get_name(channel));
switch_channel *channel;
if (((channel = switch_core_session_get_channel(tech_pvt->session)) != 0)
&& switch_channel_get_state(channel) <= CS_HANGUP) {
- int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- int frames = (int) (tech_pvt->read_frame.datalen / bytes);
+ int bytes, frames;
+
+ if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
+ //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "audio with no codec yet!\n");
+ break;
+ }
+
+ bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
+ frames = (int) (tech_pvt->read_frame.datalen / bytes);
+
+
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
/* wake up the i/o thread */
/* read audio from 1 channel and write it to the other */
if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS && read_frame->datalen) {
-
-
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "write: %s Bad Frame....[%u] Bubye!\n", switch_channel_get_name(chan_b), read_frame->datalen);
data->running = -1;
!switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
!switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
((time(NULL) - start) < timelimit)) {
-
+
/* read from the channel while we wait if the audio is up on it */
if (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
if (switch_core_session_read_frame(session, &read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
break;
}
if (read_frame) {
- memset(read_frame->data, 0, read_frame->datalen);
+ //memset(read_frame->data, 0, read_frame->datalen);
if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
break;
}
} else {
switch_yield(1000);
}
+
}
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
msg.pointer_arg = peer_session;
switch_core_session_receive_message(session, &msg);
+
switch_core_session_launch_thread(peer_session, audio_bridge_thread, (void *) &other_audio_thread);
audio_bridge_thread(NULL, (void *) &this_audio_thread);
for(;;) {
bytes = sizeof(rtp_msg_t);
status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *)&rtp_session->recv_msg, &bytes);
-
+
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && rtp_session->from_addr->port != rtp_session->remote_port) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port to %u\n", rtp_session->from_addr->port);
rtp_session->remote_addr->port = rtp_session->from_addr->port;
if (bytes < 0) {
frame->datalen = 0;
return SWITCH_STATUS_GENERR;
+ } else if (bytes == 0) {
+ frame->datalen = 0;
+ return SWITCH_STATUS_BREAK;
} else {
bytes -= rtp_header_len;
}
static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint8_t payload, switch_frame_flag *flags)
{
switch_size_t bytes;
+ uint8_t packetize = (rtp_session->packet_size > datalen && (payload == rtp_session->payload)) ? 1 : 0;
uint8_t fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)) ? 1 : 0;
rtp_msg_t *send_msg;
} else {
send_msg = &rtp_session->send_msg;
send_msg->header.pt = rtp_session->payload;
- if (rtp_session->packet_size > datalen && (payload == rtp_session->payload)) {
+ if (packetize) {
if (!rtp_session->packet_buffer) {
if (switch_buffer_create(rtp_session->pool, &rtp_session->packet_buffer, rtp_session->packet_size * 2) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Buffer memory error\n");
}
+SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp *rtp_session, switch_frame *frame, uint32_t ts)
+{
+ uint8_t fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
+ uint8_t packetize = (rtp_session->packet_size > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
+ void *data;
+ uint32_t len;
+
+ if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
+ return -1;
+ }
+
+ if (fwd && !packetize) {
+ data = frame->packet;
+ len = frame->packetlen;
+ } else {
+ data = frame->data;
+ len = frame->datalen;
+ rtp_session->ts += ts;
+ rtp_session->seq = ntohs(rtp_session->seq) + 1;
+ rtp_session->seq = htons(rtp_session->seq);
+ rtp_session->send_msg.header.seq = rtp_session->seq;
+ rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
+ }
+
+ return rtp_common_write(rtp_session, data, len, rtp_session->payload, &frame->flags);
+
+}
+
SWITCH_DECLARE(int) switch_rtp_write_payload(switch_rtp *rtp_session, void *data, uint16_t datalen, uint8_t payload, uint32_t ts, uint16_t mseq, switch_frame_flag *flags)
{