Allow repeat-frame to work with 3D.
[dcpomatic.git] / test / recover_test.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file  test/recover_test.cc
22  *  @brief Test recovery of a DCP transcode after a crash.
23  *  @ingroup specific
24  */
25
26 #include "test.h"
27 #include "lib/film.h"
28 #include "lib/dcp_content_type.h"
29 #include "lib/image_content.h"
30 #include "lib/ffmpeg_content.h"
31 #include "lib/video_content.h"
32 #include "lib/ratio.h"
33 #include <dcp/mono_picture_asset.h>
34 #include <dcp/stereo_picture_asset.h>
35 #include <boost/test/unit_test.hpp>
36 #include <iostream>
37
38 using std::cout;
39 using std::string;
40 using boost::shared_ptr;
41
42 static void
43 note (dcp::NoteType t, string n)
44 {
45         if (t == dcp::DCP_ERROR) {
46                 cout << n << "\n";
47         }
48 }
49
50 BOOST_AUTO_TEST_CASE (recover_test_2d)
51 {
52         shared_ptr<Film> film = new_test_film ("recover_test_2d");
53         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
54         film->set_container (Ratio::from_id ("185"));
55         film->set_name ("recover_test");
56
57         shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts"));
58         film->examine_and_add_content (content);
59         wait_for_jobs ();
60
61         film->make_dcp ();
62         wait_for_jobs ();
63
64         boost::filesystem::path const video = "build/test/recover_test_2d/video/185_2K_517799e697fdd13033f9f7e836e7dc43_24_100000000_P_S_0_1200000.mxf";
65         boost::filesystem::copy_file (
66                 video,
67                 "build/test/recover_test_2d/original.mxf"
68                 );
69
70         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
71
72         film->make_dcp ();
73         wait_for_jobs ();
74
75         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d/original.mxf"));
76         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
77
78         dcp::EqualityOptions eq;
79         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
80 }
81
82 BOOST_AUTO_TEST_CASE (recover_test_3d)
83 {
84         shared_ptr<Film> film = new_test_film ("recover_test_3d");
85         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
86         film->set_container (Ratio::from_id ("185"));
87         film->set_name ("recover_test");
88         film->set_three_d (true);
89
90         shared_ptr<ImageContent> content (new ImageContent (film, "test/data/3d_test"));
91         content->video->set_frame_type (VIDEO_FRAME_TYPE_3D_LEFT_RIGHT);
92         film->examine_and_add_content (content);
93         wait_for_jobs ();
94
95         film->make_dcp ();
96         wait_for_jobs ();
97
98         boost::filesystem::path const video = "build/test/recover_test_3d/video/185_2K_961f053444e90c5ddbf978eb0ebfa772_24_100000000_P_S_3D_0_96000.mxf";
99
100         boost::filesystem::copy_file (
101                 video,
102                 "build/test/recover_test_3d/original.mxf"
103                 );
104
105         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
106
107         film->make_dcp ();
108         wait_for_jobs ();
109
110         shared_ptr<dcp::StereoPictureAsset> A (new dcp::StereoPictureAsset ("build/test/recover_test_3d/original.mxf"));
111         shared_ptr<dcp::StereoPictureAsset> B (new dcp::StereoPictureAsset (video));
112
113         dcp::EqualityOptions eq;
114         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
115 }
116
117
118 BOOST_AUTO_TEST_CASE (recover_test_2d_encrypted)
119 {
120         shared_ptr<Film> film = new_test_film ("recover_test_2d_encrypted");
121         film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
122         film->set_container (Ratio::from_id ("185"));
123         film->set_name ("recover_test");
124         film->set_encrypted (true);
125
126         shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts"));
127         film->examine_and_add_content (content);
128         wait_for_jobs ();
129
130         film->make_dcp ();
131         wait_for_jobs ();
132
133         boost::filesystem::path const video =
134                 "build/test/recover_test_2d_encrypted/video/185_2K_517799e697fdd13033f9f7e836e7dc43_24_100000000_E_S_0_1200000.mxf";
135
136         boost::filesystem::copy_file (
137                 video,
138                 "build/test/recover_test_2d_encrypted/original.mxf"
139                 );
140
141         boost::filesystem::resize_file (video, 2 * 1024 * 1024);
142
143         film->make_dcp ();
144         wait_for_jobs ();
145
146         shared_ptr<dcp::MonoPictureAsset> A (new dcp::MonoPictureAsset ("build/test/recover_test_2d_encrypted/original.mxf"));
147         A->set_key (film->key ());
148         shared_ptr<dcp::MonoPictureAsset> B (new dcp::MonoPictureAsset (video));
149         B->set_key (film->key ());
150
151         dcp::EqualityOptions eq;
152         BOOST_CHECK (A->equals (B, eq, boost::bind (&note, _1, _2)));
153 }