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