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::dynamic_pointer_cast;
37 : _video_from (VIDEO_NONE)
38 , _audio_from (AUDIO_NONE)
44 Playlist::setup (ContentList content)
46 _video_from = VIDEO_NONE;
47 _audio_from = AUDIO_NONE;
50 _imagemagick.clear ();
53 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
54 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
58 _video_from = VIDEO_FFMPEG;
59 if (_audio_from == AUDIO_NONE) {
60 _audio_from = AUDIO_FFMPEG;
64 shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (*i);
66 _imagemagick.push_back (ic);
67 if (_video_from == VIDEO_NONE) {
68 _video_from = VIDEO_IMAGEMAGICK;
72 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (*i);
74 _sndfile.push_back (sc);
75 _audio_from = AUDIO_SNDFILE;
81 Playlist::audio_length () const
83 switch (_audio_from) {
87 return _ffmpeg->audio_length ();
90 ContentAudioFrame l = 0;
91 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
92 l += (*i)->audio_length ();
102 Playlist::audio_channels () const
104 switch (_audio_from) {
108 return _ffmpeg->audio_channels ();
112 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
113 c += (*i)->audio_channels ();
123 Playlist::audio_frame_rate () const
125 switch (_audio_from) {
129 return _ffmpeg->audio_frame_rate ();
131 return _sndfile.front()->audio_frame_rate ();
138 Playlist::audio_channel_layout () const
140 switch (_audio_from) {
144 return _ffmpeg->audio_channel_layout ();
154 Playlist::video_frame_rate () const
156 switch (_video_from) {
160 return _ffmpeg->video_frame_rate ();
161 case VIDEO_IMAGEMAGICK:
169 Playlist::video_size () const
171 switch (_video_from) {
173 return libdcp::Size ();
175 return _ffmpeg->video_size ();
176 case VIDEO_IMAGEMAGICK:
178 return _imagemagick.front()->video_size ();
181 return libdcp::Size ();
185 Playlist::video_length () const
187 switch (_video_from) {
191 return _ffmpeg->video_length ();
192 case VIDEO_IMAGEMAGICK:
194 ContentVideoFrame l = 0;
195 for (list<shared_ptr<const ImageMagickContent> >::const_iterator i = _imagemagick.begin(); i != _imagemagick.end(); ++i) {
196 l += (*i)->video_length ();
206 Playlist::has_audio () const
208 return _audio_from != AUDIO_NONE;