+ _audio_frame_rate = asset->sampling_rate ();
+ } else if (_audio_frame_rate.get() != asset->sampling_rate ()) {
+ throw DCPError (_("Mismatched audio sample rates in DCP"));
+ }
+
+ _audio_length += i->main_sound()->actual_duration();
+ _audio_language = try_to_parse_language (asset->language());
+ }
+
+ if (i->main_subtitle ()) {
+ if (!i->main_subtitle()->asset_ref().resolved()) {
+ /* We are missing this asset so we can't continue; examination will be repeated later */
+ _needs_assets = true;
+ LOG_GENERAL ("Main subtitle %1 of reel %2 is missing", i->main_subtitle()->id(), i->id());
+ return;
+ }
+
+ LOG_GENERAL ("Main subtitle %1 of reel %2 found", i->main_subtitle()->id(), i->id());
+
+ _text_count[static_cast<int>(TextType::OPEN_SUBTITLE)] = 1;
+ _open_subtitle_language = try_to_parse_language (i->main_subtitle()->language());
+ }
+
+ for (auto j: i->closed_captions()) {
+ if (!j->asset_ref().resolved()) {
+ /* We are missing this asset so we can't continue; examination will be repeated later */
+ _needs_assets = true;
+ LOG_GENERAL ("Closed caption %1 of reel %2 is missing", j->id(), i->id());
+ return;
+ }
+
+ LOG_GENERAL ("Closed caption %1 of reel %2 found", j->id(), i->id());
+
+ _text_count[static_cast<int>(TextType::CLOSED_CAPTION)]++;
+ _dcp_text_tracks.push_back (DCPTextTrack(j->annotation_text().get_value_or(""), try_to_parse_language(j->language())));
+ }
+
+ if (i->main_markers ()) {
+ auto rm = i->main_markers()->get();
+ _markers.insert (rm.begin(), rm.end());
+ }
+
+ if (i->atmos()) {
+ _has_atmos = true;
+ _atmos_length += i->atmos()->actual_duration();
+ if (_atmos_edit_rate != dcp::Fraction()) {
+ DCPOMATIC_ASSERT (i->atmos()->edit_rate() == _atmos_edit_rate);
+ }
+ _atmos_edit_rate = i->atmos()->edit_rate();
+ }
+
+ if (i->main_picture()) {
+ _reel_lengths.push_back (i->main_picture()->actual_duration());
+ } else if (i->main_sound()) {
+ _reel_lengths.push_back (i->main_sound()->actual_duration());
+ } else if (i->main_subtitle()) {
+ _reel_lengths.push_back (i->main_subtitle()->actual_duration());
+ } else if (!i->closed_captions().empty()) {
+ _reel_lengths.push_back (i->closed_captions().front()->actual_duration());
+ } else if (!i->atmos()) {
+ _reel_lengths.push_back (i->atmos()->actual_duration());
+ }
+ }
+
+ _encrypted = cpl->any_encrypted ();
+ _kdm_valid = true;
+
+ LOG_GENERAL_NC ("Check that everything encrypted has a key");
+
+ /* Check first that anything encrypted has a key. We must do this, as if we try to
+ * read encrypted data with asdcplib without even offering a key it will just return
+ * the encrypted data. Secondly, check that we can read the first thing from each
+ * asset in each reel. This checks that when we do have a key it's the right one.
+ */
+ try {
+ for (auto i: cpl->reels()) {
+ LOG_GENERAL ("Reel %1", i->id());
+ auto pic = i->main_picture()->asset();
+ if (pic->encrypted() && !pic->key()) {
+ _kdm_valid = false;
+ LOG_GENERAL_NC ("Picture has no key");
+ break;
+ }
+ auto mono = dynamic_pointer_cast<dcp::MonoPictureAsset>(pic);
+ auto stereo = dynamic_pointer_cast<dcp::StereoPictureAsset>(pic);
+
+ if (mono) {
+ auto reader = mono->start_read();
+ reader->set_check_hmac (false);
+ reader->get_frame(0)->xyz_image();
+ } else {
+ auto reader = stereo->start_read();
+ reader->set_check_hmac (false);
+ reader->get_frame(0)->xyz_image(dcp::Eye::LEFT);
+ }
+
+ if (i->main_sound()) {
+ auto sound = i->main_sound()->asset ();
+ if (sound->encrypted() && !sound->key()) {
+ _kdm_valid = false;
+ LOG_GENERAL_NC ("Sound has no key");
+ break;
+ }
+ auto reader = i->main_sound()->asset()->start_read();
+ reader->set_check_hmac (false);
+ reader->get_frame(0);
+ }
+
+ if (i->main_subtitle()) {
+ auto sub = i->main_subtitle()->asset();
+ auto mxf_sub = dynamic_pointer_cast<dcp::MXF>(sub);
+ if (mxf_sub && mxf_sub->encrypted() && !mxf_sub->key()) {
+ _kdm_valid = false;
+ LOG_GENERAL_NC ("Subtitle has no key");
+ break;
+ }
+ sub->subtitles ();