2 Copyright (C) 2012-2015 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 #include "lib/ratio.h"
22 #include "lib/filter.h"
24 #include "lib/server.h"
25 #include "lib/dcp_video.h"
26 #include "lib/decoder.h"
27 #include "lib/exceptions.h"
28 #include "lib/file_log.h"
29 #include "lib/video_decoder.h"
30 #include "lib/player.h"
31 #include "lib/player_video.h"
33 #include "lib/server_description.h"
43 using boost::shared_ptr;
45 static shared_ptr<Film> film;
46 static ServerDescription* server;
47 static shared_ptr<FileLog> log_ (new FileLog ("servomatictest.log"));
48 static int frame_count = 0;
51 process_video (shared_ptr<PlayerVideo> pvf)
53 shared_ptr<DCPVideo> local (new DCPVideo (pvf, frame_count, film->video_frame_rate(), 250000000, RESOLUTION_2K, log_));
54 shared_ptr<DCPVideo> remote (new DCPVideo (pvf, frame_count, film->video_frame_rate(), 250000000, RESOLUTION_2K, log_));
56 cout << "Frame " << frame_count << ": ";
61 Data local_encoded = local->encode_locally (boost::bind (&Log::dcp_log, log_.get(), _1, _2));
66 remote_encoded = remote->encode_remotely (*server);
67 } catch (NetworkError& e) {
68 remote_error = e.what ();
71 if (!remote_error.empty ()) {
72 cout << "\033[0;31mnetwork problem: " << remote_error << "\033[0m\n";
76 if (local_encoded.size() != remote_encoded.size()) {
77 cout << "\033[0;31msizes differ\033[0m\n";
81 uint8_t* p = local_encoded.data().get ();
82 uint8_t* q = remote_encoded.data().get ();
83 for (int i = 0; i < local_encoded.size(); ++i) {
85 cout << "\033[0;31mdata differ\033[0m at byte " << i << "\n";
90 cout << "\033[0;32mgood\033[0m\n";
96 cerr << "Syntax: " << n << " [--help] --film <film> --server <host>\n";
101 main (int argc, char* argv[])
107 static struct option long_options[] = {
108 { "help", no_argument, 0, 'h'},
109 { "server", required_argument, 0, 's'},
110 { "film", required_argument, 0, 'f'},
114 int option_index = 0;
115 int c = getopt_long (argc, argv, "hs:f:", long_options, &option_index);
126 server_host = optarg;
134 if (server_host.empty() || film_dir.empty()) {
142 server = new ServerDescription (server_host, 1);
143 film.reset (new Film (film_dir));
144 film->read_metadata ();
146 shared_ptr<Player> player (new Player (film, film->playlist ()));
148 DCPTime const frame = DCPTime::from_frames (1, film->video_frame_rate ());
149 for (DCPTime t; t < film->length(); t += frame) {
150 process_video (player->get_video(t, true).front ());
152 } catch (std::exception& e) {
153 cerr << "Error: " << e.what() << "\n";