Merge master into direct-mxf.
[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 class AudioBuffers;
28
29 namespace libdcp {
30         class MonoPictureAsset;
31         class MonoPictureAssetWriter;
32         class SoundAsset;
33         class SoundAssetWriter;
34 }
35
36 class Writer
37 {
38 public:
39         Writer (boost::shared_ptr<Film>);
40         
41         void write (boost::shared_ptr<const EncodedData>, int);
42         void write (boost::shared_ptr<const AudioBuffers>);
43         void repeat (int f);
44         void finish ();
45
46 private:
47
48         void thread ();
49         void check_existing_picture_mxf ();
50
51         boost::shared_ptr<Film> _film;
52         int _first_nonexistant_frame;
53
54         boost::thread* _thread;
55         bool _finish;
56         std::list<std::pair<boost::shared_ptr<const EncodedData>, int> > _queue;
57         mutable boost::mutex _mutex;
58         boost::condition _condition;
59         boost::shared_ptr<const EncodedData> _last_written;
60         std::list<int> _pending;
61         int _last_written_frame;
62         static const unsigned int _maximum_frames_in_memory;
63
64         boost::shared_ptr<libdcp::MonoPictureAsset> _picture_asset;
65         boost::shared_ptr<libdcp::MonoPictureAssetWriter> _picture_asset_writer;
66         boost::shared_ptr<libdcp::SoundAsset> _sound_asset;
67         boost::shared_ptr<libdcp::SoundAssetWriter> _sound_asset_writer;
68 };