fix for everyone

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5489 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-07-02 20:17:10 +00:00
parent 51fe761840
commit 88053d9740
4 changed files with 36 additions and 8 deletions

View File

@ -55,8 +55,9 @@ static switch_status_t switch_raw_encode(switch_codec_t *codec,
uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate,
unsigned int *flag)
{
printf("WTF %d %d\n", codec->implementation->samples_per_second , other_codec->implementation->samples_per_second );
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
if (codec && other_codec && codec->implementation && other_codec->implementation && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(encoded_data, decoded_data, decoded_data_len);
*encoded_data_len = decoded_data_len;
return SWITCH_STATUS_RESAMPLE;
@ -71,7 +72,7 @@ static switch_status_t switch_raw_decode(switch_codec_t *codec,
uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate,
unsigned int *flag)
{
if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
if (codec && other_codec && codec->implementation && other_codec->implementation && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(decoded_data, encoded_data, encoded_data_len);
*decoded_data_len = encoded_data_len;
return SWITCH_STATUS_RESAMPLE;

View File

@ -756,7 +756,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
free(sql);
sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
assert(sql != NULL);
sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
free(sql);
@ -775,6 +775,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
switch_safe_free(sstr);
if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", to_user, to_host, to_user, to_host))) {

View File

@ -94,7 +94,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
{
switch_io_event_hook_read_frame_t *ptr;
switch_status_t status;
int need_codec, perfect, do_bugs = 0;
int need_codec, perfect, do_bugs = 0, do_resample = 0;
unsigned int flag = 0;
top:
@ -149,6 +149,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
goto done;
}
if ((*frame)->codec->implementation->samples_per_second != session->write_codec->implementation->samples_per_second) {
do_resample = 1;
}
if (session->bugs && !need_codec) {
do_bugs = 1;
need_codec = 1;
@ -166,6 +170,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
session->read_codec->implementation->samples_per_second,
session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate, &flag);
if (do_resample && status == SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_RESAMPLE;
}
switch (status) {
case SWITCH_STATUS_RESAMPLE:
if (!session->read_resampler) {
@ -384,7 +392,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
switch_status_t status = SWITCH_STATUS_FALSE;
switch_frame_t *enc_frame = NULL, *write_frame = frame;
unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0;
unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0, do_resample = 0;
switch_io_flag_t io_flag = SWITCH_IO_FLAG_NOOP;
assert(session != NULL);
@ -423,6 +431,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
need_codec = 1;
}
if (frame->codec->implementation->samples_per_second != session->read_codec->implementation->samples_per_second) {
need_codec = 1;
do_resample = 1;
}
if (need_codec) {
if (frame->codec) {
session->raw_write_frame.datalen = session->raw_write_frame.buflen;
@ -434,6 +447,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag);
if (do_resample && status == SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_RESAMPLE;
}
switch (status) {
case SWITCH_STATUS_RESAMPLE:
write_frame = &session->raw_write_frame;
@ -570,7 +589,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
}
}
if (perfect) {
enc_frame = write_frame;
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
@ -630,16 +648,24 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
for (x = 0; x < frames; x++) {
if ((session->raw_write_frame.datalen = (uint32_t)
switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes)) != 0) {
int rate;
enc_frame = &session->raw_write_frame;
session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
if (frame->codec && frame->codec->implementation) {
rate = frame->codec->implementation->samples_per_second;
} else {
rate = session->write_codec->implementation->samples_per_second;
}
printf("WTF %d %d %d\n", rate, enc_frame->datalen, session->enc_write_frame.datalen);
status = switch_core_codec_encode(session->write_codec,
frame->codec,
enc_frame->data,
enc_frame->datalen,
frame->codec->implementation->samples_per_second,
rate,
session->enc_write_frame.data,
&session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);

View File

@ -187,7 +187,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj)
switch_core_session_receive_message(session_a, &msg);
switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK);
switch_core_session_reset(session_a);
switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a));
switch_channel_clear_flag(chan_a, CF_BRIDGED);