Switch to testing on Ubuntu 16.04 and 22.04.
[libdcp.git] / src / mono_picture_frame.cc
index fb451e08bf9474b4167bd6e41f5490463e1e882a..2abd57e453248d68bb916ea513163fa3f559e85e 100644 (file)
@@ -41,6 +41,8 @@
 #include "compose.hpp"
 #include "crypto_context.h"
 #include "exceptions.h"
+#include "file.h"
+#include "filesystem.h"
 #include "j2k_transcode.h"
 #include "mono_picture_frame.h"
 #include "rgb_xyz.h"
@@ -58,17 +60,14 @@ using namespace dcp;
 
 MonoPictureFrame::MonoPictureFrame (boost::filesystem::path path)
 {
-       auto const size = boost::filesystem::file_size (path);
+       auto const size = filesystem::file_size(path);
        _buffer.reset(new ASDCP::JP2K::FrameBuffer(size));
-       auto f = fopen_boost (path, "rb");
+       File f(path, "rb");
        if (!f) {
                boost::throw_exception (FileError("could not open JPEG2000 file", path, errno));
        }
 
-       size_t n = fread (data(), 1, size, f);
-       fclose (f);
-
-       if (n != size) {
+       if (f.read(data(), 1, size) != size) {
                boost::throw_exception (FileError("could not read from JPEG2000 file", path, errno));
        }
 
@@ -80,13 +79,14 @@ MonoPictureFrame::MonoPictureFrame (boost::filesystem::path path)
  *  @param reader Reader for the asset's MXF file.
  *  @param n Frame within the asset, not taking EntryPoint into account.
  *  @param c Context for decryption, or 0.
+ *  @param check_hmac true to check the HMAC and give an error if it is not as expected.
  */
-MonoPictureFrame::MonoPictureFrame (ASDCP::JP2K::MXFReader* reader, int n, shared_ptr<DecryptionContext> c)
+MonoPictureFrame::MonoPictureFrame (ASDCP::JP2K::MXFReader* reader, int n, shared_ptr<DecryptionContext> c, bool check_hmac)
 {
        /* XXX: unfortunate guesswork on this buffer size */
        _buffer = make_shared<ASDCP::JP2K::FrameBuffer>(4 * Kumu::Megabyte);
 
-       auto const r = reader->ReadFrame (n, *_buffer, c->context(), c->hmac());
+       auto const r = reader->ReadFrame (n, *_buffer, c->context(), check_hmac ? c->hmac() : nullptr);
 
        if (ASDCP_FAILURE(r)) {
                boost::throw_exception (ReadError(String::compose ("could not read video frame %1 (%2)", n, static_cast<int>(r))));