using namespace boost;
using namespace libdcp;
-PictureAsset::PictureAsset (
- sigc::slot<string, int> get_path,
- string directory,
- string mxf_name,
- sigc::signal1<void, float>* progress,
- int fps,
- int length,
- int width,
- int height)
- : Asset (directory, mxf_name, progress, fps, length)
- , _width (width)
- , _height (height)
-{
- construct (get_path);
-}
-
-PictureAsset::PictureAsset (
- vector<string> const & files,
- string directory,
- string mxf_name,
- sigc::signal1<void, float>* progress,
- int fps,
- int length,
- int width,
- int height)
- : Asset (directory, mxf_name, progress, fps, length)
- , _width (width)
- , _height (height)
-{
- construct (sigc::bind (sigc::mem_fun (*this, &PictureAsset::path_from_list), files));
-}
-
-PictureAsset::PictureAsset (string directory, string mxf_name, int fps, int length)
- : Asset (directory, mxf_name, 0, fps, length)
-{
- ASDCP::JP2K::MXFReader reader;
- if (ASDCP_FAILURE (reader.OpenRead (mxf_path().string().c_str()))) {
- throw FileError ("could not open MXF file for reading", mxf_path().string());
- }
-
- ASDCP::JP2K::PictureDescriptor desc;
- if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
- throw DCPReadError ("could not read video MXF information");
- }
-
- _width = desc.StoredWidth;
- _height = desc.StoredHeight;
-
-}
-
-string
-PictureAsset::path_from_list (int f, vector<string> const & files) const
-{
- return files[f];
-}
-
-void
-PictureAsset::construct (sigc::slot<string, int> get_path)
+PictureAsset::PictureAsset (string directory, string mxf_name, sigc::signal1<void, float>* progress, int fps, int entry_point, int length)
+ : MXFAsset (directory, mxf_name, progress, fps, entry_point, length)
+ , _width (0)
+ , _height (0)
{
- ASDCP::JP2K::CodestreamParser j2k_parser;
- ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
- if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) {
- throw FileError ("could not open JPEG2000 file for reading", get_path (0));
- }
-
- ASDCP::JP2K::PictureDescriptor picture_desc;
- j2k_parser.FillPictureDescriptor (picture_desc);
- picture_desc.EditRate = ASDCP::Rational (_fps, 1);
-
- ASDCP::WriterInfo writer_info;
- fill_writer_info (&writer_info);
-
- ASDCP::JP2K::MXFWriter mxf_writer;
- if (ASDCP_FAILURE (mxf_writer.OpenWrite (mxf_path().string().c_str(), writer_info, picture_desc))) {
- throw FileError ("could not open MXF file for writing", mxf_path().string());
- }
-
- for (int i = 0; i < _length; ++i) {
-
- string const path = get_path (i);
-
- if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) {
- throw FileError ("could not open JPEG2000 file for reading", path);
- }
- /* XXX: passing 0 to WriteFrame ok? */
- if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
- throw MiscError ("error in writing video MXF");
- }
-
- (*_progress) (0.5 * float (i) / _length);
- }
-
- if (ASDCP_FAILURE (mxf_writer.Finalize())) {
- throw MiscError ("error in finalising video MXF");
- }
}
void
{
s << " <MainPicture>\n"
<< " <Id>urn:uuid:" << _uuid << "</Id>\n"
- << " <AnnotationText>" << _mxf_name << "</AnnotationText>\n"
+ << " <AnnotationText>" << _file_name << "</AnnotationText>\n"
<< " <EditRate>" << _fps << " 1</EditRate>\n"
<< " <IntrinsicDuration>" << _length << "</IntrinsicDuration>\n"
<< " <EntryPoint>0</EntryPoint>\n"
list<string>
PictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
{
- list<string> notes = Asset::equals (other, opt);
+ list<string> notes = MXFAsset::equals (other, opt);
if (opt.flags & MXF_INSPECT) {
ASDCP::JP2K::MXFReader reader_A;
- if (ASDCP_FAILURE (reader_A.OpenRead (mxf_path().string().c_str()))) {
- throw FileError ("could not open MXF file for reading", mxf_path().string());
+ if (ASDCP_FAILURE (reader_A.OpenRead (path().string().c_str()))) {
+ throw FileError ("could not open MXF file for reading", path().string());
}
ASDCP::JP2K::MXFReader reader_B;
- if (ASDCP_FAILURE (reader_B.OpenRead (other->mxf_path().string().c_str()))) {
- throw FileError ("could not open MXF file for reading", mxf_path().string());
+ if (ASDCP_FAILURE (reader_B.OpenRead (other->path().string().c_str()))) {
+ throw FileError ("could not open MXF file for reading", path().string());
}
ASDCP::JP2K::PictureDescriptor desc_A;
return notes;
}
-opj_image_t *
-PictureAsset::decompress_j2k (uint8_t* data, int64_t size) const
+MonoPictureAsset::MonoPictureAsset (
+ sigc::slot<string, int> get_path,
+ string directory,
+ string mxf_name,
+ sigc::signal1<void, float>* progress,
+ int fps,
+ int length,
+ int width,
+ int height)
+ : PictureAsset (directory, mxf_name, progress, fps, 0, length)
{
- opj_dinfo_t* decoder = opj_create_decompress (CODEC_J2K);
- opj_dparameters_t parameters;
- opj_set_default_decoder_parameters (¶meters);
- opj_setup_decoder (decoder, ¶meters);
- opj_cio_t* cio = opj_cio_open ((opj_common_ptr) decoder, data, size);
- opj_image_t* image = opj_decode (decoder, cio);
- if (!image) {
- opj_destroy_decompress (decoder);
- opj_cio_close (cio);
- throw DCPReadError ("could not decode JPEG2000 codestream");
+ _width = width;
+ _height = height;
+ construct (get_path);
+}
+
+MonoPictureAsset::MonoPictureAsset (
+ vector<string> const & files,
+ string directory,
+ string mxf_name,
+ sigc::signal1<void, float>* progress,
+ int fps,
+ int length,
+ int width,
+ int height)
+ : PictureAsset (directory, mxf_name, progress, fps, 0, length)
+{
+ _width = width;
+ _height = height;
+ construct (sigc::bind (sigc::mem_fun (*this, &MonoPictureAsset::path_from_list), files));
+}
+
+MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name, int fps, int entry_point, int length)
+ : PictureAsset (directory, mxf_name, 0, fps, entry_point, length)
+{
+ ASDCP::JP2K::MXFReader reader;
+ if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
+ throw FileError ("could not open MXF file for reading", path().string());
+ }
+
+ ASDCP::JP2K::PictureDescriptor desc;
+ if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
+ throw DCPReadError ("could not read video MXF information");
}
- opj_cio_close (cio);
- return image;
+ _width = desc.StoredWidth;
+ _height = desc.StoredHeight;
+}
+
+void
+MonoPictureAsset::construct (sigc::slot<string, int> get_path)
+{
+ ASDCP::JP2K::CodestreamParser j2k_parser;
+ ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte);
+ if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (get_path(0).c_str(), frame_buffer))) {
+ throw FileError ("could not open JPEG2000 file for reading", get_path (0));
+ }
+
+ ASDCP::JP2K::PictureDescriptor picture_desc;
+ j2k_parser.FillPictureDescriptor (picture_desc);
+ picture_desc.EditRate = ASDCP::Rational (_fps, 1);
+
+ ASDCP::WriterInfo writer_info;
+ fill_writer_info (&writer_info);
+
+ ASDCP::JP2K::MXFWriter mxf_writer;
+ if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc))) {
+ throw FileError ("could not open MXF file for writing", path().string());
+ }
+
+ for (int i = 0; i < _length; ++i) {
+
+ string const path = get_path (i);
+
+ if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) {
+ throw FileError ("could not open JPEG2000 file for reading", path);
+ }
+
+ /* XXX: passing 0 to WriteFrame ok? */
+ if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
+ throw MiscError ("error in writing video MXF");
+ }
+
+ (*_progress) (0.5 * float (i) / _length);
+ }
+
+ if (ASDCP_FAILURE (mxf_writer.Finalize())) {
+ throw MiscError ("error in finalising video MXF");
+ }
+}
+
+string
+MonoPictureAsset::path_from_list (int f, vector<string> const & files) const
+{
+ return files[f];
+}
+
+shared_ptr<const MonoPictureFrame>
+MonoPictureAsset::get_frame (int n) const
+{
+ return shared_ptr<const MonoPictureFrame> (new MonoPictureFrame (path().string(), n + _entry_point));
+}
+
+StereoPictureAsset::StereoPictureAsset (string directory, string mxf_name, int fps, int entry_point, int length)
+ : PictureAsset (directory, mxf_name, 0, fps, entry_point, length)
+{
+ ASDCP::JP2K::MXFSReader reader;
+ if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
+ throw FileError ("could not open MXF file for reading", path().string());
+ }
+
+ ASDCP::JP2K::PictureDescriptor desc;
+ if (ASDCP_FAILURE (reader.FillPictureDescriptor (desc))) {
+ throw DCPReadError ("could not read video MXF information");
+ }
+
+ _width = desc.StoredWidth;
+ _height = desc.StoredHeight;
}
-shared_ptr<const PictureFrame>
-PictureAsset::get_frame (int n) const
+shared_ptr<const StereoPictureFrame>
+StereoPictureAsset::get_frame (int n) const
{
- return shared_ptr<const PictureFrame> (new PictureFrame (mxf_path().string(), n));
+ return shared_ptr<const StereoPictureFrame> (new StereoPictureFrame (path().string(), n + _entry_point));
}