Bug 804387. Part 1: Make AllocateInputPort addref the returned port. r=jesup
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 23 Nov 2012 11:25:05 +1300
changeset 130763 5a403ead198d2c57109acbb42288cfa77b07eaa6
parent 130762 b1533f8a8e128f80a683fab54c31133e35b890b3
child 130764 3664bcfb874a938bd743cc329f361697def9b0b6
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.