Bug 1425277 - p4: RAII for CVBuffer. r=jya
authorJohn Lin <jolin@mozilla.com>
Mon, 26 Nov 2018 18:28:13 +0000
changeset 448074 6dbd2767e7abfb93b88da4e9744bfc1f44aab74d
parent 448073 4dd46901846aff3dd5c512cf21e05957a73ff6b0
child 448075 3bf7f358af16db7285ad8025d7aae82869d805be
push id35105
push userrmaries@mozilla.com
push dateTue, 27 Nov 2018 09:41:18 +0000
treeherdermozilla-central@b0e69b136883 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1425277
milestone65.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 1425277 - p4: RAII for CVBuffer. r=jya Differential Revision: https://phabricator.services.mozilla.com/D7560
dom/media/platforms/apple/AppleUtils.h
--- a/dom/media/platforms/apple/AppleUtils.h
+++ b/dom/media/platforms/apple/AppleUtils.h
@@ -3,41 +3,50 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Utility functions to help with Apple API calls.
 
 #ifndef mozilla_AppleUtils_h
 #define mozilla_AppleUtils_h
 
 #include "mozilla/Attributes.h"
+#include <CoreFoundation/CFBase.h>  // For CFRelease()
+#include <CoreVideo/CVBuffer.h>     // For CVBufferRelease()
 
 namespace mozilla {
 
-// Wrapper class to call CFRelease on reference types
+// Wrapper class to call CFRelease/CVBufferRelease on reference types
 // when they go out of scope.
-template <class T>
-class AutoCFRelease {
+template <class T, class F, F relFunc>
+class AutoObjRefRelease {
  public:
-  MOZ_IMPLICIT AutoCFRelease(T aRef) : mRef(aRef) {}
-  ~AutoCFRelease() {
+  MOZ_IMPLICIT AutoObjRefRelease(T aRef) : mRef(aRef) {}
+  ~AutoObjRefRelease() {
     if (mRef) {
-      CFRelease(mRef);
+      relFunc(mRef);
     }
   }
   // Return the wrapped ref so it can be used as an in parameter.
   operator T() { return mRef; }
   // Return a pointer to the wrapped ref for use as an out parameter.
   T* receive() { return &mRef; }
 
  private:
   // Copy operator isn't supported and is not implemented.
-  AutoCFRelease<T>& operator=(const AutoCFRelease<T>&);
+  AutoObjRefRelease<T, F, relFunc>& operator=(
+      const AutoObjRefRelease<T, F, relFunc>&);
   T mRef;
 };
 
+template <typename T>
+using AutoCFRelease = AutoObjRefRelease<T, decltype(&CFRelease), &CFRelease>;
+template <typename T>
+using AutoCVBufferRelease =
+    AutoObjRefRelease<T, decltype(&CVBufferRelease), &CVBufferRelease>;
+
 // CFRefPtr: A CoreFoundation smart pointer.
 template <class T>
 class CFRefPtr {
  public:
   explicit CFRefPtr(T aRef) : mRef(aRef) {
     if (mRef) {
       CFRetain(mRef);
     }