Basics of joining.
[dcpomatic.git] / src / lib / ffmpeg_content.h
1 /*
2     Copyright (C) 2013 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 <boost/enable_shared_from_this.hpp>
24 #include "video_content.h"
25 #include "audio_content.h"
26 #include "subtitle_content.h"
27 #include "audio_mapping.h"
28
29 class Filter;
30 class ffmpeg_pts_offset_test;
31
32 class FFmpegAudioStream
33 {
34 public:
35         FFmpegAudioStream (std::string n, int i, int f, int c)
36                 : name (n)
37                 , id (i)
38                 , frame_rate (f)
39                 , channels (c)
40                 , mapping (c)
41         {
42                 mapping.make_default ();
43         }
44
45         FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
46
47         void as_xml (xmlpp::Node *) const;
48         
49         std::string name;
50         int id;
51         int frame_rate;
52         int channels;
53         AudioMapping mapping;
54         boost::optional<double> first_audio;
55
56 private:
57         friend class ffmpeg_pts_offset_test;
58
59         /* Constructor for tests */
60         FFmpegAudioStream ()
61                 : mapping (1)
62         {}
63 };
64
65 extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
66 extern bool operator!= (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
67
68 class FFmpegSubtitleStream
69 {
70 public:
71         FFmpegSubtitleStream (std::string n, int i)
72                 : name (n)
73                 , id (i)
74         {}
75         
76         FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
77
78         void as_xml (xmlpp::Node *) const;
79         
80         std::string name;
81         int id;
82 };
83
84 extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
85 extern bool operator!= (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
86
87 class FFmpegContentProperty : public VideoContentProperty
88 {
89 public:
90         static int const SUBTITLE_STREAMS;
91         static int const SUBTITLE_STREAM;
92         static int const AUDIO_STREAMS;
93         static int const AUDIO_STREAM;
94         static int const FILTERS;
95 };
96
97 class FFmpegContent : public VideoContent, public AudioContent, public SubtitleContent
98 {
99 public:
100         FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
101         FFmpegContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
102         FFmpegContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
103
104         boost::shared_ptr<FFmpegContent> shared_from_this () {
105                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
106         }
107         
108         void examine (boost::shared_ptr<Job>);
109         std::string summary () const;
110         std::string technical_summary () const;
111         std::string information () const;
112         void as_xml (xmlpp::Node *) const;
113         Time full_length () const;
114
115         std::string identifier () const;
116         
117         /* AudioContent */
118         int audio_channels () const;
119         AudioContent::Frame audio_length () const;
120         int content_audio_frame_rate () const;
121         int output_audio_frame_rate () const;
122         AudioMapping audio_mapping () const;
123         void set_audio_mapping (AudioMapping);
124
125         void set_filters (std::vector<Filter const *> const &);
126         
127         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _subtitle_streams;
130         }
131
132         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
133                 boost::mutex::scoped_lock lm (_mutex);
134                 return _subtitle_stream;
135         }
136
137         std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _audio_streams;
140         }
141         
142         boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _audio_stream;
145         }
146
147         std::vector<Filter const *> filters () const {
148                 boost::mutex::scoped_lock lm (_mutex);
149                 return _filters;
150         }
151
152         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
153         void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
154
155         boost::optional<double> first_video () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 return _first_video;
158         }
159
160 private:
161         friend class ffmpeg_pts_offset_test;
162         
163         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
164         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
165         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
166         boost::shared_ptr<FFmpegAudioStream> _audio_stream;
167         boost::optional<double> _first_video;
168         /** Video filters that should be used when generating DCPs */
169         std::vector<Filter const *> _filters;
170 };
171
172 #endif