Merge master and multifarious hackery.
[dcpomatic.git] / src / lib / ffmpeg_content.h
1 /* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
2
3 /*
4     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 */
21
22 #ifndef DCPOMATIC_FFMPEG_CONTENT_H
23 #define DCPOMATIC_FFMPEG_CONTENT_H
24
25 #include <boost/enable_shared_from_this.hpp>
26 #include "video_content.h"
27 #include "audio_content.h"
28
29 class Filter;
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 };
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
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         ContentAudioFrame audio_length () const;
104         int content_audio_frame_rate () const;
105         int output_audio_frame_rate () const;
106         AudioMapping audio_mapping () const;
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         /** Video filters that should be used when generating DCPs */
144         std::vector<Filter const *> _filters;
145 };
146
147 #endif