Merge branch 'ubuntu-build'
[dcpomatic.git] / src / lib / decoder.cc
index 9332511bcea0c96b7670dc2126e794aa3c7966b4..973582ca49237e3bd88739edce39389fe0fc88af 100644 (file)
@@ -165,20 +165,22 @@ Decoder::process_end ()
           in to get it to the right length.
        */
 
-       int const audio_short_by_frames =
-               (decoding_frames() * dcp_audio_sample_rate (_fs->audio_sample_rate) / _fs->frames_per_second)
+       int64_t const audio_short_by_frames =
+               ((int64_t) decoding_frames() * dcp_audio_sample_rate (_fs->audio_sample_rate) / _fs->frames_per_second)
                - _audio_frames_processed;
 
-       int bytes = audio_short_by_frames * _fs->audio_channels * _fs->bytes_per_sample();
-
-       int const silence_size = 64 * 1024;
-       uint8_t silence[silence_size];
-       memset (silence, 0, silence_size);
-
-       while (bytes) {
-               int const t = min (bytes, silence_size);
-               Audio (silence, t);
-               bytes -= t;
+       if (audio_short_by_frames >= 0) {
+               int bytes = audio_short_by_frames * _fs->audio_channels * _fs->bytes_per_sample();
+               
+               int const silence_size = 64 * 1024;
+               uint8_t silence[silence_size];
+               memset (silence, 0, silence_size);
+               
+               while (bytes) {
+                       int const t = min (bytes, silence_size);
+                       Audio (silence, t);
+                       bytes -= t;
+               }
        }
 }
 
@@ -462,12 +464,18 @@ Decoder::setup_video_filters ()
          << sample_aspect_ratio_denominator();
 
        int r;
+
        if ((r = avfilter_graph_create_filter (&_buffer_src_context, buffer_src, "in", a.str().c_str(), 0, graph)) < 0) {
                throw DecodeError ("could not create buffer source");
        }
 
-       enum PixelFormat pixel_formats[] = { pixel_format(), PIX_FMT_NONE };
-       if (avfilter_graph_create_filter (&_buffer_sink_context, buffer_sink, "out", 0, pixel_formats, graph) < 0) {
+       AVBufferSinkParams* sink_params = av_buffersink_params_alloc ();
+       PixelFormat* pixel_fmts = new PixelFormat[2];
+       pixel_fmts[0] = pixel_format ();
+       pixel_fmts[1] = PIX_FMT_NONE;
+       sink_params->pixel_fmts = pixel_fmts;
+       
+       if (avfilter_graph_create_filter (&_buffer_sink_context, buffer_sink, "out", 0, sink_params, graph) < 0) {
                throw DecodeError ("could not create buffer sink.");
        }