Missing files.
[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 namespace std;
34 using namespace boost;
35 using namespace libdcp;
36
37 MXFAsset::MXFAsset (string directory, string file_name, sigc::signal1<void, float>* progress, int fps, int length)
38         : Asset (directory, file_name)
39         , _progress (progress)
40         , _fps (fps)
41         , _length (length)
42 {
43         
44 }
45
46 void
47 MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info) const
48 {
49         writer_info->ProductVersion = Metadata::instance()->product_version;
50         writer_info->CompanyName = Metadata::instance()->company_name;
51         writer_info->ProductName = Metadata::instance()->product_name.c_str();
52
53         writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
54         unsigned int c;
55         Kumu::hex2bin (_uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
56         assert (c == Kumu::UUID_Length);
57 }
58
59 list<string>
60 MXFAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
61 {
62         shared_ptr<const MXFAsset> other_mxf = dynamic_pointer_cast<const MXFAsset> (other);
63         if (!other_mxf) {
64                 return list<string> ();
65         }
66         
67         list<string> notes;
68         
69         if (opt.flags & LIBDCP_METADATA) {
70                 if (_file_name != other_mxf->_file_name) {
71                         notes.push_back ("MXF names differ");
72                 }
73                 if (_fps != other_mxf->_fps) {
74                         notes.push_back ("MXF frames per second differ");
75                 }
76                 if (_length != other_mxf->_length) {
77                         notes.push_back ("MXF lengths differ");
78                 }
79         }
80         
81         if (opt.flags & MXF_BITWISE) {
82
83                 if (digest() != other_mxf->digest()) {
84                         notes.push_back ("MXF digests differ");
85                 }
86                 
87                 if (filesystem::file_size (path()) != filesystem::file_size (other_mxf->path())) {
88                         notes.push_back (path().string() + " and " + other_mxf->path().string() + " sizes differ");
89                         return notes;
90                 }
91                 
92                 ifstream a (path().string().c_str(), ios::binary);
93                 ifstream b (other_mxf->path().string().c_str(), ios::binary);
94
95                 int buffer_size = 65536;
96                 char abuffer[buffer_size];
97                 char bbuffer[buffer_size];
98
99                 int n = filesystem::file_size (path ());
100
101                 while (n) {
102                         int const t = min (n, buffer_size);
103                         a.read (abuffer, t);
104                         b.read (bbuffer, t);
105
106                         if (memcmp (abuffer, bbuffer, t) != 0) {
107                                 notes.push_back (path().string() + " and " + other_mxf->path().string() + " content differs");
108                                 return notes;
109                         }
110
111                         n -= t;
112                 }
113         }
114
115         return notes;
116 }
117
118 int
119 MXFAsset::length () const
120 {
121         return _length;
122 }
123
124