提交 021ea0e7 authored 作者: Anthony Minessale's avatar Anthony Minessale

update

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1181 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 c0ac7216
......@@ -118,7 +118,7 @@ CLEANFILES = src/include/switch_version.h
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
libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3 -ljitterbuffer
nodist_libfreeswitch_la_SOURCES = src/include/switch_version.h
bin_PROGRAMS = freeswitch
......@@ -156,6 +156,7 @@ depends:
./build/buildlib.sh . libresample-0.1.3.tgz --prefix=$(PREFIX)
./build/buildlib.sh . install libteletone --prefix=$(PREFIX)
./build/buildlib.sh . install srtp --prefix=$(PREFIX)
./build/buildlib.sh . install jitterbuffer --prefix=$(PREFIX)
rm build/freeswitch.env
......
......@@ -333,7 +333,7 @@ CLEANFILES = src/include/switch_version.h
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
libfreeswitch_la_LIBADD = -lteletone -lresample -lsrtp -lsqlite3 -ljitterbuffer
nodist_libfreeswitch_la_SOURCES = src/include/switch_version.h
freeswitch_SOURCES = src/switch.c\
src/include/switch_version.h
......@@ -1056,6 +1056,7 @@ depends:
./build/buildlib.sh . libresample-0.1.3.tgz --prefix=$(PREFIX)
./build/buildlib.sh . install libteletone --prefix=$(PREFIX)
./build/buildlib.sh . install srtp --prefix=$(PREFIX)
./build/buildlib.sh . install jitterbuffer --prefix=$(PREFIX)
rm build/freeswitch.env
modules: $(NAME)
......
差异被折叠。
差异被折叠。
......@@ -46,6 +46,12 @@ extern "C" {
struct switch_frame {
/*! a pointer to the codec information */
switch_codec *codec;
/*! the originating source of the frame */
const char *source;
/*! the raw packet */
void *packet;
/*! the size of the raw packet when applicable*/
uint32_t packetlen;
/*! the frame data */
void *data;
/*! the size of the buffer that is in use */
......@@ -56,6 +62,10 @@ struct switch_frame {
uint32_t samples;
/*! the rate of the frame */
uint32_t rate;
/*! the payload of the frame */
uint32_t payload;
/*! the timestamp of the frame */
uint32_t timestamp;
/*! frame flags */
switch_frame_flag flags;
};
......
......@@ -244,15 +244,24 @@ SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp *rtp_session, void *dat
*/
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags);
/*!
\brief Read data from a given RTP session without copying
\param rtp_session the RTP session to read from
\param frame a frame to populate with information
\return the number of bytes read
*/
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read_frame(switch_rtp *rtp_session, switch_frame *frame);
/*!
\brief Write data to a given RTP session
\param rtp_session the RTP session to write to
\param data data to write
\param datalen the size of the data
\param ts then number of bytes to increment the timestamp by
\param flags frame flags
\return the number of bytes written
*/
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts);
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 with a specified payload and sequence number to a given RTP session
......@@ -262,9 +271,10 @@ SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32
\param payload the IANA payload number
\param ts then number of bytes to increment the timestamp by
\param mseq the specific sequence number to use
\param flags frame flags
\return the number of bytes written
*/
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_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);
/*!
\brief Retrieve the SSRC from a given RTP session
......
......@@ -103,6 +103,7 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
SWITCH_RTP_FLAG_USE_TIMER - Timeout Reads and replace with a CNG Frame
SWITCH_RTP_FLAG_SECURE - Secure RTP
SWITCH_RTP_FLAG_AUTOADJ - Auto-Adjust the dest based on the source
SWITCH_RTP_FLAG_RAW_WRITE - Try to forward packets unscathed
</pre>
*/
typedef enum {
......@@ -110,7 +111,8 @@ typedef enum {
SWITCH_RTP_FLAG_IO = (1 << 1),
SWITCH_RTP_FLAG_USE_TIMER = (1 << 2),
SWITCH_RTP_FLAG_SECURE = (1 << 3),
SWITCH_RTP_FLAG_AUTOADJ = (1 << 4)
SWITCH_RTP_FLAG_AUTOADJ = (1 << 4),
SWITCH_RTP_FLAG_RAW_WRITE = (1 << 5)
} switch_rtp_flag_t;
/*!
......@@ -316,11 +318,13 @@ typedef enum {
\brief Frame Flags
<pre>
CF_CNG = (1 << 0) - Frame represents comfort noise
SFF_CNG = (1 << 0) - Frame represents comfort noise
SFF_RAW_RTP = (1 << 1) - Frame has raw rtp accessible
</pre>
*/
typedef enum {
SFF_CNG = (1 << 0)
SFF_CNG = (1 << 0),
SFF_RAW_RTP = (1 << 1)
} switch_frame_flag;
......
......@@ -815,7 +815,7 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
for (x = 0; x < loops; x++) {
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
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", tech_pvt->out_digit, ts,
tech_pvt->out_digit_sofar, duration);
......@@ -840,7 +840,7 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
ts = tech_pvt->timestamp_dtmf += samples;
tech_pvt->out_digit_seq++;
for (x = 0; x < 3; x++) {
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
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);
......@@ -858,7 +858,7 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
//printf("%s send %d bytes %d samples in %d frames ts=%d\n", switch_channel_get_name(channel), frame->datalen, samples, frames, tech_pvt->timestamp_send);
if (switch_rtp_write(tech_pvt->rtp_session, frame->data, frame->datalen, samples) < 0) {
if (switch_rtp_write(tech_pvt->rtp_session, frame->data, frame->datalen, samples, &frame->flags) < 0) {
return SWITCH_STATUS_FALSE;
}
tech_pvt->timestamp_send += (int) samples;
......
......@@ -604,15 +604,12 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
&& tech_pvt->read_frame.datalen == 0) {
now = switch_time_now();
tech_pvt->read_frame.flags = 0;
if (switch_rtp_zerocopy_read(tech_pvt->rtp_session,
&tech_pvt->read_frame.data,
&tech_pvt->read_frame.datalen,
&payload,
&tech_pvt->read_frame.flags) != SWITCH_STATUS_SUCCESS) {
if (switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame) != SWITCH_STATUS_SUCCESS) {
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) {
......@@ -735,7 +732,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
for (x = 0; x < loops; x++) {
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
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",
tech_pvt->out_digit,
......@@ -762,7 +759,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
ts = tech_pvt->timestamp_dtmf += samples;
tech_pvt->out_digit_seq++;
for (x = 0; x < 3; x++) {
switch_rtp_write_payload(tech_pvt->rtp_session, tech_pvt->out_digit_packet, 4, 101, ts, tech_pvt->out_digit_seq);
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);
}
......@@ -776,7 +773,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
//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);
switch_rtp_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
switch_rtp_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples, &frame->flags);
tech_pvt->timestamp_send += (int) samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
......
......@@ -487,7 +487,7 @@ SWITCH_DECLARE(void) switch_rtp_clear_flag(switch_rtp *rtp_session, switch_rtp_f
}
static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_type, switch_frame_flag *flags)
static int rtp_common_read(switch_rtp *rtp_session, int *payload_type, switch_frame_flag *flags)
{
switch_size_t bytes;
switch_status status;
......@@ -566,17 +566,19 @@ static int rtp_common_read(switch_rtp *rtp_session, void *data, int *payload_typ
*flags |= SFF_CNG;
}
return (int)(bytes - rtp_header_len);
return (int) bytes;
}
SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp *rtp_session, void *data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags)
{
int bytes = rtp_common_read(rtp_session, data, payload_type, flags);
int bytes = rtp_common_read(rtp_session, payload_type, flags);
if (bytes < 0) {
*datalen = 0;
return SWITCH_STATUS_GENERR;
} else {
bytes -= rtp_header_len;
}
*datalen = bytes;
......@@ -586,58 +588,91 @@ SWITCH_DECLARE(switch_status) switch_rtp_read(switch_rtp *rtp_session, void *dat
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read_frame(switch_rtp *rtp_session, switch_frame *frame)
{
int bytes = rtp_common_read(rtp_session, &frame->payload, &frame->flags);
frame->data = rtp_session->recv_msg.body;
frame->packet = &rtp_session->recv_msg;
frame->packetlen = bytes;
frame->source = __FILE__;
frame->flags |= SFF_RAW_RTP;
if (bytes < 0) {
frame->datalen = 0;
return SWITCH_STATUS_GENERR;
} else {
bytes -= rtp_header_len;
}
frame->datalen = bytes;
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status) switch_rtp_zerocopy_read(switch_rtp *rtp_session, void **data, uint32_t *datalen, int *payload_type, switch_frame_flag *flags)
{
int bytes = rtp_common_read(rtp_session, data, payload_type, flags);
int bytes = rtp_common_read(rtp_session, payload_type, flags);
*data = rtp_session->recv_msg.body;
if (bytes < 0) {
*datalen = 0;
return SWITCH_STATUS_GENERR;
} else {
bytes -= rtp_header_len;
}
*datalen = bytes;
return SWITCH_STATUS_SUCCESS;
}
static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint8_t payload)
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 fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)) ? 1 : 0;
rtp_msg_t *send_msg;
if (rtp_session->packet_size > datalen && (payload == rtp_session->payload)) {
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");
return -1;
if (fwd) {
bytes = datalen;
send_msg = (rtp_msg_t *) data;
} 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 (!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");
return -1;
}
}
switch_buffer_write(rtp_session->packet_buffer, data, datalen);
if (switch_buffer_inuse(rtp_session->packet_buffer) >= rtp_session->packet_size) {
switch_buffer_read(rtp_session->packet_buffer, send_msg->body, rtp_session->packet_size);
datalen = rtp_session->packet_size;
} else {
return datalen;
}
}
switch_buffer_write(rtp_session->packet_buffer, data, datalen);
if (switch_buffer_inuse(rtp_session->packet_buffer) >= rtp_session->packet_size) {
switch_buffer_read(rtp_session->packet_buffer, rtp_session->send_msg.body, rtp_session->packet_size);
datalen = rtp_session->packet_size;
} else {
return datalen;
memcpy(send_msg->body, data, datalen);
}
} else {
memcpy(rtp_session->send_msg.body, data, datalen);
bytes = datalen + rtp_header_len;
}
bytes = datalen + rtp_header_len;
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
int sbytes = (int)bytes;
err_status_t stat;
stat = srtp_protect(rtp_session->send_ctx, &rtp_session->send_msg.header, &sbytes);
stat = srtp_protect(rtp_session->send_ctx, &send_msg->header, &sbytes);
if (stat) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error: srtp unprotection failed with code %d\n", stat);
}
bytes = sbytes;
}
rtp_session->send_msg.header.pt = rtp_session->payload;
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)&rtp_session->send_msg, &bytes);
switch_socket_sendto(rtp_session->sock, rtp_session->remote_addr, 0, (void*)send_msg, &bytes);
if (rtp_session->ice_user) {
if (ice_out(rtp_session) != SWITCH_STATUS_SUCCESS) {
return -1;
......@@ -648,7 +683,7 @@ static int rtp_common_write(switch_rtp *rtp_session, void *data, uint32_t datale
}
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts)
SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32_t datalen, uint32_t ts, switch_frame_flag *flags)
{
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
......@@ -661,11 +696,11 @@ SWITCH_DECLARE(int) switch_rtp_write(switch_rtp *rtp_session, void *data, uint32
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, datalen, rtp_session->payload);
return rtp_common_write(rtp_session, data, datalen, rtp_session->payload, 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_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)
{
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
......@@ -676,7 +711,7 @@ SWITCH_DECLARE(int) switch_rtp_write_payload(switch_rtp *rtp_session, void *data
rtp_session->send_msg.header.seq = htons(mseq);
rtp_session->send_msg.header.ts = htonl(rtp_session->ts);
return rtp_common_write(rtp_session, data, datalen, payload);
return rtp_common_write(rtp_session, data, datalen, payload, flags);
}
SWITCH_DECLARE(uint32_t) switch_rtp_get_ssrc(switch_rtp *rtp_session)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论