From bc09fbc79580f56c93e35de25230af18b30e0e1e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 11 Aug 2012 22:52:47 +0100 Subject: [PATCH] Access sound asset sampling rate, channels; access sound asset from DCP; fix bad cast to float. --- run-tests.sh | 9 +++++++-- src/cpl.cc | 8 ++++++-- src/dcp.cc | 13 +++++++++++++ src/dcp.h | 2 ++ src/sound_asset.cc | 19 +++++++++++++++++++ src/sound_asset.h | 6 ++++++ src/wscript | 1 + 7 files changed, 54 insertions(+), 4 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index f9ef16f9..8873a3e9 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -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" diff --git a/src/cpl.cc b/src/cpl.cc index a95218d6..9dfe446d 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -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"); diff --git a/src/dcp.cc b/src/dcp.cc index 99cc517a..fa94c44d 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -418,3 +418,16 @@ DCP::picture_asset () const return shared_ptr (); } + +shared_ptr +DCP::sound_asset () const +{ + for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { + shared_ptr s = dynamic_pointer_cast (*i); + if (s) { + return s; + } + } + + return shared_ptr (); +} diff --git a/src/dcp.h b/src/dcp.h index 924a9f4f..3817913c 100644 --- 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 picture_asset () const; + boost::shared_ptr sound_asset () const; std::list equals (DCP const & other, EqualityOptions options) const; diff --git a/src/sound_asset.cc b/src/sound_asset.cc index d8ea94d1..a8b63727 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -245,3 +245,22 @@ SoundAsset::equals (shared_ptr 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; +} + diff --git a/src/sound_asset.h b/src/sound_asset.h index e9faeb8b..f686e4bd 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -85,6 +85,12 @@ public: void write_to_cpl (std::ostream& s) const; std::list equals (boost::shared_ptr other, EqualityOptions opt) const; + + int channels () const { + return _channels; + } + + int sampling_rate () const; private: void construct (sigc::slot get_path); diff --git a/src/wscript b/src/wscript index 361a9344..f96755c7 100644 --- a/src/wscript +++ b/src/wscript @@ -30,6 +30,7 @@ def build(bld): test_mode.h version.h picture_asset.h + sound_asset.h asset.h picture_frame.h """ -- 2.30.2