Changeset 1679 for pjproject/trunk
- Timestamp:
- Jan 11, 2008 4:30:22 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/encdec.c
r1678 r1679 53 53 ; 54 54 55 #define HAS_G729_CODEC 0 55 #ifndef HAS_G729_CODEC 56 # define HAS_G729_CODEC 0 57 #endif 58 56 59 #if HAS_G729_CODEC 57 #include "keystream_g729ab.h" 58 #endif 59 60 #if 0 60 #include <keystream_g729ab.h> 61 #endif 62 63 //#undef PJ_TRACE 64 //#define PJ_TRACE 1 65 66 #ifndef PJ_TRACE 67 # define PJ_TRACE 0 68 #endif 69 70 #if PJ_TRACE 61 71 # define TRACE_(expr) PJ_LOG(4,expr) 62 72 #else … … 91 101 pjmedia_codec_mgr *cm; 92 102 pjmedia_codec *codec; 93 pjmedia_codec_info *pci;103 const pjmedia_codec_info *pci; 94 104 pjmedia_codec_param param; 95 105 unsigned cnt, samples_per_frame; 96 106 pj_str_t tmp; 97 107 pjmedia_port *wavin, *wavout; 108 unsigned lost_pct; 98 109 pj_status_t status; 99 110 111 #define T file_msec_duration/1000, file_msec_duration%1000 112 100 113 pool = pjmedia_endpt_create_pool(mept, "encdec", 1000, 1000); 101 114 102 115 cm = pjmedia_endpt_get_codec_mgr(mept); 103 116 117 #ifdef LOST_PCT 118 lost_pct = LOST_PCT; 119 #else 120 lost_pct = 0; 121 #endif 122 104 123 cnt = 1; 105 124 CHECK( pjmedia_codec_mgr_find_codecs_by_id(cm, pj_cstr(&tmp, codec_id), … … 110 129 111 130 /* Control VAD */ 112 param.setting.vad = 0;131 param.setting.vad = 1; 113 132 114 133 /* Open wav for reading */ … … 144 163 break;; 145 164 165 /* Update duration */ 166 file_msec_duration += samples_per_frame * 1000 / 167 param.info.clock_rate; 168 146 169 /* Encode */ 147 170 frm_bit.buf = bitstream; … … 149 172 CHECK(codec->op->encode(codec, &frm_pcm, sizeof(bitstream), &frm_bit)); 150 173 174 /* On DTX, write zero frame to wavout to maintain duration */ 175 if (frm_bit.size == 0 || frm_bit.type != PJMEDIA_FRAME_TYPE_AUDIO) { 176 out_frm.buf = (char*)pcmbuf; 177 out_frm.size = 160; 178 CHECK( pjmedia_port_put_frame(wavout, &out_frm) ); 179 TRACE_((THIS_FILE, "%d.%03d read: %u, enc: %u", 180 T, frm_pcm.size, frm_bit.size)); 181 continue; 182 } 183 184 /* Simulate jitter buffer bug */ 185 if (pci->pt==PJMEDIA_RTP_PT_G729 && frm_bit.size == 2) { 186 TRACE_((THIS_FILE, "%d.%03d G729 SID frame masqueraded", T)); 187 frm_bit.size = 10; 188 } 189 151 190 /* Parse the bitstream (not really necessary for this case 152 191 * since we always decode 1 frame, but it's still good … … 159 198 CHECK( (cnt==1 ? PJ_SUCCESS : -1) ); 160 199 161 /* Decode */200 /* Decode or simulate packet loss */ 162 201 out_frm.buf = (char*)pcmbuf; 163 202 out_frm.size = sizeof(pcmbuf); 164 CHECK( codec->op->decode(codec, &frames[0], sizeof(pcmbuf), 165 &out_frm) ); 203 204 if ((pj_rand() % 100) < lost_pct) { 205 /* Simulate loss */ 206 CHECK( codec->op->recover(codec, sizeof(pcmbuf), &out_frm) ); 207 TRACE_((THIS_FILE, "%d.%03d Packet lost", T)); 208 } else { 209 /* Decode */ 210 CHECK( codec->op->decode(codec, &frames[0], sizeof(pcmbuf), 211 &out_frm) ); 212 } 166 213 167 214 /* Write to WAV */ 168 215 CHECK( pjmedia_port_put_frame(wavout, &out_frm) ); 169 216 170 file_msec_duration += samples_per_frame * 1000 / 171 param.info.clock_rate; 172 173 TRACE_((THIS_FILE, "Bytes read: %u, encode: %u, decode/write: %u", 174 frm_pcm.size, frm_bit.size, out_frm.size)); 217 TRACE_((THIS_FILE, "%d.%03d read: %u, enc: %u, dec/write: %u", 218 T, frm_pcm.size, frm_bit.size, out_frm.size)); 175 219 } 176 220 … … 238 282 printf("Duration: %ds.%03d\n", file_msec_duration/1000, 239 283 file_msec_duration%1000); 240 printf("Time: % ds.%03d\n", t1.sec, t1.msec);284 printf("Time: %lds.%03ld\n", t1.sec, t1.msec); 241 285 } 242 286
Note: See TracChangeset
for help on using the changeset viewer.