diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-11 22:52:47 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-11 22:52:47 +0100 |
| commit | bc09fbc79580f56c93e35de25230af18b30e0e1e (patch) | |
| tree | 8e640910c78d04b4e234668c7d8c7f1feac60873 /src | |
| parent | 2cd9086c95686117ffbce92188d50d525ed488bb (diff) | |
Access sound asset sampling rate, channels; access sound asset from DCP; fix bad cast to float.
Diffstat (limited to 'src')
| -rw-r--r-- | src/cpl.cc | 8 | ||||
| -rw-r--r-- | src/dcp.cc | 13 | ||||
| -rw-r--r-- | src/dcp.h | 2 | ||||
| -rw-r--r-- | src/sound_asset.cc | 19 | ||||
| -rw-r--r-- | src/sound_asset.h | 6 | ||||
| -rw-r--r-- | src/wscript | 1 |
6 files changed, 47 insertions, 2 deletions
@@ -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"); @@ -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> (); +} @@ -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; 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<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; +} + 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<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); 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 """ |
