summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array_data.cc28
-rw-r--r--src/array_data.h16
-rw-r--r--src/data.cc74
-rw-r--r--src/data.h65
-rw-r--r--src/j2k.cc4
-rw-r--r--src/smpte_subtitle_asset.cc5
-rw-r--r--src/util.cc2
-rw-r--r--src/wscript2
8 files changed, 156 insertions, 40 deletions
diff --git a/src/array_data.cc b/src/array_data.cc
index 9d8473b8..a6f73868 100644
--- a/src/array_data.cc
+++ b/src/array_data.cc
@@ -85,31 +85,3 @@ ArrayData::ArrayData (boost::filesystem::path file)
fclose (f);
}
-
-void
-ArrayData::write (boost::filesystem::path file) const
-{
- FILE* f = fopen_boost (file, "wb");
- if (!f) {
- throw FileError ("could not write to file", file, errno);
- }
- size_t const r = fwrite (_data.get(), 1, _size, f);
- if (r != size_t (_size)) {
- fclose (f);
- throw FileError ("could not write to file", file, errno);
- }
- fclose (f);
-}
-
-void
-ArrayData::write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const
-{
- write (temp);
- boost::filesystem::rename (temp, final);
-}
-
-bool
-dcp::operator== (ArrayData const & a, ArrayData const & b)
-{
- return (a.size() == b.size() && memcmp (a.data().get(), b.data().get(), a.size()) == 0);
-}
diff --git a/src/array_data.h b/src/array_data.h
index 06ccec27..09cfd09d 100644
--- a/src/array_data.h
+++ b/src/array_data.h
@@ -34,13 +34,16 @@
#ifndef LIBDCP_ARRAY_DATA_H
#define LIBDCP_ARRAY_DATA_H
+
+#include "data.h"
#include <boost/shared_array.hpp>
#include <boost/filesystem.hpp>
#include <stdint.h>
namespace dcp {
-class ArrayData
+
+class ArrayData : public Data
{
public:
ArrayData ();
@@ -51,11 +54,12 @@ public:
virtual ~ArrayData () {}
- void write (boost::filesystem::path file) const;
- void write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const;
+ uint8_t const * data () const {
+ return _data.get();
+ }
- boost::shared_array<uint8_t> data () const {
- return _data;
+ uint8_t * data () {
+ return _data.get();
}
int size () const {
@@ -72,8 +76,6 @@ private:
int _size;
};
-bool operator==(ArrayData const & a, ArrayData const & b);
-
}
#endif
diff --git a/src/data.cc b/src/data.cc
new file mode 100644
index 00000000..ab6ae698
--- /dev/null
+++ b/src/data.cc
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2015-2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+#include "data.h"
+#include "util.h"
+#include "exceptions.h"
+#include <cstdio>
+#include <cerrno>
+
+
+using namespace dcp;
+
+
+void
+Data::write (boost::filesystem::path file) const
+{
+ FILE* f = fopen_boost (file, "wb");
+ if (!f) {
+ throw FileError ("could not write to file", file, errno);
+ }
+ size_t const r = fwrite (data(), 1, size(), f);
+ if (r != size_t(size())) {
+ fclose (f);
+ throw FileError ("could not write to file", file, errno);
+ }
+ fclose (f);
+}
+
+
+void
+Data::write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const
+{
+ write (temp);
+ boost::filesystem::rename (temp, final);
+}
+
+
+bool
+dcp::operator== (Data const & a, Data const & b)
+{
+ return (a.size() == b.size() && memcmp(a.data(), b.data(), a.size()) == 0);
+}
+
diff --git a/src/data.h b/src/data.h
new file mode 100644
index 00000000..dfc49fe0
--- /dev/null
+++ b/src/data.h
@@ -0,0 +1,65 @@
+/*
+ Copyright (C) 2015-2020 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+#ifndef LIBDCP_DATA_H
+#define LIBDCP_DATA_H
+
+
+#include <boost/filesystem.hpp>
+#include <stdint.h>
+
+
+namespace dcp {
+
+
+class Data
+{
+public:
+ virtual ~Data () {}
+
+ void write (boost::filesystem::path file) const;
+ void write_via_temp (boost::filesystem::path temp, boost::filesystem::path final) const;
+
+ virtual uint8_t const * data () const = 0;
+ virtual uint8_t * data () = 0;
+ virtual int size () const = 0;
+};
+
+
+bool operator==(Data const & a, Data const & b);
+
+
+}
+
+#endif
diff --git a/src/j2k.cc b/src/j2k.cc
index 46359d90..53039831 100644
--- a/src/j2k.cc
+++ b/src/j2k.cc
@@ -52,7 +52,7 @@ using namespace dcp;
shared_ptr<dcp::OpenJPEGImage>
dcp::decompress_j2k (ArrayData data, int reduce)
{
- return dcp::decompress_j2k (data.data().get(), data.size(), reduce);
+ return dcp::decompress_j2k (data.data(), data.size(), reduce);
}
#ifdef LIBDCP_OPENJPEG2
@@ -229,7 +229,7 @@ public:
OPJ_SIZE_T write (void* buffer, OPJ_SIZE_T nb_bytes)
{
DCP_ASSERT ((_offset + nb_bytes) < MAX_J2K_SIZE);
- memcpy (_data.data().get() + _offset, buffer, nb_bytes);
+ memcpy (_data.data() + _offset, buffer, nb_bytes);
_offset += nb_bytes;
if (_offset > OPJ_SIZE_T (_data.size())) {
_data.set_size (_offset);
diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc
index c9545052..224ae8ba 100644
--- a/src/smpte_subtitle_asset.cc
+++ b/src/smpte_subtitle_asset.cc
@@ -418,7 +418,8 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
}
if (j != _fonts.end ()) {
ASDCP::TimedText::FrameBuffer buffer;
- buffer.SetData (j->data.data().get(), j->data.size());
+ ArrayData data_copy(j->data);
+ buffer.SetData (data_copy.data(), data_copy.size());
buffer.Size (j->data.size());
r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac());
if (ASDCP_FAILURE (r)) {
@@ -433,7 +434,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const
shared_ptr<SubtitleImage> si = dynamic_pointer_cast<SubtitleImage>(i);
if (si) {
ASDCP::TimedText::FrameBuffer buffer;
- buffer.SetData (si->png_image().data().get(), si->png_image().size());
+ buffer.SetData (si->png_image().data(), si->png_image().size());
buffer.Size (si->png_image().size());
r = writer.WriteAncillaryResource (buffer, enc.context(), enc.hmac());
if (ASDCP_FAILURE(r)) {
diff --git a/src/util.cc b/src/util.cc
index b62def07..56b44889 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -102,7 +102,7 @@ dcp::make_digest (ArrayData data)
{
SHA_CTX sha;
SHA1_Init (&sha);
- SHA1_Update (&sha, data.data().get(), data.size());
+ SHA1_Update (&sha, data.data(), data.size());
byte_t byte_buffer[SHA_DIGEST_LENGTH];
SHA1_Final (byte_buffer, &sha);
char digest[64];
diff --git a/src/wscript b/src/wscript
index 85d4a6cb..1222dbde 100644
--- a/src/wscript
+++ b/src/wscript
@@ -47,6 +47,7 @@ def build(bld):
colour_conversion.cc
combine.cc
cpl.cc
+ data.cc
dcp.cc
dcp_time.cc
decrypted_kdm.cc
@@ -129,6 +130,7 @@ def build(bld):
compose.hpp
cpl.h
crypto_context.h
+ data.h
dcp.h
dcp_assert.h
dcp_time.h