Encoder::Encoder (shared_ptr<const Film> film, shared_ptr<Writer> writer)
: _film (film)
, _position (0)
- , _terminate_enqueue (false)
- , _terminate_encoding (false)
, _writer (writer)
{
servers_list_changed ();
Encoder::~Encoder ()
{
terminate_threads ();
-
- boost::mutex::scoped_lock lm (_queue_mutex);
- _terminate_enqueue = true;
- _full_condition.notify_all ();
- _empty_condition.notify_all ();
}
void
/* XXX: discard 3D here if required */
/* Wait until the queue has gone down a bit */
- while (_queue.size() >= threads * 2 && !_terminate_enqueue) {
+ while (_queue.size() >= threads * 2) {
LOG_TIMING ("decoder-sleep queue=%1", _queue.size());
_full_condition.wait (queue_lock);
LOG_TIMING ("decoder-wake queue=%1", _queue.size());
}
- if (_terminate_enqueue) {
- return;
- }
-
_writer->rethrow ();
/* Re-throw any exception raised by one of our threads. If more
than one has thrown an exception, only one will be rethrown, I think;
void
Encoder::terminate_threads ()
{
- {
- boost::mutex::scoped_lock queue_lock (_queue_mutex);
- _terminate_encoding = true;
- }
-
boost::mutex::scoped_lock threads_lock (_threads_mutex);
int n = 0;
for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
LOG_GENERAL ("Terminating thread %1 of %2", n + 1, _threads.size ());
(*i)->interrupt ();
- if ((*i)->joinable ()) {
- (*i)->join ();
- }
+ DCPOMATIC_ASSERT ((*i)->joinable ());
+ (*i)->join ();
delete *i;
LOG_GENERAL_NC ("Thread terminated");
++n;
}
_threads.clear ();
- _terminate_encoding = false;
}
void
LOG_TIMING ("encoder-sleep thread=%1", boost::this_thread::get_id());
boost::mutex::scoped_lock lock (_queue_mutex);
- while (_queue.empty () && !_terminate_encoding) {
+ while (_queue.empty ()) {
_empty_condition.wait (lock);
}
- if (_terminate_encoding) {
- return;
- }
-
LOG_TIMING ("encoder-wake thread=%1 queue=%2", boost::this_thread::get_id(), _queue.size());
shared_ptr<DCPVideo> vf = _queue.front ();
LOG_TIMING ("encoder-pop thread=%1 frame=%2 eyes=%3", boost::this_thread::get_id(), vf->index(), vf->eyes ());
{
public:
Encoder (boost::shared_ptr<const Film>, boost::shared_ptr<Writer>);
- virtual ~Encoder ();
+ ~Encoder ();
/** Called to indicate that a processing run is about to begin */
void begin ();
/** Current DCP frame index */
Frame _position;
- /* XXX: probably should be atomic */
- bool _terminate_enqueue;
- bool _terminate_encoding;
/** Mutex for _threads */
mutable boost::mutex _threads_mutex;
std::list<boost::thread *> _threads;
/* This seems to be required to allow the gauge to shrink under OS X */
_gauge->SetMinSize (wxSize (0, -1));
_gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
- _message = new wxStaticText (container, wxID_ANY, wxT (" \n "));
+ _message = new wxStaticText (container, wxID_ANY, wxT (" \n "), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
_gauge_message->Add (_message, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
++n;