Better error checking in Resampler.
authorCarl Hetherington <cth@carlh.net>
Fri, 4 Sep 2015 17:29:09 +0000 (18:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 4 Sep 2015 19:59:48 +0000 (20:59 +0100)
src/lib/resampler.cc

index f54f4ec6abd3ab16c16ac48de8a408f93d4f254a..78e1da114976dc0a0faef01b868e8a9de7659a15 100644 (file)
@@ -39,6 +39,9 @@ Resampler::Resampler (int in, int out, int channels)
        , _channels (channels)
 {
        _swr_context = swr_alloc ();
+       if (!_swr_context) {
+               throw StringError (N_("could not allocate resampler contexct"));
+       }
 
        /* Sample formats */
        av_opt_set_int (_swr_context, "isf", AV_SAMPLE_FMT_FLTP, 0);
@@ -54,7 +57,12 @@ Resampler::Resampler (int in, int out, int channels)
 
        av_opt_set (_swr_context, "resampler", "soxr", 0);
 
-       swr_init (_swr_context);
+       int const r = swr_init (_swr_context);
+       if (r) {
+               char buf[256];
+               av_strerror (r, buf, sizeof(buf));
+               throw StringError (String::compose (N_ ("could not initialise sample-rate converter (%1)"), r));
+       }
 }
 
 Resampler::~Resampler ()