45 #include <asdcp/AS_DCP.h>
46 #include <asdcp/KM_fileio.h>
53 using std::shared_ptr;
59 ASDCP::JP2K::MXFSWriter mxf_writer;
63 StereoJ2KPictureAssetWriter::StereoJ2KPictureAssetWriter (
J2KPictureAsset* mxf, boost::filesystem::path file,
bool overwrite)
71 StereoJ2KPictureAssetWriter::~StereoJ2KPictureAssetWriter()
76 _state->mxf_writer.Finalize();
83 StereoJ2KPictureAssetWriter::start (uint8_t
const * data,
int size)
85 dcp::start (
this, _state, _picture_asset, data, size);
86 _picture_asset->set_frame_rate (
Fraction (_picture_asset->edit_rate().numerator * 2, _picture_asset->edit_rate().denominator));
99 if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
100 boost::throw_exception (
MiscError (
"could not parse J2K frame"));
103 _state->frame_buffer.PlaintextOffset(0);
105 uint64_t
const before_offset = _state->mxf_writer.Tell ();
108 auto r = _state->mxf_writer.WriteFrame (
109 _state->frame_buffer,
110 _next_eye == Eye::LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT,
111 _crypto_context->context(),
112 _crypto_context->hmac(),
116 if (ASDCP_FAILURE (r)) {
117 boost::throw_exception (
MXFFileError (
"error in writing video MXF",
_file.string(), r));
120 _next_eye = _next_eye == Eye::LEFT ? Eye::RIGHT : Eye::LEFT;
122 if (_next_eye == Eye::LEFT) {
126 return J2KFrameInfo(before_offset, _state->mxf_writer.Tell() - before_offset, hash);
131 StereoJ2KPictureAssetWriter::fake_write(
J2KFrameInfo const& info)
136 auto r = _state->mxf_writer.FakeWriteFrame(info.size, _next_eye == Eye::LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT);
137 if (ASDCP_FAILURE(r)) {
138 boost::throw_exception (
MXFFileError(
"error in writing video MXF",
_file.string(), r));
141 _next_eye = _next_eye == Eye::LEFT ? Eye::RIGHT : Eye::LEFT;
142 if (_next_eye == Eye::LEFT) {
152 auto r = _state->mxf_writer.Finalize();
153 if (ASDCP_FAILURE(r)) {
154 boost::throw_exception (
MXFFileError(
"error in finalizing video MXF",
_file.string(), r));
boost::filesystem::path _file
A fraction (i.e. a thing with an integer numerator and an integer denominator).
Parent class for classes which write picture assets.
An asset made up of JPEG2000 data.
An exception related to an MXF file.
A miscellaneous exception.
int64_t _intrinsic_duration
A helper class for writing to StereoJ2KPictureAssets.
J2KFrameInfo write(uint8_t const *data, int size) override
Exceptions thrown by libdcp.
Common parts of J2KPictureAssetWriter.
Namespace for everything in libdcp.
StereoJ2KPictureAssetWriter class.