Basic detach of FFmpegContent, ImageContent, DCPContent
[dcpomatic.git] / src / lib / ffmpeg_content.h
1 /*
2     Copyright (C) 2013-2015 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 #ifndef DCPOMATIC_FFMPEG_CONTENT_H
21 #define DCPOMATIC_FFMPEG_CONTENT_H
22
23 #include "audio_content.h"
24 #include "subtitle_content.h"
25
26 struct AVFormatContext;
27 struct AVStream;
28
29 class Filter;
30 class FFmpegSubtitleStream;
31 class FFmpegAudioStream;
32 class VideoContent;
33 struct ffmpeg_pts_offset_test;
34 struct audio_sampling_rate_test;
35
36 class FFmpegContentProperty : public VideoContentProperty
37 {
38 public:
39         static int const SUBTITLE_STREAMS;
40         /** The chosen subtitle stream, or something about it */
41         static int const SUBTITLE_STREAM;
42         static int const FILTERS;
43 };
44
45 class FFmpegContent : public AudioContent, public SubtitleContent
46 {
47 public:
48         FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
49         FFmpegContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version, std::list<std::string> &);
50         FFmpegContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
51
52         boost::shared_ptr<FFmpegContent> shared_from_this () {
53                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
54         }
55
56         void examine (boost::shared_ptr<Job>);
57         std::string summary () const;
58         std::string technical_summary () const;
59         void as_xml (xmlpp::Node *) const;
60         DCPTime full_length () const;
61
62         std::string identifier () const;
63
64         /* VideoContent */
65         void set_default_colour_conversion ();
66
67         /* AudioContent */
68         std::vector<AudioStreamPtr> audio_streams () const;
69
70         /* SubtitleContent */
71         bool has_text_subtitles () const;
72         bool has_image_subtitles () const;
73         double subtitle_video_frame_rate () const {
74                 return video_frame_rate ();
75         }
76
77         void set_filters (std::vector<Filter const *> const &);
78
79         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
80                 boost::mutex::scoped_lock lm (_mutex);
81                 return _subtitle_streams;
82         }
83
84         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
85                 boost::mutex::scoped_lock lm (_mutex);
86                 return _subtitle_stream;
87         }
88
89         std::vector<boost::shared_ptr<FFmpegAudioStream> > ffmpeg_audio_streams () const {
90                 boost::mutex::scoped_lock lm (_mutex);
91                 return _audio_streams;
92         }
93
94         std::vector<Filter const *> filters () const {
95                 boost::mutex::scoped_lock lm (_mutex);
96                 return _filters;
97         }
98
99         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
100
101         boost::optional<ContentTime> first_video () const {
102                 boost::mutex::scoped_lock lm (_mutex);
103                 return _first_video;
104         }
105
106         std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
107         std::list<ContentTimePeriod> text_subtitles_during (ContentTimePeriod, bool starting) const;
108
109         void signal_subtitle_stream_changed ();
110
111         boost::shared_ptr<VideoContent> video;
112
113 protected:
114         void add_properties (std::list<UserProperty> &) const;
115
116 private:
117         friend struct ffmpeg_pts_offset_test;
118         friend struct audio_sampling_rate_test;
119
120         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
121         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
122         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
123         boost::optional<ContentTime> _first_video;
124         /** Video filters that should be used when generating DCPs */
125         std::vector<Filter const *> _filters;
126
127         AVColorRange _color_range;
128         AVColorPrimaries _color_primaries;
129         AVColorTransferCharacteristic _color_trc;
130         AVColorSpace _colorspace;
131         boost::optional<int> _bits_per_pixel;
132 };
133
134 #endif