+
+ _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;
+ }
+ 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;
+ }
+ 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;
+ }
+ sub->subtitles ();
+ }
+
+ if (i->atmos()) {
+ auto atmos = i->atmos()->asset();
+ if (atmos->encrypted() && !atmos->key()) {
+ _kdm_valid = false;
+ }
+ auto reader = atmos->start_read();
+ reader->set_check_hmac (false);
+ reader->get_frame(0);
+ }
+ }
+ } catch (dcp::ReadError& e) {
+ _kdm_valid = false;
+ } catch (dcp::MiscError& e) {
+ _kdm_valid = false;
+ }
+
+ _standard = cpl->standard();
+ _three_d = !cpl->reels().empty() && cpl->reels().front()->main_picture() &&
+ dynamic_pointer_cast<dcp::StereoPictureAsset> (cpl->reels().front()->main_picture()->asset());
+ _ratings = cpl->ratings();
+ for (auto i: cpl->content_versions()) {
+ _content_versions.push_back (i.label_text);
+ }
+
+ _cpl = cpl->id ();