More various AudioStream hacks.
[dcpomatic.git] / src / lib / stream.h
1 /*
2     Copyright (C) 2012 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_STREAM_H
21 #define DVDOMATIC_STREAM_H
22
23 #include <stdint.h>
24 extern "C" {
25 #include <libavutil/audioconvert.h>
26 }
27
28 class Stream
29 {
30 public:
31         Stream ()
32                 : _id (-1)
33         {}
34         
35         Stream (std::string n, int i)
36                 : _name (n)
37                 , _id (i)
38         {}
39
40         virtual std::string to_string () const = 0;
41         
42         std::string name () const {
43                 return _name;
44         }
45
46         int id () const {
47                 return _id;
48         }
49
50 protected:
51         std::string _name;
52         int _id;
53 };
54
55 struct AudioStream : public Stream
56 {
57 public:
58         AudioStream (std::string t);
59         
60         AudioStream (std::string n, int id, int r, int64_t l)
61                 : Stream (n, id)
62                 , _sample_rate (r)
63                 , _channel_layout (l)
64         {}
65
66         std::string to_string () const;
67
68         int channels () const {
69                 return av_get_channel_layout_nb_channels (_channel_layout);
70         }
71
72         int sample_rate () const {
73                 return _sample_rate;
74         }
75
76         int64_t channel_layout () const {
77                 return _channel_layout;
78         }
79
80 private:
81         int _sample_rate;
82         int64_t _channel_layout;
83 };
84
85 class SubtitleStream : public Stream
86 {
87 public:
88         SubtitleStream (std::string t);
89
90         SubtitleStream (std::string n, int i)
91                 : Stream (n, i)
92         {}
93
94         std::string to_string () const;
95 };
96
97 #endif