Log some stats from the writer.
[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 struct QueueItem
37 {
38 public:
39         enum Type {
40                 FULL,
41                 FAKE,
42                 REPEAT
43         } type;
44
45         /** encoded data for FULL */
46         boost::shared_ptr<const EncodedData> encoded;
47         /** size of data for FAKE */
48         int size;
49         /** frame index */
50         int frame;
51 };
52
53 bool operator< (QueueItem const & a, QueueItem const & b);
54 bool operator== (QueueItem const & a, QueueItem const & b);
55
56 class Writer
57 {
58 public:
59         Writer (boost::shared_ptr<Film>);
60
61         bool can_fake_write (int) const;
62         
63         void write (boost::shared_ptr<const EncodedData>, int);
64         void fake_write (int);
65         void write (boost::shared_ptr<const AudioBuffers>);
66         void repeat (int f);
67         void finish ();
68
69 private:
70
71         void thread ();
72         void check_existing_picture_mxf ();
73
74         boost::shared_ptr<Film> _film;
75         int _first_nonexistant_frame;
76
77         boost::thread* _thread;
78         bool _finish;
79         std::list<QueueItem> _queue;
80         int _queued_full_in_memory;
81         mutable boost::mutex _mutex;
82         boost::condition _condition;
83         boost::shared_ptr<const EncodedData> _last_written;
84         int _last_written_frame;
85         static const int _maximum_frames_in_memory;
86
87         int _full_written;
88         int _fake_written;
89         int _repeat_written;
90         int _pushed_to_disk;
91
92         boost::shared_ptr<libdcp::MonoPictureAsset> _picture_asset;
93         boost::shared_ptr<libdcp::MonoPictureAssetWriter> _picture_asset_writer;
94         boost::shared_ptr<libdcp::SoundAsset> _sound_asset;
95         boost::shared_ptr<libdcp::SoundAssetWriter> _sound_asset_writer;
96 };