Mostly-merge master.
[dcpomatic.git] / src / lib / decoded.h
index a9b9227691c0ee258c1a3053fc6c26b6b85560da..ebf4e57c1a724f6aa6ab69679c5b1f4528110134 100644 (file)
 #ifndef DCPOMATIC_LIB_DECODED_H
 #define DCPOMATIC_LIB_DECODED_H
 
+#include <dcp/subtitle_string.h>
 #include "types.h"
 #include "rect.h"
+#include "util.h"
 
 class Image;
 
@@ -33,14 +35,17 @@ public:
                , dcp_time (0)
        {}
 
-       Decoded (DCPTime ct)
-               : content_time (ct)
+       Decoded (ContentTime t)
+               : content_time (t)
                , dcp_time (0)
        {}
 
        virtual ~Decoded () {}
 
-       virtual void set_dcp_times (float speed_up, DCPTime offset) = 0;
+       virtual void set_dcp_times (FrameRateChange frc, DCPTime offset)
+       {
+               dcp_time = DCPTime (content_time, frc) + offset;
+       }
 
        ContentTime content_time;
        DCPTime dcp_time;
@@ -55,17 +60,13 @@ public:
                , same (false)
        {}
 
-       DecodedVideo (boost::shared_ptr<const Image> im, Eyes e, bool s, ContentTime ct)
-               : Decoded (ct)
+       DecodedVideo (ContentTime t, boost::shared_ptr<const Image> im, Eyes e, bool s)
+               : Decoded (t)
                , image (im)
                , eyes (e)
                , same (s)
        {}
 
-       void set_dcp_times (float speed_up, DCPTime offset) {
-               dcp_time = rint (content_time / speed_up) + offset;
-       }
-       
        boost::shared_ptr<const Image> image;
        Eyes eyes;
        bool same;
@@ -74,44 +75,68 @@ public:
 class DecodedAudio : public Decoded
 {
 public:
-       DecodedAudio (boost::shared_ptr<const AudioBuffers> d, ContentTime ct)
-               : Decoded (ct)
+       DecodedAudio (ContentTime t, boost::shared_ptr<const AudioBuffers> d)
+               : Decoded (t)
                , data (d)
        {}
-
-       void set_dcp_times (float speed_up, DCPTime offset) {
-               dcp_time = rint (content_time / speed_up) + offset;
-       }
        
        boost::shared_ptr<const AudioBuffers> data;
 };
 
-class DecodedSubtitle : public Decoded
+class DecodedImageSubtitle : public Decoded
 {
 public:
-       DecodedSubtitle ()
+       DecodedImageSubtitle ()
                : content_time_to (0)
                , dcp_time_to (0)
        {}
 
-       /* XXX: content/dcp time here */
-       DecodedSubtitle (boost::shared_ptr<Image> im, dcpomatic::Rect<double> r, DCPTime f, DCPTime t)
+       DecodedImageSubtitle (ContentTime f, ContentTime t, boost::shared_ptr<Image> im, dcpomatic::Rect<double> r)
                : Decoded (f)
+               , content_time_to (t)
+               , dcp_time_to (0)
                , image (im)
                , rect (r)
-               , content_time_to (t)
-               , dcp_time_to (t)
        {}
 
-       void set_dcp_times (float speed_up, DCPTime offset) {
-               dcp_time = rint (content_time / speed_up) + offset;
-               dcp_time_to = rint (content_time_to / speed_up) + offset;
+       void set_dcp_times (FrameRateChange frc, DCPTime offset)
+       {
+               Decoded::set_dcp_times (frc, offset);
+               dcp_time_to = DCPTime (content_time_to, frc) + offset;
        }
 
+       ContentTime content_time_to;
+       DCPTime dcp_time_to;
        boost::shared_ptr<Image> image;
        dcpomatic::Rect<double> rect;
+};
+
+class DecodedTextSubtitle : public Decoded
+{
+public:
+       DecodedTextSubtitle ()
+               : content_time_to (0)
+               , dcp_time_to (0)
+       {}
+
+       /* Assuming that all subs are at the same time */
+       DecodedTextSubtitle (std::list<dcp::SubtitleString> s)
+               : Decoded (ContentTime::from_seconds (s.front().in().to_ticks() * 4 / 1000.0))
+               , content_time_to (ContentTime::from_seconds (s.front().out().to_ticks() * 4 / 1000.0))
+               , subs (s)
+       {
+               
+       }
+
+       void set_dcp_times (FrameRateChange frc, DCPTime offset)
+       {
+               Decoded::set_dcp_times (frc, offset);
+               dcp_time_to = DCPTime (content_time_to, frc) + offset;
+       }
+
        ContentTime content_time_to;
        DCPTime dcp_time_to;
+       std::list<dcp::SubtitleString> subs;
 };
 
 #endif