Merge branch '1.0' of /home/carl/git/dvdomatic into 1.0
[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
28 class Filter;
29
30 class FFmpegAudioStream
31 {
32 public:
33         FFmpegAudioStream (std::string n, int i, int f, int c)
34                 : name (n)
35                 , id (i)
36                 , frame_rate (f)
37                 , channels (c)
38                 , mapping (c)
39         {}
40
41         FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
42
43         void as_xml (xmlpp::Node *) const;
44         
45         std::string name;
46         int id;
47         int frame_rate;
48         int channels;
49         AudioMapping mapping;
50         boost::optional<double> first_audio;
51 };
52
53 extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
54
55 class FFmpegSubtitleStream
56 {
57 public:
58         FFmpegSubtitleStream (std::string n, int i)
59                 : name (n)
60                 , id (i)
61         {}
62         
63         FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
64
65         void as_xml (xmlpp::Node *) const;
66         
67         std::string name;
68         int id;
69 };
70
71 extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
72
73 class FFmpegContentProperty : public VideoContentProperty
74 {
75 public:
76         static int const SUBTITLE_STREAMS;
77         static int const SUBTITLE_STREAM;
78         static int const AUDIO_STREAMS;
79         static int const AUDIO_STREAM;
80         static int const FILTERS;
81 };
82
83 class FFmpegContent : public VideoContent, public AudioContent, public SubtitleContent
84 {
85 public:
86         FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
87         FFmpegContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
88         FFmpegContent (FFmpegContent const &);
89
90         boost::shared_ptr<FFmpegContent> shared_from_this () {
91                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
92         }
93         
94         void examine (boost::shared_ptr<Job>);
95         std::string summary () const;
96         std::string information () const;
97         void as_xml (xmlpp::Node *) const;
98         boost::shared_ptr<Content> clone () const;
99         Time length () const;
100
101         /* AudioContent */
102         int audio_channels () const;
103         AudioContent::Frame audio_length () const;
104         int content_audio_frame_rate () const;
105         int output_audio_frame_rate () const;
106         AudioMapping audio_mapping () const;
107         void set_audio_mapping (AudioMapping);
108
109         void set_filters (std::vector<Filter const *> const &);
110         
111         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 return _subtitle_streams;
114         }
115
116         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
117                 boost::mutex::scoped_lock lm (_mutex);
118                 return _subtitle_stream;
119         }
120
121         std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 return _audio_streams;
124         }
125         
126         boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _audio_stream;
129         }
130
131         std::vector<Filter const *> filters () const {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 return _filters;
134         }
135
136         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
137         void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
138
139         boost::optional<Time> first_video () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _first_video;
142         }
143         
144 private:
145         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
146         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
147         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
148         boost::shared_ptr<FFmpegAudioStream> _audio_stream;
149         boost::optional<Time> _first_video;
150         /** Video filters that should be used when generating DCPs */
151         std::vector<Filter const *> _filters;
152 };
153
154 #endif