Various fixes.
authorCarl Hetherington <cth@carlh.net>
Sun, 4 Nov 2012 23:56:53 +0000 (23:56 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 4 Nov 2012 23:56:53 +0000 (23:56 +0000)
src/lib/decoder.cc
src/lib/j2k_wav_encoder.cc
src/lib/job.cc
src/lib/transcode_job.cc

index e25a106d2186ab8bc3b3bc9a2bfeecd9e7250b92..617d57ff6762b3a02e32e49fde586396ac0729dd 100644 (file)
@@ -116,6 +116,11 @@ Decoder::process_end ()
                        black->make_black ();
                        for (int i = 0; i < black_video_frames; ++i) {
                                emit_video (black, shared_ptr<Subtitle> ());
+
+                               /* This is a bit of a hack, but you can sort-of justify it if you squint at it right.
+                                  It's important because the encoder will probably use this to name its output frame.
+                               */
+                               ++_video_frames_in;
                        }
 
                        /* Now recompute our check value */
@@ -232,6 +237,8 @@ Decoder::process_audio (uint8_t* data, int size)
 
        _delay_line->feed (audio);
 
+       int const in_frames = audio->frames ();
+
        if (_opt->decode_range) {
                /* Decode range in audio frames */
                pair<int64_t, int64_t> required_range (
@@ -244,10 +251,13 @@ Decoder::process_audio (uint8_t* data, int size)
                        _audio_frames_in,
                        _audio_frames_in + audio->frames()
                        );
-               
-               if (required_range.first >= this_range.first && required_range.first < this_range.second) {
+
+               if (this_range.second < required_range.first || required_range.second < this_range.first) {
+                       /* No part of this audio is within the required range */
+                       audio->set_frames (0);
+               } else if (required_range.first >= this_range.first && required_range.first < this_range.second) {
                        /* Trim start */
-                       int64_t const shift = this_range.first - required_range.first;
+                       int64_t const shift = required_range.first - this_range.first;
                        audio->move (shift, 0, audio->frames() - shift);
                        audio->set_frames (audio->frames() - shift);
                } else if (required_range.second >= this_range.first && required_range.second < this_range.second) {
@@ -259,6 +269,8 @@ Decoder::process_audio (uint8_t* data, int size)
        if (audio->frames()) {
                emit_audio (audio);
        }
+
+       _audio_frames_in += in_frames;
 }
 
 void
@@ -317,9 +329,8 @@ Decoder::process_video (AVFrame* frame)
                }
 
                emit_video (*i, sub);
+               ++_video_frames_in;
        }
-
-       ++_video_frames_in;
 }
 
 void
@@ -331,6 +342,7 @@ Decoder::repeat_last_video ()
        }
 
        emit_video (_last_image, _last_subtitle);
+       ++_video_frames_in;
 }
 
 void
index 38078efb16d32e03679392186433b5772a4210bb..09e87757999ad56c094d895317881ba258147555 100644 (file)
@@ -163,7 +163,7 @@ J2KWAVEncoder::encoder_thread (ServerDescription* server)
 
                TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
                boost::shared_ptr<DCPVideoFrame> vf = _queue.front ();
-               _film->log()->log (String::compose ("Encoder thread %1 pops frame %2 from queue", boost::this_thread::get_id(), vf->frame()));
+               _film->log()->log (String::compose ("Encoder thread %1 pops frame %2 from queue", boost::this_thread::get_id(), vf->frame()), Log::VERBOSE);
                _queue.pop_front ();
                
                lock.unlock ();
@@ -278,7 +278,7 @@ J2KWAVEncoder::process_end ()
 
        /* Keep waking workers until the queue is empty */
        while (!_queue.empty ()) {
-               _film->log()->log ("Waking with " + lexical_cast<string> (_queue.size ()));
+               _film->log()->log ("Waking with " + lexical_cast<string> (_queue.size ()), Log::VERBOSE);
                _worker_condition.notify_all ();
                _worker_condition.wait (lock);
        }
index c5a254a2a60b5829f742e10cd784642108907eb2..3309fe16c64393b6a961841677512f8db02254f6 100644 (file)
@@ -236,7 +236,7 @@ Job::status () const
        float const p = overall_progress ();
        int const t = elapsed_time ();
        int const r = remaining_time ();
-       
+
        stringstream s;
        if (!finished () && p >= 0 && t > 10 && r > 0) {
                s << rint (p * 100) << "%; " << seconds_to_approximate_hms (r) << " remaining";
index 2690d8ed1095ecd678575d66d1e4fe1293dc948b..db4fb86e1304482e1e63b98337743274778c2210 100644 (file)
@@ -111,6 +111,6 @@ TranscodeJob::remaining_time () const
        }
 
        /* We assume that dcp_length() is valid */
-       SourceFrame const left = _film->dcp_length().get() - _encoder->last_frame() - _film->dcp_trim_start();
+       SourceFrame const left = _film->dcp_trim_start() + _film->dcp_length().get() - _encoder->last_frame();
        return left / fps;
 }