Some basics of AudioMapping.
[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 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 };
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         Time length (boost::shared_ptr<const Film>) const;
97
98         /* AudioContent */
99         int audio_channels () const;
100         ContentAudioFrame audio_length () const;
101         int content_audio_frame_rate () const;
102         int output_audio_frame_rate (boost::shared_ptr<const Film>) const;
103         AudioMapping audio_mapping () const;
104         
105         std::vector<FFmpegSubtitleStream> subtitle_streams () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _subtitle_streams;
108         }
109
110         boost::optional<FFmpegSubtitleStream> subtitle_stream () const {
111                 boost::mutex::scoped_lock lm (_mutex);
112                 return _subtitle_stream;
113         }
114
115         std::vector<FFmpegAudioStream> audio_streams () const {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 return _audio_streams;
118         }
119         
120         boost::optional<FFmpegAudioStream> audio_stream () const {
121                 boost::mutex::scoped_lock lm (_mutex);
122                 return _audio_stream;
123         }
124
125         void set_subtitle_stream (FFmpegSubtitleStream);
126         void set_audio_stream (FFmpegAudioStream);
127         
128 private:
129         std::vector<FFmpegSubtitleStream> _subtitle_streams;
130         boost::optional<FFmpegSubtitleStream> _subtitle_stream;
131         std::vector<FFmpegAudioStream> _audio_streams;
132         boost::optional<FFmpegAudioStream> _audio_stream;
133 };
134
135 #endif