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"
34 using boost::shared_ptr;
35 using boost::weak_ptr;
36 using boost::dynamic_pointer_cast;
39 : _video_from (VIDEO_NONE)
40 , _audio_from (AUDIO_NONE)
46 Playlist::setup (ContentList content)
48 _video_from = VIDEO_NONE;
49 _audio_from = AUDIO_NONE;
52 _imagemagick.clear ();
55 for (list<boost::signals2::connection>::iterator i = _content_connections.begin(); i != _content_connections.end(); ++i) {
59 _content_connections.clear ();
61 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
62 shared_ptr<FFmpegContent> fc = dynamic_pointer_cast<FFmpegContent> (*i);
66 _video_from = VIDEO_FFMPEG;
67 if (_audio_from == AUDIO_NONE) {
68 _audio_from = AUDIO_FFMPEG;
72 shared_ptr<ImageMagickContent> ic = dynamic_pointer_cast<ImageMagickContent> (*i);
74 _imagemagick.push_back (ic);
75 if (_video_from == VIDEO_NONE) {
76 _video_from = VIDEO_IMAGEMAGICK;
80 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (*i);
82 _sndfile.push_back (sc);
83 _audio_from = AUDIO_SNDFILE;
86 _content_connections.push_back ((*i)->Changed.connect (bind (&Playlist::content_changed, this, _1, _2)));
93 Playlist::audio_length () const
95 switch (_audio_from) {
99 return _ffmpeg->audio_length ();
102 ContentAudioFrame l = 0;
103 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
104 l += (*i)->audio_length ();
114 Playlist::audio_channels () const
116 switch (_audio_from) {
120 return _ffmpeg->audio_channels ();
124 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
125 c += (*i)->audio_channels ();
135 Playlist::audio_frame_rate () const
137 switch (_audio_from) {
141 return _ffmpeg->audio_frame_rate ();
143 return _sndfile.front()->audio_frame_rate ();
150 Playlist::audio_channel_layout () const
152 switch (_audio_from) {
156 return _ffmpeg->audio_channel_layout ();
166 Playlist::video_frame_rate () const
168 switch (_video_from) {
172 return _ffmpeg->video_frame_rate ();
173 case VIDEO_IMAGEMAGICK:
181 Playlist::video_size () const
183 switch (_video_from) {
185 return libdcp::Size ();
187 return _ffmpeg->video_size ();
188 case VIDEO_IMAGEMAGICK:
190 return _imagemagick.front()->video_size ();
193 return libdcp::Size ();
197 Playlist::video_length () const
199 switch (_video_from) {
203 return _ffmpeg->video_length ();
204 case VIDEO_IMAGEMAGICK:
206 ContentVideoFrame l = 0;
207 for (list<shared_ptr<const ImageMagickContent> >::const_iterator i = _imagemagick.begin(); i != _imagemagick.end(); ++i) {
208 l += (*i)->video_length ();
218 Playlist::has_audio () const
220 return _audio_from != AUDIO_NONE;
224 Playlist::content_changed (weak_ptr<Content> c, int p)
226 ContentChanged (c, p);
230 Playlist::default_audio_mapping () const
234 switch (_audio_from) {
238 if (_ffmpeg->audio_channels() == 1) {
239 /* Map mono sources to centre */
240 m.add (AudioMapping::Channel (_ffmpeg, 0), libdcp::CENTRE);
242 int const N = min (_ffmpeg->audio_channels (), MAX_AUDIO_CHANNELS);
243 /* Otherwise just start with a 1:1 mapping */
244 for (int i = 0; i < N; ++i) {
245 m.add (AudioMapping::Channel (_ffmpeg, i), (libdcp::Channel) i);
253 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
254 cout << "sndfile " << (*i)->audio_channels() << "\n";
255 for (int j = 0; j < (*i)->audio_channels(); ++j) {
256 m.add (AudioMapping::Channel (*i, j), (libdcp::Channel) n);
258 if (n >= MAX_AUDIO_CHANNELS) {
262 if (n >= MAX_AUDIO_CHANNELS) {