diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-04-02 00:03:45 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-04-02 00:03:45 +0100 |
| commit | fff7a8232b18ce6191e60ba911c29b64b9063d4d (patch) | |
| tree | 3c61d950f341717c7b2478c110c9f1f6c3bef05a /src/lib | |
| parent | 6809fdcbf8c65afe3c986b0e2b430d55ce7b124c (diff) | |
Various bits.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/content.h | 19 | ||||
| -rw-r--r-- | src/lib/decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/encoder.h | 2 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.cc | 19 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.h | 19 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 1 | ||||
| -rw-r--r-- | src/lib/film.cc | 56 | ||||
| -rw-r--r-- | src/lib/film.h | 7 | ||||
| -rw-r--r-- | src/lib/imagemagick_content.cc | 46 | ||||
| -rw-r--r-- | src/lib/imagemagick_content.h | 24 | ||||
| -rw-r--r-- | src/lib/imagemagick_decoder.cc | 14 | ||||
| -rw-r--r-- | src/lib/imagemagick_decoder.h | 11 | ||||
| -rw-r--r-- | src/lib/playlist.cc | 23 | ||||
| -rw-r--r-- | src/lib/playlist.h | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 14 | ||||
| -rw-r--r-- | src/lib/util.h | 83 | ||||
| -rw-r--r-- | src/lib/video_content.cc | 8 | ||||
| -rw-r--r-- | src/lib/wscript | 1 |
18 files changed, 225 insertions, 126 deletions
diff --git a/src/lib/content.h b/src/lib/content.h index 3a94d2297..87ef46581 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -1,3 +1,22 @@ +/* + Copyright (C) 2013 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. + +*/ + #ifndef DVDOMATIC_CONTENT_H #define DVDOMATIC_CONTENT_H diff --git a/src/lib/decoder.h b/src/lib/decoder.h index 4ccdc046f..34accf6c7 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -58,8 +58,6 @@ public: virtual bool seek (double); virtual bool seek_to_last (); - boost::signals2::signal<void()> OutputChanged; - protected: boost::shared_ptr<const Film> _film; diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 86880bc34..2cbd498e8 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -106,7 +106,7 @@ private: static int const _history_size; /** Number of video frames received so far */ - SourceFrame _video_frames_in; + ContentVideoFrame _video_frames_in; /** Number of video frames written for the DCP so far */ int _video_frames_out; diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 42e04e838..50a69ae7b 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -1,3 +1,22 @@ +/* + Copyright (C) 2013 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. + +*/ + #include <libcxml/cxml.h> #include "ffmpeg_content.h" #include "ffmpeg_decoder.h" diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index 95e24b7b3..c56dc0a61 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -1,3 +1,22 @@ +/* + Copyright (C) 2013 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. + +*/ + #ifndef DVDOMATIC_FFMPEG_CONTENT_H #define DVDOMATIC_FFMPEG_CONTENT_H diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 25ca9bb88..ced9b95e9 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -592,7 +592,6 @@ FFmpegDecoder::film_changed (Film::Property p) boost::mutex::scoped_lock lm (_filter_graphs_mutex); _filter_graphs.clear (); } - OutputChanged (); break; default: diff --git a/src/lib/film.cc b/src/lib/film.cc index fe16a65fa..19e900784 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -1043,6 +1043,62 @@ Film::add_content (shared_ptr<Content> c) examine_content (c); } +void +Film::remove_content (shared_ptr<Content> c) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + ContentList::iterator i = find (_content.begin(), _content.end(), c); + if (i != _content.end ()) { + _content.erase (i); + } + } + + signal_changed (CONTENT); +} + +void +Film::move_content_earlier (shared_ptr<Content> c) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + ContentList::iterator i = find (_content.begin(), _content.end(), c); + if (i == _content.begin () || i == _content.end()) { + return; + } + + ContentList::iterator j = i; + --j; + + swap (*i, *j); + } + + signal_changed (CONTENT); +} + +void +Film::move_content_later (shared_ptr<Content> c) +{ + { + boost::mutex::scoped_lock lm (_state_mutex); + ContentList::iterator i = find (_content.begin(), _content.end(), c); + if (i == _content.end()) { + return; + } + + ContentList::iterator j = i; + ++j; + if (j == _content.end ()) { + return; + } + + swap (*i, *j); + } + + signal_changed (CONTENT); + +} + ContentAudioFrame Film::audio_length () const { diff --git a/src/lib/film.h b/src/lib/film.h index 6e097d44e..9682a37d7 100644 --- a/src/lib/film.h +++ b/src/lib/film.h @@ -38,6 +38,7 @@ extern "C" { #include "dcp_content_type.h" #include "util.h" #include "dci_metadata.h" +#include "types.h" class Format; class Job; @@ -171,7 +172,7 @@ public: return _trust_content_headers; } - std::list<boost::shared_ptr<Content> > content () const { + ContentList content () const { boost::mutex::scoped_lock lm (_state_mutex); return _content; } @@ -268,6 +269,9 @@ public: void set_use_dci_name (bool); void set_trust_content_headers (bool); void add_content (boost::shared_ptr<Content>); + void remove_content (boost::shared_ptr<Content>); + void move_content_earlier (boost::shared_ptr<Content>); + void move_content_later (boost::shared_ptr<Content>); void set_dcp_content_type (DCPContentType const *); void set_format (Format const *); void set_crop (Crop); @@ -325,7 +329,6 @@ private: std::string _name; /** True if a auto-generated DCI-compliant name should be used for our DCP */ bool _use_dci_name; - typedef std::list<boost::shared_ptr<Content> > ContentList; ContentList _content; bool _trust_content_headers; /** The type of content that this Film represents (feature, trailer etc.) */ diff --git a/src/lib/imagemagick_content.cc b/src/lib/imagemagick_content.cc index cb712b417..f9572b518 100644 --- a/src/lib/imagemagick_content.cc +++ b/src/lib/imagemagick_content.cc @@ -1,5 +1,25 @@ +/* + Copyright (C) 2013 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. + +*/ + #include <libcxml/cxml.h> #include "imagemagick_content.h" +#include "imagemagick_decoder.h" #include "compose.hpp" #include "i18n.h" @@ -11,8 +31,7 @@ ImageMagickContent::ImageMagickContent (boost::filesystem::path f) : Content (f) , VideoContent (f) { - /* XXX */ - _video_length = 10 * 24; + } ImageMagickContent::ImageMagickContent (shared_ptr<const cxml::Node> node) @@ -35,3 +54,26 @@ ImageMagickContent::valid_file (boost::filesystem::path f) transform (ext.begin(), ext.end(), ext.begin(), ::tolower); return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp"); } + +void +ImageMagickContent::as_xml (xmlpp::Node* node) const +{ + node->add_child("Type")->add_child_text ("ImageMagick"); + Content::as_xml (node); + VideoContent::as_xml (node); +} + +void +ImageMagickContent::examine (shared_ptr<Film> film, shared_ptr<Job> job, bool quick) +{ + Content::examine (film, job, quick); + shared_ptr<ImageMagickDecoder> decoder (new ImageMagickDecoder (film, shared_from_this())); + + { + boost::mutex::scoped_lock lm (_mutex); + /* XXX */ + _video_length = 10 * 24; + } + + take_from_video_decoder (decoder); +} diff --git a/src/lib/imagemagick_content.h b/src/lib/imagemagick_content.h index 99b614512..5820bd807 100644 --- a/src/lib/imagemagick_content.h +++ b/src/lib/imagemagick_content.h @@ -1,16 +1,38 @@ +/* + Copyright (C) 2013 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. + +*/ + +#include <boost/enable_shared_from_this.hpp> #include "video_content.h" namespace cxml { class Node; } -class ImageMagickContent : public VideoContent +class ImageMagickContent : public VideoContent, public boost::enable_shared_from_this<ImageMagickContent> { public: ImageMagickContent (boost::filesystem::path); ImageMagickContent (boost::shared_ptr<const cxml::Node>); + void examine (boost::shared_ptr<Film>, boost::shared_ptr<Job>, bool); std::string summary () const; + void as_xml (xmlpp::Node *) const; static bool valid_file (boost::filesystem::path); }; diff --git a/src/lib/imagemagick_decoder.cc b/src/lib/imagemagick_decoder.cc index 279c8bf32..508863e3e 100644 --- a/src/lib/imagemagick_decoder.cc +++ b/src/lib/imagemagick_decoder.cc @@ -52,6 +52,12 @@ ImageMagickDecoder::native_size () const return s; } +int +ImageMagickDecoder::video_length () const +{ + return _imagemagick_content->video_length (); +} + bool ImageMagickDecoder::pass () { @@ -120,11 +126,3 @@ ImageMagickDecoder::seek (double t) _position = f; return false; } - -void -ImageMagickDecoder::film_changed (Film::Property p) -{ - if (p == Film::CROP) { - OutputChanged (); - } -} diff --git a/src/lib/imagemagick_decoder.h b/src/lib/imagemagick_decoder.h index 7ad08df03..424cefe08 100644 --- a/src/lib/imagemagick_decoder.h +++ b/src/lib/imagemagick_decoder.h @@ -31,16 +31,11 @@ public: ImageMagickDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const ImageMagickContent>); float frames_per_second () const { - /* We don't know */ - return 0; + return 24; } libdcp::Size native_size () const; - - ContentVideoFrame video_length () const { - /* We don't know */ - return 0; - } + ContentVideoFrame video_length () const; int audio_channels () const { return 0; @@ -80,8 +75,6 @@ protected: } private: - void film_changed (Film::Property); - boost::shared_ptr<const ImageMagickContent> _imagemagick_content; ContentVideoFrame _position; }; diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index d9bf8ac36..609d4096c 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -27,6 +27,7 @@ #include "imagemagick_decoder.h" using std::list; +using std::cout; using boost::shared_ptr; using boost::dynamic_pointer_cast; @@ -38,12 +39,12 @@ Playlist::Playlist () } void -Playlist::setup (list<shared_ptr<Content> > content) +Playlist::setup (ContentList content) { _video_from = VIDEO_NONE; _audio_from = AUDIO_NONE; - for (list<shared_ptr<Content> >::const_iterator i = content.begin(); i != content.end(); ++i) { + for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) { shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i); if (fc) { assert (!_ffmpeg); @@ -287,11 +288,12 @@ Player::process_audio (shared_ptr<AudioBuffers> b) Audio (b); } +/** @return true on error */ bool Player::seek (double t) { bool r = false; - + switch (_playlist->video_from()) { case Playlist::VIDEO_NONE: break; @@ -301,7 +303,20 @@ Player::seek (double t) } break; case Playlist::VIDEO_IMAGEMAGICK: - if ((*_imagemagick_decoder)->seek (t)) { + /* Find the decoder that contains this position */ + _imagemagick_decoder = _imagemagick_decoders.begin (); + while (_imagemagick_decoder != _imagemagick_decoders.end ()) { + double const this_length = (*_imagemagick_decoder)->video_length() / _film->video_frame_rate (); + if (this_length < t) { + break; + } + t -= this_length; + ++_imagemagick_decoder; + } + + if (_imagemagick_decoder != _imagemagick_decoders.end()) { + (*_imagemagick_decoder)->seek (t); + } else { r = true; } break; diff --git a/src/lib/playlist.h b/src/lib/playlist.h index 827849049..403fb58d4 100644 --- a/src/lib/playlist.h +++ b/src/lib/playlist.h @@ -40,7 +40,7 @@ class Playlist public: Playlist (); - void setup (std::list<boost::shared_ptr<Content> >); + void setup (ContentList); ContentAudioFrame audio_length () const; int audio_channels () const; diff --git a/src/lib/util.cc b/src/lib/util.cc index 1c020875a..e0de82c64 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -476,16 +476,6 @@ dcp_audio_sample_rate (int fs) return 96000; } -bool operator== (Crop const & a, Crop const & b) -{ - return (a.left == b.left && a.right == b.right && a.top == b.top && a.bottom == b.bottom); -} - -bool operator!= (Crop const & a, Crop const & b) -{ - return !(a == b); -} - /** @param index Colour LUT index. * @return Human-readable name. */ @@ -867,13 +857,13 @@ ensure_ui_thread () assert (this_thread::get_id() == ui_thread); } -/** @param v Source video frame. +/** @param v Content video frame. * @param audio_sample_rate Source audio sample rate. * @param frames_per_second Number of video frames per second. * @return Equivalent number of audio frames for `v'. */ int64_t -video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second) +video_frames_to_audio_frames (ContentVideoFrame v, float audio_sample_rate, float frames_per_second) { return ((int64_t) v * audio_sample_rate / frames_per_second); } diff --git a/src/lib/util.h b/src/lib/util.h index b8c1e3116..23ebd52bc 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -37,6 +37,7 @@ extern "C" { #include <libavfilter/avfilter.h> } #include "compose.hpp" +#include "types.h" #ifdef DVDOMATIC_DEBUG #define TIMING(...) _film->log()->microsecond_log (String::compose (__VA_ARGS__), Log::TIMING); @@ -65,10 +66,6 @@ extern std::string audio_channel_name (int); extern boost::filesystem::path mo_path (); #endif -typedef int SourceFrame; -typedef int64_t ContentAudioFrame; -typedef int ContentVideoFrame; - struct FrameRateConversion { FrameRateConversion (float, int); @@ -106,82 +103,6 @@ struct FrameRateConversion int best_dcp_frame_rate (float); -/** @struct Crop - * @brief A description of the crop of an image or video. - */ -struct Crop -{ - Crop () : left (0), right (0), top (0), bottom (0) {} - - /** Number of pixels to remove from the left-hand side */ - int left; - /** Number of pixels to remove from the right-hand side */ - int right; - /** Number of pixels to remove from the top */ - int top; - /** Number of pixels to remove from the bottom */ - int bottom; -}; - -extern bool operator== (Crop const & a, Crop const & b); -extern bool operator!= (Crop const & a, Crop const & b); - -/** @struct Position - * @brief A position. - */ -struct Position -{ - Position () - : x (0) - , y (0) - {} - - Position (int x_, int y_) - : x (x_) - , y (y_) - {} - - /** x coordinate */ - int x; - /** y coordinate */ - int y; -}; - -/** @struct Rect - * @brief A rectangle. - */ -struct Rect -{ - Rect () - : x (0) - , y (0) - , width (0) - , height (0) - {} - - Rect (int x_, int y_, int w_, int h_) - : x (x_) - , y (y_) - , width (w_) - , height (h_) - {} - - int x; - int y; - int width; - int height; - - Position position () const { - return Position (x, y); - } - - libdcp::Size size () const { - return libdcp::Size (width, height); - } - - Rect intersection (Rect const & other) const; -}; - extern std::string crop_string (Position, libdcp::Size); extern int dcp_audio_sample_rate (int); extern std::string colour_lut_index_to_name (int index); @@ -286,7 +207,7 @@ private: int _source_channels; }; -extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second); +extern int64_t video_frames_to_audio_frames (ContentVideoFrame v, float audio_sample_rate, float frames_per_second); extern std::pair<std::string, int> cpu_info (); #endif diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 8a4414c18..e697a281d 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -39,10 +39,14 @@ VideoContent::as_xml (xmlpp::Node* node) const void VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d) { + /* These decoder calls could call other content methods which take a lock on the mutex */ + libdcp::Size const vs = d->native_size (); + float const vfr = d->frames_per_second (); + { boost::mutex::scoped_lock lm (_mutex); - _video_size = d->native_size (); - _video_frame_rate = d->frames_per_second (); + _video_size = vs; + _video_frame_rate = vfr; } Changed (VideoContentProperty::VIDEO_SIZE); diff --git a/src/lib/wscript b/src/lib/wscript index 303a9951f..f2bb678aa 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -49,6 +49,7 @@ sources = """ timer.cc transcode_job.cc transcoder.cc + types.cc ui_signaller.cc util.cc version.cc |
