Somewhat untested and sketchy basics of trimming.
[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
67 class FFmpegSubtitleStream
68 {
69 public:
70         FFmpegSubtitleStream (std::string n, int i)
71                 : name (n)
72                 , id (i)
73         {}
74         
75         FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
76
77         void as_xml (xmlpp::Node *) const;
78         
79         std::string name;
80         int id;
81 };
82
83 extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
84
85 class FFmpegContentProperty : public VideoContentProperty
86 {
87 public:
88         static int const SUBTITLE_STREAMS;
89         static int const SUBTITLE_STREAM;
90         static int const AUDIO_STREAMS;
91         static int const AUDIO_STREAM;
92         static int const FILTERS;
93 };
94
95 class FFmpegContent : public VideoContent, public AudioContent, public SubtitleContent
96 {
97 public:
98         FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
99         FFmpegContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>);
100
101         boost::shared_ptr<FFmpegContent> shared_from_this () {
102                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
103         }
104         
105         void examine (boost::shared_ptr<Job>);
106         std::string summary () const;
107         std::string technical_summary () const;
108         std::string information () const;
109         void as_xml (xmlpp::Node *) const;
110         Time full_length () const;
111
112         std::string identifier () const;
113         
114         /* AudioContent */
115         int audio_channels () const;
116         AudioContent::Frame audio_length () const;
117         int content_audio_frame_rate () const;
118         int output_audio_frame_rate () const;
119         AudioMapping audio_mapping () const;
120         void set_audio_mapping (AudioMapping);
121
122         void set_filters (std::vector<Filter const *> const &);
123         
124         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
125                 boost::mutex::scoped_lock lm (_mutex);
126                 return _subtitle_streams;
127         }
128
129         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _subtitle_stream;
132         }
133
134         std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
135                 boost::mutex::scoped_lock lm (_mutex);
136                 return _audio_streams;
137         }
138         
139         boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _audio_stream;
142         }
143
144         std::vector<Filter const *> filters () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _filters;
147         }
148
149         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
150         void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
151
152         boost::optional<double> first_video () const {
153                 boost::mutex::scoped_lock lm (_mutex);
154                 return _first_video;
155         }
156         
157 private:
158         friend class ffmpeg_pts_offset_test;
159         
160         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
161         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
162         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
163         boost::shared_ptr<FFmpegAudioStream> _audio_stream;
164         boost::optional<double> _first_video;
165         /** Video filters that should be used when generating DCPs */
166         std::vector<Filter const *> _filters;
167 };
168
169 #endif