OLD | NEW |
1 /* Copyright (c) 2011-2013 Xiph.Org Foundation | 1 /* Copyright (c) 2011-2013 Xiph.Org Foundation |
2 Written by Gregory Maxwell */ | 2 Written by Gregory Maxwell */ |
3 /* | 3 /* |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 - Redistributions of source code must retain the above copyright | 8 - Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 | 10 |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 int payload_offset, ret; | 717 int payload_offset, ret; |
718 fprintf(stdout,"\n Packet header parsing tests\n"); | 718 fprintf(stdout,"\n Packet header parsing tests\n"); |
719 fprintf(stdout," ---------------------------------------------------\n"); | 719 fprintf(stdout," ---------------------------------------------------\n"); |
720 memset(packet,0,sizeof(char)*1276); | 720 memset(packet,0,sizeof(char)*1276); |
721 packet[0]=63<<2; | 721 packet[0]=63<<2; |
722 if(opus_packet_parse(packet,1,&toc,frames,0,&payload_offset)!=OPUS_BAD_ARG)te
st_failed(); | 722 if(opus_packet_parse(packet,1,&toc,frames,0,&payload_offset)!=OPUS_BAD_ARG)te
st_failed(); |
723 cfgs_total=cfgs=1; | 723 cfgs_total=cfgs=1; |
724 /*code 0*/ | 724 /*code 0*/ |
725 for(i=0;i<64;i++) | 725 for(i=0;i<64;i++) |
726 { | 726 { |
| 727 packet[0]=i<<2; |
727 UNDEFINE_FOR_PARSE | 728 UNDEFINE_FOR_PARSE |
728 ret=opus_packet_parse(packet,4,&toc,frames,size,&payload_offset); | 729 ret=opus_packet_parse(packet,4,&toc,frames,size,&payload_offset); |
729 cfgs++; | 730 cfgs++; |
730 if(ret!=1)test_failed(); | 731 if(ret!=1)test_failed(); |
731 if(size[0]!=3)test_failed(); | 732 if(size[0]!=3)test_failed(); |
732 if(frames[0]!=packet+1)test_failed(); | 733 if(frames[0]!=packet+1)test_failed(); |
733 } | 734 } |
734 fprintf(stdout," code 0 (%2d cases) ............................ OK.\n",cf
gs); | 735 fprintf(stdout," code 0 (%2d cases) ............................ OK.\n",cf
gs); |
735 cfgs_total+=cfgs;cfgs=0; | 736 cfgs_total+=cfgs;cfgs=0; |
736 | 737 |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 " OPUS_SET_SIGNAL .............................. OK.\n", | 1345 " OPUS_SET_SIGNAL .............................. OK.\n", |
1345 " OPUS_GET_SIGNAL .............................. OK.\n") | 1346 " OPUS_GET_SIGNAL .............................. OK.\n") |
1346 | 1347 |
1347 err=opus_encoder_ctl(enc,OPUS_GET_LSB_DEPTH((opus_int32 *)NULL)); | 1348 err=opus_encoder_ctl(enc,OPUS_GET_LSB_DEPTH((opus_int32 *)NULL)); |
1348 if(err!=OPUS_BAD_ARG)test_failed(); | 1349 if(err!=OPUS_BAD_ARG)test_failed(); |
1349 cfgs++; | 1350 cfgs++; |
1350 CHECK_SETGET(OPUS_SET_LSB_DEPTH(i),OPUS_GET_LSB_DEPTH(&i),7,25,16,24, | 1351 CHECK_SETGET(OPUS_SET_LSB_DEPTH(i),OPUS_GET_LSB_DEPTH(&i),7,25,16,24, |
1351 " OPUS_SET_LSB_DEPTH ........................... OK.\n", | 1352 " OPUS_SET_LSB_DEPTH ........................... OK.\n", |
1352 " OPUS_GET_LSB_DEPTH ........................... OK.\n") | 1353 " OPUS_GET_LSB_DEPTH ........................... OK.\n") |
1353 | 1354 |
| 1355 err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED(&i)); |
| 1356 if(i!=0)test_failed(); |
| 1357 cfgs++; |
| 1358 err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED((opus_int32 *)NULL)); |
| 1359 if(err!=OPUS_BAD_ARG)test_failed(); |
| 1360 cfgs++; |
| 1361 CHECK_SETGET(OPUS_SET_PREDICTION_DISABLED(i),OPUS_GET_PREDICTION_DISABLED(&i)
,-1,2,1,0, |
| 1362 " OPUS_SET_PREDICTION_DISABLED ................. OK.\n", |
| 1363 " OPUS_GET_PREDICTION_DISABLED ................. OK.\n") |
| 1364 |
1354 err=opus_encoder_ctl(enc,OPUS_GET_EXPERT_FRAME_DURATION((opus_int32 *)NULL)); | 1365 err=opus_encoder_ctl(enc,OPUS_GET_EXPERT_FRAME_DURATION((opus_int32 *)NULL)); |
1355 if(err!=OPUS_BAD_ARG)test_failed(); | 1366 if(err!=OPUS_BAD_ARG)test_failed(); |
1356 cfgs++; | 1367 cfgs++; |
1357 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_2_5_MS
)); | 1368 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_2_5_MS
)); |
1358 if(err!=OPUS_OK)test_failed(); | 1369 if(err!=OPUS_OK)test_failed(); |
1359 cfgs++; | 1370 cfgs++; |
1360 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_5_MS))
; | 1371 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_5_MS))
; |
1361 if(err!=OPUS_OK)test_failed(); | 1372 if(err!=OPUS_OK)test_failed(); |
1362 cfgs++; | 1373 cfgs++; |
1363 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_10_MS)
); | 1374 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_10_MS)
); |
1364 if(err!=OPUS_OK)test_failed(); | 1375 if(err!=OPUS_OK)test_failed(); |
1365 cfgs++; | 1376 cfgs++; |
1366 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS)
); | 1377 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS)
); |
1367 if(err!=OPUS_OK)test_failed(); | 1378 if(err!=OPUS_OK)test_failed(); |
1368 cfgs++; | 1379 cfgs++; |
1369 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_40_MS)
); | 1380 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_40_MS)
); |
1370 if(err!=OPUS_OK)test_failed(); | 1381 if(err!=OPUS_OK)test_failed(); |
1371 cfgs++; | 1382 cfgs++; |
1372 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_60_MS)
); | 1383 err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_60_MS)
); |
1373 if(err!=OPUS_OK)test_failed(); | 1384 if(err!=OPUS_OK)test_failed(); |
1374 cfgs++; | 1385 cfgs++; |
1375 CHECK_SETGET(OPUS_SET_EXPERT_FRAME_DURATION(i),OPUS_GET_EXPERT_FRAME_DURATION
(&i),0,-1, | 1386 CHECK_SETGET(OPUS_SET_EXPERT_FRAME_DURATION(i),OPUS_GET_EXPERT_FRAME_DURATION
(&i),0,-1, |
1376 OPUS_FRAMESIZE_VARIABLE,OPUS_FRAMESIZE_ARG, | 1387 OPUS_FRAMESIZE_60_MS,OPUS_FRAMESIZE_ARG, |
1377 " OPUS_SET_EXPERT_FRAME_DURATION ............... OK.\n", | 1388 " OPUS_SET_EXPERT_FRAME_DURATION ............... OK.\n", |
1378 " OPUS_GET_EXPERT_FRAME_DURATION ............... OK.\n") | 1389 " OPUS_GET_EXPERT_FRAME_DURATION ............... OK.\n") |
1379 | 1390 |
1380 /*OPUS_SET_FORCE_MODE is not tested here because it's not a public API, howev
er the encoder tests use it*/ | 1391 /*OPUS_SET_FORCE_MODE is not tested here because it's not a public API, howev
er the encoder tests use it*/ |
1381 | 1392 |
1382 err=opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL)); | 1393 err=opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL)); |
1383 if(err!=OPUS_BAD_ARG)test_failed(); | 1394 if(err!=OPUS_BAD_ARG)test_failed(); |
1384 cfgs++; | 1395 cfgs++; |
1385 if(opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test
_failed(); | 1396 if(opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test
_failed(); |
1386 cfgs++; | 1397 cfgs++; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 int ret,cfgs,i,j,k; | 1439 int ret,cfgs,i,j,k; |
1429 OpusRepacketizer *rp; | 1440 OpusRepacketizer *rp; |
1430 unsigned char *packet; | 1441 unsigned char *packet; |
1431 unsigned char *po; | 1442 unsigned char *po; |
1432 cfgs=0; | 1443 cfgs=0; |
1433 fprintf(stdout,"\n Repacketizer tests\n"); | 1444 fprintf(stdout,"\n Repacketizer tests\n"); |
1434 fprintf(stdout," ---------------------------------------------------\n"); | 1445 fprintf(stdout," ---------------------------------------------------\n"); |
1435 | 1446 |
1436 packet=malloc(max_out); | 1447 packet=malloc(max_out); |
1437 if(packet==NULL)test_failed(); | 1448 if(packet==NULL)test_failed(); |
1438 po=malloc(max_out); | 1449 memset(packet,0,max_out); |
| 1450 po=malloc(max_out+256); |
1439 if(po==NULL)test_failed(); | 1451 if(po==NULL)test_failed(); |
1440 memset(packet,0,max_out); | |
1441 | 1452 |
1442 i=opus_repacketizer_get_size(); | 1453 i=opus_repacketizer_get_size(); |
1443 if(i<=0)test_failed(); | 1454 if(i<=0)test_failed(); |
1444 cfgs++; | 1455 cfgs++; |
1445 fprintf(stdout," opus_repacketizer_get_size()=%d ............. OK.\n",i); | 1456 fprintf(stdout," opus_repacketizer_get_size()=%d ............. OK.\n",i); |
1446 | 1457 |
1447 rp=malloc(i); | 1458 rp=malloc(i); |
1448 rp=opus_repacketizer_init(rp); | 1459 rp=opus_repacketizer_init(rp); |
1449 if(rp==NULL)test_failed(); | 1460 if(rp==NULL)test_failed(); |
1450 cfgs++; | 1461 cfgs++; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 { | 1543 { |
1533 int len; | 1544 int len; |
1534 len=k*rcnt+((rcnt*i)>2?2:1); | 1545 len=k*rcnt+((rcnt*i)>2?2:1); |
1535 if(ret!=len)test_failed(); | 1546 if(ret!=len)test_failed(); |
1536 if((rcnt*i)<2&&(po[0]&3)!=0)test_failed();
/* Code 0 */ | 1547 if((rcnt*i)<2&&(po[0]&3)!=0)test_failed();
/* Code 0 */ |
1537 if((rcnt*i)==2&&(po[0]&3)!=1)test_failed();
/* Code 1 */ | 1548 if((rcnt*i)==2&&(po[0]&3)!=1)test_failed();
/* Code 1 */ |
1538 if((rcnt*i)>2&&(((po[0]&3)!=3)||(po[1]!=rcnt*i)))test_failed()
; /* Code 3 CBR */ | 1549 if((rcnt*i)>2&&(((po[0]&3)!=3)||(po[1]!=rcnt*i)))test_failed()
; /* Code 3 CBR */ |
1539 cfgs++; | 1550 cfgs++; |
1540 if(opus_repacketizer_out(rp,po,len)!=len)test_failed(); | 1551 if(opus_repacketizer_out(rp,po,len)!=len)test_failed(); |
1541 cfgs++; | 1552 cfgs++; |
| 1553 if(opus_packet_unpad(po,len)!=len)test_failed(); |
| 1554 cfgs++; |
| 1555 if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed(); |
| 1556 cfgs++; |
| 1557 if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed(); |
| 1558 cfgs++; |
| 1559 if(opus_packet_unpad(po,len+256)!=len)test_failed(); |
| 1560 cfgs++; |
| 1561 if(opus_multistream_packet_unpad(po,len,1)!=len)test_failed(); |
| 1562 cfgs++; |
| 1563 if(opus_multistream_packet_pad(po,len,len+1,1)!=OPUS_OK)test_f
ailed(); |
| 1564 cfgs++; |
| 1565 if(opus_multistream_packet_pad(po,len+1,len+256,1)!=OPUS_OK)te
st_failed(); |
| 1566 cfgs++; |
| 1567 if(opus_multistream_packet_unpad(po,len+256,1)!=len)test_faile
d(); |
| 1568 cfgs++; |
1542 if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)t
est_failed(); | 1569 if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)t
est_failed(); |
1543 cfgs++; | 1570 cfgs++; |
1544 if(len>1) | 1571 if(len>1) |
1545 { | 1572 { |
1546 if(opus_repacketizer_out(rp,po,1)!=OPUS_BUFFER_TOO_SMALL)te
st_failed(); | 1573 if(opus_repacketizer_out(rp,po,1)!=OPUS_BUFFER_TOO_SMALL)te
st_failed(); |
1547 cfgs++; | 1574 cfgs++; |
1548 } | 1575 } |
1549 if(opus_repacketizer_out(rp,po,0)!=OPUS_BUFFER_TOO_SMALL)test_
failed(); | 1576 if(opus_repacketizer_out(rp,po,0)!=OPUS_BUFFER_TOO_SMALL)test_
failed(); |
1550 cfgs++; | 1577 cfgs++; |
1551 } else if (ret!=OPUS_BAD_ARG)test_failed();
/* M must not be 0 */ | 1578 } else if (ret!=OPUS_BAD_ARG)test_failed();
/* M must not be 0 */ |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 } else if (ret!=OPUS_INVALID_PACKET)test_failed(); | 1658 } else if (ret!=OPUS_INVALID_PACKET)test_failed(); |
1632 cfgs++; | 1659 cfgs++; |
1633 len=sum+(rcnt<2?1:rcnt<3?2:2+rcnt-1); | 1660 len=sum+(rcnt<2?1:rcnt<3?2:2+rcnt-1); |
1634 if(opus_repacketizer_out(rp,po,max_out)!=len)test_failed(); | 1661 if(opus_repacketizer_out(rp,po,max_out)!=len)test_failed(); |
1635 if(rcnt>2&&(po[1]&63)!=rcnt)test_failed(); | 1662 if(rcnt>2&&(po[1]&63)!=rcnt)test_failed(); |
1636 if(rcnt==2&&(po[0]&3)!=2)test_failed(); | 1663 if(rcnt==2&&(po[0]&3)!=2)test_failed(); |
1637 if(rcnt==1&&(po[0]&3)!=0)test_failed(); | 1664 if(rcnt==1&&(po[0]&3)!=0)test_failed(); |
1638 cfgs++; | 1665 cfgs++; |
1639 if(opus_repacketizer_out(rp,po,len)!=len)test_failed(); | 1666 if(opus_repacketizer_out(rp,po,len)!=len)test_failed(); |
1640 cfgs++; | 1667 cfgs++; |
| 1668 if(opus_packet_unpad(po,len)!=len)test_failed(); |
| 1669 cfgs++; |
| 1670 if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed(); |
| 1671 cfgs++; |
| 1672 if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed(); |
| 1673 cfgs++; |
| 1674 if(opus_packet_unpad(po,len+256)!=len)test_failed(); |
| 1675 cfgs++; |
| 1676 if(opus_multistream_packet_unpad(po,len,1)!=len)test_failed(); |
| 1677 cfgs++; |
| 1678 if(opus_multistream_packet_pad(po,len,len+1,1)!=OPUS_OK)test_failed(); |
| 1679 cfgs++; |
| 1680 if(opus_multistream_packet_pad(po,len+1,len+256,1)!=OPUS_OK)test_failed
(); |
| 1681 cfgs++; |
| 1682 if(opus_multistream_packet_unpad(po,len+256,1)!=len)test_failed(); |
| 1683 cfgs++; |
1641 if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_faile
d(); | 1684 if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_faile
d(); |
1642 cfgs++; | 1685 cfgs++; |
1643 if(len>1) | 1686 if(len>1) |
1644 { | 1687 { |
1645 if(opus_repacketizer_out(rp,po,1)!=OPUS_BUFFER_TOO_SMALL)test_failed
(); | 1688 if(opus_repacketizer_out(rp,po,1)!=OPUS_BUFFER_TOO_SMALL)test_failed
(); |
1646 cfgs++; | 1689 cfgs++; |
1647 } | 1690 } |
1648 if(opus_repacketizer_out(rp,po,0)!=OPUS_BUFFER_TOO_SMALL)test_failed(); | 1691 if(opus_repacketizer_out(rp,po,0)!=OPUS_BUFFER_TOO_SMALL)test_failed(); |
1649 cfgs++; | 1692 cfgs++; |
1650 } | 1693 } |
1651 } | 1694 } |
1652 | 1695 |
| 1696 po[0]='O'; |
| 1697 po[1]='p'; |
| 1698 if(opus_packet_pad(po,4,4)!=OPUS_OK)test_failed(); |
| 1699 cfgs++; |
| 1700 if(opus_multistream_packet_pad(po,4,4,1)!=OPUS_OK)test_failed(); |
| 1701 cfgs++; |
| 1702 if(opus_packet_pad(po,4,5)!=OPUS_BAD_ARG)test_failed(); |
| 1703 cfgs++; |
| 1704 if(opus_multistream_packet_pad(po,4,5,1)!=OPUS_BAD_ARG)test_failed(); |
| 1705 cfgs++; |
| 1706 if(opus_packet_pad(po,0,5)!=OPUS_BAD_ARG)test_failed(); |
| 1707 cfgs++; |
| 1708 if(opus_multistream_packet_pad(po,0,5,1)!=OPUS_BAD_ARG)test_failed(); |
| 1709 cfgs++; |
| 1710 if(opus_packet_unpad(po,0)!=OPUS_BAD_ARG)test_failed(); |
| 1711 cfgs++; |
| 1712 if(opus_multistream_packet_unpad(po,0,1)!=OPUS_BAD_ARG)test_failed(); |
| 1713 cfgs++; |
| 1714 if(opus_packet_unpad(po,4)!=OPUS_INVALID_PACKET)test_failed(); |
| 1715 cfgs++; |
| 1716 if(opus_multistream_packet_unpad(po,4,1)!=OPUS_INVALID_PACKET)test_failed(); |
| 1717 cfgs++; |
| 1718 po[0]=0; |
| 1719 po[1]=0; |
| 1720 po[2]=0; |
| 1721 if(opus_packet_pad(po,5,4)!=OPUS_BAD_ARG)test_failed(); |
| 1722 cfgs++; |
| 1723 if(opus_multistream_packet_pad(po,5,4,1)!=OPUS_BAD_ARG)test_failed(); |
| 1724 cfgs++; |
| 1725 |
1653 fprintf(stdout," opus_repacketizer_cat ........................ OK.\n"); | 1726 fprintf(stdout," opus_repacketizer_cat ........................ OK.\n"); |
1654 fprintf(stdout," opus_repacketizer_out ........................ OK.\n"); | 1727 fprintf(stdout," opus_repacketizer_out ........................ OK.\n"); |
1655 fprintf(stdout," opus_repacketizer_out_range .................. OK.\n"); | 1728 fprintf(stdout," opus_repacketizer_out_range .................. OK.\n"); |
| 1729 fprintf(stdout," opus_packet_pad .............................. OK.\n"); |
| 1730 fprintf(stdout," opus_packet_unpad ............................ OK.\n"); |
| 1731 fprintf(stdout," opus_multistream_packet_pad .................. OK.\n"); |
| 1732 fprintf(stdout," opus_multistream_packet_unpad ................ OK.\n"); |
1656 | 1733 |
1657 opus_repacketizer_destroy(rp); | 1734 opus_repacketizer_destroy(rp); |
1658 cfgs++; | 1735 cfgs++; |
1659 free(packet); | 1736 free(packet); |
1660 free(po); | 1737 free(po); |
1661 fprintf(stdout," All repacketizer tests passed\n"); | 1738 fprintf(stdout," All repacketizer tests passed\n"); |
1662 fprintf(stdout," (%7d API invocations)\n",cfgs); | 1739 fprintf(stdout," (%7d API invocations)\n",cfgs); |
1663 | 1740 |
1664 return cfgs; | 1741 return cfgs; |
1665 } | 1742 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 total+=test_msdec_api(); | 1888 total+=test_msdec_api(); |
1812 total+=test_parse(); | 1889 total+=test_parse(); |
1813 total+=test_enc_api(); | 1890 total+=test_enc_api(); |
1814 total+=test_repacketizer_api(); | 1891 total+=test_repacketizer_api(); |
1815 total+=test_malloc_fail(); | 1892 total+=test_malloc_fail(); |
1816 | 1893 |
1817 fprintf(stderr,"\nAll API tests passed.\nThe libopus API was invoked %d times
.\n",total); | 1894 fprintf(stderr,"\nAll API tests passed.\nThe libopus API was invoked %d times
.\n",total); |
1818 | 1895 |
1819 return 0; | 1896 return 0; |
1820 } | 1897 } |
OLD | NEW |