Encoded data must be copied; disambiguate second lock in encoder_thread.
authorCarl Hetherington <cth@carlh.net>
Fri, 11 Jan 2013 19:20:51 +0000 (19:20 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 11 Jan 2013 19:20:51 +0000 (19:20 +0000)
src/lib/dcp_video_frame.cc
src/lib/dcp_video_frame.h
src/lib/encoder.cc

index 8b70b0aa4697286e82f3b0da3abad72b7f3e95c9..f84fa8a3f1be39053b4bb77c75a7f2e1938ca789 100644 (file)
@@ -59,6 +59,7 @@
 using std::string;
 using std::stringstream;
 using std::ofstream;
+using std::cout;
 using boost::shared_ptr;
 
 /** Construct a DCP video frame.
@@ -371,6 +372,18 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv)
        return e;
 }
 
+EncodedData::EncodedData (int s)
+       : _data (new uint8_t[s])
+       , _size (s)
+{
+
+}
+
+EncodedData::~EncodedData ()
+{
+       delete[] _data;
+}
+
 /** Write this data to a J2K file.
  *  @param opt Options.
  *  @param frame Frame index.
@@ -413,14 +426,15 @@ EncodedData::send (shared_ptr<Socket> socket)
        socket->write (_data, _size, 30);
 }
 
-/** @param s Size of data in bytes */
-RemotelyEncodedData::RemotelyEncodedData (int s)
-       : EncodedData (new uint8_t[s], s)
+LocallyEncodedData::LocallyEncodedData (uint8_t* d, int s)
+       : EncodedData (s)
 {
-
+       memcpy (_data, d, s);
 }
 
-RemotelyEncodedData::~RemotelyEncodedData ()
+/** @param s Size of data in bytes */
+RemotelyEncodedData::RemotelyEncodedData (int s)
+       : EncodedData (s)
 {
-       delete[] _data;
+
 }
index 57e7e6203fe158970bfcb124136fbbf60ae46f86..f5ffa467e81b8ef45de2b4941ff95940ae80f9df 100644 (file)
@@ -39,15 +39,11 @@ class Subtitle;
 class EncodedData
 {
 public:
-       /** @param d Data (will not be freed by this class, but may be by subclasses)
-        *  @param s Size of data, in bytes.
+       /** @param s Size of data, in bytes.
         */
-       EncodedData (uint8_t* d, int s)
-               : _data (d)
-               , _size (s)
-       {}
+       EncodedData (int s);
 
-       virtual ~EncodedData () {}
+       virtual ~EncodedData ();
 
        void send (boost::shared_ptr<Socket> socket);
        void write (boost::shared_ptr<const EncodeOptions>, SourceFrame);
@@ -65,6 +61,10 @@ public:
 protected:
        uint8_t* _data; ///< data
        int _size;      ///< data size in bytes
+
+private:
+       /* No copy construction */
+       EncodedData (EncodedData const &);
 };
 
 /** @class LocallyEncodedData
@@ -75,12 +75,10 @@ protected:
 class LocallyEncodedData : public EncodedData
 {
 public:
-       /** @param d Data (which will not be freed by this class)
+       /** @param d Data (which will be copied by this class)
         *  @param s Size of data, in bytes.
         */
-       LocallyEncodedData (uint8_t* d, int s)
-               : EncodedData (d, s)
-       {}
+       LocallyEncodedData (uint8_t* d, int s);
 };
 
 /** @class RemotelyEncodedData
@@ -91,7 +89,6 @@ class RemotelyEncodedData : public EncodedData
 {
 public:
        RemotelyEncodedData (int s);
-       ~RemotelyEncodedData ();
 };
 
 /** @class DCPVideoFrame
index 93a364fedbdb74ce92824b763aa69231c112b285..f6d0cc40eb7d79eacd438b0e8a9c33b8b7232dfa 100644 (file)
@@ -536,7 +536,7 @@ Encoder::encoder_thread (ServerDescription* server)
                }
 
                if (encoded) {
-                       boost::mutex::scoped_lock lock (_writer_mutex);
+                       boost::mutex::scoped_lock lock2 (_writer_mutex);
                        _write_queue.push_back (make_pair (encoded, vf->frame ()));
                        _writer_condition.notify_all ();
                } else {