#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>
+#include <boost/date_time.hpp>
#include "format.h"
#include "film.h"
#include "filter.h"
Config::instance()->set_num_local_encoding_threads (1);
Config::instance()->set_servers (vector<ServerDescription*> ());
Config::instance()->set_server_port (61920);
+ Config::instance()->set_default_dci_metadata (DCIMetadata ());
+}
+
+boost::filesystem::path
+test_film_dir (string name)
+{
+ boost::filesystem::path p;
+ p /= "build";
+ p /= "test";
+ p /= name;
+ return p;
}
shared_ptr<Film>
new_test_film (string name)
{
- string const d = String::compose ("build/test/%1", name);
- if (boost::filesystem::exists (d)) {
- boost::filesystem::remove_all (d);
+ boost::filesystem::path p = test_film_dir (name);
+ if (boost::filesystem::exists (p)) {
+ boost::filesystem::remove_all (p);
}
- return shared_ptr<Film> (new Film (d, false));
+
+ return shared_ptr<Film> (new Film (p.string(), false));
}
-BOOST_AUTO_TEST_CASE (film_metadata_test)
+
+/* Check that Image::make_black works, and doesn't use values which crash
+ sws_scale().
+*/
+BOOST_AUTO_TEST_CASE (make_black_test)
{
+ /* This needs to happen in the first test */
dvdomatic_setup ();
+
+ libdcp::Size in_size (512, 512);
+ libdcp::Size out_size (1024, 1024);
+
+ {
+ /* Plain RGB input */
+ boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_RGB24, in_size, true));
+ foo->make_black ();
+ boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true);
+
+ uint8_t* p = bar->data()[0];
+ for (int y = 0; y < bar->size().height; ++y) {
+ uint8_t* q = p;
+ for (int x = 0; x < bar->line_size()[0]; ++x) {
+ BOOST_CHECK_EQUAL (*q++, 0);
+ }
+ p += bar->stride()[0];
+ }
+ }
+
+ {
+ /* YUV420P input */
+ boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_YUV420P, in_size, true));
+ foo->make_black ();
+ boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true);
+
+ uint8_t* p = bar->data()[0];
+ for (int y = 0; y < bar->size().height; ++y) {
+ uint8_t* q = p;
+ for (int x = 0; x < bar->line_size()[0]; ++x) {
+ BOOST_CHECK_EQUAL (*q++, 0);
+ }
+ p += bar->stride()[0];
+ }
+ }
+
+ {
+ /* YUV422P10LE input */
+ boost::shared_ptr<Image> foo (new SimpleImage (AV_PIX_FMT_YUV422P10LE, in_size, true));
+ foo->make_black ();
+ boost::shared_ptr<Image> bar = foo->scale_and_convert_to_rgb (out_size, 0, Scaler::from_id ("bicubic"), true);
+
+ uint8_t* p = bar->data()[0];
+ for (int y = 0; y < bar->size().height; ++y) {
+ uint8_t* q = p;
+ for (int x = 0; x < bar->line_size()[0]; ++x) {
+ BOOST_CHECK_EQUAL (*q++, 0);
+ }
+ p += bar->stride()[0];
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE (film_metadata_test)
+{
setup_test_config ();
string const test_film = "build/test/film_metadata_test";
BOOST_CHECK_THROW (new Film (test_film, true), OpenFileError);
shared_ptr<Film> f (new Film (test_film, false));
+ f->_dci_date = boost::gregorian::from_undelimited_string ("20130211");
BOOST_CHECK (f->format() == 0);
BOOST_CHECK (f->dcp_content_type() == 0);
BOOST_CHECK (f->filters ().empty());
BOOST_AUTO_TEST_CASE (client_server_test)
{
- shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), false));
+ shared_ptr<Image> image (new SimpleImage (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true));
uint8_t* p = image->data()[0];
for (int y = 0; y < 1080; ++y) {
+ uint8_t* q = p;
for (int x = 0; x < 1998; ++x) {
- *p++ = x % 256;
- *p++ = y % 256;
- *p++ = (x + y) % 256;
+ *q++ = x % 256;
+ *q++ = y % 256;
+ *q++ = (x + y) % 256;
}
+ p += image->stride()[0];
}
- shared_ptr<Image> sub_image (new SimpleImage (PIX_FMT_RGBA, libdcp::Size (100, 200), false));
+ shared_ptr<Image> sub_image (new SimpleImage (PIX_FMT_RGBA, libdcp::Size (100, 200), true));
p = sub_image->data()[0];
for (int y = 0; y < 200; ++y) {
+ uint8_t* q = p;
for (int x = 0; x < 100; ++x) {
- *p++ = y % 256;
- *p++ = x % 256;
- *p++ = (x + y) % 256;
- *p++ = 1;
+ *q++ = y % 256;
+ *q++ = x % 256;
+ *q++ = (x + y) % 256;
+ *q++ = 1;
}
+ p += sub_image->stride()[0];
}
shared_ptr<Subtitle> subtitle (new Subtitle (Position (50, 60), sub_image));
film->set_content ("../../../test/test.mp4");
film->set_format (Format::from_nickname ("Flat"));
film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
- film->make_dcp (true);
+ film->make_dcp ();
+ film->write_metadata ();
while (JobManager::instance()->work_to_do ()) {
dvdomatic_sleep (1);
BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false);
}
+/** Test Film::have_dcp(). Requires the output from make_dcp_test above */
+BOOST_AUTO_TEST_CASE (have_dcp_test)
+{
+ boost::filesystem::path p = test_film_dir ("make_dcp_test");
+ Film f (p.string ());
+ BOOST_CHECK (f.have_dcp());
+
+ p /= f.dcp_name();
+ p /= "video.mxf";
+ boost::filesystem::remove (p);
+ BOOST_CHECK (!f.have_dcp ());
+}
+
BOOST_AUTO_TEST_CASE (make_dcp_with_range_test)
{
shared_ptr<Film> film = new_test_film ("make_dcp_with_range_test");
film->set_format (Format::from_nickname ("Flat"));
film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
film->set_trim_end (42);
- film->make_dcp (true);
+ film->make_dcp ();
while (JobManager::instance()->work_to_do() && !JobManager::instance()->errors()) {
dvdomatic_sleep (1);
class TestJob : public Job
{
public:
- TestJob (shared_ptr<Film> f, shared_ptr<Job> req)
- : Job (f, req)
+ TestJob (shared_ptr<Film> f)
+ : Job (f)
{
}
{
shared_ptr<Film> f;
- /* Single job, no dependency */
- shared_ptr<TestJob> a (new TestJob (f, shared_ptr<Job> ()));
+ /* Single job */
+ shared_ptr<TestJob> a (new TestJob (f));
JobManager::instance()->add (a);
dvdomatic_sleep (1);
a->set_finished_ok ();
dvdomatic_sleep (2);
BOOST_CHECK_EQUAL (a->finished_ok(), true);
-
- /* Two jobs, dependency */
- a.reset (new TestJob (f, shared_ptr<Job> ()));
- shared_ptr<TestJob> b (new TestJob (f, a));
-
- JobManager::instance()->add (a);
- JobManager::instance()->add (b);
- dvdomatic_sleep (2);
- BOOST_CHECK_EQUAL (a->running(), true);
- BOOST_CHECK_EQUAL (b->running(), false);
- a->set_finished_ok ();
- dvdomatic_sleep (2);
- BOOST_CHECK_EQUAL (a->finished_ok(), true);
- BOOST_CHECK_EQUAL (b->running(), true);
- b->set_finished_ok ();
- dvdomatic_sleep (2);
- BOOST_CHECK_EQUAL (b->finished_ok(), true);
-
- /* Two jobs, dependency, first fails */
- a.reset (new TestJob (f, shared_ptr<Job> ()));
- b.reset (new TestJob (f, a));
-
- JobManager::instance()->add (a);
- JobManager::instance()->add (b);
- dvdomatic_sleep (2);
- BOOST_CHECK_EQUAL (a->running(), true);
- BOOST_CHECK_EQUAL (b->running(), false);
- a->set_finished_error ();
- dvdomatic_sleep (2);
- BOOST_CHECK_EQUAL (a->finished_in_error(), true);
- BOOST_CHECK_EQUAL (b->running(), false);
}
BOOST_AUTO_TEST_CASE (compact_image_test)