Writer::Writer (shared_ptr<const Film> film, weak_ptr<Job> j)
: _film (film)
, _job (j)
- , _thread (0)
, _finish (false)
, _queued_full_in_memory (0)
/* These will be reset to sensible values when J2KEncoder is created */
void
Writer::start ()
{
- _thread = new boost::thread (boost::bind (&Writer::thread, this));
+ _thread = boost::thread (boost::bind(&Writer::thread, this));
#ifdef DCPOMATIC_LINUX
- pthread_setname_np (_thread->native_handle(), "writer");
+ pthread_setname_np (_thread.native_handle(), "writer");
#endif
}
size_t const reel = video_reel (frame);
Frame const reel_frame = frame - _reels[reel].start ();
- FILE* file = fopen_boost (_film->info_file(_reels[reel].period()), "rb");
- if (!file) {
- throw ReadFileError (_film->info_file(_reels[reel].period()));
- }
- dcp::FrameInfo info = _reels[reel].read_frame_info (file, reel_frame, eyes);
- fclose (file);
-
QueueItem qi;
qi.type = QueueItem::FAKE;
- qi.size = info.size;
+
+ {
+ shared_ptr<InfoFileHandle> info_file = _film->info_file_handle(_reels[reel].period(), true);
+ qi.size = _reels[reel].read_frame_info(info_file, reel_frame, eyes).size;
+ }
+
qi.reel = reel;
qi.frame = reel_frame;
if (_film->three_d() && eyes == EYES_BOTH) {
/* Easy case: we can write all the audio to this reel */
_audio_reel->write (audio);
t = end;
+ } else if (_audio_reel->period().to <= t) {
+ /* This reel is entirely before the start of our audio; just skip the reel */
+ ++_audio_reel;
} else {
- /* Split the audio into two and write the first part */
+ /* This audio is over a reel boundary; split the audio into two and write the first part */
DCPTime part_lengths[2] = {
_audio_reel->period().to - t,
end - _audio_reel->period().to
};
if (part_frames[0]) {
- shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), part_frames[0]));
- part->copy_from (audio.get(), part_frames[0], 0, 0);
+ shared_ptr<AudioBuffers> part (new AudioBuffers(audio, part_frames[0], 0));
_audio_reel->write (part);
}
if (part_frames[1]) {
- shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), part_frames[1]));
- part->copy_from (audio.get(), part_frames[1], part_frames[0], 0);
- audio = part;
+ audio.reset (new AudioBuffers(audio, part_frames[1], part_frames[0]));
} else {
audio.reset ();
}
Writer::terminate_thread (bool can_throw)
{
boost::mutex::scoped_lock lock (_state_mutex);
- if (_thread == 0) {
+ if (!_thread.joinable()) {
return;
}
_full_condition.notify_all ();
lock.unlock ();
- if (_thread->joinable ()) {
- _thread->join ();
- }
+ _thread.join ();
if (can_throw) {
rethrow ();
}
-
- delete _thread;
- _thread = 0;
}
void
Writer::finish ()
{
- if (!_thread) {
+ if (!_thread.joinable()) {
return;
}
cpl->set_metadata (meta);
cpl->set_ratings (vector_to_list(_film->ratings()));
+ cpl->set_content_version_label_text (_film->content_version());
shared_ptr<const dcp::CertificateChain> signer;
if (_film->is_signed ()) {
boost::filesystem::path const cover = _film->file ("COVER_SHEET.txt");
FILE* f = fopen_boost (cover, "w");
if (!f) {
- throw OpenFileError (cover, errno, false);
+ throw OpenFileError (cover, errno, OpenFileError::WRITE);
}
string text = Config::instance()->cover_sheet ();
}
job->set_progress (min_progress);
+
+ Waker waker;
+ waker.nudge ();
}