Fix up AudioMapping confusions with respect to number of content channels.
[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 information () const;
108         void as_xml (xmlpp::Node *) const;
109         Time length () const;
110
111         std::string identifier () const;
112         
113         /* AudioContent */
114         int audio_channels () const;
115         AudioContent::Frame audio_length () const;
116         int content_audio_frame_rate () const;
117         int output_audio_frame_rate () const;
118         AudioMapping audio_mapping () const;
119         void set_audio_mapping (AudioMapping);
120
121         void set_filters (std::vector<Filter const *> const &);
122         
123         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
124                 boost::mutex::scoped_lock lm (_mutex);
125                 return _subtitle_streams;
126         }
127
128         boost::shared_ptr<FFmpegSubtitleStream> subtitle_stream () const {
129                 boost::mutex::scoped_lock lm (_mutex);
130                 return _subtitle_stream;
131         }
132
133         std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams () const {
134                 boost::mutex::scoped_lock lm (_mutex);
135                 return _audio_streams;
136         }
137         
138         boost::shared_ptr<FFmpegAudioStream> audio_stream () const {
139                 boost::mutex::scoped_lock lm (_mutex);
140                 return _audio_stream;
141         }
142
143         std::vector<Filter const *> filters () const {
144                 boost::mutex::scoped_lock lm (_mutex);
145                 return _filters;
146         }
147
148         void set_subtitle_stream (boost::shared_ptr<FFmpegSubtitleStream>);
149         void set_audio_stream (boost::shared_ptr<FFmpegAudioStream>);
150
151         boost::optional<double> first_video () const {
152                 boost::mutex::scoped_lock lm (_mutex);
153                 return _first_video;
154         }
155         
156 private:
157         friend class ffmpeg_pts_offset_test;
158         
159         std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams;
160         boost::shared_ptr<FFmpegSubtitleStream> _subtitle_stream;
161         std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams;
162         boost::shared_ptr<FFmpegAudioStream> _audio_stream;
163         boost::optional<double> _first_video;
164         /** Video filters that should be used when generating DCPs */
165         std::vector<Filter const *> _filters;
166 };
167
168 #endif