#include "film.h"
#include "log.h"
#include "config.h"
-#include "dcp_video_frame.h"
+#include "dcp_video.h"
#include "server.h"
#include "cross.h"
#include "writer.h"
#include "server_finder.h"
#include "player.h"
-#include "player_video_frame.h"
+#include "player_video.h"
#include "i18n.h"
#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
#define LOG_ERROR(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_ERROR);
-#define LOG_TIMING(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_TIMING);
+#define LOG_TIMING(...) _film->log()->microsecond_log (String::compose (__VA_ARGS__), Log::TYPE_TIMING);
using std::pair;
using std::string;
, _video_frames_out (0)
, _terminate (false)
{
- _have_a_real_frame[EYES_BOTH] = false;
- _have_a_real_frame[EYES_LEFT] = false;
- _have_a_real_frame[EYES_RIGHT] = false;
+
}
Encoder::~Encoder ()
/* Keep waking workers until the queue is empty */
while (!_queue.empty ()) {
- _condition.notify_all ();
- _condition.wait (lock);
+ _empty_condition.notify_all ();
+ _full_condition.wait (lock);
}
lock.unlock ();
So just mop up anything left in the queue here.
*/
- for (list<shared_ptr<DCPVideoFrame> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
+ for (list<shared_ptr<DCPVideo> >::iterator i = _queue.begin(); i != _queue.end(); ++i) {
LOG_GENERAL (N_("Encode left-over frame %1"), (*i)->index ());
try {
_writer->write ((*i)->encode_locally(), (*i)->index (), (*i)->eyes ());
}
void
-Encoder::process_video (shared_ptr<PlayerVideoFrame> pvf, bool same)
+Encoder::process_video (shared_ptr<PlayerVideo> pvf)
{
_waker.nudge ();
/* Wait until the queue has gone down a bit */
while (_queue.size() >= _threads.size() * 2 && !_terminate) {
LOG_TIMING ("decoder sleeps with queue of %1", _queue.size());
- _condition.wait (lock);
+ _full_condition.wait (lock);
LOG_TIMING ("decoder wakes with queue of %1", _queue.size());
}
if (_writer->can_fake_write (_video_frames_out)) {
_writer->fake_write (_video_frames_out, pvf->eyes ());
- _have_a_real_frame[pvf->eyes()] = false;
- frame_done ();
- } else if (same && _have_a_real_frame[pvf->eyes()]) {
- /* Use the last frame that we encoded. */
- _writer->repeat (_video_frames_out, pvf->eyes());
frame_done ();
} else {
/* Queue this new frame for encoding */
LOG_TIMING ("adding to queue of %1", _queue.size ());
- _queue.push_back (shared_ptr<DCPVideoFrame> (
- new DCPVideoFrame (
- pvf, _video_frames_out, _film->video_frame_rate(),
- _film->j2k_bandwidth(), _film->resolution(), _film->log()
+ _queue.push_back (shared_ptr<DCPVideo> (
+ new DCPVideo (
+ pvf,
+ _video_frames_out,
+ _film->video_frame_rate(),
+ _film->j2k_bandwidth(),
+ _film->resolution(),
+ _film->log()
)
));
-
- _condition.notify_all ();
- _have_a_real_frame[pvf->eyes()] = true;
+
+ /* The queue might not be empty any more, so notify anything which is
+ waiting on that.
+ */
+ _empty_condition.notify_all ();
}
if (pvf->eyes() != EYES_LEFT) {
{
boost::mutex::scoped_lock lock (_mutex);
_terminate = true;
- _condition.notify_all ();
+ _full_condition.notify_all ();
+ _empty_condition.notify_all ();
}
for (list<boost::thread *>::iterator i = _threads.begin(); i != _threads.end(); ++i) {
*/
int remote_backoff = 0;
- while (1) {
+ while (true) {
- LOG_TIMING ("encoder thread %1 sleeps", boost::this_thread::get_id());
+ LOG_TIMING ("[%1] encoder thread sleeps", boost::this_thread::get_id());
boost::mutex::scoped_lock lock (_mutex);
while (_queue.empty () && !_terminate) {
- _condition.wait (lock);
+ _empty_condition.wait (lock);
}
if (_terminate) {
return;
}
- LOG_TIMING ("encoder thread %1 wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
- shared_ptr<DCPVideoFrame> vf = _queue.front ();
- LOG_TIMING ("encoder thread %1 pops frame %2 (%3) from queue", boost::this_thread::get_id(), vf->index(), vf->eyes ());
+ LOG_TIMING ("[%1] encoder thread wakes with queue of %2", boost::this_thread::get_id(), _queue.size());
+ shared_ptr<DCPVideo> vf = _queue.front ();
+ LOG_TIMING ("[%1] encoder thread pops frame %2 (%3) from queue", boost::this_thread::get_id(), vf->index(), vf->eyes ());
_queue.pop_front ();
lock.unlock ();
} else {
try {
- LOG_TIMING ("encoder thread %1 begins local encode of %2", boost::this_thread::get_id(), vf->index());
+ LOG_TIMING ("[%1] encoder thread begins local encode of %2", boost::this_thread::get_id(), vf->index());
encoded = vf->encode_locally ();
- LOG_TIMING ("encoder thread %1 finishes local encode of %2", boost::this_thread::get_id(), vf->index());
+ LOG_TIMING ("[%1] encoder thread finishes local encode of %2", boost::this_thread::get_id(), vf->index());
} catch (std::exception& e) {
LOG_ERROR (N_("Local encode failed (%1)"), e.what ());
}
frame_done ();
} else {
lock.lock ();
- LOG_GENERAL (N_("Encoder thread %1 pushes frame %2 back onto queue after failure"), boost::this_thread::get_id(), vf->index());
+ LOG_GENERAL (N_("[%1] Encoder thread pushes frame %2 back onto queue after failure"), boost::this_thread::get_id(), vf->index());
_queue.push_front (vf);
lock.unlock ();
}
dcpomatic_sleep (remote_backoff);
}
+ /* The queue might not be full any more, so notify anything that is waiting on that */
lock.lock ();
- _condition.notify_all ();
+ _full_condition.notify_all ();
}
}
catch (...)