#include <iostream>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
#include <sndfile.h>
#include <openjpeg.h>
#include "j2k_wav_encoder.h"
/* Wait until the queue has gone down a bit */
while (_queue.size() >= _worker_threads.size() * 2 && !_process_end) {
+ _log->microsecond_log ("Decoder sleeps", Log::TIMING);
_worker_condition.wait (lock);
+ _log->microsecond_log ("Decoder wakes", Log::TIMING);
}
if (_process_end) {
/* Only do the processing if we don't already have a file for this frame */
if (!boost::filesystem::exists (_opt->frame_out_path (frame, false))) {
pair<string, string> const s = Filter::ffmpeg_strings (_fs->filters);
+ _log->microsecond_log ("Adding to queue of " + boost::lexical_cast<string> (_queue.size ()), Log::TIMING);
_queue.push_back (boost::shared_ptr<DCPVideoFrame> (
new DCPVideoFrame (
yuv, _opt->out_size, _opt->padding, _fs->scaler, frame, _fs->frames_per_second, s.second,
));
_worker_condition.notify_all ();
+ } else {
+ frame_skipped ();
}
}
void
-J2KWAVEncoder::encoder_thread (Server* server)
+J2KWAVEncoder::encoder_thread (ServerDescription* server)
{
/* Number of seconds that we currently wait between attempts
to connect to the server; not relevant for localhost
while (1) {
boost::mutex::scoped_lock lock (_worker_mutex);
while (_queue.empty () && !_process_end) {
+ _log->microsecond_log ("Encoder thread sleeps", Log::TIMING);
_worker_condition.wait (lock);
+ _log->microsecond_log ("Encoder thread wakes", Log::TIMING);
}
if (_process_end) {
}
boost::shared_ptr<DCPVideoFrame> vf = _queue.front ();
+ _log->microsecond_log ("Encoder thread wakes with queue of " + boost::lexical_cast<string> (_queue.size ()), Log::TIMING);
_queue.pop_front ();
lock.unlock ();
} else {
try {
+ _log->microsecond_log ("Encoder thread begins local encode of " + lexical_cast<string> (vf->frame ()), Log::TIMING);
encoded = vf->encode_locally ();
+ _log->microsecond_log ("Encoder thread finishes local encode of " + lexical_cast<string> (vf->frame ()), Log::TIMING);
} catch (std::exception& e) {
stringstream s;
s << "Local encode failed " << e.what() << ".";
if (encoded) {
encoded->write (_opt, vf->frame ());
- frame_done ();
+ frame_done (vf->frame ());
} else {
lock.lock ();
_queue.push_front (vf);
J2KWAVEncoder::process_begin ()
{
for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
- _worker_threads.push_back (new boost::thread (boost::bind (&J2KWAVEncoder::encoder_thread, this, (Server *) 0)));
+ _worker_threads.push_back (new boost::thread (boost::bind (&J2KWAVEncoder::encoder_thread, this, (ServerDescription *) 0)));
}
- vector<Server*> servers = Config::instance()->servers ();
+ vector<ServerDescription*> servers = Config::instance()->servers ();
- for (vector<Server*>::iterator i = servers.begin(); i != servers.end(); ++i) {
+ for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
for (int j = 0; j < (*i)->threads (); ++j) {
_worker_threads.push_back (new boost::thread (boost::bind (&J2KWAVEncoder::encoder_thread, this, *i)));
}
{
boost::mutex::scoped_lock lock (_worker_mutex);
+ _log->log ("Clearing queue of " + lexical_cast<string> (_queue.size ()));
+
/* Keep waking workers until the queue is empty */
while (!_queue.empty ()) {
+ _log->log ("Waking with " + lexical_cast<string> (_queue.size ()));
_worker_condition.notify_all ();
_worker_condition.wait (lock);
}
terminate_worker_threads ();
+ _log->log ("Mopping up " + lexical_cast<string> (_queue.size()));
+
/* The following sequence of events can occur in the above code:
1. a remote worker takes the last image off the queue
2. the loop above terminates
try {
shared_ptr<EncodedData> e = (*i)->encode_locally ();
e->write (_opt, (*i)->frame ());
- frame_done ();
+ frame_done ((*i)->frame ());
} catch (std::exception& e) {
stringstream s;
s << "Local encode failed " << e.what() << ".";