From c2b6ca1193107581b433d294aa2327a936f77383 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 12 Jul 2013 15:17:45 +0100 Subject: [PATCH] Tidy up video state identifer code slightly. --- src/lib/content.h | 1 + src/lib/ffmpeg_content.cc | 20 ++++++++++++++++++++ src/lib/ffmpeg_content.h | 2 ++ src/lib/film.cc | 10 +++++----- src/lib/film.h | 2 +- src/lib/imagemagick_content.cc | 7 +++++++ src/lib/imagemagick_content.h | 2 ++ src/lib/playlist.cc | 13 ++++--------- src/lib/playlist.h | 2 +- src/lib/video_content.cc | 18 ++++++++++++++++++ src/lib/video_content.h | 1 + 11 files changed, 62 insertions(+), 16 deletions(-) diff --git a/src/lib/content.h b/src/lib/content.h index 5dcf27597..a190a393f 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -62,6 +62,7 @@ public: return _file; } + /** @return MD5 digest of the content's file */ std::string digest () const { boost::mutex::scoped_lock lm (_mutex); return _digest; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 35f9f71f2..b4c1ecbfa 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -378,3 +378,23 @@ FFmpegContent::set_audio_mapping (AudioMapping m) audio_stream()->mapping = m; signal_changed (AudioContentProperty::AUDIO_MAPPING); } + +string +FFmpegContent::identifier () const +{ + stringstream s; + + s << VideoContent::identifier(); + + boost::mutex::scoped_lock lm (_mutex); + + if (_subtitle_stream) { + s << "_" << _subtitle_stream->id; + } + + for (vector::const_iterator i = _filters.begin(); i != _filters.end(); ++i) { + s << "_" << (*i)->id (); + } + + return s.str (); +} diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index 5b9f1f579..2d8a043f7 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -98,6 +98,8 @@ public: boost::shared_ptr clone () const; Time length () const; + std::string identifier () const; + /* AudioContent */ int audio_channels () const; AudioContent::Frame audio_length () const; diff --git a/src/lib/film.cc b/src/lib/film.cc index 16b34110c..a49e549a7 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -151,14 +151,14 @@ Film::Film (Film const & o) } string -Film::video_state_identifier () const +Film::video_identifier () const { assert (container ()); LocaleGuard lg; stringstream s; s << container()->id() - << "_" << _playlist->video_digest() + << "_" << _playlist->video_identifier() << "_" << _dcp_video_frame_rate << "_" << scaler()->id() << "_" << j2k_bandwidth() @@ -173,7 +173,7 @@ Film::info_dir () const { boost::filesystem::path p; p /= "info"; - p /= video_state_identifier (); + p /= video_identifier (); return dir (p.string()); } @@ -186,7 +186,7 @@ Film::internal_video_mxf_dir () const string Film::internal_video_mxf_filename () const { - return video_state_identifier() + ".mxf"; + return video_identifier() + ".mxf"; } string @@ -685,7 +685,7 @@ Film::j2c_path (int f, bool t) const { boost::filesystem::path p; p /= "j2c"; - p /= video_state_identifier (); + p /= video_identifier (); stringstream s; s.width (8); diff --git a/src/lib/film.h b/src/lib/film.h index 2bf1a0e90..c107541a0 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -237,7 +237,7 @@ public: private: void signal_changed (Property); - std::string video_state_identifier () const; + std::string video_identifier () const; void playlist_changed (); void playlist_content_changed (boost::weak_ptr, int); std::string filename_safe_name () const; diff --git a/src/lib/imagemagick_content.cc b/src/lib/imagemagick_content.cc index 2fd65ffa0..42e3776f5 100644 --- a/src/lib/imagemagick_content.cc +++ b/src/lib/imagemagick_content.cc @@ -107,3 +107,10 @@ ImageMagickContent::length () const return video_length() * frc.factor() * TIME_HZ / film->dcp_video_frame_rate (); } +string +ImageMagickContent::identifier () const +{ + stringstream s; + s << VideoContent::identifier (); + s << "_" << video_length(); +} diff --git a/src/lib/imagemagick_content.h b/src/lib/imagemagick_content.h index 04425af08..dab3158e3 100644 --- a/src/lib/imagemagick_content.h +++ b/src/lib/imagemagick_content.h @@ -43,6 +43,8 @@ public: boost::shared_ptr clone () const; Time length () const; + std::string identifier () const; + void set_video_length (VideoContent::Frame); static bool valid_file (boost::filesystem::path); diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index 995067b66..9e7f7f5f5 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -94,19 +94,14 @@ Playlist::content_changed (weak_ptr c, int p) } string -Playlist::video_digest () const +Playlist::video_identifier () const { string t; for (ContentList::const_iterator i = _content.begin(); i != _content.end(); ++i) { - if (!dynamic_pointer_cast (*i)) { - continue; - } - - t += (*i)->digest (); - shared_ptr fc = dynamic_pointer_cast (*i); - if (fc && fc->subtitle_stream()) { - t += fc->subtitle_stream()->id; + shared_ptr vc = dynamic_pointer_cast (*i); + if (vc) { + t += vc->identifier (); } } diff --git a/src/lib/playlist.h b/src/lib/playlist.h index 2d243fe8f..cf0f09b31 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -73,7 +73,7 @@ public: return _content; } - std::string video_digest () const; + std::string video_identifier () const; int loop () const { return _loop; diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 3818fa792..c1f4d0089 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -222,3 +222,21 @@ VideoContent::set_ratio (Ratio const * r) signal_changed (VideoContentProperty::VIDEO_RATIO); } + +/** @return string which includes everything about how this content looks */ +string +VideoContent::identifier () const +{ + stringstream s; + s << Content::digest() + << "_" << crop().left + << "_" << crop().right + << "_" << crop().top + << "_" << crop().bottom; + + if (ratio()) { + s << "_" << ratio()->id (); + } + + return s.str (); +} diff --git a/src/lib/video_content.h b/src/lib/video_content.h index 372cab3bd..e7bbad9e1 100644 --- a/src/lib/video_content.h +++ b/src/lib/video_content.h @@ -46,6 +46,7 @@ public: void as_xml (xmlpp::Node *) const; virtual std::string information () const; + virtual std::string identifier () const; VideoContent::Frame video_length () const { boost::mutex::scoped_lock lm (_mutex); -- 2.30.2