Support Dolby-style WAV back surround names when guessing mappings (#2427).
[dcpomatic.git] / src / lib / active_text.cc
index 885aa034ce88d131ced81e892a3de6e8c8e66186..2a5c4d836468a7a8fb3e359e81085c31d807ad55 100644 (file)
 
 */
 
+
 #include "active_text.h"
-#include "piece.h"
 #include "text_content.h"
-#include <boost/shared_ptr.hpp>
-#include <boost/weak_ptr.hpp>
+
 
 using std::list;
 using std::pair;
 using std::make_pair;
-using boost::weak_ptr;
-using boost::shared_ptr;
+using std::weak_ptr;
+using std::shared_ptr;
 using boost::optional;
+using namespace dcpomatic;
+
+
+ActiveText::ActiveText(ActiveText&& other)
+       : _data(std::move(other._data))
+{
+
+}
+
+
+ActiveText&
+ActiveText::operator=(ActiveText&& other)
+{
+       if (this != &other) {
+               _data = std::move(other._data);
+       }
+       return *this;
+}
 
-/** Get the subtitles that should be burnt into a given period.
+
+/** Get the open captions that should be burnt into a given period.
  *  @param period Period of interest.
- *  @param always_burn_subtitles Always burn subtitles even if their content is not set to burn.
+ *  @param always_burn_captions Always burn captions even if their content is not set to burn.
  */
 list<PlayerText>
-ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const
+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) {
+       for (auto const& i: _data) {
 
-               shared_ptr<Piece> piece = i->first.lock ();
-               if (!piece) {
+               auto caption = i.first.lock ();
+               if (!caption) {
                        continue;
                }
 
-               if (!piece->content->subtitle->use() || (!always_burn_subtitles && !piece->content->subtitle->burn())) {
-                       /* Not burning this piece */
+               if (!caption->use() || (!always_burn_captions && !caption->burn())) {
+                       /* Not burning this content */
                        continue;
                }
 
-               BOOST_FOREACH (Period j, i->second) {
+               for (auto j: i.second) {
                        DCPTimePeriod test (j.from, j.to.get_value_or(DCPTime::max()));
-                       optional<DCPTimePeriod> overlap = period.overlap (test);
+                       auto overlap = period.overlap (test);
                        if (overlap && overlap->duration() > DCPTime(period.duration().get() / 2)) {
                                ps.push_back (j.subs);
                        }
@@ -64,67 +84,79 @@ ActiveText::get_burnt (DCPTimePeriod period, bool always_burn_subtitles) const
        return ps;
 }
 
+
 /** Remove subtitles that finish before a given time from our list.
  *  @param time Time to remove before.
  */
 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) {
+       for (auto const& i: _data) {
                list<Period> as;
-               BOOST_FOREACH (Period j, i->second) {
+               for (auto j: i.second) {
                        if (!j.to || j.to.get() >= time) {
                                as.push_back (j);
                        }
                }
                if (!as.empty ()) {
-                       updated[i->first] = as;
+                       updated[i.first] = as;
                }
        }
        _data = updated;
 }
 
+
 /** Add a new subtitle with a from time.
- *  @param piece Piece that the subtitle is from.
+ *  @param content Content that the subtitle is from.
  *  @param ps Subtitles.
  *  @param from From time for these subtitles.
  */
 void
-ActiveText::add_from (weak_ptr<Piece> piece, PlayerText ps, DCPTime from)
+ActiveText::add_from (weak_ptr<const TextContent> content, PlayerText ps, DCPTime from)
 {
-       if (_data.find(piece) == _data.end()) {
-               _data[piece] = list<Period>();
+       boost::mutex::scoped_lock lm (_mutex);
+
+       if (_data.find(content) == _data.end()) {
+               _data[content] = list<Period>();
        }
-       _data[piece].push_back (Period (ps, from));
+       _data[content].push_back (Period (ps, from));
 }
 
-/** Add the to time for the last subtitle added from a piece.
- *  @param piece Piece that the subtitle is from.
- *  @param to To time for the last subtitle submitted to add_from for this piece.
+
+/** Add the to time for the last subtitle added from a piece of content.
+ *  @param content Content that the subtitle is from.
+ *  @param to To time for the last subtitle submitted to add_from for this content.
  *  @return Return the corresponding subtitles and their from time.
  */
 pair<PlayerText, DCPTime>
-ActiveText::add_to (weak_ptr<Piece> piece, DCPTime to)
+ActiveText::add_to (weak_ptr<const TextContent> content, DCPTime to)
 {
-       DCPOMATIC_ASSERT (_data.find(piece) != _data.end());
+       boost::mutex::scoped_lock lm (_mutex);
+
+       DCPOMATIC_ASSERT (_data.find(content) != _data.end());
 
-       _data[piece].back().to = to;
+       _data[content].back().to = to;
 
-       BOOST_FOREACH (PlainText& i, _data[piece].back().subs.text) {
+       for (auto& i: _data[content].back().subs.string) {
                i.set_out (dcp::Time(to.seconds(), 1000));
        }
 
-       return make_pair (_data[piece].back().subs, _data[piece].back().from);
+       return make_pair (_data[content].back().subs, _data[content].back().from);
 }
 
-/** @param piece A piece.
- *  @return true if we have any active subtitles from this piece.
+
+/** @param content Some content.
+ *  @return true if we have any active subtitles from this content.
  */
 bool
-ActiveText::have (weak_ptr<Piece> piece) const
+ActiveText::have (weak_ptr<const TextContent> content) const
 {
-       Map::const_iterator i = _data.find(piece);
+       boost::mutex::scoped_lock lm (_mutex);
+
+       auto i = _data.find(content);
        if (i == _data.end()) {
                return false;
        }
@@ -132,8 +164,10 @@ ActiveText::have (weak_ptr<Piece> piece) const
        return !i->second.empty();
 }
 
+
 void
 ActiveText::clear ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _data.clear ();
 }