using std::string;
using std::stringstream;
using std::ofstream;
+ using std::cout;
using boost::shared_ptr;
+using libdcp::Size;
/** Construct a DCP video frame.
* @param input Input image.
return e;
}
+ EncodedData::EncodedData (int s)
+ : _data (new uint8_t[s])
+ , _size (s)
+ {
+
+ }
+
+ EncodedData::~EncodedData ()
+ {
+ delete[] _data;
+ }
+
/** Write this data to a J2K file.
* @param opt Options.
- * @param frame Frame index.
+ * @param frame DCP Frame index.
*/
void
-EncodedData::write (shared_ptr<const EncodeOptions> opt, SourceFrame frame)
+EncodedData::write (shared_ptr<const Film> film, int frame)
{
- string const tmp_j2k = opt->frame_out_path (frame, true);
+ string const tmp_j2k = film->frame_out_path (frame, true);
FILE* f = fopen (tmp_j2k.c_str (), "wb");
class EncodedData
{
public:
- /** @param d Data (will not be freed by this class, but may be by subclasses)
- * @param s Size of data, in bytes.
+ /** @param s Size of data, in bytes.
*/
- EncodedData (uint8_t* d, int s)
- : _data (d)
- , _size (s)
- {}
+ EncodedData (int s);
- virtual ~EncodedData () {}
+ virtual ~EncodedData ();
void send (boost::shared_ptr<Socket> socket);
- void write (boost::shared_ptr<const EncodeOptions>, SourceFrame);
+ void write (boost::shared_ptr<const Film>, int);
/** @return data */
uint8_t* data () const {
#ifdef HAVE_SWRESAMPLE
, _swr_context (0)
#endif
- , _process_end (false)
- , _audio_frames_written (0)
+ , _terminate_encoder (false)
+ , _writer_thread (0)
+ , _terminate_writer (false)
{
if (_film->audio_stream()) {
/* Create sound output files with .tmp suffixes; we will rename
}
}
+ /* Mop up any unwritten things in the writer's queue */
+ for (list<pair<shared_ptr<EncodedData>, int> >::iterator i = _write_queue.begin(); i != _write_queue.end(); ++i) {
+ i->first->write (_opt, i->second);
+ }
+
/* Now do links (or copies on windows) to duplicate frames */
for (list<pair<int, int> >::iterator i = _links_required.begin(); i != _links_required.end(); ++i) {
- link (_opt->frame_out_path (i->first, false), _opt->frame_out_path (i->second, false));
- link (_opt->hash_out_path (i->first, false), _opt->hash_out_path (i->second, false));
+ link (_film->frame_out_path (i->first, false), _film->frame_out_path (i->second, false));
+ link (_film->hash_out_path (i->first, false), _film->hash_out_path (i->second, false));
}
}
} else {
/* Queue this new frame for encoding */
pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
- TIMING ("adding to queue of %1", _queue.size ());
- _queue.push_back (boost::shared_ptr<DCPVideoFrame> (
+ TIMING ("adding to queue of %1", _encode_queue.size ());
+ _encode_queue.push_back (boost::shared_ptr<DCPVideoFrame> (
new DCPVideoFrame (
- image, sub, _opt->out_size, _opt->padding, _film->subtitle_offset(), _film->subtitle_scale(),
- _film->scaler(), _video_frame, _film->frames_per_second(), s.second,
- Config::instance()->colour_lut_index (), Config::instance()->j2k_bandwidth (),
+ image, sub, _film->format()->dcp_size(), _film->format()->dcp_padding (_film),
+ _film->subtitle_offset(), _film->subtitle_scale(),
+ _film->scaler(), _video_frames_out, _film->frames_per_second(), s.second,
+ _film->colour_lut(), _film->j2k_bandwidth(),
_film->log()
)
));
bool _just_skipped;
/** Number of video frames received so far */
- SourceFrame _video_frame;
+ SourceFrame _video_frames_in;
/** Number of audio frames received so far */
- int64_t _audio_frame;
-
-private:
- void close_sound_files ();
- void write_audio (boost::shared_ptr<const AudioBuffers> audio);
-
- void encoder_thread (ServerDescription *);
- void terminate_worker_threads ();
- void link (std::string, std::string) const;
+ int64_t _audio_frames_in;
+ /** Number of video frames written for the DCP so far */
+ int _video_frames_out;
+ /** Number of audio frames written for the DCP so far */
+ int64_t _audio_frames_out;
+ void writer_thread ();
+ void terminate_writer_thread ();
+
#if HAVE_SWRESAMPLE
SwrContext* _swr_context;
#endif
std::list<std::pair<int, int> > _links_required;
std::vector<SNDFILE*> _sound_files;
- int64_t _audio_frames_written;
boost::optional<int> _last_real_frame;
- bool _process_end;
- std::list<boost::shared_ptr<DCPVideoFrame> > _queue;
+ bool _terminate_encoder;
+ std::list<boost::shared_ptr<DCPVideoFrame> > _encode_queue;
std::list<boost::thread *> _worker_threads;
mutable boost::mutex _worker_mutex;
boost::condition _worker_condition;