Merge remote-tracking branch 'origin/master' into 2.0
[dcpomatic.git] / src / lib / ffmpeg_content.h
1 /*
2     Copyright (C) 2013-2014 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 <boost/lexical_cast.hpp>
25 #include "video_content.h"
26 #include "audio_content.h"
27 #include "subtitle_content.h"
28 #include "audio_mapping.h"
29
30 struct AVFormatContext;
31 struct AVStream;
32
33 class Filter;
34 class FFmpegSubtitleStream;
35 class FFmpegAudioStream;
36 struct ffmpeg_pts_offset_test;
37
38 class FFmpegContentProperty : public VideoContentProperty
39 {
40 public:
41         static int const SUBTITLE_STREAMS;
42         static int const SUBTITLE_STREAM;
43         static int const AUDIO_STREAMS;
44         static int const AUDIO_STREAM;
45         static int const FILTERS;
46 };
47
48 class FFmpegContent : public VideoContent, public AudioContent, public SubtitleContent
49 {
50 public:
51         FFmpegContent (boost::shared_ptr<const Film>, boost::filesystem::path);
52         FFmpegContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version, std::list<std::string> &);
53         FFmpegContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
54
55         boost::shared_ptr<FFmpegContent> shared_from_this () {
56                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
57         }
58         
59         void examine (boost::shared_ptr<Job>);
60         std::string summary () const;
61         std::string technical_summary () const;
62         std::string information () const;
63         void as_xml (xmlpp::Node *) const;
64         DCPTime full_length () const;
65
66         std::string identifier () const;
67         
68         /* AudioContent */
69         int audio_channels () const;
70         ContentTime audio_length () const;
71         int audio_frame_rate () const;
72         AudioMapping audio_mapping () const;
73         void set_audio_mapping (AudioMapping);
74         boost::filesystem::path audio_analysis_path () const;
75
76         /* SubtitleContent */
77         bool has_subtitles () const;
78
79         void set_filters (std::vector<Filter const *> const &);
80         
81         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
82                 boost::mutex::scoped_lock lm (_mutex);
83                 return _subtitle_streams;
84         }
85
86         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
87                 boost::mutex::scoped_lock lm (_mutex);
88                 return _subtitle_stream;
89         }
90
91         std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
92                 boost::mutex::scoped_lock lm (_mutex);
93                 return _audio_streams;
94         }
95         
96         boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
97                 boost::mutex::scoped_lock lm (_mutex);
98                 return _audio_stream;
99         }
100
101         std::vector<Filter const *> filters () const {
102                 boost::mutex::scoped_lock lm (_mutex);
103                 return _filters;
104         }
105
106         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
107         void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
108
109         boost::optional<ContentTime> first_video () const {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 return _first_video;
112         }
113
114         std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod, bool starting) const;
115
116 private:
117         friend struct ffmpeg_pts_offset_test;
118         
119         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
120         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
121         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
122         boost::shared_ptr<FFmpegAudioStream> _audio_stream;
123         boost::optional<ContentTime> _first_video;
124         /** Video filters that should be used when generating DCPs */
125         std::vector<Filter const *> _filters;
126 };
127
128 #endif