Add writer class to pull some stuff out of Encoder.
[dcpomatic.git] / src / lib / writer.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <list>
21 #include <boost/shared_ptr.hpp>
22 #include <boost/thread.hpp>
23 #include <boost/thread/condition.hpp>
24
25 class Film;
26 class EncodedData;
27
28 namespace libdcp {
29         class MonoPictureAsset;
30         class MonoPictureAssetWriter;
31 }
32
33 class Writer
34 {
35 public:
36         Writer (boost::shared_ptr<const Film>);
37         
38         void write (boost::shared_ptr<EncodedData>, int);
39         void repeat (int f);
40         void finish ();
41
42 private:
43
44         void thread ();
45
46         boost::shared_ptr<const Film> _film;
47
48         boost::thread* _thread;
49         bool _finish;
50         std::list<std::pair<boost::shared_ptr<EncodedData>, int> > _queue;
51         mutable boost::mutex _mutex;
52         boost::condition _condition;
53         boost::shared_ptr<EncodedData> _last_written;
54         std::list<int> _pending;
55         int _last_written_frame;
56         static const unsigned int _maximum_frames_in_memory;
57
58         boost::shared_ptr<libdcp::MonoPictureAsset> _picture_asset;
59         boost::shared_ptr<libdcp::MonoPictureAssetWriter> _picture_asset_writer;
60 };