Partial merge of examine content and thumbnail jobs.
authorCarl Hetherington <cth@carlh.net>
Sun, 21 Oct 2012 12:09:10 +0000 (13:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 21 Oct 2012 12:09:10 +0000 (13:09 +0100)
12 files changed:
src/lib/decoder.cc
src/lib/examine_content_job.cc
src/lib/film.cc
src/lib/film.h
src/lib/film_state.cc
src/lib/film_state.h
src/lib/thumbs_job.cc [deleted file]
src/lib/thumbs_job.h [deleted file]
src/lib/wscript
src/wx/film_editor.cc
src/wx/film_viewer.cc
src/wx/film_viewer.h

index d78089265d65b848709d9870c157123744970a16..c398c53a01e01e128c35d3322ec07e757629b0b1 100644 (file)
@@ -166,7 +166,7 @@ Decoder::pass ()
                _have_setup_video_filters = true;
        }
        
-       if (_video_frame >= _fs->dcp_length()) {
+       if (!_ignore_length && _video_frame >= _fs->dcp_length()) {
                return true;
        }
 
index fd574e2d058281dba42c77115ce0b6afacee7634..5800c6f24dd643e40d2bf4db26f426be08681e04 100644 (file)
@@ -26,6 +26,8 @@
 #include "film_state.h"
 #include "decoder_factory.h"
 #include "decoder.h"
+#include "imagemagick_encoder.h"
+#include "transcoder.h"
 
 using namespace std;
 using namespace boost;
@@ -49,13 +51,49 @@ ExamineContentJob::name () const
 void
 ExamineContentJob::run ()
 {
+       shared_ptr<FilmState> fs = _fs->state_copy ();
+       
+       /* Decode the content to get an accurate length */
+       
        shared_ptr<Options> o (new Options ("", "", ""));
        o->out_size = Size (512, 512);
        o->apply_crop = false;
 
-       _decoder = decoder_factory (_fs, o, this, _log, true, true);
+       descend (0.5);
+
+       _decoder = decoder_factory (fs, o, this, _log, true, true);
        _decoder->go ();
-       
+       fs->set_length (last_video_frame ());
+
+       ascend ();
+
+       /* Now make thumbnails for it */
+
+       descend (0.5);
+
+       try {
+               o.reset (new Options (fs->dir ("thumbs"), ".png", ""));
+               o->out_size = fs->size ();
+               o->apply_crop = false;
+               o->decode_audio = false;
+               o->decode_video_frequency = 128;
+               o->decode_subtitles = true;
+               shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (fs, o, _log));
+               Transcoder w (fs, o, this, _log, e);
+               w.go ();
+               set_progress (1);
+               set_state (FINISHED_OK);
+               
+       } catch (std::exception& e) {
+
+               ascend ();
+               set_progress (1);
+               set_error (e.what ());
+               set_state (FINISHED_ERROR);
+               
+       }
+
+       ascend ();
        set_progress (1);
        set_state (FINISHED_OK);
 }
index 1f511add76a3875396a68fb57205a7e10c9d4c7a..74e5d0bb234380422f90bb8d4feecfc437e187ca 100644 (file)
@@ -103,47 +103,6 @@ Film::~Film ()
        delete _log;
 }
          
-/** The pre-processing GUI part of a thumbs update.
- *  Must be called from the GUI thread.
- */
-void
-Film::update_thumbs_pre_gui ()
-{
-       set_thumbs (vector<int> ());
-       filesystem::remove_all (dir ("thumbs"));
-
-       /* This call will recreate the directory */
-       dir ("thumbs");
-}
-
-/** The post-processing GUI part of a thumbs update.
- *  Must be called from the GUI thread.
- */
-void
-Film::update_thumbs_post_gui ()
-{
-       string const tdir = dir ("thumbs");
-       vector<int> thumbs;
-       
-       for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) {
-
-               /* Aah, the sweet smell of progress */
-#if BOOST_FILESYSTEM_VERSION == 3              
-               string const l = filesystem::path(*i).leaf().generic_string();
-#else
-               string const l = i->leaf ();
-#endif
-               
-               size_t const d = l.find (".png");
-               if (d != string::npos) {
-                       thumbs.push_back (atoi (l.substr (0, d).c_str()));
-               }
-       }
-
-       sort (thumbs.begin(), thumbs.end());
-       set_thumbs (thumbs);
-}
-
 /** @return The path to the directory to write JPEG2000 files to */
 string
 Film::j2k_dir () const
@@ -281,6 +240,12 @@ Film::examine_content ()
        if (_examine_content_job) {
                return;
        }
+
+       set_thumbs (vector<int> ());
+       filesystem::remove_all (dir ("thumbs"));
+
+       /* This call will recreate the directory */
+       dir ("thumbs");
        
        _examine_content_job.reset (new ExamineContentJob (state_copy (), log(), shared_ptr<Job> ()));
        _examine_content_job->Finished.connect (sigc::mem_fun (*this, &Film::examine_content_post_gui));
@@ -292,6 +257,27 @@ Film::examine_content_post_gui ()
 {
        set_length (_examine_content_job->last_video_frame ());
        _examine_content_job.reset ();
+
+       string const tdir = dir ("thumbs");
+       vector<int> thumbs;
+       
+       for (filesystem::directory_iterator i = filesystem::directory_iterator (tdir); i != filesystem::directory_iterator(); ++i) {
+
+               /* Aah, the sweet smell of progress */
+#if BOOST_FILESYSTEM_VERSION == 3              
+               string const l = filesystem::path(*i).leaf().generic_string();
+#else
+               string const l = i->leaf ();
+#endif
+               
+               size_t const d = l.find (".png");
+               if (d != string::npos) {
+                       thumbs.push_back (atoi (l.substr (0, d).c_str()));
+               }
+       }
+
+       sort (thumbs.begin(), thumbs.end());
+       set_thumbs (thumbs);    
 }
 
 
@@ -370,3 +356,10 @@ Film::thumb_subtitle (int n) const
        
        return sub;
 }
+
+void
+Film::set_content (string c)
+{
+       FilmState::set_content (c);
+       examine_content ();
+}
index d5c7420f866b2f6b47ebd6dc31da47a125838415..59589b325af3a3b0f863689f9e8d88c9cac8dc5e 100644 (file)
@@ -55,11 +55,7 @@ public:
        ~Film ();
 
        std::string j2k_dir () const;
-
        std::vector<std::string> audio_files () const;
-
-       void update_thumbs_pre_gui ();
-       void update_thumbs_post_gui ();
        std::pair<Position, std::string> thumb_subtitle (int) const;
 
        void copy_from_dvd_post_gui ();
@@ -79,7 +75,10 @@ public:
 
        int encoded_frames () const;
        
-private:
+       void set_content (std::string);
+
+private:       
+       
        /** Log to write to */
        Log* _log;
 
index 09c5e3efd19e89b3c8617e97bd57059581879e01..6ce88f2bb7356c9c3e8bf2175053376e3e5f29a8 100644 (file)
@@ -529,7 +529,6 @@ FilmState::set_content (string c)
        shared_ptr<Decoder> d = decoder_factory (s, o, 0, 0);
        
        set_size (d->native_size ());
-       set_length (d->length_in_frames ());
        set_frames_per_second (d->frames_per_second ());
        set_audio_sample_rate (d->audio_sample_rate ());
        set_has_subtitles (d->has_subtitles ());
@@ -834,5 +833,3 @@ FilmState::audio_channels () const
        return _audio_streams[_audio_stream].channels ();
 }
 
-
-       
index c76e845f34c0e5f67d95dc77cb92f1a2b1aaa2ab..43df2ba8fe067965d42ad10d2448df2182013049 100644 (file)
@@ -302,7 +302,7 @@ public:
        void set_directory (std::string);
        void set_name (std::string);
        void set_use_dci_name (bool);
-       void set_content (std::string);
+       virtual void set_content (std::string);
        void set_dcp_content_type (DCPContentType const *);
        void set_format (Format const *);
        void set_crop (Crop);
diff --git a/src/lib/thumbs_job.cc b/src/lib/thumbs_job.cc
deleted file mode 100644 (file)
index 845dc96..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file src/thumbs_job.cc
- *  @brief A job to create thumbnails.
- */
-
-#include <exception>
-#include "thumbs_job.h"
-#include "film_state.h"
-#include "imagemagick_encoder.h"
-#include "transcoder.h"
-#include "options.h"
-
-using namespace std;
-using namespace boost;
-
-/** @param s FilmState to use.
- *  @param o Options.
- *  @param l A log that we can write to.
- */
-ThumbsJob::ThumbsJob (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l, shared_ptr<Job> req)
-       : Job (s, o, l, req)
-{
-       
-}
-
-string
-ThumbsJob::name () const
-{
-       return String::compose ("Update thumbs for %1", _fs->name());
-}
-
-void
-ThumbsJob::run ()
-{
-       try {
-               shared_ptr<ImageMagickEncoder> e (new ImageMagickEncoder (_fs, _opt, _log));
-               Transcoder w (_fs, _opt, this, _log, e);
-               w.go ();
-               set_progress (1);
-               set_state (FINISHED_OK);
-
-       } catch (std::exception& e) {
-
-               set_progress (1);
-               set_error (e.what ());
-               set_state (FINISHED_ERROR);
-       }
-}
diff --git a/src/lib/thumbs_job.h b/src/lib/thumbs_job.h
deleted file mode 100644 (file)
index f7e30d5..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/** @file src/thumbs_job.h
- *  @brief A job to create thumbnails.
- */
-
-#include "job.h"
-
-class FilmState;
-
-/** @class ThumbsJob
- *  @brief A job to create thumbnails (single frames of the film spaced out throughout the film).
- */
-class ThumbsJob : public Job
-{
-public:
-       ThumbsJob (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> o, Log* l, boost::shared_ptr<Job> req);
-       std::string name () const;
-       void run ();
-};
index 6ce216d81f799151b6430872cc907cd5befc472f..04db716a480e7d37ed38ecfebddc77ca3942f4fe 100644 (file)
@@ -45,7 +45,6 @@ def build(bld):
                  sound_processor.cc
                  stream.cc
                  subtitle.cc
-                thumbs_job.cc
                  tiff_decoder.cc
                  timer.cc
                 transcode_job.cc
index 15755b9db43b756e0cf7a62ac7f851c7839d0e06..5d651364882b60cf722561f65aff9aecc22e7df7 100644 (file)
@@ -32,7 +32,6 @@
 #include "lib/transcode_job.h"
 #include "lib/exceptions.h"
 #include "lib/ab_transcode_job.h"
-#include "lib/thumbs_job.h"
 #include "lib/job_manager.h"
 #include "lib/filter.h"
 #include "lib/screen.h"
index a3827fba1df1e6acc5c67ca7dca661d97bda95ec..f029a1a38368421a60c56d1b1126b4bb3226a230 100644 (file)
@@ -26,7 +26,6 @@
 #include "lib/film.h"
 #include "lib/format.h"
 #include "lib/util.h"
-#include "lib/thumbs_job.h"
 #include "lib/job_manager.h"
 #include "lib/film_state.h"
 #include "lib/options.h"
@@ -277,8 +276,6 @@ FilmViewer::film_changed (FilmState::Property p)
                break;
        case FilmState::CONTENT:
                setup_visibility ();
-               _film->examine_content ();
-               update_thumbs ();
                break;
        case FilmState::CROP:
        case FilmState::FORMAT:
@@ -312,28 +309,6 @@ FilmViewer::set_film (Film* f)
        setup_visibility ();
 }
 
-void
-FilmViewer::update_thumbs ()
-{
-       if (!_film) {
-               return;
-       }
-
-       _film->update_thumbs_pre_gui ();
-
-       shared_ptr<const FilmState> s = _film->state_copy ();
-       shared_ptr<Options> o (new Options (s->dir ("thumbs"), ".png", ""));
-       o->out_size = _film->size ();
-       o->apply_crop = false;
-       o->decode_audio = false;
-       o->decode_video_frequency = 128;
-       o->decode_subtitles = true;
-       
-       shared_ptr<Job> j (new ThumbsJob (s, o, _film->log(), shared_ptr<Job> ()));
-       j->Finished.connect (sigc::mem_fun (_film, &Film::update_thumbs_post_gui));
-       JobManager::instance()->add (j);
-}
-
 void
 FilmViewer::setup_visibility ()
 {
index d2e597637fcfac6fd9a2ad6f2ed9b92be93b4626..b5112c8bb2f9701fd3da1fc4c1e1e2ec559fa367 100644 (file)
@@ -39,7 +39,6 @@ public:
 
 private:
        void slider_changed (wxCommandEvent &);
-       void update_thumbs ();
        void set_thumbnail (int);
        void film_changed (FilmState::Property);