+void
+do_remote_encode (shared_ptr<DCPVideoFrame> frame, ServerDescription* description, shared_ptr<EncodedData> locally_encoded, int N)
+{
+ shared_ptr<EncodedData> remotely_encoded;
+ BOOST_CHECK_NO_THROW (remotely_encoded = frame->encode_remotely (description));
+ BOOST_CHECK (remotely_encoded);
+
+ BOOST_CHECK_EQUAL (locally_encoded->size(), remotely_encoded->size());
+ BOOST_CHECK (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()) == 0);
+}
+
+BOOST_AUTO_TEST_CASE (client_server_test)
+{
+ shared_ptr<Image> image (new CompactImage (PIX_FMT_RGB24, Size (1998, 1080)));
+ uint8_t* p = image->data()[0];
+
+ for (int y = 0; y < 1080; ++y) {
+ for (int x = 0; x < 1998; ++x) {
+ *p++ = x % 256;
+ *p++ = y % 256;
+ *p++ = (x + y) % 256;
+ }
+ }
+
+ shared_ptr<Image> sub_image (new CompactImage (PIX_FMT_RGBA, Size (100, 200)));
+ p = sub_image->data()[0];
+ for (int y = 0; y < 200; ++y) {
+ for (int x = 0; x < 100; ++x) {
+ *p++ = y % 256;
+ *p++ = x % 256;
+ *p++ = (x + y) % 256;
+ *p++ = 1;
+ }
+ }
+
+ shared_ptr<Subtitle> subtitle (new Subtitle (Position (50, 60), sub_image));
+
+ FileLog log ("build/test/client_server_test.log");
+
+ shared_ptr<DCPVideoFrame> frame (
+ new DCPVideoFrame (
+ image,
+ subtitle,
+ Size (1998, 1080),
+ 0,
+ 0,
+ 1,
+ Scaler::from_id ("bicubic"),
+ 0,
+ 24,
+ "",
+ 0,
+ 200000000,
+ &log
+ )
+ );
+
+ shared_ptr<EncodedData> locally_encoded = frame->encode_locally ();
+ BOOST_ASSERT (locally_encoded);
+
+ Server* server = new Server (&log);
+
+ new thread (boost::bind (&Server::run, server, 2));
+
+ /* Let the server get itself ready */
+ dvdomatic_sleep (1);
+
+ ServerDescription description ("localhost", 2);
+
+ list<thread*> threads;
+ for (int i = 0; i < 8; ++i) {
+ threads.push_back (new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded, i)));
+ }
+
+ for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
+ (*i)->join ();
+ }
+
+ for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
+ delete *i;
+ }
+}
+
+BOOST_AUTO_TEST_CASE (make_dcp_test)
+{
+ shared_ptr<Film> film = new_test_film ("make_dcp_test");
+ film->set_name ("test_film2");
+ 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);
+
+ while (JobManager::instance()->work_to_do ()) {
+ dvdomatic_sleep (1);
+ }
+
+ BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false);
+}
+
+BOOST_AUTO_TEST_CASE (make_dcp_with_range_test)
+{
+ shared_ptr<Film> film = new_test_film ("make_dcp_with_range_test");
+ film->set_name ("test_film3");
+ film->set_content ("../../../test/test.mp4");
+ film->examine_content ();
+ film->set_format (Format::from_nickname ("Flat"));
+ film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+ film->set_dcp_trim_end (42);
+ film->make_dcp (true);
+
+ while (JobManager::instance()->work_to_do() && !JobManager::instance()->errors()) {
+ dvdomatic_sleep (1);
+ }
+
+ BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false);
+}
+
+BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
+{
+ shared_ptr<Film> f = new_test_film ("audio_sampling_rate_test");
+ f->set_frames_per_second (24);
+
+ f->set_audio_sample_rate (48000);
+ BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 48000);
+
+ f->set_audio_sample_rate (44100);
+ BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 48000);
+
+ f->set_audio_sample_rate (80000);
+ BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 96000);
+
+ f->set_frames_per_second (23.976);
+ f->set_audio_sample_rate (48000);
+ BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 47952);
+
+ f->set_frames_per_second (29.97);
+ f->set_audio_sample_rate (48000);
+ BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 47952);
+}
+
+class TestJob : public Job
+{
+public:
+ TestJob (shared_ptr<Film> f, shared_ptr<Job> req)
+ : Job (f, req)
+ {
+
+ }
+
+ void set_finished_ok () {
+ set_state (FINISHED_OK);
+ }
+
+ void set_finished_error () {
+ set_state (FINISHED_ERROR);
+ }
+
+ void run ()
+ {
+ while (1) {
+ if (finished ()) {
+ return;
+ }
+ }
+ }
+
+ string name () const {
+ return "";
+ }
+};
+
+BOOST_AUTO_TEST_CASE (job_manager_test)
+{
+ shared_ptr<Film> f;
+
+ /* Single job, no dependency */
+ shared_ptr<TestJob> a (new TestJob (f, shared_ptr<Job> ()));
+
+ JobManager::instance()->add (a);
+ dvdomatic_sleep (1);
+ BOOST_CHECK_EQUAL (a->running (), true);
+ 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 (stream_test)
+{
+ AudioStream a ("4 9 hello there world");
+ BOOST_CHECK_EQUAL (a.id(), 4);
+ BOOST_CHECK_EQUAL (a.channels(), 9);
+ BOOST_CHECK_EQUAL (a.name(), "hello there world");
+ BOOST_CHECK_EQUAL (a.to_string(), "4 9 hello there world");
+
+ SubtitleStream s ("5 a b c");
+ BOOST_CHECK_EQUAL (s.id(), 5);
+ BOOST_CHECK_EQUAL (s.name(), "a b c");