Merge master.
[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 DVDOMATIC_FFMPEG_CONTENT_H
21 #define DVDOMATIC_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 FFmpegAudioStream
28 {
29 public:
30         FFmpegAudioStream (std::string n, int i, int f, int64_t c)
31                 : name (n)
32                 , id (i)
33                 , frame_rate (f)
34                 , channel_layout (c)
35         {}
36
37         FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
38
39         void as_xml (xmlpp::Node *) const;
40         
41         int channels () const {
42                 return av_get_channel_layout_nb_channels (channel_layout);
43         }
44         
45         std::string name;
46         int id;
47         int frame_rate;
48         int64_t channel_layout;
49 };
50
51 extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
52
53 class FFmpegSubtitleStream
54 {
55 public:
56         FFmpegSubtitleStream (std::string n, int i)
57                 : name (n)
58                 , id (i)
59         {}
60         
61         FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
62
63         void as_xml (xmlpp::Node *) const;
64         
65         std::string name;
66         int id;
67 };
68
69 extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
70
71 class FFmpegContentProperty : public VideoContentProperty
72 {
73 public:
74         static int const SUBTITLE_STREAMS;
75         static int const SUBTITLE_STREAM;
76         static int const AUDIO_STREAMS;
77         static int const AUDIO_STREAM;
78 };
79
80 class FFmpegContent : public VideoContent, public AudioContent
81 {
82 public:
83         FFmpegContent (boost::filesystem::path);
84         FFmpegContent (boost::shared_ptr<const cxml::Node>);
85         FFmpegContent (FFmpegContent const &);
86
87         boost::shared_ptr<FFmpegContent> shared_from_this () {
88                 return boost::dynamic_pointer_cast<FFmpegContent> (Content::shared_from_this ());
89         }
90         
91         void examine (boost::shared_ptr<Film>, boost::shared_ptr<Job>, bool);
92         std::string summary () const;
93         std::string information () const;
94         void as_xml (xmlpp::Node *) const;
95         boost::shared_ptr<Content> clone () const;
96
97         /* AudioContent */
98         int audio_channels () const;
99         ContentAudioFrame audio_length () const;
100         int audio_frame_rate () const;
101         int64_t audio_channel_layout () const;
102         
103         std::vector<FFmpegSubtitleStream> subtitle_streams () const {
104                 boost::mutex::scoped_lock lm (_mutex);
105                 return _subtitle_streams;
106         }
107
108         boost::optional<FFmpegSubtitleStream> subtitle_stream () const {
109                 boost::mutex::scoped_lock lm (_mutex);
110                 return _subtitle_stream;
111         }
112
113         std::vector<FFmpegAudioStream> audio_streams () const {
114                 boost::mutex::scoped_lock lm (_mutex);
115                 return _audio_streams;
116         }
117         
118         boost::optional<FFmpegAudioStream> audio_stream () const {
119                 boost::mutex::scoped_lock lm (_mutex);
120                 return _audio_stream;
121         }
122
123         void set_subtitle_stream (FFmpegSubtitleStream);
124         void set_audio_stream (FFmpegAudioStream);
125         
126 private:
127         std::vector<FFmpegSubtitleStream> _subtitle_streams;
128         boost::optional<FFmpegSubtitleStream> _subtitle_stream;
129         std::vector<FFmpegAudioStream> _audio_streams;
130         boost::optional<FFmpegAudioStream> _audio_stream;
131 };
132
133 #endif