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