Missing files.
[dcpomatic.git] / src / lib / active_text.cc
index de3dc816563cb8b3c0e46807dbab4bb27218ba1f..3a7e1a27ebeff7a43e63877e65416fc82b102bb0 100644 (file)
@@ -29,36 +29,7 @@ using std::make_pair;
 using boost::weak_ptr;
 using boost::shared_ptr;
 using boost::optional;
-
-void
-ActiveText::add (DCPTimePeriod period, list<PlayerText>& pc, list<Period> p) const
-{
-       BOOST_FOREACH (Period i, p) {
-               DCPTimePeriod test (i.from, i.to.get_value_or(DCPTime::max()));
-               optional<DCPTimePeriod> overlap = period.overlap (test);
-               if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) {
-                       pc.push_back (i.subs);
-               }
-       }
-}
-
-list<PlayerText>
-ActiveText::get (DCPTimePeriod period) const
-{
-       list<PlayerText> ps;
-
-       for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) {
-
-               shared_ptr<const TextContent> caption = i->first.lock ();
-               if (!caption || !caption->use()) {
-                       continue;
-               }
-
-               add (period, ps, i->second);
-       }
-
-       return ps;
-}
+using namespace dcpomatic;
 
 /** Get the open captions that should be burnt into a given period.
  *  @param period Period of interest.
@@ -67,6 +38,8 @@ ActiveText::get (DCPTimePeriod period) const
 list<PlayerText>
 ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        list<PlayerText> ps;
 
        for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) {
@@ -81,7 +54,13 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const
                        continue;
                }
 
-               add (period, ps, i->second);
+               BOOST_FOREACH (Period j, i->second) {
+                       DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max()));
+                       optional<DCPTimePeriod> overlap = period.overlap (test);
+                       if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) {
+                               ps.push_back (j.subs);
+                       }
+               }
        }
 
        return ps;
@@ -93,6 +72,8 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_captions) const
 void
 ActiveText::clear_before (DCPTime time)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        Map updated;
        for (Map::const_iterator i = _data.begin(); i != _data.end(); ++i) {
                list<Period> as;
@@ -116,6 +97,8 @@ ActiveText::clear_before (DCPTime time)
 void
 ActiveText::add_from (weak_ptr<const TextContent> content, PlayerText ps, DCPTime from)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        if (_data.find(content) == _data.end()) {
                _data[content] = list<Period>();
        }
@@ -130,11 +113,13 @@ ActiveText::add_from (weak_ptr<const TextContent> content, PlayerText ps, DCPTim
 pair<PlayerText, DCPTime>
 ActiveText::add_to (weak_ptr<const TextContent> content, DCPTime to)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        DCPOMATIC_ASSERT (_data.find(content) != _data.end());
 
        _data[content].back().to = to;
 
-       BOOST_FOREACH (StringText& i, _data[content].back().subs.text) {
+       BOOST_FOREACH (StringText& i, _data[content].back().subs.string) {
                i.set_out (dcp::Time(to.seconds(), 1000));
        }
 
@@ -147,6 +132,8 @@ ActiveText::add_to (weak_ptr<const TextContent> content, DCPTime to)
 bool
 ActiveText::have (weak_ptr<const TextContent> content) const
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        Map::const_iterator i = _data.find(content);
        if (i == _data.end()) {
                return false;
@@ -158,5 +145,6 @@ ActiveText::have (weak_ptr<const TextContent> content) const
 void
 ActiveText::clear ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _data.clear ();
 }