Tidy up test film naming.
[dcpomatic.git] / src / lib / decoder.cc
index 173360ec1036435dbaba9c312c4d3a04c3f93c52..045c1b818270052d58a93249377a7e2a6f5c6e27 100644 (file)
@@ -105,14 +105,14 @@ Decoder::process_end ()
                uint8_t remainder[-_delay_in_bytes];
                _delay_line->get_remaining (remainder);
                _audio_frames_processed += _delay_in_bytes / (_fs->audio_channels() * bytes_per_audio_sample());
-               emit_audio (remainder, _delay_in_bytes);
+               emit_audio (remainder, -_delay_in_bytes);
        }
 
        /* If we cut the decode off, the audio may be short; push some silence
           in to get it to the right length.
        */
 
-       int64_t const video_length_in_audio_frames = ((int64_t) _fs->dcp_length() * _fs->target_sample_rate() / _fs->frames_per_second());
+       int64_t const video_length_in_audio_frames = ((int64_t) _fs->dcp_length() * _fs->audio_sample_rate() / _fs->frames_per_second());
        int64_t const audio_short_by_frames = video_length_in_audio_frames - _audio_frames_processed;
 
        _log->log (
@@ -127,6 +127,10 @@ Decoder::process_end ()
                _log->log (String::compose ("DCP length is %1; %2 frames of audio processed.", _fs->dcp_length(), _audio_frames_processed));
                _log->log (String::compose ("Adding %1 frames of silence to the end.", audio_short_by_frames));
 
+               /* XXX: this is slightly questionable; does memset () give silence with all
+                  sample formats?
+               */
+
                int64_t bytes = audio_short_by_frames * _fs->audio_channels() * bytes_per_audio_sample();
                
                int64_t const silence_size = 16 * 1024 * _fs->audio_channels() * bytes_per_audio_sample();
@@ -262,7 +266,7 @@ Decoder::emit_audio (uint8_t* data, int size)
        }
 
        /* Update the number of audio frames we've pushed to the encoder */
-       _audio_frames_processed += frames;
+       _audio_frames_processed += audio->frames ();
 
        Audio (audio);
 }
@@ -348,7 +352,7 @@ Decoder::process_video (AVFrame* frame)
                        }
 
                        shared_ptr<Subtitle> sub;
-                       if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / rint (_fs->frames_per_second()))) {
+                       if (_timed_subtitle && _timed_subtitle->displayed_at (double (last_video_frame()) / _fs->frames_per_second())) {
                                sub = _timed_subtitle->subtitle ();
                        }
 
@@ -459,7 +463,7 @@ Decoder::process_subtitle (shared_ptr<TimedSubtitle> s)
 {
        _timed_subtitle = s;
        
-       if (_opt->apply_crop) {
+       if (_timed_subtitle && _opt->apply_crop) {
                Position const p = _timed_subtitle->subtitle()->position ();
                _timed_subtitle->subtitle()->set_position (Position (p.x - _fs->crop().left, p.y - _fs->crop().top));
        }