Fix crash on using delay; fix x-thread GUI access caused by FilmState default copy...
authorCarl Hetherington <cth@carlh.net>
Mon, 22 Oct 2012 12:33:11 +0000 (13:33 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 22 Oct 2012 12:33:11 +0000 (13:33 +0100)
src/lib/decoder.cc
src/lib/examine_content_job.cc
src/lib/examine_content_job.h
src/lib/film_state.h
src/lib/util.cc
src/lib/util.h
src/wx/film_editor.cc
src/wx/film_viewer.cc

index 173360ec1036435dbaba9c312c4d3a04c3f93c52..a90c14b2bdc995af6664e51965a68bd7995978f8 100644 (file)
@@ -105,7 +105,7 @@ 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
index d91fc2136e8e3545b32b57e201de8eb3e731712a..d12e060691e61a08d876e764aedc1907761d895a 100644 (file)
@@ -70,7 +70,6 @@ ExamineContentJob::run ()
        _decoder->go ();
 
        fs->set_length (_decoder->last_video_frame ());
-       fs->set_audio_delay (-_decoder->audio_to_discard ());
 
        _log->log (String::compose ("Video length is %1 frames", _decoder->last_video_frame()));
        _log->log (String::compose ("%1ms of audio to discard", _decoder->audio_to_discard()));
@@ -112,3 +111,10 @@ ExamineContentJob::last_video_frame () const
 {
        return _decoder->last_video_frame ();
 }
+
+int
+ExamineContentJob::audio_to_discard () const
+{
+       return _decoder->audio_to_discard ();
+}
+
index 3bbd673a87e66aab5521b0ddb1666d5404da66ab..d8e94f1ec2f6cb5755336a4ffd682a0c866f476c 100644 (file)
@@ -38,6 +38,7 @@ public:
        void run ();
 
        int last_video_frame () const;
+       int audio_to_discard () const;
 
 private:
        boost::shared_ptr<Decoder> _decoder;
index aa427fcad2ccd5a8bdcb3a17e67e440796bc80a8..294b9aa10ebcb301f220a6850acabd64016b799e 100644 (file)
@@ -76,6 +76,46 @@ public:
                , _dirty (false)
        {}
 
+       FilmState (FilmState const & o)
+               : _directory         (o._directory)
+               , _name              (o._name)
+               , _use_dci_name      (o._use_dci_name)
+               , _content           (o._content)
+               , _dcp_content_type  (o._dcp_content_type)
+               , _format            (o._format)
+               , _crop              (o._crop)
+               , _filters           (o._filters)
+               , _scaler            (o._scaler)
+               , _dcp_frames        (o._dcp_frames)
+               , _dcp_trim_action   (o._dcp_trim_action)
+               , _dcp_ab            (o._dcp_ab)
+               , _audio_stream      (o._audio_stream)
+               , _audio_gain        (o._audio_gain)
+               , _audio_delay       (o._audio_delay)
+               , _still_duration    (o._still_duration)
+               , _subtitle_stream   (o._subtitle_stream)
+               , _with_subtitles    (o._with_subtitles)
+               , _subtitle_offset   (o._subtitle_offset)
+               , _subtitle_scale    (o._subtitle_scale)
+               , _audio_language    (o._audio_language)
+               , _subtitle_language (o._subtitle_language)
+               , _territory         (o._territory)
+               , _rating            (o._rating)
+               , _studio            (o._studio)
+               , _facility          (o._facility)
+               , _package_type      (o._package_type)
+               , _thumbs            (o._thumbs)
+               , _size              (o._size)
+               , _length            (o._length)
+               , _audio_sample_rate (o._audio_sample_rate)
+               , _content_digest    (o._content_digest)
+               , _has_subtitles     (o._has_subtitles)
+               , _audio_streams     (o._audio_streams)
+               , _subtitle_streams  (o._subtitle_streams)
+               , _frames_per_second (o._frames_per_second)
+               , _dirty             (o._dirty)
+       {}
+
        virtual ~FilmState () {}
 
        std::string file (std::string f) const;
index 52a75474b6597565e281bb75a0d491ada3c5c163..6221b8b62c6aacb0a2ee164595678a284ffdc8bf 100644 (file)
@@ -36,6 +36,7 @@
 #include <boost/bind.hpp>
 #include <boost/lambda/lambda.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/thread.hpp>
 #include <openjpeg.h>
 #include <openssl/md5.h>
 #include <magick/MagickCore.h>
@@ -65,6 +66,8 @@ extern "C" {
 using namespace std;
 using namespace boost;
 
+thread::id ui_thread;
+
 /** Convert some number of seconds to a string representation
  *  in hours, minutes and seconds.
  *
@@ -265,7 +268,9 @@ sigchld_handler (int, siginfo_t* info, void *)
 }
 #endif
 
-/** Call the required functions to set up DVD-o-matic's static arrays, etc. */
+/** Call the required functions to set up DVD-o-matic's static arrays, etc.
+ *  Must be called from the UI thread, if there is one.
+ */
 void
 dvdomatic_setup ()
 {
@@ -275,6 +280,8 @@ dvdomatic_setup ()
        Filter::setup_filters ();
        SoundProcessor::setup_sound_processors ();
 
+       ui_thread = this_thread::get_id ();
+
 #ifdef DVDOMATIC_POSIX 
        struct sigaction sa;
        sa.sa_flags = SA_SIGINFO;
@@ -727,5 +734,8 @@ AudioBuffers::set_frames (int f)
        _frames = f;
 }
 
-       
-       
+void
+ensure_ui_thread ()
+{
+       assert (this_thread::get_id() == ui_thread);
+}
index a6d95b85d3f004ee46eb1c4abe0f1dd75dd87174..2265dfe707520e2c3d43813c2bab6f9ea47e801a 100644 (file)
@@ -52,6 +52,7 @@ extern void dvdomatic_setup ();
 extern std::vector<std::string> split_at_spaces_considering_quotes (std::string);
 extern std::string md5_digest (std::string);
 extern std::string md5_digest (void const *, int);
+extern void ensure_ui_thread ();
 
 enum ContentType {
        STILL,
index 5d651364882b60cf722561f65aff9aecc22e7df7..47e093b36c3749f91f89c134ea399e4f2a28e3c9 100644 (file)
@@ -401,6 +401,8 @@ FilmEditor::subtitle_scale_changed (wxCommandEvent &)
 void
 FilmEditor::film_changed (FilmState::Property p)
 {
+       ensure_ui_thread ();
+       
        if (!_film || _ignore_changes == p) {
                return;
        }
index 8c1ce34e0486df31703a53cf2ecf17c28453bb21..5262338332e7073884b37bbc398c9d007eb057ca 100644 (file)
@@ -262,6 +262,8 @@ FilmViewer::slider_changed (wxCommandEvent &)
 void
 FilmViewer::film_changed (FilmState::Property p)
 {
+       ensure_ui_thread ();
+       
        switch (p) {
        case FilmState::THUMBS:
                if (_film && _film->thumbs().size() > 1) {