Use a template as a basis for Frames.
authorCarl Hetherington <cth@carlh.net>
Tue, 27 Sep 2016 10:22:03 +0000 (11:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 27 Sep 2016 10:22:03 +0000 (11:22 +0100)
src/frame.h [new file with mode: 0644]
src/sound_asset.h
src/sound_asset_reader.h
src/sound_asset_writer.h
src/sound_frame.cc [deleted file]
src/sound_frame.h
src/wscript

diff --git a/src/frame.h b/src/frame.h
new file mode 100644 (file)
index 0000000..54b74e5
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+    This file is part of libdcp.
+
+    libdcp 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.
+
+    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of portions of this program with the
+    OpenSSL library under certain conditions as described in each
+    individual source file, and distribute linked combinations
+    including the two.
+
+    You must obey the GNU General Public License in all respects
+    for all of the code used other than OpenSSL.  If you modify
+    file(s) with this exception, you may extend this exception to your
+    version of the file(s), but you are not obligated to do so.  If you
+    do not wish to do so, delete this exception statement from your
+    version.  If you delete this exception statement from all source
+    files in the program, then also delete it here.
+*/
+
+#include "decryption_context.h"
+#include "exceptions.h"
+#include <asdcp/KM_fileio.h>
+#include <asdcp/AS_DCP.h>
+#include <boost/noncopyable.hpp>
+
+namespace dcp {
+
+template <class R, class B>
+class Frame : public boost::noncopyable
+{
+public:
+       Frame (R* reader, int n, boost::shared_ptr<const DecryptionContext> c)
+       {
+               /* XXX: unfortunate guesswork on this buffer size */
+               _buffer = new B (Kumu::Megabyte);
+
+               if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->decryption()))) {
+                       boost::throw_exception (DCPReadError ("could not read frame"));
+               }
+       }
+
+       ~Frame ()
+       {
+               delete _buffer;
+       }
+
+       uint8_t const * data () const
+       {
+               return _buffer->RoData ();
+       }
+
+       int size () const
+       {
+               return _buffer->Size ();
+       }
+
+private:
+       B* _buffer;
+};
+
+}
index a29eecd032746880c75cb51748ef4f8d8dd65061..9278eeeea1a13483e21fa719c95007096e6cebcb 100644 (file)
 #include "mxf.h"
 #include "types.h"
 #include "metadata.h"
+#include "sound_frame.h"
 
 namespace dcp
 {
 
-class SoundFrame;
 class SoundAssetWriter;
 class SoundAssetReader;
 
index 5a02322c61eed9838e271e66021dc4dced46e402..b2213b59d74effec756f00b7e775f4a044e3a0b4 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 #include "asset_reader.h"
+#include "sound_frame.h"
 #include <boost/shared_ptr.hpp>
 
 namespace ASDCP {
@@ -42,7 +43,6 @@ namespace ASDCP {
 
 namespace dcp {
 
-class SoundFrame;
 class SoundAsset;
 
 class SoundAssetReader : public AssetReader
index 0263942327687edb800fbe7b86411b4036909512..95d13855343e97655c136bb179821890198a905d 100644 (file)
 
 #include "asset_writer.h"
 #include "types.h"
+#include "sound_frame.h"
 #include <boost/shared_ptr.hpp>
 #include <boost/filesystem.hpp>
 
 namespace dcp {
 
-class SoundFrame;
 class SoundAsset;
 
 /** @class SoundAssetWriter
diff --git a/src/sound_frame.cc b/src/sound_frame.cc
deleted file mode 100644 (file)
index 132d25b..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
-
-    This file is part of libdcp.
-
-    libdcp 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.
-
-    libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
-
-    In addition, as a special exception, the copyright holders give
-    permission to link the code of portions of this program with the
-    OpenSSL library under certain conditions as described in each
-    individual source file, and distribute linked combinations
-    including the two.
-
-    You must obey the GNU General Public License in all respects
-    for all of the code used other than OpenSSL.  If you modify
-    file(s) with this exception, you may extend this exception to your
-    version of the file(s), but you are not obligated to do so.  If you
-    do not wish to do so, delete this exception statement from your
-    version.  If you delete this exception statement from all source
-    files in the program, then also delete it here.
-*/
-
-/** @file  src/sound_frame.cc
- *  @brief SoundFrame class.
- */
-
-#include "sound_frame.h"
-#include "exceptions.h"
-#include "decryption_context.h"
-#include <asdcp/AS_DCP.h>
-#include <asdcp/KM_fileio.h>
-
-using namespace dcp;
-using boost::shared_ptr;
-
-SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, shared_ptr<DecryptionContext> c)
-{
-       /* XXX: unfortunate guesswork on this buffer size */
-       _buffer = new ASDCP::PCM::FrameBuffer (1 * Kumu::Megabyte);
-
-       if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->decryption()))) {
-               boost::throw_exception (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 ();
-}
index 3cd3246b71009cd85b4f9e2cee92882bc7db481d..2b78c8e1d1116ae2e4ad600c838882d919e8ecfc 100644 (file)
 #ifndef LIBDCP_SOUND_FRAME_H
 #define LIBDCP_SOUND_FRAME_H
 
-#include <boost/noncopyable.hpp>
-#include <boost/filesystem.hpp>
-#include <stdint.h>
-#include <string>
-
-namespace ASDCP {
-       namespace PCM {
-               class FrameBuffer;
-               class MXFReader;
-       }
-       class AESDecContext;
-}
+#include "frame.h"
+#include <asdcp/AS_DCP.h>
 
 namespace dcp {
 
-class DecryptionContext;
-
-/** @class SoundFrame
- *  @brief One &lsquo;frame&rsquo; of sound data from a SoundAsset.
- */
-class SoundFrame : public boost::noncopyable
-{
-public:
-       ~SoundFrame ();
-
-       uint8_t const * data () const;
-       int size () const;
-
-private:
-       friend class SoundAssetReader;
-
-       SoundFrame (ASDCP::PCM::MXFReader* reader, int n, boost::shared_ptr<DecryptionContext>);
-
-       /** a buffer to hold the frame */
-       ASDCP::PCM::FrameBuffer* _buffer;
-};
+typedef Frame<ASDCP::PCM::MXFReader, ASDCP::PCM::FrameBuffer> SoundFrame;
 
 }
 
index 489d669e57b25c2ed1d79c9d1cb912179cea785a..dfb106be8fa667c01f35cd7cbabb50aabc3669a8 100644 (file)
@@ -90,7 +90,6 @@ def build(bld):
              sound_asset.cc
              sound_asset_reader.cc
              sound_asset_writer.cc
-             sound_frame.cc
              stereo_picture_asset.cc
              stereo_picture_asset_reader.cc
              stereo_picture_asset_writer.cc