Bug 804387. Part 1: Make AllocateInputPort addref the returned port. r=jesup
☠☠ backed out by 58ea26c5a810 ☠ ☠
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 23 Nov 2012 11:25:05 +1300
changeset 130702 000b88ac40a7f1380132e33ea18f779d7320ece1
parent 130701 15dd558ca1018ef9d585dcbaa26900a8e56fcf06
child 130703 53d5ed687612a9e7410890fa78eaf9ba4e4e61c5
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs804387
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 804387. Part 1: Make AllocateInputPort addref the returned port. r=jesup
content/media/MediaStreamGraph.cpp
content/media/MediaStreamGraph.h
--- a/content/media/MediaStreamGraph.cpp
+++ b/content/media/MediaStreamGraph.cpp
@@ -2211,34 +2211,37 @@ MediaInputPort::GraphImpl()
 }
 
 MediaStreamGraph*
 MediaInputPort::Graph()
 {
   return gGraph;
 }
 
-MediaInputPort*
+already_AddRefed<MediaInputPort>
 ProcessedMediaStream::AllocateInputPort(MediaStream* aStream, uint32_t aFlags)
 {
+  // This method creates two references to the MediaInputPort: one for
+  // the main thread, and one for the MediaStreamGraph.
   class Message : public ControlMessage {
   public:
     Message(MediaInputPort* aPort)
       : ControlMessage(aPort->GetDestination()),
         mPort(aPort) {}
     virtual void Run()
     {
       mPort->Init();
+      // The graph holds its reference implicitly
+      mPort.forget();
     }
-    MediaInputPort* mPort;
+    nsRefPtr<MediaInputPort> mPort;
   };
-  MediaInputPort* port = new MediaInputPort(aStream, this, aFlags);
-  NS_ADDREF(port);
+  nsRefPtr<MediaInputPort> port = new MediaInputPort(aStream, this, aFlags);
   GraphImpl()->AppendMessage(new Message(port));
-  return port;
+  return port.forget();
 }
 
 void
 ProcessedMediaStream::Finish()
 {
   class Message : public ControlMessage {
   public:
     Message(ProcessedMediaStream* aStream)
--- a/content/media/MediaStreamGraph.h
+++ b/content/media/MediaStreamGraph.h
@@ -738,17 +738,18 @@ public:
     : MediaStream(aWrapper), mAutofinish(false), mInCycle(false)
   {}
 
   // Control API.
   /**
    * Allocates a new input port attached to source aStream.
    * This stream can be removed by calling MediaInputPort::Remove().
    */
-  MediaInputPort* AllocateInputPort(MediaStream* aStream, uint32_t aFlags = 0);
+  already_AddRefed<MediaInputPort> AllocateInputPort(MediaStream* aStream,
+                                                     uint32_t aFlags = 0);
   /**
    * Force this stream into the finished state.
    */
   void Finish();
   /**
    * Set the autofinish flag on this stream (defaults to false). When this flag
    * is set, and all input streams are in the finished state (including if there
    * are no input streams), this stream automatically enters the finished state.