git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2458 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2006-08-30 19:46:43 +00:00
parent 2565f310cf
commit 9b9000a147
2 changed files with 56 additions and 9 deletions

View File

@ -80,6 +80,26 @@ static switch_status_t switch_g726_destroy(switch_codec_t *codec)
typedef int (*encoder_t)(int, int, g726_state *);
typedef int (*decoder_t)(int, int, g726_state *);
static void print_bits(uint8_t byte)
{
int i;
for (i=7;i>=0;i--) {
//for (i=0;i<=7;i++) {
if(byte & (1 << i)) {
printf("1");
} else {
printf("0");
}
}
}
static switch_status_t switch_g726_encode(switch_codec_t *codec,
switch_codec_t *other_codec,
void *decoded_data,
@ -132,15 +152,29 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
int edata = encoder(*ddp, AUDIO_ENCODING_LINEAR, context);
int bits = handle->bbits + handle->bits_per_frame;
handle->ecount++;
if (!handle->bbits) {
//printf("new byte assign the %d bits\n", handle->bits_per_frame);
*handle->ptr = edata;
} else if ((handle->bbits + handle->bits_per_frame) <= BITS_IN_A_BYTE) {
printf ("WTF %d\n", BITS_IN_A_BYTE - (handle->bits_per_frame * handle->ecount));
*handle->ptr += (edata << (BITS_IN_A_BYTE - (handle->bits_per_frame * handle->ecount)));
handle->ecount = 0;
} else if (bits <= BITS_IN_A_BYTE) {
int shift_by = ((handle->bits_per_frame * (handle->ecount)) - handle->bits_per_frame);
//printf ("shift by %d and add %d bits\n", shift_by, handle->bits_per_frame);
//*handle->ptr <<= shift_by;
//*handle->ptr |= edata;
if (shift_by);
//printf("edata\n");
//print_bits(edata);
//printf("\n");
*handle->ptr |= (edata << 4);
//printf("handle\n");
//print_bits(*handle->ptr);
//printf("\n");
} else {
int remain, next, rdata, ndata;
@ -155,9 +189,17 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
handle->bbits = 0;
handle->ecount = 0;
}
handle->bits += handle->bits_per_frame;
handle->bits = bits;
handle->bbits += handle->bits_per_frame;
if (0) {
for(x = 0; x < 5; x++) {
print_bits(handle->buf[x]);
printf(" ");
}
printf("\n");
}
if ((handle->bits % BITS_IN_A_BYTE) == 0) {
int bytes = handle->bits / BITS_IN_A_BYTE, count;
for(count = 0; count < bytes; count++) {
@ -165,6 +207,7 @@ static switch_status_t switch_g726_encode(switch_codec_t *codec,
}
handle->bits = handle->bbits = 0;
handle->ptr = handle->buf;
handle->ecount = 0;
memset(handle->buf, 0, sizeof(handle->buf));
}
ddp++;

View File

@ -317,8 +317,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_local_address(switch_rtp_t *rtp_s
}
if (rtp_session->sock) {
switch_socket_close(rtp_session->sock);
rtp_session->sock = NULL;
switch_rtp_kill_socket(rtp_session);
}
if (switch_socket_create(&rtp_session->sock, AF_INET, SOCK_DGRAM, 0, rtp_session->pool) != SWITCH_STATUS_SUCCESS) {
@ -541,8 +540,10 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_activate_ice(switch_rtp_t *rtp_sessio
SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session)
{
switch_mutex_lock(rtp_session->flag_mutex);
apr_socket_shutdown(rtp_session->sock, APR_SHUTDOWN_READWRITE);
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_IO);
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_IO);
switch_mutex_unlock(rtp_session->flag_mutex);
}
SWITCH_DECLARE(uint8_t) switch_rtp_ready(switch_rtp_t *rtp_session)
@ -557,8 +558,11 @@ SWITCH_DECLARE(void) switch_rtp_destroy(switch_rtp_t **rtp_session)
return;
}
switch_mutex_lock((*rtp_session)->flag_mutex);
switch_rtp_kill_socket(*rtp_session);
switch_socket_close((*rtp_session)->sock);
(*rtp_session)->sock = NULL;
switch_mutex_unlock((*rtp_session)->flag_mutex);
if (switch_test_flag((*rtp_session), SWITCH_RTP_FLAG_VAD)) {
switch_rtp_disable_vad(*rtp_session);