Mostly-merge master.
[dcpomatic.git] / src / lib / decoded.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 DCPOMATIC_LIB_DECODED_H
21 #define DCPOMATIC_LIB_DECODED_H
22
23 #include <dcp/subtitle_string.h>
24 #include "types.h"
25 #include "rect.h"
26 #include "util.h"
27
28 class Image;
29
30 class Decoded
31 {
32 public:
33         Decoded ()
34                 : content_time (0)
35                 , dcp_time (0)
36         {}
37
38         Decoded (ContentTime t)
39                 : content_time (t)
40                 , dcp_time (0)
41         {}
42
43         virtual ~Decoded () {}
44
45         virtual void set_dcp_times (FrameRateChange frc, DCPTime offset)
46         {
47                 dcp_time = DCPTime (content_time, frc) + offset;
48         }
49
50         ContentTime content_time;
51         DCPTime dcp_time;
52 };
53
54 /** One frame of video from a VideoDecoder */
55 class DecodedVideo : public Decoded
56 {
57 public:
58         DecodedVideo ()
59                 : eyes (EYES_BOTH)
60                 , same (false)
61         {}
62
63         DecodedVideo (ContentTime t, boost::shared_ptr<const Image> im, Eyes e, bool s)
64                 : Decoded (t)
65                 , image (im)
66                 , eyes (e)
67                 , same (s)
68         {}
69
70         boost::shared_ptr<const Image> image;
71         Eyes eyes;
72         bool same;
73 };
74
75 class DecodedAudio : public Decoded
76 {
77 public:
78         DecodedAudio (ContentTime t, boost::shared_ptr<const AudioBuffers> d)
79                 : Decoded (t)
80                 , data (d)
81         {}
82         
83         boost::shared_ptr<const AudioBuffers> data;
84 };
85
86 class DecodedImageSubtitle : public Decoded
87 {
88 public:
89         DecodedImageSubtitle ()
90                 : content_time_to (0)
91                 , dcp_time_to (0)
92         {}
93
94         DecodedImageSubtitle (ContentTime f, ContentTime t, boost::shared_ptr<Image> im, dcpomatic::Rect<double> r)
95                 : Decoded (f)
96                 , content_time_to (t)
97                 , dcp_time_to (0)
98                 , image (im)
99                 , rect (r)
100         {}
101
102         void set_dcp_times (FrameRateChange frc, DCPTime offset)
103         {
104                 Decoded::set_dcp_times (frc, offset);
105                 dcp_time_to = DCPTime (content_time_to, frc) + offset;
106         }
107
108         ContentTime content_time_to;
109         DCPTime dcp_time_to;
110         boost::shared_ptr<Image> image;
111         dcpomatic::Rect<double> rect;
112 };
113
114 class DecodedTextSubtitle : public Decoded
115 {
116 public:
117         DecodedTextSubtitle ()
118                 : content_time_to (0)
119                 , dcp_time_to (0)
120         {}
121
122         /* Assuming that all subs are at the same time */
123         DecodedTextSubtitle (std::list<dcp::SubtitleString> s)
124                 : Decoded (ContentTime::from_seconds (s.front().in().to_ticks() * 4 / 1000.0))
125                 , content_time_to (ContentTime::from_seconds (s.front().out().to_ticks() * 4 / 1000.0))
126                 , subs (s)
127         {
128                 
129         }
130
131         void set_dcp_times (FrameRateChange frc, DCPTime offset)
132         {
133                 Decoded::set_dcp_times (frc, offset);
134                 dcp_time_to = DCPTime (content_time_to, frc) + offset;
135         }
136
137         ContentTime content_time_to;
138         DCPTime dcp_time_to;
139         std::list<dcp::SubtitleString> subs;
140 };
141
142 #endif