2 Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/lib/content.h
21 * @brief Content class.
24 #ifndef DCPOMATIC_CONTENT_H
25 #define DCPOMATIC_CONTENT_H
28 #include "signaller.h"
29 #include "dcpomatic_time.h"
30 #include <libxml++/libxml++.h>
31 #include <libcxml/cxml.h>
32 #include <boost/filesystem.hpp>
33 #include <boost/signals2.hpp>
34 #include <boost/thread/mutex.hpp>
35 #include <boost/enable_shared_from_this.hpp>
47 static int const PATH;
48 static int const POSITION;
49 static int const LENGTH;
50 static int const TRIM_START;
51 static int const TRIM_END;
55 * @brief A piece of content represented by one or more files on disk.
57 class Content : public boost::enable_shared_from_this<Content>, public Signaller, public boost::noncopyable
60 Content (boost::shared_ptr<const Film>);
61 Content (boost::shared_ptr<const Film>, DCPTime);
62 Content (boost::shared_ptr<const Film>, boost::filesystem::path);
63 Content (boost::shared_ptr<const Film>, cxml::ConstNodePtr);
64 Content (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
65 virtual ~Content () {}
67 /** Examine the content to establish digest, frame rates and any other
69 * @param job Job to use to report progress, or 0.
71 virtual void examine (boost::shared_ptr<Job> job);
73 /** @return Quick one-line summary of the content, as will be presented in the
76 virtual std::string summary () const = 0;
78 /** @return Technical details of this content; these are written to logs to
79 * help with debugging.
81 virtual std::string technical_summary () const;
83 virtual void as_xml (xmlpp::Node *) const;
84 virtual DCPTime full_length () const = 0;
85 virtual std::string identifier () const;
87 std::list<std::pair<std::string, std::string> > properties () const;
89 boost::shared_ptr<Content> clone () const;
91 void set_path (boost::filesystem::path);
93 std::string path_summary () const;
95 std::vector<boost::filesystem::path> paths () const {
96 boost::mutex::scoped_lock lm (_mutex);
100 size_t number_of_paths () const {
101 boost::mutex::scoped_lock lm (_mutex);
102 return _paths.size ();
105 boost::filesystem::path path (size_t i) const {
106 boost::mutex::scoped_lock lm (_mutex);
110 bool paths_valid () const;
112 /** @return Digest of the content's file(s). Note: this is
113 * not a complete MD5-or-whatever hash, but a sort of poor
114 * man's version (see comments in ::examine).
116 std::string digest () const {
117 boost::mutex::scoped_lock lm (_mutex);
121 void set_position (DCPTime);
123 /** DCPTime that this content starts; i.e. the time that the first
124 * bit of the content (trimmed or not) will happen.
126 DCPTime position () const {
127 boost::mutex::scoped_lock lm (_mutex);
131 void set_trim_start (DCPTime);
133 DCPTime trim_start () const {
134 boost::mutex::scoped_lock lm (_mutex);
138 void set_trim_end (DCPTime);
140 DCPTime trim_end () const {
141 boost::mutex::scoped_lock lm (_mutex);
145 /** @return Time immediately after the last thing in this content */
146 DCPTime end () const {
147 return position() + length_after_trim();
150 DCPTime length_after_trim () const;
152 void set_change_signals_frequent (bool f) {
153 _change_signals_frequent = f;
156 boost::shared_ptr<const Film> film () const {
157 return _film.lock ();
160 boost::signals2::signal<void (boost::weak_ptr<Content>, int, bool)> Changed;
163 void signal_changed (int);
164 virtual void add_properties (std::list<std::pair<std::string, std::string> > &) const {}
166 boost::weak_ptr<const Film> _film;
168 /** _mutex which should be used to protect accesses, as examine
169 * jobs can update content state in threads other than the main one.
171 mutable boost::mutex _mutex;
173 /** Paths of our data files */
174 std::vector<boost::filesystem::path> _paths;
181 bool _change_signals_frequent;