shithub: opus-tools

Download patch

ref: 979aca94eb2c5d6bcab6a06c9304b3e1c7521853
parent: 8dfba387f8e72aa921b39c785bce9a8ef219bbf8
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 29 10:18:45 EDT 2011

Error handling

--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -388,6 +388,7 @@
 
 static OpusMSDecoder *process_header(ogg_packet *op, opus_int32 *rate, int *channels, int *preskip, float *gain, int quiet)
 {
+   int err;
    OpusMSDecoder *st;
    OpusHeader header;
    unsigned char mapping[256] = {0,1};
@@ -409,7 +410,12 @@
    if (!*rate)
       *rate = header.input_sample_rate;
    *preskip = header.preskip;
-   st = opus_multistream_decoder_create(48000, header.channels, 1, header.channels==2 ? 1 : 0, mapping);
+   st = opus_multistream_decoder_create(48000, header.channels, 1, header.channels==2 ? 1 : 0, mapping, &err);
+   if (err != OPUS_OK)
+   {
+     fprintf(stderr, "Cannot create encoder: %s\n", opus_strerror(err));
+     return NULL;
+   }
    if (!st)
    {
       fprintf (stderr, "Decoder initialization failed.\n");
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -323,6 +323,7 @@
    int extra_samples;
    int signal = OPUS_SIGNAL_AUTO;
    unsigned char mapping[256] = {0, 1};
+   int err;
 
    opus_version = opus_get_version_string();
    snprintf(vendor_string, sizeof(vendor_string), "%s\n",opus_version);
@@ -481,7 +482,6 @@
 
    if (rate != 48000)
    {
-      int err;
       fprintf(stderr, "Resampling from %d Hz to %d Hz before encoding\n", rate, 48000);
       resampler = speex_resampler_init(chan, rate, 48000, 5, &err);
       if (err!=0)
@@ -499,7 +499,12 @@
    bytes_per_packet = MAX_FRAME_BYTES;
    
    /*Initialize OPUS encoder*/
-   st = opus_multistream_encoder_create(48000, chan, 1, chan==2, mapping, OPUS_APPLICATION_AUDIO);
+   st = opus_multistream_encoder_create(48000, chan, 1, chan==2, mapping, OPUS_APPLICATION_AUDIO, &err);
+   if (err != OPUS_OK)
+   {
+     fprintf(stderr, "Cannot create encoder: %s\n", opus_strerror(err));
+     return 1;
+   }
    opus_multistream_encoder_ctl(st, OPUS_SET_SIGNAL(signal));
    header.channels = chan;
    opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&lookahead));