X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fencoder.cc;h=195b10f443bf65f66508dd885bb74a17747de4c8;hb=01c3453026ecc303cc2ee49516650db95bf88ca8;hp=08f4e66d482bbf4ec8f2c437cdf5a9d6cd3c83f1;hpb=de2c48f3a95e847b6fbfd42d24737d42dbf9f7a6;p=dcpomatic.git diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index 08f4e66d4..195b10f44 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -71,32 +71,9 @@ Encoder::~Encoder () terminate_threads (); } -/** Add a worker thread for a each thread on a remote server. Caller must hold - * a lock on _mutex, or know that one is not currently required to - * safely modify _threads. - */ -void -Encoder::add_worker_threads (ServerDescription d) -{ - LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), d.threads(), d.host_name ()); - for (int i = 0; i < d.threads(); ++i) { - _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, d))); - } - - _writer->set_encoder_threads (_threads.size ()); -} - void Encoder::begin () { - if (!Config::instance()->only_servers_encode ()) { - for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) { - _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ()))); - } - } - - _writer->set_encoder_threads (_threads.size ()); - if (!ServerFinder::instance()->disabled ()) { _server_found_connection = ServerFinder::instance()->ServersListChanged.connect (boost::bind (&Encoder::servers_list_changed, this)); } @@ -292,6 +269,12 @@ void Encoder::encoder_thread (optional server) try { + if (server) { + LOG_TIMING ("start-encoder-thread thread=%1 server=%2", boost::this_thread::get_id (), server->host_name ()); + } else { + LOG_TIMING ("start-encoder-thread thread=%1 server=localhost", boost::this_thread::get_id ()); + } + /* Number of seconds that we currently wait between attempts to connect to the server; not relevant for localhost encodings. @@ -380,7 +363,21 @@ void Encoder::servers_list_changed () { terminate_threads (); + + /* XXX: could re-use threads */ + + if (!Config::instance()->only_servers_encode ()) { + for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) { + _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, optional ()))); + } + } + BOOST_FOREACH (ServerDescription i, ServerFinder::instance()->servers ()) { - add_worker_threads (i); + LOG_GENERAL (N_("Adding %1 worker threads for remote %2"), i.threads(), i.host_name ()); + for (int j = 0; j < i.threads(); ++j) { + _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, i))); + } } + + _writer->set_encoder_threads (_threads.size ()); }