, _thread (0)
, _finish (false)
, _queued_full_in_memory (0)
- , _maximum_frames_in_memory (0)
- , _maximum_queue_size (0)
+ /* These will be reset to sensible values when J2KEncoder is created */
+ , _maximum_frames_in_memory (8)
+ , _maximum_queue_size (8)
, _full_written (0)
, _fake_written (0)
, _repeat_written (0)
_reels.push_back (ReelWriter (film, p, job, reel_index++, reels.size(), _film->content_summary(p)));
}
- /* We can keep track of the current audio and subtitle reels easily because audio
- and subs arrive to the Writer in sequence. This is not so for video.
+ /* We can keep track of the current audio, subtitle and closed caption reels easily because audio
+ and captions arrive to the Writer in sequence. This is not so for video.
*/
_audio_reel = _reels.begin ();
- _subtitle_reel = _reels.begin ();
+ for (int i = 0; i < TEXT_COUNT; ++i) {
+ _text_reel[i] = _reels.begin ();
+ }
/* Check that the signer is OK if we need one */
string reason;
boost::mutex::scoped_lock lock (_state_mutex);
while (_queued_full_in_memory > _maximum_frames_in_memory) {
- /* There are too many full frames in memory; wait until that is sorted out */
+ /* There are too many full frames in memory; wake the main writer thread and
+ wait until it sorts everything out */
+ _empty_condition.notify_all ();
_full_condition.wait (lock);
}
{
boost::mutex::scoped_lock lock (_state_mutex);
- while (_queue.size() > _maximum_queue_size) {
- /* The queue is too big; wait until that is sorted out */
+ while (_queue.size() > _maximum_queue_size && have_sequenced_image_at_queue_head()) {
+ /* The queue is too big, and the main writer thread can run and fix it, so
+ wake it and wait until it has done.
+ */
+ _empty_condition.notify_all ();
_full_condition.wait (lock);
}
{
boost::mutex::scoped_lock lock (_state_mutex);
- while (_queue.size() > _maximum_queue_size) {
- /* The queue is too big; wait until that is sorted out */
+ while (_queue.size() > _maximum_queue_size && have_sequenced_image_at_queue_head()) {
+ /* The queue is too big, and the main writer thread can run and fix it, so
+ wake it and wait until it has done.
+ */
+ _empty_condition.notify_all ();
_full_condition.wait (lock);
}
}
void
-Writer::write (PlayerSubtitles subs, DCPTimePeriod period)
+Writer::write (PlayerCaption text, TextType type, DCPTimePeriod period)
{
- if (subs.text.empty ()) {
- return;
- }
-
- while (_subtitle_reel->period().to <= period.from) {
- ++_subtitle_reel;
- DCPOMATIC_ASSERT (_subtitle_reel != _reels.end());
+ while (_text_reel[type]->period().to <= period.from) {
+ ++_text_reel[type];
+ DCPOMATIC_ASSERT (_text_reel[type] != _reels.end());
}
- DCPOMATIC_ASSERT (_subtitle_reel != _reels.end());
+ DCPOMATIC_ASSERT (_text_reel[type] != _reels.end());
- _subtitle_reel->write (subs);
+ _text_reel[type]->write (text, type, period);
}
void
void
Writer::set_encoder_threads (int threads)
{
+ boost::mutex::scoped_lock lm (_state_mutex);
_maximum_frames_in_memory = lrint (threads * Config::instance()->frames_in_memory_multiplier());
- _maximum_queue_size = lrint (threads * 16);
+ _maximum_queue_size = threads * 16;
}
void