2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/shared_ptr.hpp>
22 #include "sndfile_content.h"
23 #include "sndfile_decoder.h"
24 #include "ffmpeg_content.h"
25 #include "ffmpeg_decoder.h"
26 #include "imagemagick_content.h"
27 #include "imagemagick_decoder.h"
30 using boost::shared_ptr;
31 using boost::dynamic_pointer_cast;
33 Playlist::Playlist (shared_ptr<const Film> f, list<shared_ptr<Content> > c)
35 , _video_from (VIDEO_NONE)
36 , _audio_from (AUDIO_NONE)
37 , _have_setup_decoders (false)
38 , _ffmpeg_decoder_done (false)
41 for (list<shared_ptr<Content> >::const_iterator i = c.begin(); i != c.end(); ++i) {
42 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
46 _video_from = VIDEO_FFMPEG;
47 if (_audio_from == AUDIO_NONE) {
48 _audio_from = AUDIO_FFMPEG;
52 shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (*i);
54 _imagemagick.push_back (ic);
55 if (_video_from == VIDEO_NONE) {
56 _video_from = VIDEO_IMAGEMAGICK;
60 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (*i);
62 _sndfile.push_back (sc);
63 _audio_from = AUDIO_SNDFILE;
69 Playlist::audio_length () const
71 switch (_audio_from) {
75 return _ffmpeg->audio_length ();
78 ContentAudioFrame l = 0;
79 for (list<shared_ptr<SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
80 l += (*i)->audio_length ();
90 Playlist::audio_channels () const
92 switch (_audio_from) {
96 return _ffmpeg->audio_channels ();
100 for (list<shared_ptr<SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
101 c += (*i)->audio_channels ();
111 Playlist::audio_frame_rate () const
113 switch (_audio_from) {
117 return _ffmpeg->audio_frame_rate ();
119 return _sndfile.front()->audio_frame_rate ();
126 Playlist::audio_channel_layout () const
128 switch (_audio_from) {
132 return _ffmpeg->audio_channel_layout ();
142 Playlist::video_frame_rate () const
144 switch (_video_from) {
148 return _ffmpeg->video_frame_rate ();
149 case VIDEO_IMAGEMAGICK:
157 Playlist::video_size () const
159 switch (_video_from) {
161 return libdcp::Size ();
163 return _ffmpeg->video_size ();
164 case VIDEO_IMAGEMAGICK:
166 return _imagemagick.front()->video_size ();
169 return libdcp::Size ();
173 Playlist::video_length () const
175 switch (_video_from) {
179 return _ffmpeg->video_length ();
180 case VIDEO_IMAGEMAGICK:
182 ContentVideoFrame l = 0;
183 for (list<shared_ptr<ImageMagickContent> >::const_iterator i = _imagemagick.begin(); i != _imagemagick.end(); ++i) {
184 l += (*i)->video_length ();
194 Playlist::has_audio () const
196 return _audio_from != AUDIO_NONE;
200 Playlist::disable_video ()
202 _video_from = VIDEO_NONE;
206 Playlist::disable_audio ()
208 _audio_from = AUDIO_NONE;
212 Playlist::disable_subtitles ()
220 if (!_have_setup_decoders) {
222 _have_setup_decoders = true;
227 if (_video_from == VIDEO_FFMPEG || _audio_from == AUDIO_FFMPEG) {
228 if (!_ffmpeg_decoder_done) {
229 if (_ffmpeg_decoder->pass ()) {
230 _ffmpeg_decoder_done = true;
237 if (_video_from == VIDEO_IMAGEMAGICK) {
238 if (_imagemagick_decoder != _imagemagick_decoders.end ()) {
239 if ((*_imagemagick_decoder)->pass ()) {
240 _imagemagick_decoder++;
243 if (_imagemagick_decoder != _imagemagick_decoders.end ()) {
255 Playlist::set_progress (shared_ptr<Job> job)
261 Playlist::process_video (shared_ptr<Image> i, bool same, shared_ptr<Subtitle> s)
267 Playlist::process_audio (shared_ptr<AudioBuffers> b)
273 Playlist::seek (double t)
277 switch (_video_from) {
281 if (_ffmpeg_decoder->seek (t)) {
285 case VIDEO_IMAGEMAGICK:
286 if ((*_imagemagick_decoder)->seek (t)) {
292 /* XXX: don't seek audio because we don't need to... */
298 Playlist::seek_to_last ()
302 switch (_video_from) {
306 if (_ffmpeg_decoder->seek_to_last ()) {
310 case VIDEO_IMAGEMAGICK:
311 if ((*_imagemagick_decoder)->seek_to_last ()) {
317 /* XXX: don't seek audio because we don't need to... */
323 Playlist::setup_decoders ()
325 if (_video_from == VIDEO_FFMPEG || _audio_from == AUDIO_FFMPEG) {
326 _ffmpeg_decoder.reset (
328 _film, _ffmpeg, _video_from == VIDEO_FFMPEG, _audio_from == AUDIO_FFMPEG, _film->with_subtitles(), _video_sync
333 if (_video_from == VIDEO_FFMPEG) {
334 _ffmpeg_decoder->connect_video (shared_from_this ());
337 if (_audio_from == AUDIO_FFMPEG) {
338 _ffmpeg_decoder->connect_audio (shared_from_this ());
341 if (_video_from == VIDEO_IMAGEMAGICK) {
342 for (list<shared_ptr<ImageMagickContent> >::iterator i = _imagemagick.begin(); i != _imagemagick.end(); ++i) {
343 shared_ptr<ImageMagickDecoder> d (new ImageMagickDecoder (_film, *i));
344 _imagemagick_decoders.push_back (d);
345 d->connect_video (shared_from_this ());
348 _imagemagick_decoder = _imagemagick_decoders.begin ();
351 if (_audio_from == AUDIO_SNDFILE) {
352 for (list<shared_ptr<SndfileContent> >::iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
353 shared_ptr<SndfileDecoder> d (new SndfileDecoder (_film, *i));
354 _sndfile_decoders.push_back (d);
355 d->connect_audio (shared_from_this ());
361 Playlist::disable_video_sync ()