XML metadata and some other bits.
[dcpomatic.git] / src / lib / ffmpeg_content.h
1 #ifndef DVDOMATIC_FFMPEG_CONTENT_H
2 #define DVDOMATIC_FFMPEG_CONTENT_H
3
4 #include <boost/enable_shared_from_this.hpp>
5 #include "video_content.h"
6 #include "audio_content.h"
7
8 class FFmpegAudioStream
9 {
10 public:
11         FFmpegAudioStream (std::string n, int i, int f, int64_t c)
12                 : name (n)
13                 , id (i)
14                 , frame_rate (f)
15                 , channel_layout (c)
16         {}
17
18         FFmpegAudioStream (boost::shared_ptr<const cxml::Node>);
19
20         void as_xml (xmlpp::Node *) const;
21         
22         int channels () const {
23                 return av_get_channel_layout_nb_channels (channel_layout);
24         }
25         
26         std::string name;
27         int id;
28         int frame_rate;
29         int64_t channel_layout;
30 };
31
32 extern bool operator== (FFmpegAudioStream const & a, FFmpegAudioStream const & b);
33
34 class FFmpegSubtitleStream
35 {
36 public:
37         FFmpegSubtitleStream (std::string n, int i)
38                 : name (n)
39                 , id (i)
40         {}
41         
42         FFmpegSubtitleStream (boost::shared_ptr<const cxml::Node>);
43
44         void as_xml (xmlpp::Node *) const;
45         
46         std::string name;
47         int id;
48 };
49
50 extern bool operator== (FFmpegSubtitleStream const & a, FFmpegSubtitleStream const & b);
51
52 class FFmpegContentProperty : public VideoContentProperty
53 {
54 public:
55         static int const SUBTITLE_STREAMS;
56         static int const SUBTITLE_STREAM;
57         static int const AUDIO_STREAMS;
58         static int const AUDIO_STREAM;
59 };
60
61 class FFmpegContent : public VideoContent, public AudioContent, public boost::enable_shared_from_this<FFmpegContent>
62 {
63 public:
64         FFmpegContent (boost::filesystem::path);
65         FFmpegContent (boost::shared_ptr<const cxml::Node>);
66         
67         void examine (boost::shared_ptr<Film>, boost::shared_ptr<Job>, bool);
68         std::string summary () const;
69         void as_xml (xmlpp::Node *) const;
70
71         /* AudioContent */
72         int audio_channels () const;
73         ContentAudioFrame audio_length () const;
74         int audio_frame_rate () const;
75         int64_t audio_channel_layout () const;
76         
77         std::vector<FFmpegSubtitleStream> subtitle_streams () const {
78                 boost::mutex::scoped_lock lm (_mutex);
79                 return _subtitle_streams;
80         }
81
82         boost::optional<FFmpegSubtitleStream> subtitle_stream () const {
83                 boost::mutex::scoped_lock lm (_mutex);
84                 return _subtitle_stream;
85         }
86
87         std::vector<FFmpegAudioStream> audio_streams () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _audio_streams;
90         }
91         
92         boost::optional<FFmpegAudioStream> audio_stream () const {
93                 boost::mutex::scoped_lock lm (_mutex);
94                 return _audio_stream;
95         }
96
97         void set_subtitle_stream (FFmpegSubtitleStream);
98         void set_audio_stream (FFmpegAudioStream);
99         
100 private:
101         std::vector<FFmpegSubtitleStream> _subtitle_streams;
102         boost::optional<FFmpegSubtitleStream> _subtitle_stream;
103         std::vector<FFmpegAudioStream> _audio_streams;
104         boost::optional<FFmpegAudioStream> _audio_stream;
105 };
106
107 #endif