#include <cstdio>
-using boost::shared_array;
using namespace dcp;
ArrayData::ArrayData ()
+ : _data(std::make_shared<std::vector<uint8_t>>())
{
}
ArrayData::ArrayData (int size)
- : _data (new uint8_t[size])
- , _size (size)
+ : _data(std::make_shared<std::vector<uint8_t>>(size))
{
}
ArrayData::ArrayData (uint8_t const * data, int size)
- : _data (new uint8_t[size])
- , _size (size)
-{
- memcpy (_data.get(), data, size);
-}
-
-
-ArrayData::ArrayData (shared_array<uint8_t> data, int size)
- : _data (data)
- , _size (size)
+ : _data(std::make_shared<std::vector<uint8_t>>(data, data + size))
{
}
ArrayData::ArrayData (boost::filesystem::path file)
{
- _size = boost::filesystem::file_size (file);
- _data.reset (new uint8_t[_size]);
+ auto const size = boost::filesystem::file_size (file);
+ _data = std::make_shared<std::vector<uint8_t>>(size);
File f(file, "rb");
if (!f) {
throw FileError ("could not open file for reading", file, errno);
}
- if (f.read(_data.get(), 1, _size) != static_cast<size_t>(_size)) {
+ if (f.read(_data->data(), 1, size) != static_cast<size_t>(size)) {
throw FileError ("could not read from file", file, errno);
}
}
explicit ArrayData (int size);
ArrayData (uint8_t const * data, int size);
- /** Create an ArrayData by copying a shared_array<>
- * @param data shared_array<> to copy (the shared_array<> is copied, not the data)
- * @param size Size of data in bytes
- */
- ArrayData (boost::shared_array<uint8_t> data, int size);
-
/** Create an ArrayData by reading the contents of a file
* @param file Filename to read
*/
- explicit ArrayData (boost::filesystem::path file);
-
- virtual ~ArrayData () {}
+ explicit ArrayData(boost::filesystem::path file);
uint8_t const * data () const override {
- return _data.get();
+ return _data->data();
}
uint8_t * data () override {
- return _data.get();
+ return _data->data();
}
/** @return size of the data in _data, or whatever was last
* passed to a set_size() call
*/
int size () const override {
- return _size;
+ return _data->size();
}
/** Set the size that will be returned from size() */
void set_size (int s) {
- _size = s;
+ _data->resize(s);
}
private:
- boost::shared_array<uint8_t> _data;
- /** amount of `valid' data in _data; the array may be larger */
- int _size = 0;
+ std::shared_ptr<std::vector<uint8_t>> _data;
};
class WriteBuffer
{
public:
-/* XXX: is there a better strategy for this? */
-#define MAX_J2K_SIZE (1024 * 1024 * 2)
- WriteBuffer ()
- : _data (shared_array<uint8_t>(new uint8_t[MAX_J2K_SIZE]), MAX_J2K_SIZE)
- , _offset (0)
- {
- _data.set_size (0);
- }
-
OPJ_SIZE_T write (void* buffer, OPJ_SIZE_T nb_bytes)
{
- DCP_ASSERT ((_offset + nb_bytes) < MAX_J2K_SIZE);
- memcpy (_data.data() + _offset, buffer, nb_bytes);
- _offset += nb_bytes;
- if (_offset > OPJ_SIZE_T(_data.size())) {
- _data.set_size (_offset);
+ auto const new_offset = _offset + nb_bytes;
+ if (new_offset > OPJ_SIZE_T(_data.size())) {
+ _data.set_size(new_offset);
}
+ memcpy(_data.data() + _offset, buffer, nb_bytes);
+ _offset = new_offset;
return nb_bytes;
}
private:
ArrayData _data;
- OPJ_SIZE_T _offset;
+ OPJ_SIZE_T _offset = 0;
};
char id[64];
Kumu::bin2UUIDhex (i->ResourceID, ASDCP::UUIDlen, id, sizeof(id));
- shared_array<uint8_t> data (new uint8_t[buffer.Size()]);
- memcpy (data.get(), buffer.RoData(), buffer.Size());
-
switch (i->Type) {
case ASDCP::TimedText::MT_OPENTYPE:
{
}
if (j != _load_font_nodes.end ()) {
- _fonts.push_back (Font ((*j)->id, (*j)->urn, ArrayData (data, buffer.Size ())));
+ _fonts.push_back(Font((*j)->id, (*j)->urn, ArrayData(buffer.RoData(), buffer.Size())));
}
break;
}
}
if (j != _subtitles.end()) {
- dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image (ArrayData(data, buffer.Size()));
+ dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image(ArrayData(buffer.RoData(), buffer.Size()));
}
break;
}