diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-08-02 18:23:36 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-08-02 18:23:36 +0200 |
| commit | 7d9e108ba3629b2e9120bc1da3354935c41aca37 (patch) | |
| tree | c8ffdb2bca75d62bfe9fa2262e9fc4cd19c45027 | |
| parent | 6f98afd8021f9475bbd342bdcb39162b3167fa9e (diff) | |
WIP: more hacks.shared-ptr
| -rw-r--r-- | src/asset_reader.h | 5 | ||||
| -rw-r--r-- | src/data.h | 13 | ||||
| -rw-r--r-- | src/frame.h | 10 | ||||
| -rw-r--r-- | src/mono_j2k_picture_asset.cc | 4 | ||||
| -rw-r--r-- | src/mono_j2k_picture_frame.cc | 21 | ||||
| -rw-r--r-- | src/mono_j2k_picture_frame.h | 8 | ||||
| -rw-r--r-- | src/mono_mpeg2_picture_frame.cc | 14 | ||||
| -rw-r--r-- | src/mono_mpeg2_picture_frame.h | 3 | ||||
| -rw-r--r-- | src/mpeg2_transcode.cc | 8 | ||||
| -rw-r--r-- | src/mpeg2_transcode.h | 2 | ||||
| -rw-r--r-- | src/sound_asset.cc | 10 | ||||
| -rw-r--r-- | src/stereo_j2k_picture_asset.cc | 48 | ||||
| -rw-r--r-- | src/stereo_j2k_picture_frame.cc | 40 | ||||
| -rw-r--r-- | src/stereo_j2k_picture_frame.h | 18 | ||||
| -rw-r--r-- | src/verify.cc | 10 | ||||
| -rw-r--r-- | src/verify_j2k.cc | 6 | ||||
| -rw-r--r-- | src/verify_j2k.h | 4 | ||||
| -rw-r--r-- | test/dcp_test.cc | 16 | ||||
| -rw-r--r-- | test/decryption_test.cc | 4 | ||||
| -rw-r--r-- | test/kdm_test.cc | 2 | ||||
| -rw-r--r-- | test/round_trip_test.cc | 14 | ||||
| -rw-r--r-- | test/sound_asset_writer_test.cc | 6 | ||||
| -rw-r--r-- | test/sound_frame_test.cc | 8 | ||||
| -rw-r--r-- | test/sync_test.cc | 16 | ||||
| -rw-r--r-- | tools/dcpdecryptmxf.cc | 16 | ||||
| -rw-r--r-- | tools/dcpinfo.cc | 10 |
26 files changed, 180 insertions, 136 deletions
diff --git a/src/asset_reader.h b/src/asset_reader.h index 091ac915..89f6c699 100644 --- a/src/asset_reader.h +++ b/src/asset_reader.h @@ -70,10 +70,9 @@ public: delete _reader; } - std::shared_ptr<const F> get_frame (int n) const + F get_frame(int n) const { - /* Can't use make_shared here as the constructor is private */ - return std::shared_ptr<const F> (new F(_reader, n, _crypto_context, _check_hmac)); + return F(_reader, n, _crypto_context, _check_hmac); } R* reader () const { @@ -48,6 +48,19 @@ namespace dcp { +class ConstantData +{ +public: + virtual ~ConstantData() {} + + 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 int size () const = 0; +}; + + class Data { public: diff --git a/src/frame.h b/src/frame.h index d49be8f1..8a8a7814 100644 --- a/src/frame.h +++ b/src/frame.h @@ -65,6 +65,16 @@ public: Frame (Frame const&) = delete; Frame& operator= (Frame const&) = delete; + Frame(Frame&& other) + : _buffer(std::move(other._buffer)) + {} + + Frame& operator=(Frame&& other) + { + _buffer = std::move(other._buffer); + return *this; + } + uint8_t const * data () const { return _buffer.RoData(); diff --git a/src/mono_j2k_picture_asset.cc b/src/mono_j2k_picture_asset.cc index f718525d..55c06b6a 100644 --- a/src/mono_j2k_picture_asset.cc +++ b/src/mono_j2k_picture_asset.cc @@ -164,8 +164,8 @@ MonoJ2KPictureAsset::equals(shared_ptr<const Asset> other, EqualityOptions const if (!frame_buffer_equals ( i, opt, bind (&storing_note_handler, boost::ref(notes), _1, _2), - frame_A->data(), frame_A->size(), - frame_B->data(), frame_B->size() + frame_A.data(), frame_A.size(), + frame_B.data(), frame_B.size() )) { result = false; } diff --git a/src/mono_j2k_picture_frame.cc b/src/mono_j2k_picture_frame.cc index c2b3cfd2..c7af0e2e 100644 --- a/src/mono_j2k_picture_frame.cc +++ b/src/mono_j2k_picture_frame.cc @@ -66,7 +66,7 @@ MonoJ2KPictureFrame::MonoJ2KPictureFrame (boost::filesystem::path path) boost::throw_exception (FileError("could not open JPEG2000 file", path, errno)); } - if (f.read(data(), 1, _buffer.Capacity()) != _buffer.Capacity()) { + if (f.read(_buffer.Data(), 1, _buffer.Capacity()) != _buffer.Capacity()) { boost::throw_exception (FileError("could not read from JPEG2000 file", path, errno)); } @@ -99,17 +99,24 @@ MonoJ2KPictureFrame::MonoJ2KPictureFrame (uint8_t const * data, int size) } -uint8_t const * -MonoJ2KPictureFrame::data () const +MonoJ2KPictureFrame::MonoJ2KPictureFrame(MonoJ2KPictureFrame&& other) + : _buffer(std::move(other._buffer)) { - return _buffer.RoData(); + } -uint8_t * -MonoJ2KPictureFrame::data () +MonoJ2KPictureFrame& MonoJ2KPictureFrame::operator=(MonoJ2KPictureFrame&& other) { - return _buffer.Data(); + _buffer = std::move(other._buffer); + return *this; +} + + +uint8_t const * +MonoJ2KPictureFrame::data () const +{ + return _buffer.RoData(); } diff --git a/src/mono_j2k_picture_frame.h b/src/mono_j2k_picture_frame.h index af2002a1..e5864c89 100644 --- a/src/mono_j2k_picture_frame.h +++ b/src/mono_j2k_picture_frame.h @@ -67,7 +67,7 @@ class OpenJPEGImage; /** @class MonoJ2KPictureFrame * @brief A single frame of a 2D (monoscopic) picture asset */ -class MonoJ2KPictureFrame : public Data +class MonoJ2KPictureFrame : public ConstantData { public: /** Make a picture frame from a JPEG2000 file. @@ -79,6 +79,9 @@ public: MonoJ2KPictureFrame (MonoJ2KPictureFrame const&) = delete; MonoJ2KPictureFrame& operator= (MonoJ2KPictureFrame const&) = delete; + MonoJ2KPictureFrame(MonoJ2KPictureFrame&&); + MonoJ2KPictureFrame& operator=(MonoJ2KPictureFrame&&); + /** @param reduce a factor by which to reduce the resolution * of the image, expressed as a power of two (pass 0 for no * reduction). @@ -88,9 +91,6 @@ public: /** @return Pointer to JPEG2000 data */ uint8_t const * data () const override; - /** @return Pointer to JPEG2000 data */ - uint8_t* data () override; - /** @return Size of JPEG2000 data in bytes */ int size () const override; diff --git a/src/mono_mpeg2_picture_frame.cc b/src/mono_mpeg2_picture_frame.cc index 6341ae4a..09942080 100644 --- a/src/mono_mpeg2_picture_frame.cc +++ b/src/mono_mpeg2_picture_frame.cc @@ -67,6 +67,20 @@ MonoMPEG2PictureFrame::MonoMPEG2PictureFrame(ASDCP::MPEG2::MXFReader* reader, in } +MonoMPEG2PictureFrame::MonoMPEG2PictureFrame(MonoMPEG2PictureFrame&& other) + : _buffer(std::move(other._buffer)) +{ + +} + + +MonoMPEG2PictureFrame& MonoMPEG2PictureFrame::operator=(MonoMPEG2PictureFrame&& other) +{ + _buffer = std::move(other._buffer); + return *this; +} + + uint8_t const * MonoMPEG2PictureFrame::data() const { diff --git a/src/mono_mpeg2_picture_frame.h b/src/mono_mpeg2_picture_frame.h index d0ec7bfc..aac2f007 100644 --- a/src/mono_mpeg2_picture_frame.h +++ b/src/mono_mpeg2_picture_frame.h @@ -51,6 +51,9 @@ public: MonoMPEG2PictureFrame(MonoMPEG2PictureFrame const&) = delete; MonoMPEG2PictureFrame& operator=(MonoMPEG2PictureFrame const&) = delete; + MonoMPEG2PictureFrame(MonoMPEG2PictureFrame&&); + MonoMPEG2PictureFrame& operator=(MonoMPEG2PictureFrame&&); + /* XXX: couldn't we just return the frame buffer */ /** @return Pointer to MPEG2 data */ diff --git a/src/mpeg2_transcode.cc b/src/mpeg2_transcode.cc index 0ac2c1af..4e96dbe9 100644 --- a/src/mpeg2_transcode.cc +++ b/src/mpeg2_transcode.cc @@ -88,18 +88,18 @@ MPEG2Decompressor::~MPEG2Decompressor() vector<FFmpegImage> -MPEG2Decompressor::decompress_frame(shared_ptr<const MonoMPEG2PictureFrame> frame) +MPEG2Decompressor::decompress_frame(MonoMPEG2PictureFrame const& frame) { /* XXX: can we avoid this? */ - auto copy = av_malloc(frame->size() + AV_INPUT_BUFFER_PADDING_SIZE); + auto copy = av_malloc(frame.size() + AV_INPUT_BUFFER_PADDING_SIZE); if (!copy) { throw std::bad_alloc(); } - memcpy(copy, frame->data(), frame->size()); + memcpy(copy, frame.data(), frame.size()); AVPacket packet; av_init_packet(&packet); - av_packet_from_data(&packet, reinterpret_cast<uint8_t*>(copy), frame->size()); + av_packet_from_data(&packet, reinterpret_cast<uint8_t*>(copy), frame.size()); auto images = decompress_packet(&packet); diff --git a/src/mpeg2_transcode.h b/src/mpeg2_transcode.h index 1f13cfc3..80eb5237 100644 --- a/src/mpeg2_transcode.h +++ b/src/mpeg2_transcode.h @@ -73,7 +73,7 @@ public: MPEG2Decompressor(); ~MPEG2Decompressor(); - std::vector<FFmpegImage> decompress_frame(std::shared_ptr<const MonoMPEG2PictureFrame> frame); + std::vector<FFmpegImage> decompress_frame(MonoMPEG2PictureFrame const& frame); std::vector<FFmpegImage> flush(); private: diff --git a/src/sound_asset.cc b/src/sound_asset.cc index c73255b8..d36db241 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -217,15 +217,15 @@ SoundAsset::equals(shared_ptr<const Asset> other, EqualityOptions const& opt, No auto frame_A = reader->get_frame (i); auto frame_B = other_reader->get_frame (i); - if (frame_A->size() != frame_B->size()) { + if (frame_A.size() != frame_B.size()) { note (NoteType::ERROR, String::compose ("sizes of audio data for frame %1 differ", i)); return false; } - if (memcmp (frame_A->data(), frame_B->data(), frame_A->size()) != 0) { - for (int sample = 0; sample < frame_A->samples(); ++sample) { - for (int channel = 0; channel < frame_A->channels(); ++channel) { - int32_t const d = abs(frame_A->get(channel, sample) - frame_B->get(channel, sample)); + if (memcmp(frame_A.data(), frame_B.data(), frame_A.size()) != 0) { + for (int sample = 0; sample < frame_A.samples(); ++sample) { + for (int channel = 0; channel < frame_A.channels(); ++channel) { + int32_t const d = abs(frame_A.get(channel, sample) - frame_B.get(channel, sample)); if (d > opt.max_audio_sample_error) { note (NoteType::ERROR, String::compose("PCM data difference of %1 in frame %2, channel %3, sample %4", d, i, channel, sample)); return false; diff --git a/src/stereo_j2k_picture_asset.cc b/src/stereo_j2k_picture_asset.cc index 6a5e7d79..9c39f84c 100644 --- a/src/stereo_j2k_picture_asset.cc +++ b/src/stereo_j2k_picture_asset.cc @@ -143,11 +143,30 @@ StereoJ2KPictureAsset::equals(shared_ptr<const Asset> other, EqualityOptions con bool result = true; for (int i = 0; i < _intrinsic_duration; ++i) { - shared_ptr<const StereoJ2KPictureFrame> frame_A; - shared_ptr<const StereoJ2KPictureFrame> frame_B; try { - frame_A = reader->get_frame (i); - frame_B = other_reader->get_frame (i); + auto frame_A = reader->get_frame(i); + auto frame_B = other_reader->get_frame(i); + if (!frame_buffer_equals ( + i, opt, note, + frame_A.left().data(), frame_A.left().size(), + frame_B.left().data(), frame_B.left().size() + )) { + result = false; + if (!opt.keep_going) { + return result; + } + } + + if (!frame_buffer_equals ( + i, opt, note, + frame_A.right().data(), frame_A.right().size(), + frame_B.right().data(), frame_B.right().size() + )) { + result = false; + if (!opt.keep_going) { + return result; + } + } } catch (ReadError& e) { /* If there was a problem reading the frame data we'll just assume the two frames are not equal. @@ -156,27 +175,6 @@ StereoJ2KPictureAsset::equals(shared_ptr<const Asset> other, EqualityOptions con return false; } - if (!frame_buffer_equals ( - i, opt, note, - frame_A->left()->data(), frame_A->left()->size(), - frame_B->left()->data(), frame_B->left()->size() - )) { - result = false; - if (!opt.keep_going) { - return result; - } - } - - if (!frame_buffer_equals ( - i, opt, note, - frame_A->right()->data(), frame_A->right()->size(), - frame_B->right()->data(), frame_B->right()->size() - )) { - result = false; - if (!opt.keep_going) { - return result; - } - } } return result; diff --git a/src/stereo_j2k_picture_frame.cc b/src/stereo_j2k_picture_frame.cc index 8e09888a..fccd9983 100644 --- a/src/stereo_j2k_picture_frame.cc +++ b/src/stereo_j2k_picture_frame.cc @@ -55,7 +55,7 @@ using std::make_shared; using namespace dcp; -StereoJ2KPictureFrame::Part::Part (shared_ptr<ASDCP::JP2K::SFrameBuffer> buffer, Eye eye) +StereoJ2KPictureFrame::Part::Part(ASDCP::JP2K::SFrameBuffer const& buffer, Eye eye) : _buffer (buffer) , _eye (eye) { @@ -63,10 +63,10 @@ StereoJ2KPictureFrame::Part::Part (shared_ptr<ASDCP::JP2K::SFrameBuffer> buffer, } -ASDCP::JP2K::FrameBuffer & +ASDCP::JP2K::FrameBuffer const& StereoJ2KPictureFrame::Part::mono () const { - return _eye == Eye::LEFT ? _buffer->Left : _buffer->Right; + return _eye == Eye::LEFT ? _buffer.Left : _buffer.Right; } @@ -77,13 +77,6 @@ StereoJ2KPictureFrame::Part::data () const } -uint8_t * -StereoJ2KPictureFrame::Part::data () -{ - return mono().Data(); -} - - int StereoJ2KPictureFrame::Part::size () const { @@ -97,19 +90,24 @@ StereoJ2KPictureFrame::Part::size () const * @param check_hmac true to check the HMAC and give an error if it is not as expected. */ StereoJ2KPictureFrame::StereoJ2KPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, shared_ptr<DecryptionContext> c, bool check_hmac) + : _buffer(4 * Kumu::Megabyte) { - /* XXX: unfortunate guesswork on this buffer size */ - _buffer = make_shared<ASDCP::JP2K::SFrameBuffer>(4 * Kumu::Megabyte); - - if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->context(), check_hmac ? c->hmac() : nullptr))) { + if (ASDCP_FAILURE(reader->ReadFrame(n, _buffer, c->context(), check_hmac ? c->hmac() : nullptr))) { boost::throw_exception (ReadError (String::compose ("could not read video frame %1 of %2", n))); } } StereoJ2KPictureFrame::StereoJ2KPictureFrame () + : _buffer(4 * Kumu::Megabyte) { - _buffer = make_shared<ASDCP::JP2K::SFrameBuffer>(4 * Kumu::Megabyte); +} + + +StereoJ2KPictureFrame::StereoJ2KPictureFrame(StereoJ2KPictureFrame&& other) + : _buffer(std::move(other._buffer)) +{ + } @@ -123,26 +121,26 @@ StereoJ2KPictureFrame::xyz_image (Eye eye, int reduce) const { switch (eye) { case Eye::LEFT: - return decompress_j2k(_buffer->Left.RoData(), _buffer->Left.Size(), reduce); + return decompress_j2k(_buffer.Left.RoData(), _buffer.Left.Size(), reduce); case Eye::RIGHT: - return decompress_j2k(_buffer->Right.RoData(), _buffer->Right.Size(), reduce); + return decompress_j2k(_buffer.Right.RoData(), _buffer.Right.Size(), reduce); } return {}; } -shared_ptr<StereoJ2KPictureFrame::Part> +StereoJ2KPictureFrame::Part StereoJ2KPictureFrame::right () const { - return make_shared<Part>(_buffer, Eye::RIGHT); + return Part(_buffer, Eye::RIGHT); } -shared_ptr<StereoJ2KPictureFrame::Part> +StereoJ2KPictureFrame::Part StereoJ2KPictureFrame::left () const { - return make_shared<Part>(_buffer, Eye::LEFT); + return Part(_buffer, Eye::LEFT); } diff --git a/src/stereo_j2k_picture_frame.h b/src/stereo_j2k_picture_frame.h index 193960f3..e1291314 100644 --- a/src/stereo_j2k_picture_frame.h +++ b/src/stereo_j2k_picture_frame.h @@ -75,28 +75,30 @@ public: StereoJ2KPictureFrame (StereoJ2KPictureFrame const &) = delete; StereoJ2KPictureFrame& operator= (StereoJ2KPictureFrame const &) = delete; + StereoJ2KPictureFrame(StereoJ2KPictureFrame&&); + StereoJ2KPictureFrame& operator=(StereoJ2KPictureFrame&&); + std::shared_ptr<OpenJPEGImage> xyz_image (Eye eye, int reduce = 0) const; - class Part : public Data + class Part : public ConstantData { public: - Part (std::shared_ptr<ASDCP::JP2K::SFrameBuffer> buffer, Eye eye); + Part(ASDCP::JP2K::SFrameBuffer const& buffer, Eye eye); uint8_t const * data () const override; - uint8_t * data () override; int size () const override; private: friend class StereoJ2KPictureFrame; - ASDCP::JP2K::FrameBuffer& mono () const; + ASDCP::JP2K::FrameBuffer const& mono() const; - std::shared_ptr<ASDCP::JP2K::SFrameBuffer> _buffer; + ASDCP::JP2K::SFrameBuffer const& _buffer; Eye _eye; }; - std::shared_ptr<Part> left () const; - std::shared_ptr<Part> right () const; + Part left() const; + Part right() const; private: /* XXX: this is a bit of a shame, but I tried friend StereoJ2KPictureAssetReader and it's @@ -106,7 +108,7 @@ private: StereoJ2KPictureFrame (ASDCP::JP2K::MXFSReader* reader, int n, std::shared_ptr<DecryptionContext>, bool check_hmac); - std::shared_ptr<ASDCP::JP2K::SFrameBuffer> _buffer; + ASDCP::JP2K::SFrameBuffer _buffer; }; diff --git a/src/verify.cc b/src/verify.cc index 1e27514a..a1eccd23 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -564,7 +564,7 @@ verify_picture_asset( auto reader = mono_asset->start_read (); for (int64_t i = 0; i < duration; ++i) { auto frame = reader->get_frame (i); - check_frame_size(context, i, frame->size(), mono_asset->frame_rate().numerator); + check_frame_size(context, i, frame.size(), mono_asset->frame_rate().numerator); if (!mono_asset->encrypted() || mono_asset->key()) { vector<VerificationNote> j2k_notes; verify_j2k(frame, start_frame, i, mono_asset->frame_rate().numerator, j2k_notes); @@ -576,12 +576,12 @@ verify_picture_asset( auto reader = stereo_asset->start_read (); for (int64_t i = 0; i < duration; ++i) { auto frame = reader->get_frame (i); - check_frame_size(context, i, frame->left()->size(), stereo_asset->frame_rate().numerator); - check_frame_size(context, i, frame->right()->size(), stereo_asset->frame_rate().numerator); + check_frame_size(context, i, frame.left().size(), stereo_asset->frame_rate().numerator); + check_frame_size(context, i, frame.right().size(), stereo_asset->frame_rate().numerator); if (!stereo_asset->encrypted() || stereo_asset->key()) { vector<VerificationNote> j2k_notes; - verify_j2k(frame->left(), start_frame, i, stereo_asset->frame_rate().numerator, j2k_notes); - verify_j2k(frame->right(), start_frame, i, stereo_asset->frame_rate().numerator, j2k_notes); + verify_j2k(frame.left(), start_frame, i, stereo_asset->frame_rate().numerator, j2k_notes); + verify_j2k(frame.right(), start_frame, i, stereo_asset->frame_rate().numerator, j2k_notes); check_and_add (j2k_notes); } context.progress(float(i) / duration); diff --git a/src/verify_j2k.cc b/src/verify_j2k.cc index 47ee151c..12179c8d 100644 --- a/src/verify_j2k.cc +++ b/src/verify_j2k.cc @@ -65,14 +65,14 @@ public: void -dcp::verify_j2k(shared_ptr<const Data> j2k, int start_index, int frame_index, int frame_rate, vector<VerificationNote>& notes) +dcp::verify_j2k(ConstantData const& j2k, int start_index, int frame_index, int frame_rate, vector<VerificationNote>& notes) { /* See ITU-T T800 (visible on https://github.com/Ymagis/ClairMeta/issues/130) */ unsigned int const max_tile_part_size = std::floor(200e6 / (8 * frame_rate)); try { - auto ptr = j2k->data(); - auto end = ptr + j2k->size(); + auto ptr = j2k.data(); + auto end = ptr + j2k.size(); map<string, uint8_t> markers = { { "SOC", 0x4f }, diff --git a/src/verify_j2k.h b/src/verify_j2k.h index dbfc488b..02efc815 100644 --- a/src/verify_j2k.h +++ b/src/verify_j2k.h @@ -48,7 +48,7 @@ namespace dcp { -class Data; +class ConstantData; /** @param start_index Frame index within the DCP where this frame's reel starts. @@ -56,7 +56,7 @@ class Data; * @param frame_rate Video frame rate (in frames per second) to calculate how big the tile parts * can be. */ -void verify_j2k(std::shared_ptr<const Data> data, int start_index, int frame_index, int frame_rate, std::vector<VerificationNote>& notes); +void verify_j2k(ConstantData const& data, int start_index, int frame_index, int frame_rate, std::vector<VerificationNote>& notes); } diff --git a/test/dcp_test.cc b/test/dcp_test.cc index 63de990f..61cfa711 100644 --- a/test/dcp_test.cc +++ b/test/dcp_test.cc @@ -215,21 +215,21 @@ test_rewriting_sound(string name, bool modify) bool need_to_modify = modify; for (int i = 0; i < A_sound->asset()->intrinsic_duration(); ++i) { auto sf = reader->get_frame (i); - float* out[sf->channels()]; - for (int j = 0; j < sf->channels(); ++j) { - out[j] = new float[sf->samples()]; + float* out[sf.channels()]; + for (int j = 0; j < sf.channels(); ++j) { + out[j] = new float[sf.samples()]; } - for (int j = 0; j < sf->samples(); ++j) { - for (int k = 0; k < sf->channels(); ++k) { - out[k][j] = static_cast<float>(sf->get(k, j)) / (1 << 23); + for (int j = 0; j < sf.samples(); ++j) { + for (int k = 0; k < sf.channels(); ++k) { + out[k][j] = static_cast<float>(sf.get(k, j)) / (1 << 23); if (need_to_modify) { out[k][j] += 1.0 / (1 << 23); need_to_modify = false; } } } - writer->write(out, sf->channels(), sf->samples()); - for (int j = 0; j < sf->channels(); ++j) { + writer->write(out, sf.channels(), sf.samples()); + for (int j = 0; j < sf.channels(); ++j) { delete[] out[j]; } } diff --git a/test/decryption_test.cc b/test/decryption_test.cc index 1aadc461..7610d985 100644 --- a/test/decryption_test.cc +++ b/test/decryption_test.cc @@ -83,10 +83,10 @@ get_frame (dcp::DCP const & dcp) auto mono_picture = dynamic_pointer_cast<const dcp::MonoJ2KPictureAsset>(picture); auto reader = mono_picture->start_read(); auto j2k_frame = reader->get_frame(0); - auto xyz = j2k_frame->xyz_image(); + auto xyz = j2k_frame.xyz_image(); std::vector<uint8_t> argb(xyz->size().width * xyz->size().height * 4); - dcp::xyz_to_rgba(j2k_frame->xyz_image(), dcp::ColourConversion::srgb_to_xyz(), argb.data(), xyz->size().width * 4); + dcp::xyz_to_rgba(j2k_frame.xyz_image(), dcp::ColourConversion::srgb_to_xyz(), argb.data(), xyz->size().width * 4); return make_pair (argb, xyz->size ()); } diff --git a/test/kdm_test.cc b/test/kdm_test.cc index 75a6019e..2f788439 100644 --- a/test/kdm_test.cc +++ b/test/kdm_test.cc @@ -380,5 +380,5 @@ BOOST_AUTO_TEST_CASE (vf_kdm_test) BOOST_REQUIRE(mono_asset); auto reader = mono_asset->start_read(); reader->set_check_hmac(false); - reader->get_frame(0)->xyz_image(); + reader->get_frame(0).xyz_image(); } diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc index ffba5cbd..151bc1bc 100644 --- a/test/round_trip_test.cc +++ b/test/round_trip_test.cc @@ -128,16 +128,16 @@ BOOST_AUTO_TEST_CASE (round_trip_test) BOOST_CHECK (!kdm_B.keys().empty ()); asset_B->set_key (kdm_B.keys().front().key()); - auto xyz_A = asset_A->start_read()->get_frame(0)->xyz_image (); - auto xyz_B = asset_B->start_read()->get_frame(0)->xyz_image (); + auto xyz_A = asset_A->start_read()->get_frame(0).xyz_image(); + auto xyz_B = asset_B->start_read()->get_frame(0).xyz_image(); - scoped_array<uint8_t> frame_A (new uint8_t[xyz_A->size().width * xyz_A->size().height * 4]); - dcp::xyz_to_rgba (xyz_A, dcp::ColourConversion::srgb_to_xyz(), frame_A.get(), xyz_A->size().width * 4); + vector<uint8_t> frame_A(xyz_A->size().width * xyz_A->size().height * 4); + dcp::xyz_to_rgba(xyz_A, dcp::ColourConversion::srgb_to_xyz(), frame_A.data(), xyz_A->size().width * 4); - scoped_array<uint8_t> frame_B (new uint8_t[xyz_B->size().width * xyz_B->size().height * 4]); - dcp::xyz_to_rgba (xyz_B, dcp::ColourConversion::srgb_to_xyz(), frame_B.get(), xyz_B->size().width * 4); + vector<uint8_t> frame_B(xyz_B->size().width * xyz_B->size().height * 4); + dcp::xyz_to_rgba(xyz_B, dcp::ColourConversion::srgb_to_xyz(), frame_B.data(), xyz_B->size().width * 4); BOOST_CHECK_EQUAL (xyz_A->size().width, xyz_B->size().width); BOOST_CHECK_EQUAL (xyz_A->size().height, xyz_B->size().height); - BOOST_CHECK_EQUAL (memcmp (frame_A.get(), frame_B.get(), xyz_A->size().width * xyz_A->size().height * 4), 0); + BOOST_CHECK_EQUAL (memcmp (frame_A.data(), frame_B.data(), xyz_A->size().width * xyz_A->size().height * 4), 0); } diff --git a/test/sound_asset_writer_test.cc b/test/sound_asset_writer_test.cc index d5a66489..ee70c80c 100644 --- a/test/sound_asset_writer_test.cc +++ b/test/sound_asset_writer_test.cc @@ -64,7 +64,7 @@ no_padding_test(boost::filesystem::path path, std::function<void (shared_ptr<dcp for (auto channel = 0; channel < 6; ++channel) { for (auto sample = 0; sample < 2000; ++sample) { - BOOST_REQUIRE_EQUAL(frame->get(channel, sample), dist(rng)); + BOOST_REQUIRE_EQUAL(frame.get(channel, sample), dist(rng)); } } } @@ -135,13 +135,13 @@ padding_test(boost::filesystem::path path, std::function<void (shared_ptr<dcp::S for (auto channel = 0; channel < 6; ++channel) { for (auto sample = 0; sample < 2000; ++sample) { - BOOST_REQUIRE_EQUAL(frame->get(channel, sample), dist(rng)); + BOOST_REQUIRE_EQUAL(frame.get(channel, sample), dist(rng)); } } for (auto channel = 7; channel < 14; ++channel) { for (auto sample = 0; sample < 2000; ++sample) { - BOOST_REQUIRE_EQUAL(frame->get(channel, sample), 0); + BOOST_REQUIRE_EQUAL(frame.get(channel, sample), 0); } } } diff --git a/test/sound_frame_test.cc b/test/sound_frame_test.cc index a8060bd4..60a08b33 100644 --- a/test/sound_frame_test.cc +++ b/test/sound_frame_test.cc @@ -50,9 +50,9 @@ BOOST_AUTO_TEST_CASE (sound_frame_test) private_test / "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV/pcm_95734608-5d47-4d3f-bf5f-9e9186b66afa_.mxf" ); - shared_ptr<const dcp::SoundFrame> frame = asset.start_read()->get_frame(42); + auto frame = asset.start_read()->get_frame(42); - BOOST_REQUIRE_EQUAL (frame->size(), channels * frame_length * 3); + BOOST_REQUIRE_EQUAL(frame.size(), channels * frame_length * 3); boost::filesystem::path ref_file = private_test / "data" / "frame.wav"; SF_INFO info; @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE (sound_frame_test) BOOST_REQUIRE_EQUAL (read, frame_length); /* Check raw data is as we expect */ - uint8_t const * p = frame->data (); + uint8_t const * p = frame.data(); for (int i = 0; i < (frame_length * channels); ++i) { int x = ref_data[i] >> 8; if (x < 0) { @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE (sound_frame_test) int* ref = ref_data; for (int sample = 0; sample < frame_length; ++sample) { for (int channel = 0; channel < channels; ++channel) { - BOOST_REQUIRE_EQUAL ((*ref++) >> 8, frame->get(channel, sample)); + BOOST_REQUIRE_EQUAL((*ref++) >> 8, frame.get(channel, sample)); } } } diff --git a/test/sync_test.cc b/test/sync_test.cc index 67920e2f..51a18282 100644 --- a/test/sync_test.cc +++ b/test/sync_test.cc @@ -83,10 +83,10 @@ BOOST_AUTO_TEST_CASE (sync_test1) { dcp::SoundAsset asset (private_test / "data" / "atmos_pcm.mxf"); shared_ptr<dcp::SoundAssetReader> reader = asset.start_read (); - shared_ptr<const dcp::SoundFrame> frame = reader->get_frame (0); + auto frame = reader->get_frame(0); /* Read the samples from the first MXF frame of channel 14 and decode them to bits */ - uint8_t const * data = frame->data (); + uint8_t const * data = frame.data(); vector<bool> ref; /* There's 2000 samples which contain 500 bits of data */ for (int i = 0; i < 500; ++i) { @@ -146,13 +146,13 @@ BOOST_AUTO_TEST_CASE (sync_test2) dcp::SoundAsset ref (private_test / "data" / "atmos_pcm.mxf"); dcp::SoundAsset check ("build/test/foo.mxf"); - shared_ptr<dcp::SoundAssetReader> ref_read = ref.start_read (); - shared_ptr<dcp::SoundAssetReader> check_read = check.start_read (); + auto ref_read = ref.start_read(); + auto check_read = check.start_read(); - shared_ptr<const dcp::SoundFrame> ref_frame = ref_read->get_frame(0); - uint8_t const* ref_data = ref_frame->data(); - shared_ptr<const dcp::SoundFrame> check_frame = check_read->get_frame(0); - uint8_t const* check_data = check_frame->data(); + auto ref_frame = ref_read->get_frame(0); + uint8_t const* ref_data = ref_frame.data(); + auto check_frame = check_read->get_frame(0); + uint8_t const* check_data = check_frame.data(); for (int i = 0; i < frames; ++i) { int ref_sample = read_sync_sample (ref_data, i, ref.channels()); diff --git a/tools/dcpdecryptmxf.cc b/tools/dcpdecryptmxf.cc index 1145d77d..fe7a2261 100644 --- a/tools/dcpdecryptmxf.cc +++ b/tools/dcpdecryptmxf.cc @@ -82,7 +82,7 @@ void copy (T const& in, shared_ptr<U> writer, bool ignore_hmac) reader->set_check_hmac (!ignore_hmac); for (int64_t i = 0; i < in.intrinsic_duration(); ++i) { auto frame = reader->get_frame (i); - writer->write (frame->data(), frame->size()); + writer->write(frame.data(), frame.size()); } writer->finalize(); }; @@ -250,15 +250,15 @@ main (int argc, char* argv[]) reader->set_check_hmac(!ignore_hmac); for (int64_t i = 0; i < in.intrinsic_duration(); ++i) { auto frame = reader->get_frame(i); - std::vector<int32_t*> pointers(frame->channels()); - for (auto channel = 0; channel < frame->channels(); ++channel) { - pointers[channel] = new int32_t[frame->samples()]; - for (auto sample = 0; sample < frame->samples(); ++sample) { - pointers[channel][sample] = frame->get(channel, sample); + std::vector<int32_t*> pointers(frame.channels()); + for (auto channel = 0; channel < frame.channels(); ++channel) { + pointers[channel] = new int32_t[frame.samples()]; + for (auto sample = 0; sample < frame.samples(); ++sample) { + pointers[channel][sample] = frame.get(channel, sample); } } - writer->write(pointers.data(), frame->channels(), frame->samples()); - for (auto channel = 0; channel < frame->channels(); ++channel) { + writer->write(pointers.data(), frame.channels(), frame.samples()); + for (auto channel = 0; channel < frame.channels(); ++channel) { delete[] pointers[channel]; } } diff --git a/tools/dcpinfo.cc b/tools/dcpinfo.cc index f68fac24..8c7dcff7 100644 --- a/tools/dcpinfo.cc +++ b/tools/dcpinfo.cc @@ -163,16 +163,16 @@ main_picture (vector<string> const& only, shared_ptr<Reel> reel, bool analyse, b shared_ptr<MonoJ2KPictureAssetReader> reader = ma->start_read (); pair<int, int> j2k_size_range (INT_MAX, 0); for (int64_t i = 0; i < ma->intrinsic_duration(); ++i) { - shared_ptr<const MonoJ2KPictureFrame> frame = reader->get_frame (i); + auto frame = reader->get_frame(i); if (SHOULD_PICTURE) { - printf("Frame %" PRId64 " J2K size %7d", i, frame->size()); + printf("Frame %" PRId64 " J2K size %7d", i, frame.size()); } - j2k_size_range.first = min(j2k_size_range.first, frame->size()); - j2k_size_range.second = max(j2k_size_range.second, frame->size()); + j2k_size_range.first = min(j2k_size_range.first, frame.size()); + j2k_size_range.second = max(j2k_size_range.second, frame.size()); if (decompress) { try { - frame->xyz_image(); + frame.xyz_image(); if (SHOULD_PICTURE) { printf(" decrypted OK"); } |
