2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/mono_picture_mxf_writer.cc
21 * @brief MonoPictureMXFWriter class
25 #include "KM_fileio.h"
26 #include "mono_picture_mxf_writer.h"
27 #include "exceptions.h"
28 #include "picture_mxf.h"
30 #include "picture_mxf_writer_common.cc"
35 using boost::shared_ptr;
38 struct MonoPictureMXFWriter::ASDCPState : public ASDCPStateBase
40 ASDCP::JP2K::MXFWriter mxf_writer;
43 /** @param a Asset to write to. `a' must not be deleted while
44 * this writer class still exists, or bad things will happen.
46 MonoPictureMXFWriter::MonoPictureMXFWriter (PictureMXF* asset, boost::filesystem::path file, Standard standard, bool overwrite)
47 : PictureMXFWriter (asset, file, standard, overwrite)
48 , _state (new MonoPictureMXFWriter::ASDCPState)
50 _state->encryption_context = asset->encryption_context ();
54 MonoPictureMXFWriter::start (uint8_t* data, int size)
56 dcp::start (this, _state, _standard, _picture_mxf, data, size);
57 _picture_mxf->set_frame_rate (_picture_mxf->edit_rate());
61 MonoPictureMXFWriter::write (uint8_t* data, int size)
69 if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
70 boost::throw_exception (MiscError ("could not parse J2K frame"));
73 uint64_t const before_offset = _state->mxf_writer.Tell ();
76 ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _state->encryption_context, 0, &hash);
77 if (ASDCP_FAILURE (r)) {
78 boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r));
82 return FrameInfo (before_offset, _state->mxf_writer.Tell() - before_offset, hash);
86 MonoPictureMXFWriter::fake_write (int size)
91 Kumu::Result_t r = _state->mxf_writer.FakeWriteFrame (size);
92 if (ASDCP_FAILURE (r)) {
93 boost::throw_exception (MXFFileError ("error in writing video MXF", _mxf->file().string(), r));
100 MonoPictureMXFWriter::finalize ()
102 Kumu::Result_t r = _state->mxf_writer.Finalize();
103 if (ASDCP_FAILURE (r)) {
104 boost::throw_exception (MXFFileError ("error in finalizing video MXF", _mxf->file().string(), r));
107 PictureMXFWriter::finalize ();