diff --git a/src/org/jitsi/impl/neomedia/recording/WebmDataSink.java b/src/org/jitsi/impl/neomedia/recording/WebmDataSink.java
index c939c2cf4036813acc2d581c58ff76958e89c527..877e5d45c15a1e13a8210f6c36559cb6f5ed839c 100644
--- a/src/org/jitsi/impl/neomedia/recording/WebmDataSink.java
+++ b/src/org/jitsi/impl/neomedia/recording/WebmDataSink.java
@@ -40,6 +40,13 @@ public class WebmDataSink
     private RecorderEventHandler eventHandler;
     private long ssrc = -1;
 
+    /**
+     * Whether this <tt>DataSink</tt> is open and should write to its
+     * <tt>WebmWriter</tt>.
+     */
+    private boolean open = false;
+    private final Object openCloseSyncRoot = new Object();
+
     /**
      * Whether we are in a state of waiting for a keyframe and discarding
      * non-key frames.
@@ -129,21 +136,25 @@ public void addDataSinkListener(DataSinkListener dataSinkListener)
     @Override
     public void close()
     {
-        if (writer != null)
-            writer.close();
-        if (eventHandler != null && firstFrameTime != -1 && lastFramePts != -1)
+        synchronized (openCloseSyncRoot)
         {
-            RecorderEvent event = new RecorderEvent();
-            event.setType(RecorderEvent.Type.RECORDING_ENDED);
-            event.setSsrc(ssrc);
-            event.setFilename(filename);
+            if (writer != null)
+                writer.close();
+            if (eventHandler != null && firstFrameTime != -1 && lastFramePts != -1)
+            {
+                RecorderEvent event = new RecorderEvent();
+                event.setType(RecorderEvent.Type.RECORDING_ENDED);
+                event.setSsrc(ssrc);
+                event.setFilename(filename);
 
-            // make sure that the difference in the 'instant'-s of the
-            // STARTED and ENDED events matches the duration of the file
-            event.setDuration(lastFramePts);
+                // make sure that the difference in the 'instant'-s of the
+                // STARTED and ENDED events matches the duration of the file
+                event.setDuration(lastFramePts);
 
-            event.setMediaType(MediaType.VIDEO);
-            eventHandler.handleEvent(event);
+                event.setMediaType(MediaType.VIDEO);
+                eventHandler.handleEvent(event);
+            }
+            open = false;
         }
     }
 
@@ -171,22 +182,27 @@ public MediaLocator getOutputLocator()
     @Override
     public void open() throws IOException, SecurityException
     {
-        if (dataSource instanceof PushBufferDataSource)
+        synchronized (openCloseSyncRoot)
         {
-            PushBufferDataSource pbds = (PushBufferDataSource) dataSource;
-            PushBufferStream[] streams = pbds.getStreams();
-
-            //XXX: should we allow for multiple streams in the data source?
-            for (PushBufferStream stream : streams)
+            if (dataSource instanceof PushBufferDataSource)
             {
-                //XXX whats the proper way to check for this? and handle?
-                if (!stream.getFormat().matches(new VideoFormat("VP8")))
-                    throw new IOException("Unsupported stream format");
+                PushBufferDataSource pbds = (PushBufferDataSource) dataSource;
+                PushBufferStream[] streams = pbds.getStreams();
 
-                stream.setTransferHandler(this);
+                //XXX: should we allow for multiple streams in the data source?
+                for (PushBufferStream stream : streams)
+                {
+                    //XXX whats the proper way to check for this? and handle?
+                    if (!stream.getFormat().matches(new VideoFormat("VP8")))
+                        throw new IOException("Unsupported stream format");
+
+                    stream.setTransferHandler(this);
+                }
             }
+            dataSource.connect();
+
+            open = true;
         }
-        dataSource.connect();
     }
 
     /**
@@ -261,6 +277,10 @@ public void setSource(DataSource dataSource)
     @Override
     public void transferData(PushBufferStream stream)
     {
+        synchronized (openCloseSyncRoot)
+        {
+        if (!open)
+            return;
         try
         {
             stream.read(buffer);
@@ -391,6 +411,7 @@ else if (height*16 == width*9)
 
             lastFramePts = fd.pts;
         }
+        } //synchronized
     }
 
     /**