Access sound asset sampling rate, channels; access sound asset from DCP; fix bad...
authorCarl Hetherington <cth@carlh.net>
Sat, 11 Aug 2012 21:52:47 +0000 (22:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 11 Aug 2012 21:52:47 +0000 (22:52 +0100)
run-tests.sh
src/cpl.cc
src/dcp.cc
src/dcp.h
src/sound_asset.cc
src/sound_asset.h
src/wscript

index f9ef16f988a15d02e983512ea6e6bf2d97c743b5..8873a3e96bc1189fee5d39008902c74883dfaa06 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 #
 # Runs our test suite, which builds a DCP.
@@ -7,7 +7,12 @@
 # if anything is different.
 #
 
-LD_LIBRARY_PATH=build/src:build/asdcplib/src build/test/tests
+if [ "$1" == "--debug" ]; then
+  shift
+  LD_LIBRARY_PATH=build/src:build/asdcplib/src gdb --args build/test/tests
+else
+  LD_LIBRARY_PATH=build/src:build/asdcplib/src build/test/tests
+fi
 diff -ur test/ref/DCP build/test/foo
 if [ "$?" != "0" ]; then
   echo "FAIL: files differ"
index a95218d6a939d560b6ec719e931cead59517f702..9dfe446d9b0dcc675b30e45467d71c62f869f291 100644 (file)
@@ -65,8 +65,12 @@ MainPicture::MainPicture (xmlpp::Node const * node)
        } catch (XMLError& e) {
                /* Maybe it's not a fraction */
        }
-       float f = float_node ("ScreenAspectRatio");
-       screen_aspect_ratio = Fraction (f * 1000, 1000);
+       try {
+               float f = float_node ("ScreenAspectRatio");
+               screen_aspect_ratio = Fraction (f * 1000, 1000);
+       } catch (bad_cast& e) {
+
+       }
 
        ignore_node ("Hash");
 
index 99cc517a7c8c274c0a79301b3595b94b5a05f0e7..fa94c44d3d823aa05dd5777d706669f0fbd038fb 100644 (file)
@@ -418,3 +418,16 @@ DCP::picture_asset () const
 
        return shared_ptr<const PictureAsset> ();
 }
+
+shared_ptr<const SoundAsset>
+DCP::sound_asset () const
+{
+       for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
+               shared_ptr<SoundAsset> s = dynamic_pointer_cast<SoundAsset> (*i);
+               if (s) {
+                       return s;
+               }
+       }
+
+       return shared_ptr<const SoundAsset> ();
+}
index 924a9f4f5ea7444536487749ecb6138ed9906a47..3817913cb6dcf40b066f2c5284b34e6597134037 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -40,6 +40,7 @@ namespace libdcp
 
 class Asset;   
 class PictureAsset;
+class SoundAsset;
 
 /** @class DCP dcp.h libdcp/dcp.h
  *  @brief A class to create or read a DCP.
@@ -108,6 +109,7 @@ public:
        }
 
        boost::shared_ptr<const PictureAsset> picture_asset () const;
+       boost::shared_ptr<const SoundAsset> sound_asset () const;
 
        std::list<std::string> equals (DCP const & other, EqualityOptions options) const;
 
index d8ea94d14bb5864110dd8efe3537effd27c5abb9..a8b6372748c83069221fc95790bc5b8b36f6215e 100644 (file)
@@ -245,3 +245,22 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
 
        return notes;
 }
+
+
+int
+SoundAsset::sampling_rate () const
+{
+       ASDCP::PCM::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::PCM::AudioDescriptor desc;
+       if (ASDCP_FAILURE (reader.FillAudioDescriptor (desc))) {
+               throw DCPReadError ("could not read audio MXF information");
+       }
+
+       return desc.AudioSamplingRate.Numerator / desc.AudioSamplingRate.Denominator;
+}
+
index e9faeb8bb6d26c68f4fdcda46f2d6662a3f0c2ae..f686e4bd6fbbd5c67c1402665eaa3401f8d83122 100644 (file)
@@ -85,6 +85,12 @@ public:
        void write_to_cpl (std::ostream& s) const;
 
        std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const;
+
+       int channels () const {
+               return _channels;
+       }
+
+       int sampling_rate () const;
        
 private:
        void construct (sigc::slot<std::string, Channel> get_path);
index 361a93443b890cfaf4cbd51fe8cdd2ef8984aacd..f96755c7a2c22561344ddf3c08575b056f057610 100644 (file)
@@ -30,6 +30,7 @@ def build(bld):
               test_mode.h
               version.h
               picture_asset.h
+              sound_asset.h
               asset.h
               picture_frame.h
               """