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