Tweaks to dcpinfo.
authorCarl Hetherington <cth@carlh.net>
Fri, 7 Sep 2012 16:28:30 +0000 (17:28 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 7 Sep 2012 16:28:30 +0000 (17:28 +0100)
src/dcp.cc
src/exceptions.h
src/picture_asset.cc
src/sound_asset.cc
tools/dcpinfo.cc

index f2f2971af5ea4b8af0f5fdc3d61d3a1090590a97..d9604bef9e09608132e85fa810cfc3e336151a0b 100644 (file)
@@ -214,7 +214,7 @@ DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_l
 }
 
 
-DCP::DCP (string directory, bool read_mxfs)
+DCP::DCP (string directory, bool require_mxfs)
        : _directory (directory)
 {
        Files files;
@@ -329,56 +329,74 @@ DCP::DCP (string directory, bool read_mxfs)
                shared_ptr<PictureAsset> picture;
                shared_ptr<SoundAsset> sound;
                shared_ptr<SubtitleAsset> subtitle;
-               
-               if (read_mxfs && (*i)->asset_list->main_picture) {
+
+               if ((*i)->asset_list->main_picture) {
 
                        string n = pkl->asset_from_id (p->id)->original_file_name;
                        if (n.empty ()) {
                                n = p->annotation_text;
                        }
-               
-                       picture.reset (new MonoPictureAsset (
-                                              _directory,
-                                              n,
-                                              _fps,
-                                              (*i)->asset_list->main_picture->entry_point,
-                                              (*i)->asset_list->main_picture->duration
-                                              )
-                               );
+
+                       try {
+                               picture.reset (new MonoPictureAsset (
+                                                      _directory,
+                                                      n,
+                                                      _fps,
+                                                      (*i)->asset_list->main_picture->entry_point,
+                                                      (*i)->asset_list->main_picture->duration
+                                                      )
+                                       );
+                       } catch (MXFFileError) {
+                               if (require_mxfs) {
+                                       throw;
+                               }
+                       }
                        
-               } else if (read_mxfs && (*i)->asset_list->main_stereoscopic_picture) {
+               } else if ((*i)->asset_list->main_stereoscopic_picture) {
                        
                        string n = pkl->asset_from_id (p->id)->original_file_name;
                        if (n.empty ()) {
                                n = p->annotation_text;
                        }
                        
-                       picture.reset (new StereoPictureAsset (
-                                              _directory,
-                                              n,
-                                              _fps,
-                                              (*i)->asset_list->main_stereoscopic_picture->entry_point,
-                                              (*i)->asset_list->main_stereoscopic_picture->duration
-                                              )
-                               );
+                       try {
+                               picture.reset (new StereoPictureAsset (
+                                                      _directory,
+                                                      n,
+                                                      _fps,
+                                                      (*i)->asset_list->main_stereoscopic_picture->entry_point,
+                                                      (*i)->asset_list->main_stereoscopic_picture->duration
+                                                      )
+                                       );
+                       } catch (MXFFileError) {
+                               if (require_mxfs) {
+                                       throw;
+                               }
+                       }
                        
                }
                
-               if (read_mxfs && (*i)->asset_list->main_sound) {
+               if ((*i)->asset_list->main_sound) {
                        
                        string n = pkl->asset_from_id ((*i)->asset_list->main_sound->id)->original_file_name;
                        if (n.empty ()) {
                                n = (*i)->asset_list->main_sound->annotation_text;
                        }
                        
-                       sound.reset (new SoundAsset (
-                                            _directory,
-                                            n,
-                                            _fps,
-                                            (*i)->asset_list->main_sound->entry_point,
-                                            (*i)->asset_list->main_sound->duration
-                                            )
-                               );
+                       try {
+                               sound.reset (new SoundAsset (
+                                                    _directory,
+                                                    n,
+                                                    _fps,
+                                                    (*i)->asset_list->main_sound->entry_point,
+                                                    (*i)->asset_list->main_sound->duration
+                                                    )
+                                       );
+                       } catch (MXFFileError) {
+                               if (require_mxfs) {
+                                       throw;
+                               }
+                       }
                }
 
                if ((*i)->asset_list->main_subtitle) {
index cd3c5cdb9b79a92e9fa8f13e7849e238ffeb74fe..25e51c9e2d17dcd91eefb0c2846220a24509e6ce 100644 (file)
@@ -55,7 +55,14 @@ private:
        std::string _filename;
 };
 
-
+class MXFFileError : public FileError
+{
+public:
+       MXFFileError (std::string const & message, std::string const & filename)
+               : FileError (message, filename)
+       {}
+};
+       
 /** @brief A miscellaneous exception */
 class MiscError : public std::exception
 {
index 4c66bd021f89d38106971c5df2b0ed5efbc3335c..142bc8fc6ab053efa14372b1bcb1f110fe48295f 100644 (file)
@@ -72,12 +72,12 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
        if (opt.flags & MXF_INSPECT) {
                ASDCP::JP2K::MXFReader reader_A;
                if (ASDCP_FAILURE (reader_A.OpenRead (path().string().c_str()))) {
-                       throw FileError ("could not open MXF file for reading", path().string());
+                       throw MXFFileError ("could not open MXF file for reading", path().string());
                }
 
                ASDCP::JP2K::MXFReader reader_B;
                if (ASDCP_FAILURE (reader_B.OpenRead (other->path().string().c_str()))) {
-                       throw FileError ("could not open MXF file for reading", path().string());
+                       throw MXFFileError ("could not open MXF file for reading", path().string());
                }
 
                ASDCP::JP2K::PictureDescriptor desc_A;
@@ -244,7 +244,7 @@ MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name, int fps,
 {
        ASDCP::JP2K::MXFReader reader;
        if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
-               throw FileError ("could not open MXF file for reading", path().string());
+               throw MXFFileError ("could not open MXF file for reading", path().string());
        }
        
        ASDCP::JP2K::PictureDescriptor desc;
@@ -274,7 +274,7 @@ MonoPictureAsset::construct (sigc::slot<string, int> get_path)
        
        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());
+               throw MXFFileError ("could not open MXF file for writing", path().string());
        }
 
        for (int i = 0; i < _length; ++i) {
@@ -317,7 +317,7 @@ StereoPictureAsset::StereoPictureAsset (string directory, string mxf_name, int f
 {
        ASDCP::JP2K::MXFSReader reader;
        if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
-               throw FileError ("could not open MXF file for reading", path().string());
+               throw MXFFileError ("could not open MXF file for reading", path().string());
        }
        
        ASDCP::JP2K::PictureDescriptor desc;
index 732bb61029f8282492972b4c6575ab74e31ba83c..a41e5b67f05bd0218497dc4abf38494a4cb22271 100644 (file)
@@ -62,7 +62,7 @@ SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int entry_po
 {
        ASDCP::PCM::MXFReader reader;
        if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
-               throw FileError ("could not open MXF file for reading", path().string());
+               throw MXFFileError ("could not open MXF file for reading", path().string());
        }
 
        
@@ -202,13 +202,13 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
                ASDCP::PCM::MXFReader reader_A;
                if (ASDCP_FAILURE (reader_A.OpenRead (path().string().c_str()))) {
                        cout << "failed " << path() << "\n";
-                       throw FileError ("could not open MXF file for reading", path().string());
+                       throw MXFFileError ("could not open MXF file for reading", path().string());
                }
 
                ASDCP::PCM::MXFReader reader_B;
                if (ASDCP_FAILURE (reader_B.OpenRead (other->path().string().c_str()))) {
                        cout << "failed " << other->path() << "\n";
-                       throw FileError ("could not open MXF file for reading", path().string());
+                       throw MXFFileError ("could not open MXF file for reading", path().string());
                }
 
                ASDCP::PCM::AudioDescriptor desc_A;
index 66813d9570236660174776c9bd34ce0b1b990fa3..ba1fed0a66980f9bef0e47008c6747c4ff19b532 100644 (file)
@@ -5,6 +5,9 @@
 #include "dcp.h"
 #include "exceptions.h"
 #include "reel.h"
+#include "sound_asset.h"
+#include "picture_asset.h"
+#include "subtitle_asset.h"
 
 using namespace std;
 using namespace boost;
@@ -53,8 +56,6 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
-       list<string> missing_mxfs;
-
        DCP* dcp = 0;
        try {
                dcp = new DCP (argv[optind], false);
@@ -67,30 +68,20 @@ main (int argc, char* argv[])
             << "\tLength: " << dcp->length() << "\n"
             << "\tFrames per second: " << dcp->frames_per_second() << "\n";
 
-       if (!missing_mxfs.empty ()) {
-               cout << "\tmissing MXFs: ";
-               for (list<string>::const_iterator i = missing_mxfs.begin(); i != missing_mxfs.end(); ++i) {
-                       cout << *i << " " ;
-               }
-               cout << "\n";
-       }
-
        list<shared_ptr<const Reel> > reels = dcp->reels ();
 
        int R = 1;
        for (list<shared_ptr<const Reel> >::const_iterator i = reels.begin(); i != reels.end(); ++i) {
                cout << "Reel " << R << "\n";
-               cout << "\tContains: ";
                if ((*i)->main_picture()) {
-                       cout << "picture ";
+                       cout << "\tPicture:  " << (*i)->main_picture()->width() << "x" << (*i)->main_picture()->height() << "\n";
                }
                if ((*i)->main_sound()) {
-                       cout << "sound ";
+                       cout << "\tSound:    " << (*i)->main_sound()->channels() << " channels at " << (*i)->main_sound()->sampling_rate() << "Hz\n";
                }
                if ((*i)->main_subtitle()) {
-                       cout << "subtitle ";
+                       cout << "\tSubtitle: " << (*i)->main_subtitle()->subtitles().size() << " subtitles in " << (*i)->main_subtitle()->language() << "\n";
                }
-               cout << "\n";
                ++R;
        }