Changeset 646 for pjproject/trunk/pjmedia/src/pjmedia/aec_port.c
- Timestamp:
- Aug 4, 2006 11:08:00 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/aec_port.c
r643 r646 18 18 */ 19 19 #include <pjmedia/aec_port.h> 20 #include "../pjmedia-codec/speex/speex_echo.h"20 #include <pjmedia/aec.h> 21 21 #include <pjmedia/errno.h> 22 22 #include <pj/assert.h> … … 27 27 #define THIS_FILE "aec_port.c" 28 28 #define SIGNATURE PJMEDIA_PORT_SIGNATURE('A', 'E', 'C', ' ') 29 #define BUF_COUNT 32 29 30 30 31 struct aec_port 31 struct aec 32 32 { 33 33 pjmedia_port base; 34 34 pjmedia_port *dn_port; 35 SpeexEchoState *state; 36 pj_int16_t *tmp_frame; 37 pj_bool_t has_frame; 38 pj_int16_t *last_frame; 35 pjmedia_aec *aec; 39 36 }; 40 37 … … 53 50 { 54 51 const pj_str_t AEC = { "AEC", 3 }; 55 struct aec _port *aec_port;56 int sampling_rate;52 struct aec *aec; 53 pj_status_t status; 57 54 58 55 PJ_ASSERT_RETURN(pool && dn_port && p_port, PJ_EINVAL); … … 60 57 PJ_EINVAL); 61 58 62 /* Create and initialize the port*/63 aec _port = pj_pool_zalloc(pool, sizeof(struct aec_port));59 /* Create the port and the AEC itself */ 60 aec = pj_pool_zalloc(pool, sizeof(struct aec)); 64 61 65 pjmedia_port_info_init(&aec _port->base.info, &AEC, SIGNATURE,62 pjmedia_port_info_init(&aec->base.info, &AEC, SIGNATURE, 66 63 dn_port->info.clock_rate, 67 64 dn_port->info.channel_count, … … 69 66 dn_port->info.samples_per_frame); 70 67 71 aec_port->state = speex_echo_state_init(dn_port->info.samples_per_frame, 72 tail_length); 73 74 /* Set sampling rate */ 75 sampling_rate = 0; 76 speex_echo_ctl(aec_port->state, SPEEX_ECHO_GET_SAMPLING_RATE, 77 &sampling_rate); 78 sampling_rate = dn_port->info.clock_rate; 79 speex_echo_ctl(aec_port->state, SPEEX_ECHO_SET_SAMPLING_RATE, 80 &sampling_rate); 68 status = pjmedia_aec_create(pool, dn_port->info.clock_rate, 69 dn_port->info.samples_per_frame, 70 tail_length, 0, &aec->aec); 71 if (status != PJ_SUCCESS) 72 return status; 81 73 82 74 /* More init */ 83 aec_port->dn_port = dn_port; 84 aec_port->base.get_frame = &aec_get_frame; 85 aec_port->base.put_frame = &aec_put_frame; 86 aec_port->base.on_destroy = &aec_on_destroy; 87 88 aec_port->last_frame = pj_pool_zalloc(pool, sizeof(pj_int16_t) * 89 dn_port->info.samples_per_frame); 90 aec_port->tmp_frame = pj_pool_zalloc(pool, sizeof(pj_int16_t) * 91 dn_port->info.samples_per_frame); 75 aec->dn_port = dn_port; 76 aec->base.get_frame = &aec_get_frame; 77 aec->base.put_frame = &aec_put_frame; 78 aec->base.on_destroy = &aec_on_destroy; 92 79 93 80 /* Done */ 94 *p_port = &aec _port->base;81 *p_port = &aec->base; 95 82 96 PJ_LOG(4,(THIS_FILE, "AEC created for port %.*s, clock_rate=%d, "97 "samples per frame=%d, tail length=%d ms",98 (int)dn_port->info.name.slen,99 dn_port->info.name.ptr,100 dn_port->info.clock_rate,101 dn_port->info.samples_per_frame,102 tail_length * 1000 / dn_port->info.clock_rate));103 83 return PJ_SUCCESS; 104 84 } … … 108 88 const pjmedia_frame *frame) 109 89 { 110 struct aec _port *aec_port = (struct aec_port*)this_port;90 struct aec *aec = (struct aec*)this_port; 111 91 112 92 PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, PJ_EINVAL); 113 93 114 if (frame->type == PJMEDIA_FRAME_TYPE_NONE || !aec_port->has_frame) {115 return pjmedia_port_put_frame(aec _port->dn_port, frame);94 if (frame->type == PJMEDIA_FRAME_TYPE_NONE ) { 95 return pjmedia_port_put_frame(aec->dn_port, frame); 116 96 } 117 97 … … 119 99 PJ_EINVAL); 120 100 121 speex_echo_cancel(aec_port->state, 122 (const spx_int16_t*)frame->buf, 123 (const spx_int16_t*)aec_port->last_frame, 124 (spx_int16_t*)aec_port->tmp_frame, 125 NULL); 101 pjmedia_aec_capture(aec->aec, frame->buf, 0); 126 102 127 pjmedia_copy_samples(frame->buf, aec_port->tmp_frame, 128 this_port->info.samples_per_frame); 129 130 return pjmedia_port_put_frame(aec_port->dn_port, frame); 103 return pjmedia_port_put_frame(aec->dn_port, frame); 131 104 } 132 105 … … 135 108 pjmedia_frame *frame) 136 109 { 137 struct aec _port *aec_port = (struct aec_port*)this_port;110 struct aec *aec = (struct aec*)this_port; 138 111 pj_status_t status; 139 112 140 113 PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, PJ_EINVAL); 141 114 142 status = pjmedia_port_get_frame(aec_port->dn_port, frame); 143 if (status==PJ_SUCCESS && frame->type==PJMEDIA_FRAME_TYPE_AUDIO) { 144 aec_port->has_frame = PJ_TRUE; 145 pjmedia_copy_samples(aec_port->tmp_frame, frame->buf, 146 this_port->info.samples_per_frame); 147 } else { 148 aec_port->has_frame = PJ_FALSE; 115 status = pjmedia_port_get_frame(aec->dn_port, frame); 116 if (status!=PJ_SUCCESS || frame->type!=PJMEDIA_FRAME_TYPE_AUDIO) { 117 pjmedia_zero_samples(frame->buf, this_port->info.samples_per_frame); 149 118 } 119 120 pjmedia_aec_playback(aec->aec, frame->buf); 150 121 151 122 return status; … … 155 126 static pj_status_t aec_on_destroy(pjmedia_port *this_port) 156 127 { 157 struct aec _port *aec_port = (struct aec_port*)this_port;128 struct aec *aec = (struct aec*)this_port; 158 129 159 130 PJ_ASSERT_RETURN(this_port->info.signature == SIGNATURE, PJ_EINVAL); 160 131 161 speex_echo_state_destroy(aec_port->state);132 pjmedia_aec_destroy(aec->aec); 162 133 163 134 return PJ_SUCCESS;
Note: See TracChangeset
for help on using the changeset viewer.