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_channels ();
140 return _sndfile.front()->audio_frame_rate ();
147 Playlist::audio_channel_layout () const
149 /* XXX: assuming that all content has the same layout */
151 switch (_audio_from) {
154 shared_ptr<const FFmpegContent> fc = first_ffmpeg ();
156 return fc->audio_channel_layout ();
169 Playlist::video_frame_rate () const
171 if (_video.empty ()) {
175 /* XXX: assuming all the same */
176 return _video.front()->video_frame_rate ();
180 Playlist::video_size () const
182 if (_video.empty ()) {
183 return libdcp::Size ();
186 /* XXX: assuming all the same */
187 return _video.front()->video_size ();
191 Playlist::video_length () const
193 ContentVideoFrame len = 0;
194 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
195 len += (*i)->video_length ();
202 Playlist::has_audio () const
209 Playlist::content_changed (weak_ptr<Content> c, int p)
211 ContentChanged (c, p);
214 shared_ptr<const FFmpegContent>
215 Playlist::first_ffmpeg () const
217 for (list<shared_ptr<const VideoContent> >::const_iterator i = _video.begin(); i != _video.end(); ++i) {
218 shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
224 return shared_ptr<const FFmpegContent> ();
229 Playlist::default_audio_mapping () const
233 switch (_audio_from) {
236 shared_ptr<const FFmpegContent> fc = first_ffmpeg ();
241 /* XXX: assumes all the same */
242 if (fc->audio_channels() == 1) {
243 /* Map mono sources to centre */
244 m.add (AudioMapping::Channel (fc, 0), libdcp::CENTRE);
246 int const N = min (fc->audio_channels (), MAX_AUDIO_CHANNELS);
247 /* Otherwise just start with a 1:1 mapping */
248 for (int i = 0; i < N; ++i) {
249 m.add (AudioMapping::Channel (fc, i), (libdcp::Channel) i);
258 for (list<shared_ptr<const SndfileContent> >::const_iterator i = _sndfile.begin(); i != _sndfile.end(); ++i) {
259 for (int j = 0; j < (*i)->audio_channels(); ++j) {
260 m.add (AudioMapping::Channel (*i, j), (libdcp::Channel) n);
262 if (n >= MAX_AUDIO_CHANNELS) {
266 if (n >= MAX_AUDIO_CHANNELS) {