fix esf for g722

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7491 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-02-02 01:46:11 +00:00
parent 7561a30544
commit 480df2636d
2 changed files with 47 additions and 20 deletions

View File

@ -63,7 +63,7 @@ SWITCH_STANDARD_APP(bcast_function)
switch_status_t status;
switch_size_t bytes;
ls_control_packet_t control_packet;
switch_codec_t *read_codec;
switch_codec_t codec = { 0}, *read_codec, *orig_codec = NULL;
uint32_t flags = 0;
const char *err;
switch_rtp_t *rtp_session = NULL;
@ -139,15 +139,32 @@ SWITCH_STANDARD_APP(bcast_function)
goto fail;
}
if (read_frame->packet && read_frame->packetlen) {
if (read_frame->packet && read_frame->packetlen && read_codec->implementation->ianacode == 0) {
ready = SEND_TYPE_RAW;
} else {
ready = SEND_TYPE_RTP;
}
}
if (ready == SEND_TYPE_RTP) {
if (read_codec->implementation->ianacode != 0) {
if (switch_core_codec_init(&codec,
"PCMU",
NULL,
8000,
20,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
orig_codec = read_codec;
read_codec = &codec;
switch_core_session_set_read_codec(session, read_codec);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Activation Fail\n");
goto fail;
}
}
switch_find_local_ip(guess_ip, sizeof(guess_ip), AF_INET);
if (!(rtp_port = switch_rtp_request_port(guess_ip))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP Port Error\n");
@ -187,9 +204,14 @@ SWITCH_STANDARD_APP(bcast_function)
bytes = 16;
switch_socket_sendto(socket, control_packet_addr, 0, (void *)&control_packet, &bytes);
int fd;
fd = open("/tmp/wtf.ulaw", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
for(;;) {
if (write(fd, read_frame->data, read_frame->datalen));
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
@ -215,6 +237,11 @@ SWITCH_STANDARD_APP(bcast_function)
fail:
if (orig_codec) {
switch_core_session_set_read_codec(session, orig_codec);
switch_core_codec_destroy(&codec);
}
if (rtp_session && ready == SEND_TYPE_RTP && switch_rtp_ready(rtp_session)) {
switch_rtp_destroy(&rtp_session);
}

View File

@ -241,23 +241,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
goto done;
}
}
#if 0
if (session->read_resampler) {
short *data = read_frame->data;
switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
session->read_resampler->to_len =
switch_resample_process(session->read_resampler, session->read_resampler->from,
session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0);
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
read_frame->samples = session->read_resampler->to_len;
read_frame->datalen = session->read_resampler->to_len * 2;
read_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
}
#endif
if (session->bugs) {
switch_media_bug_t *bp, *dp, *last = NULL;
@ -311,6 +294,23 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
}
if (session->read_codec) {
if (session->read_resampler) {
short *data = read_frame->data;
switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
session->read_resampler->to_len =
switch_resample_process(session->read_resampler, session->read_resampler->from,
session->read_resampler->from_len, session->read_resampler->to, session->read_resampler->to_size, 0);
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
read_frame->samples = session->read_resampler->to_len;
read_frame->datalen = session->read_resampler->to_len * 2;
read_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
}
if ((*frame)->datalen == session->read_codec->implementation->bytes_per_frame) {
perfect = TRUE;
} else {