shithub: opus

Download patch

ref: 582eba6f4f703929e646f6dc6e864d9b12f4f4af
parent: 635b5f2f76ed1950e978c373c8a2469ef0637354
author: Gregory Maxwell <[email protected]>
date: Tue Aug 21 12:08:35 EDT 2012

Additional multistream tests and reject channels<1 in MS API.

--- a/src/opus_multistream.c
+++ b/src/opus_multistream.c
@@ -163,7 +163,7 @@
    int i;
    char *ptr;
 
-   if ((channels>255) || (coupled_streams>streams) ||
+   if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
        (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0))
       return OPUS_BAD_ARG;
 
@@ -540,7 +540,7 @@
    int i, ret;
    char *ptr;
 
-   if ((channels>255) || (coupled_streams>streams) ||
+   if ((channels>255) || (channels<1) || (coupled_streams>streams) ||
        (coupled_streams+streams>255) || (streams<1) || (coupled_streams<0))
       return OPUS_BAD_ARG;
 
--- a/tests/test_opus_api.c
+++ b/tests/test_opus_api.c
@@ -316,7 +316,7 @@
    OpusDecoder *streamdec;
    opus_int32 i,j,cfgs;
    unsigned char packet[1276];
-   unsigned char mapping[256] = {0,1};
+   unsigned char mapping[256];
 #ifndef DISABLE_FLOAT_API
    float fbuf[960*2];
 #endif
@@ -328,6 +328,10 @@
    nullvalue=0;
 #endif
 
+   mapping[0]=0;
+   mapping[1]=1;
+   for(i=2;i<256;i++)VG_UNDEF(&mapping[i],sizeof(unsigned char));
+
    cfgs=0;
    /*First test invalid configurations which should fail*/
    fprintf(stdout,"\n  Multistream decoder basic API tests\n");
@@ -373,6 +377,7 @@
 
    VG_UNDEF(&err,sizeof(err));
    dec = opus_multistream_decoder_create(48000, 2, 1, 0, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
    if(err==OPUS_OK || dec!=NULL)test_failed();
    cfgs++;
 
@@ -379,6 +384,7 @@
    VG_UNDEF(&err,sizeof(err));
    mapping[0]=mapping[1]=0;
    dec = opus_multistream_decoder_create(48000, 2, 1, 0, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
    if(err!=OPUS_OK || dec==NULL)test_failed();
    cfgs++;
    opus_multistream_decoder_destroy(dec);
@@ -386,13 +392,24 @@
 
    VG_UNDEF(&err,sizeof(err));
    dec = opus_multistream_decoder_create(48000, 1, 4, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
    if(err!=OPUS_OK || dec==NULL)test_failed();
    cfgs++;
+
+   err = opus_multistream_decoder_init(dec,48000, 1, 0, 0, mapping);
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+
+   err = opus_multistream_decoder_init(dec,48000, 1, 1, -1, mapping);
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+
    opus_multistream_decoder_destroy(dec);
    cfgs++;
 
    VG_UNDEF(&err,sizeof(err));
    dec = opus_multistream_decoder_create(48000, 2, 1, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
    if(err!=OPUS_OK || dec==NULL)test_failed();
    cfgs++;
    opus_multistream_decoder_destroy(dec);
@@ -399,12 +416,86 @@
    cfgs++;
 
    VG_UNDEF(&err,sizeof(err));
-   mapping[0]=0;
+   dec = opus_multistream_decoder_create(48000, 255, 255, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, -1, 1, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 0, 1, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 1, -1, 2, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 1, -1, -1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 256, 255, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 256, 255, 0, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   mapping[0]=255;
    mapping[1]=1;
-   dec = opus_multistream_decoder_create(48000, 2, 2, 0, mapping, &err);
+   mapping[2]=2;
+   dec = opus_multistream_decoder_create(48000, 3, 2, 0, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   mapping[0]=0;
+   mapping[1]=0;
+   mapping[2]=0;
+   dec = opus_multistream_decoder_create(48000, 3, 2, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
    if(err!=OPUS_OK || dec==NULL)test_failed();
    cfgs++;
+   opus_multistream_decoder_destroy(dec);
+   cfgs++;
 
+   mapping[0]=0;
+   mapping[1]=255;
+   mapping[2]=1;
+   mapping[3]=2;
+   mapping[4]=3;
+   dec = opus_multistream_decoder_create(48001, 5, 4, 1, mapping, 0);
+   if(dec!=NULL)test_failed();
+   cfgs++;
+
+   VG_UNDEF(&err,sizeof(err));
+   mapping[0]=0;
+   mapping[1]=255;
+   mapping[2]=1;
+   mapping[3]=2;
+   dec = opus_multistream_decoder_create(48000, 4, 2, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_OK || dec==NULL)test_failed();
+   cfgs++;
+
    fprintf(stdout,"    opus_multistream_decoder_create() ............ OK.\n");
    fprintf(stdout,"    opus_multistream_decoder_init() .............. OK.\n");
 
@@ -460,6 +551,12 @@
    }
    fprintf(stdout,"    OPUS_GET_GAIN ................................ OK.\n");
 
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
+   if(err != OPUS_OK || i!=0)test_failed();
+   fprintf(stdout,"    OPUS_GET_BANDWIDTH ........................... OK.\n");
+   cfgs++;
+
    err=opus_multistream_decoder_ctl(dec,OPUS_UNIMPLEMENTED);
    if(err!=OPUS_UNIMPLEMENTED)test_failed();
    fprintf(stdout,"    OPUS_UNIMPLEMENTED ........................... OK.\n");
@@ -467,11 +564,6 @@
 
 #if 0
    /*Currently unimplemented for multistream*/
-   VG_UNDEF(&i,sizeof(i));
-   err=opus_multistream_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
-   if(err != OPUS_OK || i!=0)test_failed();
-   fprintf(stdout,"    OPUS_GET_BANDWIDTH ........................... OK.\n");
-   cfgs++;
    /*GET_PITCH has different execution paths depending on the previously decoded frame.*/
    err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
    if(err!=OPUS_BAD_ARG)test_failed();
--- a/tests/test_opus_encode.c
+++ b/tests/test_opus_encode.c
@@ -113,7 +113,7 @@
 {
    static const int fsizes[6]={960*3,960*2,120,240,480,960};
    static const char *mstrings[3] = {"    LP","Hybrid","  MDCT"};
-   unsigned char mapping[256] = {0,1};
+   unsigned char mapping[256] = {0,1,255};
    unsigned char db62[36];
    opus_int32 i;
    int rc,j,err;
@@ -144,6 +144,9 @@
    MSenc = opus_multistream_encoder_create(8000, 2, 2, 0, mapping, OPUS_APPLICATION_AUDIO, &err);
    if(err != OPUS_OK || MSenc==NULL)test_failed();
 
+   if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_BITRATE(&i))!=OPUS_OK)test_failed();
+   if(opus_multistream_encoder_ctl(MSenc, OPUS_GET_LSB_DEPTH(&i))!=OPUS_OK)test_failed();
+
    dec = opus_decoder_create(48000, 2, &err);
    if(err != OPUS_OK || dec==NULL)test_failed();
 
@@ -150,7 +153,7 @@
    MSdec = opus_multistream_decoder_create(48000, 2, 2, 0, mapping, &err);
    if(err != OPUS_OK || MSdec==NULL)test_failed();
 
-   MSdec_err = opus_multistream_decoder_create(48000, 1, 2, 0, mapping, &err);
+   MSdec_err = opus_multistream_decoder_create(48000, 3, 2, 0, mapping, &err);
    if(err != OPUS_OK || MSdec_err==NULL)test_failed();
 
    dec_err[0]=(OpusDecoder *)malloc(opus_decoder_get_size(2));
@@ -178,7 +181,7 @@
 
    inbuf=(short *)malloc(sizeof(short)*SAMPLES*2);
    outbuf=(short *)malloc(sizeof(short)*SAMPLES*2);
-   out2buf=(short *)malloc(sizeof(short)*MAX_FRAME_SAMP*2);
+   out2buf=(short *)malloc(sizeof(short)*MAX_FRAME_SAMP*3);
    if(inbuf==NULL || outbuf==NULL || out2buf==NULL)test_failed();
 
    generate_music(inbuf,SAMPLES);