[asterisk-addons-commits] mnicholson: branch mnicholson/chan-mobile-refactor r793 - /team/mnicholson/ch...
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Mon Feb 23 14:38:42 CST 2009
Author: mnicholson
Date: Mon Feb 23 14:38:42 2009
New Revision: 793
URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=793
Log:
use ast_smoother to get 48 byte frames instead of custom code
Modified:
team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
Modified: team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c
URL: http://svn.digium.com/svn-view/asterisk-addons/team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c?view=diff&rev=793&r1=792&r2=793
==============================================================================
--- team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c (original)
+++ team/mnicholson/chan-mobile-refactor/channels/chan_mobile.c Mon Feb 23 14:38:42 2009
@@ -151,9 +151,8 @@
int rfcomm_socket; /* rfcomm socket descriptor */
char rfcomm_buf[256];
char io_buf[CHANNEL_FRAME_SIZE + AST_FRIENDLY_OFFSET];
- char io_save_buf[DEVICE_FRAME_SIZE];
- int io_save_len;
int io_pipe[2];
+ struct ast_smoother *smoother; /* our smoother, for making 48 byte frames */
int sco_socket; /* sco socket descriptor */
enum mbl_state state; /* monitor thread current state */
pthread_t monitor_thread; /* monitor thread handle */
@@ -726,7 +725,6 @@
if (pvt->sco_socket != -1)
close(pvt->sco_socket);
pvt->sco_socket = -1;
- pvt->io_save_len = 0;
pvt->sent_answer = 0;
pvt->skip_frames = 0;
pvt->alignment_count = 0;
@@ -737,6 +735,7 @@
pvt->do_alignment_detection = 0;
pvt->do_hangup = 1;
+ ast_smoother_reset(pvt->smoother, DEVICE_FRAME_SIZE);
ast_dsp_digitreset(pvt->dsp);
chn = ast_channel_alloc(1, state, cid_num, pvt->id, 0, 0, pvt->context, 0, "Mobile/%s-%04lx", pvt->id, ast_random() & 0xffff);
@@ -981,8 +980,7 @@
{
struct mbl_pvt *pvt = ast->tech_pvt;
- int i, io_need, num_frames;
- char *pfr;
+ struct ast_frame *f;
ast_debug(2, "*** mbl_write\n");
@@ -990,24 +988,11 @@
return 0;
}
- io_need = 0;
- if (pvt->io_save_len > 0) {
- io_need = DEVICE_FRAME_SIZE - pvt->io_save_len;
- memcpy(pvt->io_save_buf + pvt->io_save_len, frame->data.ptr, io_need);
- sco_write(pvt->sco_socket, pvt->io_save_buf, DEVICE_FRAME_SIZE);
- }
-
- num_frames = (frame->datalen - io_need) / DEVICE_FRAME_SIZE;
- pfr = frame->data.ptr + io_need;
-
- for (i=0; i<num_frames; i++) {
- sco_write(pvt->sco_socket, pfr, DEVICE_FRAME_SIZE);
- pfr += DEVICE_FRAME_SIZE;
- }
-
- pvt->io_save_len = (frame->datalen - io_need) - (num_frames * DEVICE_FRAME_SIZE);
- if (pvt->io_save_len > 0) {
- memcpy(pvt->io_save_buf, pfr, pvt->io_save_len);
+ ast_smoother_feed(pvt->smoother, frame);
+
+ while ((f = ast_smoother_read(pvt->smoother))) {
+ sco_write(pvt->sco_socket, f->data.ptr, f->datalen);
+ ast_frfree(f);
}
return 0;
@@ -3138,10 +3123,16 @@
pvt->sco_socket = -1;
pvt->monitor_thread = AST_PTHREADT_NULL;
+ /* setup the smoother */
+ if (!(pvt->smoother = ast_smoother_new(DEVICE_FRAME_SIZE))) {
+ ast_log(LOG_ERROR, "Skipping device %s. Error setting up frame smoother.\n", cat);
+ goto e_free_pvt;
+ }
+
/* setup the dsp */
if (!(pvt->dsp = ast_dsp_new())) {
ast_log(LOG_ERROR, "Skipping device %s. Error setting up dsp for dtmf detection.\n", cat);
- goto e_free_pvt;
+ goto e_free_smoother;
}
ast_dsp_set_features(pvt->dsp, DSP_FEATURE_DIGIT_DETECT);
@@ -3192,6 +3183,8 @@
e_free_dsp:
ast_dsp_free(pvt->dsp);
+e_free_smoother:
+ ast_smoother_free(pvt->smoother);
e_free_pvt:
ast_free(pvt);
e_return:
@@ -3318,6 +3311,7 @@
ast_free(pvt->hfp);
}
+ ast_smoother_free(pvt->smoother);
ast_dsp_free(pvt->dsp);
ast_free(pvt);
}
More information about the asterisk-addons-commits
mailing list