diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-08-12 20:52:15 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-08-12 20:52:15 +0100 |
| commit | 916247147468aee47354ebb3088f47b8a56fcccf (patch) | |
| tree | 90fb72f6312a8935bf61ec5affaf82f7bb8b88f6 | |
| parent | bc09fbc79580f56c93e35de25230af18b30e0e1e (diff) | |
Don't crash with no audio; get video MXF information from the MXF itself; get sampling rate from audio MXF.for-dcptovideo
| -rw-r--r-- | src/dcp.cc | 15 | ||||
| -rw-r--r-- | src/picture_asset.cc | 16 | ||||
| -rw-r--r-- | src/picture_asset.h | 2 | ||||
| -rw-r--r-- | src/sound_asset.cc | 34 | ||||
| -rw-r--r-- | src/sound_asset.h | 9 | ||||
| -rw-r--r-- | src/sound_frame.cc | 58 | ||||
| -rw-r--r-- | src/sound_frame.h | 44 | ||||
| -rw-r--r-- | src/wscript | 2 |
8 files changed, 151 insertions, 29 deletions
@@ -346,18 +346,17 @@ DCP::DCP (string directory) _directory, n, _fps, - _length, - cpl_assets->main_picture->screen_aspect_ratio.numerator, - cpl_assets->main_picture->screen_aspect_ratio.denominator + _length ) )); - n = cpl_assets->main_sound->annotation_text; - if (n.empty ()) { - n = pkl->asset_from_id(cpl_assets->main_sound->id)->original_file_name; - } - if (cpl_assets->main_sound) { + + n = cpl_assets->main_sound->annotation_text; + if (n.empty ()) { + n = pkl->asset_from_id(cpl_assets->main_sound->id)->original_file_name; + } + _assets.push_back (shared_ptr<SoundAsset> ( new SoundAsset ( _directory, diff --git a/src/picture_asset.cc b/src/picture_asset.cc index 84c187df..7b6dd293 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -72,11 +72,21 @@ PictureAsset::PictureAsset ( construct (sigc::bind (sigc::mem_fun (*this, &PictureAsset::path_from_list), files)); } -PictureAsset::PictureAsset (string directory, string mxf_name, int fps, int length, int width, int height) +PictureAsset::PictureAsset (string directory, string mxf_name, int fps, int length) : Asset (directory, mxf_name, 0, fps, length) - , _width (width) - , _height (height) { + 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; } diff --git a/src/picture_asset.h b/src/picture_asset.h index 18170f46..c0e5f649 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -77,7 +77,7 @@ public: int height ); - PictureAsset (std::string directory, std::string mxf_name, int fps, int length, int width, int height); + PictureAsset (std::string directory, std::string mxf_name, int fps, int length); /** Write details of this asset to a CPL stream. * @param s Stream. diff --git a/src/sound_asset.cc b/src/sound_asset.cc index a8b63727..189343bd 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -30,6 +30,7 @@ #include "sound_asset.h" #include "util.h" #include "exceptions.h" +#include "sound_frame.h" using namespace std; using namespace boost; @@ -40,6 +41,7 @@ SoundAsset::SoundAsset ( ) : Asset (directory, mxf_name, progress, fps, length) , _channels (files.size ()) + , _sampling_rate (0) { construct (sigc::bind (sigc::mem_fun (*this, &SoundAsset::path_from_channel), files)); } @@ -49,6 +51,7 @@ SoundAsset::SoundAsset ( ) : Asset (directory, mxf_name, progress, fps, length) , _channels (channels) + , _sampling_rate (0) { construct (get_path); } @@ -57,7 +60,19 @@ SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int length) : Asset (directory, mxf_name, 0, fps, length) , _channels (0) { + 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"); + } + _sampling_rate = desc.AudioSamplingRate.Numerator / desc.AudioSamplingRate.Denominator; + _channels = desc.ChannelCount; } string @@ -246,21 +261,8 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const return notes; } - -int -SoundAsset::sampling_rate () const +shared_ptr<const SoundFrame> +SoundAsset::get_frame (int n) 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; + return shared_ptr<const SoundFrame> (new SoundFrame (mxf_path().string(), n)); } - diff --git a/src/sound_asset.h b/src/sound_asset.h index f686e4bd..a0dd0a6e 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -30,6 +30,8 @@ namespace libdcp { +class SoundFrame; + /** @brief An asset made up of WAV files */ class SoundAsset : public Asset { @@ -86,11 +88,15 @@ public: std::list<std::string> equals (boost::shared_ptr<const Asset> other, EqualityOptions opt) const; + boost::shared_ptr<const SoundFrame> get_frame (int n) const; + int channels () const { return _channels; } - int sampling_rate () const; + int sampling_rate () const { + return _sampling_rate; + } private: void construct (sigc::slot<std::string, Channel> get_path); @@ -98,6 +104,7 @@ private: /** Number of channels in the asset */ int _channels; + int _sampling_rate; }; } diff --git a/src/sound_frame.cc b/src/sound_frame.cc new file mode 100644 index 00000000..ed626f5e --- /dev/null +++ b/src/sound_frame.cc @@ -0,0 +1,58 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "AS_DCP.h" +#include "KM_fileio.h" +#include "sound_frame.h" +#include "exceptions.h" + +using namespace std; +using namespace libdcp; + +SoundFrame::SoundFrame (string mxf_path, int n) +{ + ASDCP::PCM::MXFReader reader; + if (ASDCP_FAILURE (reader.OpenRead (mxf_path.c_str()))) { + throw FileError ("could not open MXF file for reading", mxf_path); + } + + /* XXX: unfortunate guesswork on this buffer size */ + _buffer = new ASDCP::PCM::FrameBuffer (1 * Kumu::Megabyte); + + if (ASDCP_FAILURE (reader.ReadFrame (n, *_buffer))) { + throw DCPReadError ("could not read audio frame"); + } +} + +SoundFrame::~SoundFrame () +{ + delete _buffer; +} + +uint8_t const * +SoundFrame::data () const +{ + return _buffer->RoData(); +} + +int +SoundFrame::size () const +{ + return _buffer->Size (); +} diff --git a/src/sound_frame.h b/src/sound_frame.h new file mode 100644 index 00000000..83846fc8 --- /dev/null +++ b/src/sound_frame.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <string> +#include <stdint.h> + +namespace ASDCP { + namespace PCM { + class FrameBuffer; + } +} + +namespace libdcp { + +class SoundFrame +{ +public: + SoundFrame (std::string mxf_path, int n); + ~SoundFrame (); + + uint8_t const * data () const; + int size () const; + +private: + ASDCP::PCM::FrameBuffer* _buffer; +}; + +} diff --git a/src/wscript b/src/wscript index f96755c7..0a0c3e66 100644 --- a/src/wscript +++ b/src/wscript @@ -20,6 +20,7 @@ def build(bld): test_mode.cc types.cc xml.cc + sound_frame.cc """ headers = """ @@ -33,6 +34,7 @@ def build(bld): sound_asset.h asset.h picture_frame.h + sound_frame.h """ bld.install_files('${PREFIX}/include/libdcp', headers) |
