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 "video_content.h"
25 #include "ffmpeg_decoder.h"
26 #include "ffmpeg_content.h"
27 #include "imagemagick_decoder.h"
35 using boost::shared_ptr;
36 using boost::weak_ptr;
37 using boost::dynamic_pointer_cast;
40 : _audio_from (AUDIO_FFMPEG)
46 Playlist::setup (ContentList content)
48 _audio_from = AUDIO_FFMPEG;
53 for (list<boost::signals2::connection>::iterator i = _content_connections.begin(); i != _content_connections.end(); ++i) {
57 _content_connections.clear ();
59 for (ContentList::const_iterator i = content.begin(); i != content.end(); ++i) {
60 shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> (*i);
62 _video.push_back (vc);
65 shared_ptr<SndfileContent> sc = dynamic_pointer_cast<SndfileContent> (*i);
67 _sndfile.push_back (sc);
68 _audio_from = AUDIO_SNDFILE;
71 _content_connections.push_back ((*i)->Changed.connect (bind (&Playlist::content_changed, this, _1, _2)));
78 Playlist::audio_length () const
80 ContentAudioFrame len = 0;
82 switch (_audio_from) {
84 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
85 shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
87 len += fc->audio_length ();
92 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
93 len += (*i)->audio_length ();
102 Playlist::audio_channels () const
106 switch (_audio_from) {
108 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
109 shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
111 channels = max (channels, fc->audio_channels ());
116 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
117 channels += (*i)->audio_channels ();
126 Playlist::audio_frame_rate () const
128 /* XXX: assuming that all content has the same rate */
130 switch (_audio_from) {
133 shared_ptr<const FFmpegContent> fc = first_ffmpeg ();
135 return fc->audio_frame_rate ();
140 return _sndfile.front()->audio_frame_rate ();
147 Playlist::video_frame_rate () const
149 if (_video.empty ()) {
153 /* XXX: assuming all the same */
154 return _video.front()->video_frame_rate ();
158 Playlist::video_size () const
160 if (_video.empty ()) {
161 return libdcp::Size ();
164 /* XXX: assuming all the same */
165 return _video.front()->video_size ();
169 Playlist::video_length () const
171 ContentVideoFrame len = 0;
172 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
173 len += (*i)->video_length ();
180 Playlist::has_audio () const
187 Playlist::content_changed (weak_ptr<Content> c, int p)
189 ContentChanged (c, p);
192 shared_ptr<const FFmpegContent>
193 Playlist::first_ffmpeg () const
195 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
196 shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
202 return shared_ptr<const FFmpegContent> ();
207 Playlist::default_audio_mapping () const
211 switch (_audio_from) {
214 shared_ptr<const FFmpegContent> fc = first_ffmpeg ();
219 /* XXX: assumes all the same */
220 if (fc->audio_channels() == 1) {
221 /* Map mono sources to centre */
222 m.add (AudioMapping::Channel (fc, 0), libdcp::CENTRE);
224 int const N = min (fc->audio_channels (), MAX_AUDIO_CHANNELS);
225 /* Otherwise just start with a 1:1 mapping */
226 for (int i = 0; i < N; ++i) {
227 m.add (AudioMapping::Channel (fc, i), (libdcp::Channel) i);
236 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
237 for (int j = 0; j < (*i)->audio_channels(); ++j) {
238 m.add (AudioMapping::Channel (*i, j), (libdcp::Channel) n);
240 if (n >= MAX_AUDIO_CHANNELS) {
244 if (n >= MAX_AUDIO_CHANNELS) {