Basics of multiple captions per content so that DCPContent can
[dcpomatic.git] / src / lib / dcp_examiner.cc
index 9969245305211b901a4ec66db317af6d53143c51..8ce4aee001df26f64ca57cb2cb5d2d76c3e17172 100644 (file)
@@ -39,6 +39,7 @@
 #include <dcp/sound_asset_reader.h>
 #include <dcp/subtitle_asset.h>
 #include <dcp/reel_subtitle_asset.h>
+#include <dcp/reel_closed_caption_asset.h>
 #include <dcp/sound_asset.h>
 #include <boost/foreach.hpp>
 #include <iostream>
@@ -55,7 +56,9 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
        : DCP (content)
        , _video_length (0)
        , _audio_length (0)
-       , _has_subtitles (false)
+       , _has_video (false)
+       , _has_audio (false)
+       , _captions (0)
        , _encrypted (false)
        , _needs_assets (false)
        , _kdm_valid (false)
@@ -120,6 +123,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
                                throw DCPError (_("Mismatched frame rates in DCP"));
                        }
 
+                       _has_video = true;
                        shared_ptr<dcp::PictureAsset> asset = i->main_picture()->asset ();
                        if (!_video_size) {
                                _video_size = asset->size ();
@@ -137,6 +141,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
                                return;
                        }
 
+                       _has_audio = true;
                        shared_ptr<dcp::SoundAsset> asset = i->main_sound()->asset ();
 
                        if (!_audio_channels) {
@@ -161,7 +166,17 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
                                return;
                        }
 
-                       _has_subtitles = true;
+                       ++_captions;
+               }
+
+               if (i->closed_caption ()) {
+                       if (!i->closed_caption()->asset_ref().resolved()) {
+                               /* We are missing this asset so we can't continue; examination will be repeated later */
+                               _needs_assets = true;
+                               return;
+                       }
+
+                       ++_captions;
                }
 
                if (i->main_picture()) {
@@ -170,6 +185,8 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
                        _reel_lengths.push_back (i->main_sound()->duration());
                } else if (i->main_subtitle()) {
                        _reel_lengths.push_back (i->main_subtitle()->duration());
+               } else if (i->closed_caption()) {
+                       _reel_lengths.push_back (i->closed_caption()->duration());
                }
        }
 
@@ -200,6 +217,8 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
                }
        } catch (dcp::DCPReadError& e) {
                _kdm_valid = false;
+       } catch (dcp::MiscError& e) {
+               _kdm_valid = false;
        }
 
        DCPOMATIC_ASSERT (cpl->standard ());