Try to remove need for asdcplib includes in libdcp headers.
authorCarl Hetherington <cth@carlh.net>
Mon, 21 Jan 2013 21:01:59 +0000 (21:01 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Jan 2013 21:01:59 +0000 (21:01 +0000)
src/picture_asset.cc
src/picture_asset.h
src/sound_asset.cc
src/sound_asset.h

index a2f6b584a154d97496be7e9f4ccf9c613c2feeb8..564ada796ee927ea2f7bafa277f78d8799c3db35 100644 (file)
@@ -400,11 +400,25 @@ MonoPictureAsset::start_write ()
        return shared_ptr<MonoPictureAssetWriter> (new MonoPictureAssetWriter (this));
 }
 
+struct MonoPictureAssetWriter::ASDCPState
+{
+       ASDCPState()
+               : frame_buffer (4 * Kumu::Megabyte)
+       {}
+       
+       ASDCP::JP2K::CodestreamParser j2k_parser;
+       ASDCP::JP2K::FrameBuffer frame_buffer;
+       ASDCP::JP2K::MXFWriter mxf_writer;
+       ASDCP::WriterInfo writer_info;
+       ASDCP::JP2K::PictureDescriptor picture_descriptor;
+};
+
+
 /** @param a Asset to write to.  `a' must not be deleted while
  *  this writer class still exists, or bad things will happen.
  */
 MonoPictureAssetWriter::MonoPictureAssetWriter (MonoPictureAsset* a)
-       : _frame_buffer (4 * Kumu::Megabyte)
+       : _state (new MonoPictureAssetWriter::ASDCPState)
        , _asset (a)
        , _frames_written (0)
        , _finalized (false)
@@ -417,24 +431,24 @@ MonoPictureAssetWriter::write (uint8_t* data, int size)
 {
        assert (!_finalized);
        
-       if (ASDCP_FAILURE (_j2k_parser.OpenReadFrame (data, size, _frame_buffer))) {
+       if (ASDCP_FAILURE (_state->j2k_parser.OpenReadFrame (data, size, _state->frame_buffer))) {
                throw MiscError ("could not parse J2K frame");
        }
 
        if (_frames_written == 0) {
                /* This is our first frame; set up the writer */
                
-               _j2k_parser.FillPictureDescriptor (_picture_descriptor);
-               _picture_descriptor.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
+               _state->j2k_parser.FillPictureDescriptor (_state->picture_descriptor);
+               _state->picture_descriptor.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
        
-               MXFAsset::fill_writer_info (&_writer_info, _asset->uuid());
+               MXFAsset::fill_writer_info (&_state->writer_info, _asset->uuid());
                
-               if (ASDCP_FAILURE (_mxf_writer.OpenWrite (_asset->path().c_str(), _writer_info, _picture_descriptor))) {
+               if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().c_str(), _state->writer_info, _state->picture_descriptor))) {
                        throw MXFFileError ("could not open MXF file for writing", _asset->path().string());
                }
        }
 
-       if (ASDCP_FAILURE (_mxf_writer.WriteFrame (_frame_buffer, 0, 0))) {
+       if (ASDCP_FAILURE (_state->mxf_writer.WriteFrame (_state->frame_buffer, 0, 0))) {
                throw MiscError ("error in writing video MXF");
        }
 
@@ -444,7 +458,7 @@ MonoPictureAssetWriter::write (uint8_t* data, int size)
 void
 MonoPictureAssetWriter::finalize ()
 {
-       if (ASDCP_FAILURE (_mxf_writer.Finalize())) {
+       if (ASDCP_FAILURE (_state->mxf_writer.Finalize())) {
                throw MiscError ("error in finalizing video MXF");
        }
 
index ea558e7d0c77781191000e56fa848d8d334e69ac..71900200ac52b15ccc6b8867ec1fad1438cfbd95 100644 (file)
@@ -22,7 +22,6 @@
  */
 
 #include <openjpeg.h>
-#include "AS_DCP.h"
 #include "mxf_asset.h"
 #include "util.h"
 
@@ -100,14 +99,20 @@ public:
 
 private:
        friend class MonoPictureAsset;
-       
+
        MonoPictureAssetWriter (MonoPictureAsset *);
 
-       ASDCP::JP2K::CodestreamParser _j2k_parser;
-       ASDCP::JP2K::FrameBuffer _frame_buffer;
-       ASDCP::JP2K::MXFWriter _mxf_writer;
-       ASDCP::WriterInfo _writer_info;
-       ASDCP::JP2K::PictureDescriptor _picture_descriptor;
+       /* no copy construction */
+       MonoPictureAssetWriter (MonoPictureAssetWriter const &);
+       MonoPictureAssetWriter& operator= (MonoPictureAssetWriter const &);
+
+       /* do this with an opaque pointer so we don't have to include
+          ASDCP headers
+       */
+          
+       struct ASDCPState;
+       boost::shared_ptr<ASDCPState> _state;
+
        MonoPictureAsset* _asset;
        /** Number of picture frames written to the asset so far */
        int _frames_written;
index 2ed183121afc307b1a160acf7d9d23b8c0acb589..08ca71e513e980381bb832269b44ea9dbedebdbb 100644 (file)
@@ -321,30 +321,39 @@ SoundAsset::start_write ()
        return shared_ptr<SoundAssetWriter> (new SoundAssetWriter (this));
 }
 
+struct SoundAssetWriter::ASDCPState
+{
+       ASDCP::PCM::MXFWriter mxf_writer;
+       ASDCP::PCM::FrameBuffer frame_buffer;
+       ASDCP::WriterInfo writer_info;
+       ASDCP::PCM::AudioDescriptor audio_desc;
+};
+
 SoundAssetWriter::SoundAssetWriter (SoundAsset* a)
-       : _asset (a)
+       : _state (new SoundAssetWriter::ASDCPState)
+       , _asset (a)
        , _finalized (false)
        , _frames_written (0)
        , _frame_buffer_offset (0)
 {
        /* Derived from ASDCP::Wav::SimpleWaveHeader::FillADesc */
-       _audio_desc.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
-       _audio_desc.AudioSamplingRate = ASDCP::Rational (_asset->sampling_rate(), 1);
-       _audio_desc.Locked = 0;
-       _audio_desc.ChannelCount = _asset->channels ();
-       _audio_desc.QuantizationBits = 24;
-       _audio_desc.BlockAlign = 3 * _asset->channels();
-       _audio_desc.AvgBps = _asset->sampling_rate() * _audio_desc.BlockAlign;
-       _audio_desc.LinkedTrackID = 0;
-       _audio_desc.ChannelFormat = ASDCP::PCM::CF_NONE;
+       _state->audio_desc.EditRate = ASDCP::Rational (_asset->edit_rate(), 1);
+       _state->audio_desc.AudioSamplingRate = ASDCP::Rational (_asset->sampling_rate(), 1);
+       _state->audio_desc.Locked = 0;
+       _state->audio_desc.ChannelCount = _asset->channels ();
+       _state->audio_desc.QuantizationBits = 24;
+       _state->audio_desc.BlockAlign = 3 * _asset->channels();
+       _state->audio_desc.AvgBps = _asset->sampling_rate() * _state->audio_desc.BlockAlign;
+       _state->audio_desc.LinkedTrackID = 0;
+       _state->audio_desc.ChannelFormat = ASDCP::PCM::CF_NONE;
        
-       _frame_buffer.Capacity (ASDCP::PCM::CalcFrameBufferSize (_audio_desc));
-       _frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_audio_desc));
-       memset (_frame_buffer.Data(), 0, _frame_buffer.Capacity());
+       _state->frame_buffer.Capacity (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc));
+       _state->frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc));
+       memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity());
        
-       MXFAsset::fill_writer_info (&_writer_info, _asset->uuid ());
+       MXFAsset::fill_writer_info (&_state->writer_info, _asset->uuid ());
        
-       if (ASDCP_FAILURE (_mxf_writer.OpenWrite (_asset->path().c_str(), _writer_info, _audio_desc))) {
+       if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().c_str(), _state->writer_info, _state->audio_desc))) {
                throw FileError ("could not open audio MXF for writing", _asset->path().string());
        }
 }
@@ -354,7 +363,7 @@ SoundAssetWriter::write (float const * const * data, int frames)
 {
        for (int i = 0; i < frames; ++i) {
 
-               byte_t* out = _frame_buffer.Data() + _frame_buffer_offset;
+               byte_t* out = _state->frame_buffer.Data() + _frame_buffer_offset;
 
                /* Write one sample per channel */
                for (int j = 0; j < _asset->channels(); ++j) {
@@ -365,13 +374,13 @@ SoundAssetWriter::write (float const * const * data, int frames)
                }
                _frame_buffer_offset += 3 * _asset->channels();
 
-               assert (_frame_buffer_offset <= int (_frame_buffer.Capacity()));
+               assert (_frame_buffer_offset <= int (_state->frame_buffer.Capacity()));
 
                /* Finish the MXF frame if required */
-               if (_frame_buffer_offset == int (_frame_buffer.Capacity())) {
+               if (_frame_buffer_offset == int (_state->frame_buffer.Capacity())) {
                        write_current_frame ();
                        _frame_buffer_offset = 0;
-                       memset (_frame_buffer.Data(), 0, _frame_buffer.Capacity());
+                       memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity());
                }
        }
 }
@@ -379,7 +388,7 @@ SoundAssetWriter::write (float const * const * data, int frames)
 void
 SoundAssetWriter::write_current_frame ()
 {
-       if (ASDCP_FAILURE (_mxf_writer.WriteFrame (_frame_buffer, 0, 0))) {
+       if (ASDCP_FAILURE (_state->mxf_writer.WriteFrame (_state->frame_buffer, 0, 0))) {
                throw MiscError ("could not write audio MXF frame");
        }
 
@@ -393,7 +402,7 @@ SoundAssetWriter::finalize ()
                write_current_frame ();
        }
        
-       if (ASDCP_FAILURE (_mxf_writer.Finalize())) {
+       if (ASDCP_FAILURE (_state->mxf_writer.Finalize())) {
                throw MiscError ("could not finalise audio MXF");
        }
 
index 17767b3a04fe4bf52047dcfb67c5f396bed232bb..e13c502858b5b07de840a138cf0a3b0d9d77f142 100644 (file)
@@ -24,7 +24,6 @@
  *  @brief An asset made up of PCM audio data files
  */
 
-#include "AS_DCP.h"
 #include "mxf_asset.h"
 #include "types.h"
 
@@ -47,16 +46,24 @@ private:
        friend class SoundAsset;
 
        SoundAssetWriter (SoundAsset *);
+
+       /* no copy construction */
+       SoundAssetWriter (SoundAssetWriter const &);
+       SoundAssetWriter& operator= (SoundAssetWriter const &);
+       
        void write_current_frame ();
 
+       /* do this with an opaque pointer so we don't have to include
+          ASDCP headers
+       */
+          
+       struct ASDCPState;
+       boost::shared_ptr<ASDCPState> _state;
+
        SoundAsset* _asset;
        bool _finalized;
        int _frames_written;
        int _frame_buffer_offset;
-       ASDCP::PCM::MXFWriter _mxf_writer;
-       ASDCP::PCM::FrameBuffer _frame_buffer;
-       ASDCP::WriterInfo _writer_info;
-       ASDCP::PCM::AudioDescriptor _audio_desc;
 };
 
 /** @brief An asset made up of WAV files */