2 Copyright (C) 2014 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.
23 #include <dcp/reel_picture_asset.h>
24 #include <dcp/reel_sound_asset.h>
25 #include <dcp/sound_mxf.h>
26 #include "dcp_examiner.h"
27 #include "dcp_content.h"
28 #include "exceptions.h"
33 using boost::shared_ptr;
35 DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content)
37 dcp::DCP dcp (content->directory ());
40 if (dcp.cpls().size() == 0) {
41 throw DCPError ("No CPLs found in DCP");
42 } else if (dcp.cpls().size() > 1) {
43 throw DCPError ("Multiple CPLs found in DCP");
46 _name = dcp.cpls().front()->content_title_text ();
48 list<shared_ptr<dcp::Reel> > reels = dcp.cpls().front()->reels ();
49 for (list<shared_ptr<dcp::Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) {
51 if ((*i)->main_picture ()) {
52 dcp::Fraction const frac = (*i)->main_picture()->frame_rate ();
53 float const fr = float(frac.numerator) / frac.denominator;
54 if (!_video_frame_rate) {
55 _video_frame_rate = fr;
56 } else if (_video_frame_rate.get() != fr) {
57 throw DCPError (_("Mismatched frame rates in DCP"));
60 shared_ptr<dcp::PictureMXF> mxf = (*i)->main_picture()->mxf ();
62 _video_size = mxf->size ();
63 } else if (_video_size.get() != mxf->size ()) {
64 throw DCPError (_("Mismatched video sizes in DCP"));
67 _video_length += ContentTime::from_frames ((*i)->main_picture()->duration(), _video_frame_rate.get ());
70 if ((*i)->main_sound ()) {
71 shared_ptr<dcp::SoundMXF> mxf = (*i)->main_sound()->mxf ();
73 if (!_audio_channels) {
74 _audio_channels = mxf->channels ();
75 } else if (_audio_channels.get() != mxf->channels ()) {
76 throw DCPError (_("Mismatched audio channel counts in DCP"));
79 if (!_audio_frame_rate) {
80 _audio_frame_rate = mxf->sampling_rate ();
81 } else if (_audio_frame_rate.get() != mxf->sampling_rate ()) {
82 throw DCPError (_("Mismatched audio frame rates in DCP"));
85 _audio_length += ContentTime::from_frames ((*i)->main_sound()->duration(), _video_frame_rate.get ());
88 if ((*i)->main_subtitle ()) {
89 _has_subtitles = true;