2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file test/client_server_test.cc
21 * @brief Test the server class.
23 * Create a test image and then encode it using the standard mechanism
24 * and also using a Server object running on localhost. Compare the resulting
25 * encoded data to check that they are the same.
28 #include <boost/test/unit_test.hpp>
29 #include <boost/thread.hpp>
30 #include "lib/server.h"
31 #include "lib/image.h"
32 #include "lib/cross.h"
33 #include "lib/dcp_video.h"
34 #include "lib/player_video.h"
35 #include "lib/raw_image_proxy.h"
39 using boost::shared_ptr;
41 using boost::optional;
44 do_remote_encode (shared_ptr<DCPVideo> frame, ServerDescription description, Data locally_encoded)
46 Data remotely_encoded;
47 BOOST_CHECK_NO_THROW (remotely_encoded = frame->encode_remotely (description));
49 BOOST_CHECK_EQUAL (locally_encoded.size(), remotely_encoded.size());
50 BOOST_CHECK_EQUAL (memcmp (locally_encoded.data().get(), remotely_encoded.data().get(), locally_encoded.size()), 0);
53 BOOST_AUTO_TEST_CASE (client_server_test_rgb)
55 shared_ptr<Image> image (new Image (PIX_FMT_RGB24, dcp::Size (1998, 1080), true));
56 uint8_t* p = image->data()[0];
58 for (int y = 0; y < 1080; ++y) {
60 for (int x = 0; x < 1998; ++x) {
65 p += image->stride()[0];
68 shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, dcp::Size (100, 200), true));
69 p = sub_image->data()[0];
70 for (int y = 0; y < 200; ++y) {
72 for (int x = 0; x < 100; ++x) {
78 p += sub_image->stride()[0];
81 shared_ptr<FileLog> log (new FileLog ("build/test/client_server_test_rgb.log"));
83 shared_ptr<PlayerVideo> pvf (
85 shared_ptr<ImageProxy> (new RawImageProxy (image)),
89 dcp::Size (1998, 1080),
90 dcp::Size (1998, 1080),
97 pvf->set_subtitle (PositionImage (sub_image, Position<int> (50, 60)));
99 shared_ptr<DCPVideo> frame (
110 Data locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
112 Server* server = new Server (log, true);
114 new thread (boost::bind (&Server::run, server, 2));
116 /* Let the server get itself ready */
119 ServerDescription description ("localhost", 2);
121 list<thread*> threads;
122 for (int i = 0; i < 8; ++i) {
123 threads.push_back (new thread (boost::bind (do_remote_encode, frame, description, locally_encoded)));
126 for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
130 for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
137 BOOST_AUTO_TEST_CASE (client_server_test_yuv)
139 shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (1998, 1080), true));
140 uint8_t* p = image->data()[0];
142 for (int i = 0; i < image->components(); ++i) {
143 uint8_t* p = image->data()[i];
144 for (int j = 0; j < image->line_size()[i]; ++j) {
149 shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, dcp::Size (100, 200), true));
150 p = sub_image->data()[0];
151 for (int y = 0; y < 200; ++y) {
153 for (int x = 0; x < 100; ++x) {
156 *q++ = (x + y) % 256;
159 p += sub_image->stride()[0];
162 shared_ptr<FileLog> log (new FileLog ("build/test/client_server_test_yuv.log"));
164 shared_ptr<PlayerVideo> pvf (
166 shared_ptr<ImageProxy> (new RawImageProxy (image)),
170 dcp::Size (1998, 1080),
171 dcp::Size (1998, 1080),
178 pvf->set_subtitle (PositionImage (sub_image, Position<int> (50, 60)));
180 shared_ptr<DCPVideo> frame (
191 Data locally_encoded = frame->encode_locally (boost::bind (&Log::dcp_log, log.get(), _1, _2));
193 Server* server = new Server (log, true);
195 new thread (boost::bind (&Server::run, server, 2));
197 /* Let the server get itself ready */
200 ServerDescription description ("localhost", 2);
202 list<thread*> threads;
203 for (int i = 0; i < 8; ++i) {
204 threads.push_back (new thread (boost::bind (do_remote_encode, frame, description, locally_encoded)));
207 for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
211 for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {