Bug 1043695 - Wrap FrameRef in an nsAutoPtr. r=cpearce
authorRalph Giles <giles@mozilla.com>
Thu, 24 Jul 2014 16:56:00 -0700
changeset 196825 18d6d559e00b576c2572004cd50c64dea69246de
parent 196824 b6b9ae174276407415db4cb940a9e173bfbbf57b
child 196826 a140fa9605f0cf1f3c2e92ea79d09545204489d5
push id46977
push userrgiles@mozilla.com
push dateWed, 30 Jul 2014 16:59:13 +0000
treeherdermozilla-inbound@dc0fbe8b84d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1043695
milestone34.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 1043695 - Wrap FrameRef in an nsAutoPtr. r=cpearce Everything else auto-releases, might as well do this too.
content/media/fmp4/apple/AppleVTDecoder.cpp
content/media/fmp4/apple/AppleVTDecoder.h
--- a/content/media/fmp4/apple/AppleVTDecoder.cpp
+++ b/content/media/fmp4/apple/AppleVTDecoder.cpp
@@ -154,41 +154,42 @@ static void
 PlatformCallback(void* decompressionOutputRefCon,
                  void* sourceFrameRefCon,
                  OSStatus status,
                  VTDecodeInfoFlags flags,
                  CVImageBufferRef image,
                  CMTime presentationTimeStamp,
                  CMTime presentationDuration)
 {
-  AppleVTDecoder* decoder = static_cast<AppleVTDecoder*>(decompressionOutputRefCon);
-
   LOG("AppleVideoDecoder %s status %d flags %d", __func__, status, flags);
 
   // Validate our arguments.
   if (status != noErr || !image) {
     NS_WARNING("VideoToolbox decoder returned no data");
     return;
   }
   if (flags & kVTDecodeInfo_FrameDropped) {
     NS_WARNING("  ...frame dropped...");
   }
   MOZ_ASSERT(CFGetTypeID(image) == CVPixelBufferGetTypeID(),
     "VideoToolbox returned an unexpected image type");
 
   // Forward the data back to an object method which can access
   // the correct MP4Reader callback.
-  FrameRef* frameRef = static_cast<FrameRef*>(sourceFrameRefCon);
+  AppleVTDecoder* decoder =
+    static_cast<AppleVTDecoder*>(decompressionOutputRefCon);
+  nsAutoPtr<FrameRef> frameRef =
+    nsAutoPtr<FrameRef>(static_cast<FrameRef*>(sourceFrameRefCon));
   decoder->OutputFrame(image, frameRef);
 }
 
 // Copy and return a decoded frame.
 nsresult
 AppleVTDecoder::OutputFrame(CVPixelBufferRef aImage,
-                            FrameRef* aFrameRef)
+                            nsAutoPtr<FrameRef> aFrameRef)
 {
   size_t width = CVPixelBufferGetWidth(aImage);
   size_t height = CVPixelBufferGetHeight(aImage);
   LOG("  got decoded frame data... %ux%u %s", width, height,
       CVPixelBufferIsPlanar(aImage) ? "planar" : "chunked");
 #ifdef DEBUG
   size_t planes = CVPixelBufferGetPlaneCount(aImage);
   for (size_t i = 0; i < planes; ++i) {
@@ -257,17 +258,16 @@ AppleVTDecoder::OutputFrame(CVPixelBuffe
                       buffer,
                       aFrameRef->is_sync_point,
                       aFrameRef->timestamp,
                       visible);
   // Unlock the returned image data.
   CVPixelBufferUnlockBaseAddress(aImage, kCVPixelBufferLock_ReadOnly);
 
   mCallback->Output(data.forget());
-  delete aFrameRef;
   return NS_OK;
 }
 
 // Helper to fill in a timestamp structure.
 static CMSampleTimingInfo
 TimingInfoFromSample(mp4_demuxer::MP4Sample* aSample)
 {
   CMSampleTimingInfo timestamp;
--- a/content/media/fmp4/apple/AppleVTDecoder.h
+++ b/content/media/fmp4/apple/AppleVTDecoder.h
@@ -31,17 +31,17 @@ public:
   ~AppleVTDecoder();
   virtual nsresult Init() MOZ_OVERRIDE;
   virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE;
   virtual nsresult Flush() MOZ_OVERRIDE;
   virtual nsresult Drain() MOZ_OVERRIDE;
   virtual nsresult Shutdown() MOZ_OVERRIDE;
   // Return hook for VideoToolbox callback.
   nsresult OutputFrame(CVPixelBufferRef aImage,
-                       FrameRef* frameRef);
+                       nsAutoPtr<FrameRef> frameRef);
 private:
   const mp4_demuxer::VideoDecoderConfig& mConfig;
   RefPtr<MediaTaskQueue> mTaskQueue;
   MediaDataDecoderCallback* mCallback;
   layers::ImageContainer* mImageContainer;
   CMVideoFormatDescriptionRef mFormat;
   VTDecompressionSessionRef mSession;