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"
33 using boost::shared_ptr;
34 using boost::weak_ptr;
35 using boost::dynamic_pointer_cast;
38 : _video_from (VIDEO_NONE)
39 , _audio_from (AUDIO_NONE)
45 Playlist::setup (ContentList content)
47 _video_from = VIDEO_NONE;
48 _audio_from = AUDIO_NONE;
51 _imagemagick.clear ();
54 for (list<boost::signals2::connection>::iterator i = _content_connections.begin(); i != _content_connections.end(); ++i) {
58 _content_connections.clear ();
60 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
61 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
65 _video_from = VIDEO_FFMPEG;
66 if (_audio_from == AUDIO_NONE) {
67 _audio_from = AUDIO_FFMPEG;
71 shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (*i);
73 _imagemagick.push_back (ic);
74 if (_video_from == VIDEO_NONE) {
75 _video_from = VIDEO_IMAGEMAGICK;
79 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (*i);
81 _sndfile.push_back (sc);
82 _audio_from = AUDIO_SNDFILE;
85 _content_connections.push_back ((*i)->Changed.connect (bind (&Playlist::content_changed, this, _1, _2)));
92 Playlist::audio_length () const
94 switch (_audio_from) {
98 return _ffmpeg->audio_length ();
101 ContentAudioFrame l = 0;
102 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
103 l += (*i)->audio_length ();
113 Playlist::audio_channels () const
115 switch (_audio_from) {
119 return _ffmpeg->audio_channels ();
123 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
124 c += (*i)->audio_channels ();
134 Playlist::audio_frame_rate () const
136 switch (_audio_from) {
140 return _ffmpeg->audio_frame_rate ();
142 return _sndfile.front()->audio_frame_rate ();
149 Playlist::audio_channel_layout () const
151 switch (_audio_from) {
155 return _ffmpeg->audio_channel_layout ();
165 Playlist::video_frame_rate () const
167 switch (_video_from) {
171 return _ffmpeg->video_frame_rate ();
172 case VIDEO_IMAGEMAGICK:
180 Playlist::video_size () const
182 switch (_video_from) {
184 return libdcp::Size ();
186 return _ffmpeg->video_size ();
187 case VIDEO_IMAGEMAGICK:
189 return _imagemagick.front()->video_size ();
192 return libdcp::Size ();
196 Playlist::video_length () const
198 switch (_video_from) {
202 return _ffmpeg->video_length ();
203 case VIDEO_IMAGEMAGICK:
205 ContentVideoFrame l = 0;
206 for (list<shared_ptr<const ImageMagickContent> >::const_iterator i = _imagemagick.begin(); i != _imagemagick.end(); ++i) {
207 l += (*i)->video_length ();
217 Playlist::has_audio () const
219 return _audio_from != AUDIO_NONE;
223 Playlist::content_changed (weak_ptr<Content> c, int p)
225 ContentChanged (c, p);