Changeset 2180
Legend:
- Unmodified
- Added
- Removed
-
rat/trunk/Makefile.in
r2179 r2180 18 18 TOY_OBJS = convert.o crypt.o render_3D.o repair.o sndfile.o 19 19 20 CORE_OBJS = audio.o cushion.o main.o mbus_engine.o \20 CORE_OBJS = playout.o source.o mbus_engine.o audio.o cushion.o main.o \ 21 21 mbus_ui.o mix.o net.o parameters.o pckt_queue.o \ 22 playout.ortcp.o rtcp_db.o rtcp_pckt.o session.o \23 s ource.o statistics.o tcltk.o timers.o transmit.o transcoder.o \22 rtcp.o rtcp_db.o rtcp_pckt.o session.o \ 23 statistics.o tcltk.o timers.o transmit.o transcoder.o \ 24 24 ui.o ui_audiotool.o ui_transcoder.o 25 25 -
rat/trunk/convert.c
r2178 r2180 46 46 #include "util.h" 47 47 #include "convert.h" 48 49 typedef struct s_converter_fmt{ 50 u_int16 from_channels; 51 u_int16 from_freq; 52 u_int16 to_channels; 53 u_int16 to_freq; 54 } converter_fmt_t; 48 #include "debug.h" 49 50 typedef struct s_converter { 51 struct s_pcm_converter *pcm_conv; 52 struct s_converter_fmt *conv_fmt; 53 char *data; 54 int data_len; 55 } converter_t; 56 57 /* Index to converter_id_t mapping macros */ 58 59 #define CONVERTER_ID_TO_IDX(x) ((x+17) << 2) 60 #define IDX_TO_CONVERTER_ID(x) (((x)>>2) - 17) 55 61 56 62 /* Mono-Stereo Conversion ****************************************************/ … … 1165 1171 1166 1172 typedef struct s_pcm_converter{ 1167 u_char id;1168 1173 char *name; 1169 1174 u_char enabled; … … 1176 1181 } pcm_converter_t; 1177 1182 1178 #define CONVERT_NONE 2551179 #define CONVERT_PLATFORM 11180 #define CONVERT_SRF 21181 #define CONVERT_LINEAR 31182 #define CONVERT_EXTRA 41183 1184 1183 /* In this table of converters the platform specific converters should go at the 1185 1184 * beginning, before the default (and worst) linear interpolation conversion. The … … 1190 1189 pcm_converter_t converter_tbl[] = { 1191 1190 #ifdef WIN32 1192 { CONVERT_PLATFORM,1191 { 1193 1192 "Microsoft Converter", 1194 1193 FALSE, … … 1198 1197 acm_convert, 1199 1198 acm_conv_free, 1200 sizeof(HACMSTREAM)}, 1199 sizeof(HACMSTREAM) 1200 }, 1201 1201 #endif 1202 1202 #ifdef SRF_GOOD 1203 { CONVERT_SRF,1203 { 1204 1204 "High Quality", 1205 1205 TRUE, … … 1209 1209 srf_convert, 1210 1210 srf_free, 1211 2 * sizeof(srf_state_t)}, 1211 2 * sizeof(srf_state_t) 1212 }, 1212 1213 #endif /* SRF_GOOD */ 1213 { CONVERT_LINEAR,1214 { 1214 1215 "Intermediate Quality", 1215 1216 TRUE, … … 1219 1220 linear_convert, 1220 1221 linear_free, 1221 2 * sizeof(li_state_t)}, 1222 {CONVERT_EXTRA, 1222 2 * sizeof(li_state_t) 1223 }, 1224 { 1223 1225 "Low Quality", 1224 1226 TRUE, … … 1228 1230 extra_convert, 1229 1231 extra_free, 1230 2 * sizeof(extra_state_t)}, 1231 {CONVERT_NONE, 1232 2 * sizeof(extra_state_t) 1233 }, 1234 { 1232 1235 "None", 1233 1236 TRUE, … … 1237 1240 NULL, 1238 1241 NULL, 1239 0} 1242 0 1243 } 1240 1244 }; 1241 1245 1246 #define NUM_CONVERTERS sizeof(converter_tbl)/sizeof(pcm_converter_t) 1247 #define CONVERTER_NONE (NUM_CONVERTERS - 1) 1248 1242 1249 converter_t * 1243 converter_create(pcm_converter_t *pc, int from_channels, int from_freq, int to_channels, int to_freq) 1250 converter_create(converter_id_t cid, 1251 converter_fmt_t *in_fmt) 1244 1252 { 1245 1253 converter_t *c = NULL; 1246 1254 converter_fmt_t *cf = NULL; 1247 1248 if (pc == NULL || pc->id == CONVERT_NONE) return NULL; 1249 1255 pcm_converter_t *pc; 1256 u_int32 tbl_idx; 1257 1258 tbl_idx = CONVERTER_ID_TO_IDX(cid); 1259 1260 if (tbl_idx >= NUM_CONVERTERS) { 1261 debug_msg("Converter ID invalid\n"); 1262 return NULL; 1263 } 1264 1265 if (tbl_idx == CONVERTER_NONE) return NULL; 1266 1267 pc = converter_tbl + tbl_idx; 1268 1269 assert(in_fmt != NULL); 1270 1250 1271 c = (converter_t*)xmalloc(sizeof(converter_t)); 1251 1272 … … 1261 1282 } 1262 1283 1263 cf->from_channels = from_channels; 1264 cf->from_freq = from_freq; 1265 cf->to_channels = to_channels; 1266 cf->to_freq = to_freq; 1284 memcpy(cf, in_fmt, sizeof(converter_fmt_t)); 1267 1285 1268 1286 c->pcm_conv = pc; … … 1299 1317 converters_init() 1300 1318 { 1301 pcm_converter_t *pc = converter_tbl; 1302 while(pc->id != CONVERT_NONE) { 1319 pcm_converter_t *pc, *end; 1320 1321 pc = converter_tbl; 1322 end = converter_tbl + NUM_CONVERTERS; 1323 while(pc != end) { 1303 1324 if (pc->cf_start) pc->enabled = pc->cf_start(); 1304 1325 pc++; … … 1309 1330 converters_free() 1310 1331 { 1311 pcm_converter_t *pc = converter_tbl; 1312 while(pc->id != CONVERT_NONE) { 1332 pcm_converter_t *pc, *end; 1333 1334 pc = converter_tbl; 1335 end = converter_tbl + NUM_CONVERTERS; 1336 while(pc != end) { 1313 1337 if (pc->cf_clean) pc->cf_clean(); 1314 1338 pc++; … … 1316 1340 } 1317 1341 1318 pcm_converter_t * 1319 converter_get_byname(char *name) 1320 { 1321 pcm_converter_t *pc; 1322 1323 pc = converter_tbl; 1324 while(strcmp(name, pc->name) && pc->id != CONVERT_NONE) pc++; 1325 return pc; 1326 } 1327 1328 int 1342 int 1343 converter_get_details(u_int32 idx, converter_details_t *cd) 1344 { 1345 if (idx < NUM_CONVERTERS) { 1346 cd->id = IDX_TO_CONVERTER_ID(idx); 1347 cd->name = converter_tbl[idx].name; 1348 return TRUE; 1349 } 1350 debug_msg("Getting invalid converter details\n"); 1351 return FALSE; 1352 } 1353 1354 u_int32 1329 1355 converter_get_count() 1330 1356 { 1331 int count = 1; /* convert_none always there */ 1332 pcm_converter_t *pc = converter_tbl; 1333 1334 do { 1335 if (pc->enabled) count ++; 1336 pc++; 1337 } while (pc->id != CONVERT_NONE); 1338 1339 return count; 1340 } 1341 1342 const char * 1343 converter_get_name(int idx) 1344 { 1345 pcm_converter_t *pc = converter_tbl; 1346 int count = 0; 1347 1348 do { 1349 if (pc->enabled) { 1350 if (count == idx) break; 1351 count ++; 1352 } 1353 pc++; 1354 } while (pc->id != CONVERT_NONE); 1355 1356 return pc->name; 1357 return NUM_CONVERTERS; 1357 1358 } 1358 1359 … … 1361 1362 1362 1363 int 1363 converter_ format(converter_t *c, coded_unit *in, coded_unit *out)1364 converter_process (converter_t *c, coded_unit *in, coded_unit *out) 1364 1365 { 1365 1366 converter_fmt_t *cf; … … 1393 1394 } 1394 1395 1395 #ifdef DEBUG_CONVERT 1396 1397 #define SRC_LEN 160 1398 1399 /* a.out <converter idx> <input rate> <input channels> <output rate> <output channels> */ 1400 static pcm_converter_t * 1401 converter_get_by_idx(int idx) 1402 { 1403 char buf[255], *pb; 1404 converter_get_names(buf, 255); 1405 pb = strtok(buf, "/"); 1406 while(idx > 0) { 1407 pb = strtok(NULL, "/"); 1408 idx--; 1409 } 1410 assert(pb); 1411 return converter_get_byname(pb); 1412 } 1413 1414 static void 1415 fill_data(sample *buf, int buf_len, int channels) 1416 { 1417 register int i, j, r; 1418 for(i = 0; i < buf_len; i ++) { 1419 r = (32767.0 * sin(2* M_PI * i / SRC_LEN)); 1420 for(j = 0; j < channels; j++) { 1421 *buf++ = r; 1422 } 1423 } 1424 } 1425 1426 void 1427 display_data(sample *buf, int buf_len, int channels) 1428 { 1429 int i; 1430 1431 switch(channels) { 1432 case 1: 1433 for(i = 0; i < buf_len; i++) { 1434 printf("% 3d % 5d \n", i, buf[i]); 1435 } 1436 break; 1437 case 2: 1438 buf_len /= channels; 1439 for(i = 0; i < buf_len; i++) { 1440 printf("% 3d % 5d % 5d\n", i, buf[2*i], buf[2*i + 1]); 1441 } 1442 break; 1443 } 1444 printf("\n"); 1445 } 1446 1447 void 1448 display_time_diff(struct timeval *t1, struct timeval *t2) 1449 { 1450 float diff = (t2->tv_sec - t1->tv_sec)*1.0 + (t2->tv_usec - t1->tv_usec)*1e-6; 1451 printf("Took %f seconds\n", diff); 1452 } 1453 1454 1455 int 1456 main(int argc, char **argv) 1457 { 1458 rx_queue_element_struct *rx = NULL; 1459 pcm_converter_t *pc = NULL; 1460 converter_t *c = NULL; 1461 struct rusage r1, r2; 1462 1463 int idx, in_rate, in_channels, out_rate, out_channels; 1464 1465 assert(argc == 6); 1466 idx = atoi(argv[1]); 1467 in_rate = atoi(argv[2]); 1468 in_channels = atoi(argv[3]); 1469 out_rate = atoi(argv[4]); 1470 out_channels = atoi(argv[5]); 1471 assert(in_rate % 8000 == 0); 1472 assert(out_rate % 8000 == 0); 1473 assert(in_channels == 1 || in_channels == 2); 1474 assert(out_channels == 1 || out_channels == 2); 1475 1476 converters_init(); 1477 1478 pc = converter_get_by_idx(idx); 1479 1480 assert(pc); 1481 printf("# Converter %s\n", pc->name); 1482 c = converter_create(pc, in_channels, in_rate, out_channels, out_rate); 1483 1484 rx = (rx_queue_element_struct*)xmalloc(sizeof(rx_queue_element_struct)); 1485 memset(rx,0,sizeof(rx_queue_element_struct)); 1486 1487 rx->native_data[0] = (sample*)block_alloc(sizeof(sample) * in_channels * SRC_LEN); 1488 rx->native_size[0] = in_channels * SRC_LEN * sizeof(sample); 1489 rx->native_count = 1; 1490 fill_data(rx->native_data[0], SRC_LEN,in_channels); 1491 getrusage(RUSAGE_SELF,&r1); 1492 converter_format(c, rx); 1493 getrusage(RUSAGE_SELF,&r2); 1494 printf("#");display_time_diff(&r1.ru_utime, &r2.ru_utime); 1495 1496 display_data(rx->native_data[0], rx->native_size[0] / sizeof(sample), in_channels); 1497 display_data(rx->native_data[1], rx->native_size[1] / sizeof(sample), out_channels); 1498 1499 block_free(rx->native_data[0], rx->native_size[0]); 1500 block_free(rx->native_data[1], rx->native_size[1]); 1501 xfree(rx); 1502 1503 converter_destroy(&c); 1504 converters_free(); 1505 1506 return 1; 1507 } 1508 1509 #endif /* DEBUG_CONVERT */ 1510 1511 1396 const converter_fmt_t* 1397 converter_get_format (converter_t *c) 1398 { 1399 assert(c != NULL); 1400 return c->conv_fmt; 1401 } -
rat/trunk/convert.h
r2174 r2180 46 46 struct s_coded_unit; 47 47 48 typedef struct s_converter { 49 struct s_pcm_converter *pcm_conv; 50 struct s_converter_fmt *conv_fmt; 51 char *data; 52 int data_len; 53 } converter_t; 48 typedef struct s_converter_fmt { 49 u_int16 from_channels; 50 u_int16 from_freq; 51 u_int16 to_channels; 52 u_int16 to_freq; 53 } converter_fmt_t; 54 55 typedef u_int32 converter_id_t; 56 57 typedef struct { 58 converter_id_t id; 59 const char* name; 60 } converter_details_t; 61 62 struct s_converter; 54 63 55 64 /* Application pcm conversion functions */ … … 58 67 59 68 /* Participant specific pcm conversion functions */ 60 converter_t* converter_create (struct s_pcm_converter *pc, 61 int from_channels, 62 int from_freq, 63 int to_channels, 64 int to_freq); 69 struct s_converter* converter_create (converter_id_t id, 70 converter_fmt_t *cf); 65 71 66 int converter_format (converter_t *c, 67 struct s_coded_unit *in, 68 struct s_coded_unit *out); 69 void converter_destroy (converter_t **c); 72 const converter_fmt_t* 73 converter_get_format(struct s_converter *c); 74 75 int converter_process (struct s_converter *c, 76 struct s_coded_unit *in, 77 struct s_coded_unit *out); 78 void converter_destroy (struct s_converter **c); 70 79 71 80 /* Converter selection functions */ 72 struct s_pcm_converter* converter_get_byname(char *name);73 int converter_get_count(void);74 const char* converter_get_name(int idx);81 u_int32 converter_get_count(void); 82 int converter_get_details(u_int32 idx, 83 converter_details_t *cd); 75 84 76 85 #endif /* _convert_h_ */ -
rat/trunk/mix.c
r2174 r2180 414 414 } 415 415 416 417 416 #define POWER_METER_SAMPLES 160 418 417 -
rat/trunk/source.c
r2179 r2180 48 48 #include "codec.h" 49 49 #include "codec_state.h" 50 #include "convert.h" 50 51 #include "timers.h" 51 52 … … 56 57 struct s_source *next; 57 58 struct s_source *prev; 59 u_int32 age; 60 u_int32 last_played; 58 61 struct s_rtcp_dbentry *dbe; 59 62 struct s_channel_state *channel_state; … … 242 245 assert(data_start != NULL); 243 246 247 if (src->age != 0 && 248 ts_gt(src->last_played, playout)) { 249 debug_msg("Packet late (%u > %u)- discarding\n", 250 src->last_played, 251 playout); 252 /* Up src->dbe jitter toged */ 253 return FALSE; 254 } 255 244 256 if (channel_data_create(&cd, 1) == 0) { 245 257 return FALSE; … … 277 289 278 290 int 279 source_process(source *src, u_int32 render_3d, u_int32now)291 source_process(source *src, u_int32 now) 280 292 { 281 293 media_data *md; … … 295 307 assert(md_len == sizeof(media_data)); 296 308 297 if (src->age != 0 && playout != src->last_play out+ src->last_unit_dur) {309 if (src->age != 0 && playout != src->last_played + src->last_unit_dur) { 298 310 /* Repair necessary 299 311 * - create unit at src->last_playout + src->last_unit_dur; … … 351 363 } 352 364 353 if ( ) {365 if (src->converter) { 354 366 /* convert frame */ 355 367 … … 359 371 360 372 } 373 374 src->age++; 375 src->last_played = now; 361 376 362 377 return TRUE; -
rat/trunk/source.h
r2179 r2180 71 71 int source_process (struct s_source *src, 72 72 u_int32 now); 73 74 73 75 74 u_int32 source_buffer_length_ms (struct s_source *src);
