Add basics for progressive sound asset writing.
[libdcp.git] / src / mxf_asset.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/asset.cc
21  *  @brief Parent class for assets of DCPs made up of MXF files.
22  */
23
24 #include <iostream>
25 #include <fstream>
26 #include <boost/filesystem.hpp>
27 #include "AS_DCP.h"
28 #include "KM_util.h"
29 #include "mxf_asset.h"
30 #include "util.h"
31 #include "metadata.h"
32
33 using std::string;
34 using std::list;
35 using boost::shared_ptr;
36 using boost::dynamic_pointer_cast;
37 using namespace libdcp;
38
39 MXFAsset::MXFAsset (string directory, string file_name)
40         : Asset (directory, file_name)
41         , _progress (0)
42         , _fps (0)
43         , _entry_point (0)
44         , _intrinsic_duration (0)
45         , _duration (0)
46 {
47
48 }
49
50 MXFAsset::MXFAsset (string directory, string file_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration)
51         : Asset (directory, file_name)
52         , _progress (progress)
53         , _fps (fps)
54         , _entry_point (0)
55         , _intrinsic_duration (intrinsic_duration)
56         , _duration (intrinsic_duration)
57 {
58         
59 }
60
61 void
62 MXFAsset::set_entry_point (int e)
63 {
64         _entry_point = e;
65 }
66
67 void
68 MXFAsset::set_duration (int d)
69 {
70         _duration = d;
71 }
72
73 void
74 MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info, string uuid)
75 {
76         writer_info->ProductVersion = Metadata::instance()->product_version;
77         writer_info->CompanyName = Metadata::instance()->company_name;
78         writer_info->ProductName = Metadata::instance()->product_name.c_str();
79
80         writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
81         unsigned int c;
82         Kumu::hex2bin (uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
83         assert (c == Kumu::UUID_Length);
84 }
85
86 bool
87 MXFAsset::equals (shared_ptr<const Asset> other, EqualityOptions, list<string>& notes) const
88 {
89         shared_ptr<const MXFAsset> other_mxf = dynamic_pointer_cast<const MXFAsset> (other);
90         if (!other_mxf) {
91                 notes.push_back ("comparing an MXF asset with a non-MXF asset");
92                 return false;
93         }
94         
95         if (_file_name != other_mxf->_file_name) {
96                 notes.push_back ("MXF names differ");
97                 return false;
98         }
99
100         if (_fps != other_mxf->_fps) {
101                 notes.push_back ("MXF frames per second differ");
102                 return false;
103         }
104         
105         if (_intrinsic_duration != other_mxf->_intrinsic_duration) {
106                 notes.push_back ("MXF intrinsic durations differ");
107                 return false;
108         }
109
110         if (_duration != other_mxf->_duration) {
111                 notes.push_back ("MXF durations differ");
112                 return false;
113         }
114         
115         return true;
116 }
117
118 int
119 MXFAsset::intrinsic_duration () const
120 {
121         return _intrinsic_duration;
122 }