Missing audio asset decryption.
[libdcp.git] / src / sound_asset.cc
index 9b6b48aa06bb2fa698de854127dc701f7d371b4f..0d829b75fa022def1177d772dd23be953481a6b5 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdexcept>
 #include <boost/filesystem.hpp>
 #include <boost/lexical_cast.hpp>
+#include <libxml++/nodes/element.h>
 #include "KM_fileio.h"
 #include "AS_DCP.h"
 #include "sound_asset.h"
@@ -46,10 +47,12 @@ SoundAsset::SoundAsset (
        string directory,
        string mxf_name,
        boost::signals2::signal<void (float)>* progress,
-       int fps, int intrinsic_duration,
+       int fps,
+       int intrinsic_duration,
+       bool encrypted,
        MXFMetadata const & metadata
        )
-       : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
+       : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration, encrypted)
        , _channels (files.size ())
        , _sampling_rate (0)
 {
@@ -63,10 +66,13 @@ SoundAsset::SoundAsset (
        string directory,
        string mxf_name,
        boost::signals2::signal<void (float)>* progress,
-       int fps, int intrinsic_duration, int channels,
+       int fps,
+       int intrinsic_duration,
+       int channels,
+       bool encrypted,
        MXFMetadata const & metadata
        )
-       : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
+       : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration, encrypted)
        , _channels (channels)
        , _sampling_rate (0)
 {
@@ -97,7 +103,7 @@ SoundAsset::SoundAsset (string directory, string mxf_name)
 }
 
 SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int channels, int sampling_rate)
-       : MXFAsset (directory, mxf_name, 0, fps, 0)
+       : MXFAsset (directory, mxf_name, 0, fps, 0, false)
        , _channels (channels)
        , _sampling_rate (sampling_rate)
 {
@@ -196,7 +202,7 @@ SoundAsset::construct (boost::function<string (Channel)> get_path, MXFMetadata c
                        offset += sample_size;
                }
 
-               if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
+               if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0))) {
                        boost::throw_exception (MiscError ("could not write audio MXF frame"));
                }
 
@@ -210,17 +216,10 @@ SoundAsset::construct (boost::function<string (Channel)> get_path, MXFMetadata c
        }
 }
 
-void
-SoundAsset::write_to_cpl (ostream& s) const
+string
+SoundAsset::cpl_node_name () const
 {
-       s << "        <MainSound>\n"
-         << "          <Id>urn:uuid:" << _uuid << "</Id>\n"
-         << "          <AnnotationText>" << _file_name << "</AnnotationText>\n"
-         << "          <EditRate>" << _edit_rate << " 1</EditRate>\n"
-         << "          <IntrinsicDuration>" << _intrinsic_duration << "</IntrinsicDuration>\n"
-         << "          <EntryPoint>" << _entry_point << "</EntryPoint>\n"
-         << "          <Duration>" << _duration << "</Duration>\n"
-         << "        </MainSound>\n";
+       return "MainSound";
 }
 
 bool
@@ -301,7 +300,7 @@ shared_ptr<const SoundFrame>
 SoundAsset::get_frame (int n) const
 {
        /* XXX: should add on entry point here? */
-       return shared_ptr<const SoundFrame> (new SoundFrame (path().string(), n));
+       return shared_ptr<const SoundFrame> (new SoundFrame (path().string(), n, _decryption_context));
 }
 
 shared_ptr<SoundAssetWriter>
@@ -342,7 +341,7 @@ SoundAssetWriter::SoundAssetWriter (SoundAsset* a, MXFMetadata const & m)
        _state->frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (_state->audio_desc));
        memset (_state->frame_buffer.Data(), 0, _state->frame_buffer.Capacity());
        
-       MXFAsset::fill_writer_info (&_state->writer_info, _asset->uuid (), _metadata);
+       _asset->fill_writer_info (&_state->writer_info, _asset->uuid (), _metadata);
        
        if (ASDCP_FAILURE (_state->mxf_writer.OpenWrite (_asset->path().string().c_str(), _state->writer_info, _state->audio_desc))) {
                boost::throw_exception (FileError ("could not open audio MXF for writing", _asset->path().string()));
@@ -402,7 +401,8 @@ SoundAssetWriter::finalize ()
        _asset->set_duration (_frames_written);
 }
 
-SoundAssetWriter::~SoundAssetWriter ()
+string
+SoundAsset::key_type () const
 {
-       assert (_finalized);
+       return "MDAK";
 }