Emit no audio from DCPs if none is mapped
[dcpomatic.git] / src / lib / font_id_allocator.cc
index 70eda2b0613caa2402a24502d9e89d7a769073ed..5263e7f9087525c02e8485f26f5a8330d98a7784 100644 (file)
@@ -44,11 +44,15 @@ FontIDAllocator::add_fonts_from_reels(vector<shared_ptr<dcp::Reel>> const& reels
        int reel_index = 0;
        for (auto reel: reels) {
                if (auto sub = reel->main_subtitle()) {
-                       add_fonts_from_asset(reel_index, sub->asset());
+                       if (sub->asset_ref().resolved()) {
+                               add_fonts_from_asset(reel_index, sub->asset());
+                       }
                }
 
                for (auto ccap: reel->closed_captions()) {
-                       add_fonts_from_asset(reel_index, ccap->asset());
+                       if (ccap->asset_ref().resolved()) {
+                               add_fonts_from_asset(reel_index, ccap->asset());
+                       }
                }
 
                ++reel_index;
@@ -60,17 +64,19 @@ void
 FontIDAllocator::add_fonts_from_asset(int reel_index, shared_ptr<const dcp::SubtitleAsset> asset)
 {
        for (auto const& font: asset->font_data()) {
-               _map[Font(reel_index, asset->id(), font.first)] = 0;
+               add_font(reel_index, asset->id(), font.first);
        }
-
-       _map[Font(reel_index, asset->id(), "")] = 0;
 }
 
 
 void
 FontIDAllocator::add_font(int reel_index, string asset_id, string font_id)
 {
-       _map[Font(reel_index, asset_id, font_id)] = 0;
+       auto font = Font(reel_index, asset_id, font_id);
+       if (!_default_font) {
+               _default_font = font;
+       }
+       _map[font] = 0;
 }
 
 
@@ -115,3 +121,13 @@ FontIDAllocator::font_id(int reel_index, string asset_id, string font_id) const
        return String::compose("%1_%2", iter->second, font_id);
 }
 
+
+string
+FontIDAllocator::default_font_id() const
+{
+       if (_default_font) {
+               return font_id(_default_font->reel_index, _default_font->asset_id, _default_font->font_id);
+       }
+
+       return "default";
+}