Fix tests after change to working directories.
[dcpomatic.git] / test / client_server_test.cc
index f518f938358ebd39881f77c9e8263eac5d9834a5..43084bf31db5427829ea6ee001a3a98c6a0a3c23 100644 (file)
 
 
 /** @file  test/client_server_test.cc
- *  @brief Test the server class.
+ *  @brief Test the remote encoding code.
  *  @ingroup feature
- *
- *  Create a test image and then encode it using the standard mechanism
- *  and also using a EncodeServer object running on localhost.  Compare the resulting
- *  encoded data to check that they are the same.
  */
 
 
+#include "lib/content_factory.h"
 #include "lib/cross.h"
 #include "lib/dcp_video.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/encode_server.h"
 #include "lib/encode_server_description.h"
+#include "lib/encode_server_finder.h"
 #include "lib/file_log.h"
+#include "lib/film.h"
 #include "lib/image.h"
 #include "lib/j2k_image_proxy.h"
 #include "lib/player_video.h"
@@ -51,6 +50,7 @@ using std::weak_ptr;
 using boost::thread;
 using boost::optional;
 using dcp::ArrayData;
+using namespace dcpomatic;
 
 
 void
@@ -66,7 +66,7 @@ do_remote_encode (shared_ptr<DCPVideo> frame, EncodeServerDescription descriptio
 
 BOOST_AUTO_TEST_CASE (client_server_test_rgb)
 {
-       auto image = make_shared<Image>(AV_PIX_FMT_RGB24, dcp::Size (1998, 1080), true);
+       auto image = make_shared<Image>(AV_PIX_FMT_RGB24, dcp::Size (1998, 1080), Image::Alignment::PADDED);
        uint8_t* p = image->data()[0];
 
        for (int y = 0; y < 1080; ++y) {
@@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb)
                p += image->stride()[0];
        }
 
-       auto sub_image = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (100, 200), true);
+       auto sub_image = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (100, 200), Image::Alignment::PADDED);
        p = sub_image->data()[0];
        for (int y = 0; y < 200; ++y) {
                uint8_t* q = p;
@@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb)
                ColourConversion(),
                VideoRange::FULL,
                weak_ptr<Content>(),
-               optional<Frame>(),
+               optional<ContentTime>(),
                false
                );
 
@@ -121,9 +121,9 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb)
 
        auto locally_encoded = frame->encode_locally ();
 
-       auto server = new EncodeServer (true, 2);
+       auto server = make_shared<EncodeServer>(true, 2);
 
-       auto server_thread = new thread (boost::bind(&EncodeServer::run, server));
+       thread server_thread(boost::bind(&EncodeServer::run, server));
 
        /* Let the server get itself ready */
        dcpomatic_sleep_seconds (1);
@@ -131,29 +131,25 @@ BOOST_AUTO_TEST_CASE (client_server_test_rgb)
        /* "localhost" rather than "127.0.0.1" here fails on docker; go figure */
        EncodeServerDescription description ("127.0.0.1", 1, SERVER_LINK_VERSION);
 
-       list<thread*> threads;
+       list<thread> threads;
        for (int i = 0; i < 8; ++i) {
-               threads.push_back (new thread (boost::bind (do_remote_encode, frame, description, locally_encoded)));
+               threads.push_back(thread(boost::bind(do_remote_encode, frame, description, locally_encoded)));
        }
 
-       for (auto i: threads) {
-               i->join ();
+       for (auto& i: threads) {
+               i.join();
        }
 
-       for (auto i: threads) {
-               delete i;
-       }
+       threads.clear();
 
        server->stop ();
-       server_thread->join ();
-       delete server_thread;
-       delete server;
+       server_thread.join();
 }
 
 
 BOOST_AUTO_TEST_CASE (client_server_test_yuv)
 {
-       auto image = make_shared<Image>(AV_PIX_FMT_YUV420P, dcp::Size (1998, 1080), true);
+       auto image = make_shared<Image>(AV_PIX_FMT_YUV420P, dcp::Size (1998, 1080), Image::Alignment::PADDED);
 
        for (int i = 0; i < image->planes(); ++i) {
                uint8_t* p = image->data()[i];
@@ -162,7 +158,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv)
                }
        }
 
-       auto sub_image = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (100, 200), true);
+       auto sub_image = make_shared<Image>(AV_PIX_FMT_BGRA, dcp::Size (100, 200), Image::Alignment::PADDED);
        uint8_t* p = sub_image->data()[0];
        for (int y = 0; y < 200; ++y) {
                uint8_t* q = p;
@@ -188,7 +184,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv)
                ColourConversion(),
                VideoRange::FULL,
                weak_ptr<Content>(),
-               optional<Frame>(),
+               optional<ContentTime>(),
                false
                );
 
@@ -204,9 +200,9 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv)
 
        auto locally_encoded = frame->encode_locally ();
 
-       auto server = new EncodeServer (true, 2);
+       auto server = make_shared<EncodeServer>(true, 2);
 
-       auto server_thread = new thread(boost::bind(&EncodeServer::run, server));
+       thread server_thread(boost::bind(&EncodeServer::run, server));
 
        /* Let the server get itself ready */
        dcpomatic_sleep_seconds (1);
@@ -214,29 +210,25 @@ BOOST_AUTO_TEST_CASE (client_server_test_yuv)
        /* "localhost" rather than "127.0.0.1" here fails on docker; go figure */
        EncodeServerDescription description ("127.0.0.1", 2, SERVER_LINK_VERSION);
 
-       list<thread*> threads;
+       list<thread> threads;
        for (int i = 0; i < 8; ++i) {
-               threads.push_back (new thread(boost::bind(do_remote_encode, frame, description, locally_encoded)));
+               threads.push_back(thread(boost::bind(do_remote_encode, frame, description, locally_encoded)));
        }
 
-       for (auto i: threads) {
-               i->join ();
+       for (auto& i: threads) {
+               i.join();
        }
 
-       for (auto i: threads) {
-               delete i;
-       }
+       threads.clear();
 
        server->stop ();
-       server_thread->join ();
-       delete server_thread;
-       delete server;
+       server_thread.join();
 }
 
 
 BOOST_AUTO_TEST_CASE (client_server_test_j2k)
 {
-       auto image = make_shared<Image>(AV_PIX_FMT_YUV420P, dcp::Size (1998, 1080), true);
+       auto image = make_shared<Image>(AV_PIX_FMT_YUV420P, dcp::Size (1998, 1080), Image::Alignment::PADDED);
 
        for (int i = 0; i < image->planes(); ++i) {
                uint8_t* p = image->data()[i];
@@ -258,7 +250,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_j2k)
                ColourConversion(),
                VideoRange::FULL,
                weak_ptr<Content>(),
-               optional<Frame>(),
+               optional<ContentTime>(),
                false
                );
 
@@ -283,7 +275,7 @@ BOOST_AUTO_TEST_CASE (client_server_test_j2k)
                PresetColourConversion::all().front().conversion,
                VideoRange::FULL,
                weak_ptr<Content>(),
-               optional<Frame>(),
+               optional<ContentTime>(),
                false
                );
 
@@ -297,9 +289,9 @@ BOOST_AUTO_TEST_CASE (client_server_test_j2k)
 
        auto j2k_locally_encoded = j2k_frame->encode_locally ();
 
-       auto server = new EncodeServer (true, 2);
+       auto server = make_shared<EncodeServer>(true, 2);
 
-       auto server_thread = new thread (boost::bind (&EncodeServer::run, server));
+       thread server_thread(boost::bind (&EncodeServer::run, server));
 
        /* Let the server get itself ready */
        dcpomatic_sleep_seconds (1);
@@ -307,21 +299,45 @@ BOOST_AUTO_TEST_CASE (client_server_test_j2k)
        /* "localhost" rather than "127.0.0.1" here fails on docker; go figure */
        EncodeServerDescription description ("127.0.0.1", 2, SERVER_LINK_VERSION);
 
-       list<thread*> threads;
+       list<thread> threads;
        for (int i = 0; i < 8; ++i) {
-               threads.push_back (new thread(boost::bind(do_remote_encode, j2k_frame, description, j2k_locally_encoded)));
+               threads.push_back(thread(boost::bind(do_remote_encode, j2k_frame, description, j2k_locally_encoded)));
        }
 
-       for (auto i: threads) {
-               i->join ();
+       for (auto& i: threads) {
+               i.join();
        }
 
-       for (auto i: threads) {
-               delete i;
-       }
+       threads.clear();
 
        server->stop ();
-       server_thread->join ();
-       delete server_thread;
-       delete server;
+       server_thread.join();
+
+       EncodeServerFinder::drop();
+}
+
+
+BOOST_AUTO_TEST_CASE(real_encode_with_server)
+{
+       Cleanup cl;
+
+       auto content = content_factory(TestPaths::private_data() / "dolby_aurora.vob");
+       auto film = new_test_film("real_encode_with_server", content, &cl);
+       film->set_interop(false);
+
+       EncodeServerFinder::instance();
+
+       EncodeServer server(true, 4);
+       thread server_thread(boost::bind(&EncodeServer::run, &server));
+
+       make_and_verify_dcp(film);
+
+       server.stop();
+       server_thread.join();
+
+       BOOST_CHECK(server.frames_encoded() > 0);
+       EncodeServerFinder::drop();
+
+       cl.run();
 }
+