bug 1323382 remove static FFmpegLibWrapper constructor and destructors r?jya draft
authorKarl Tomlinson <karlt+@karlt.net>
Wed, 14 Dec 2016 16:23:51 +1300
changeset 449487 e6e2cee93578f001be48afeb63b540b80a472f6c
parent 449439 1ea0c60db5d25a7d522e2f252c1978ff4fc7538e
child 539494 0490ec5786df308af32e0f70e5496429c5d965de
push id38570
push userktomlinson@mozilla.com
push dateWed, 14 Dec 2016 06:51:29 +0000
reviewersjya
bugs1323382, 1304156, 1226376
milestone53.0a1
bug 1323382 remove static FFmpegLibWrapper constructor and destructors r?jya The libraries are no longer closed, which works around bug 1304156. The MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS name seems a little odd here but it ensures the desired class behaviour and usage, and is consistent with changes for bug 1226376. MozReview-Commit-ID: JLO4HEvNrff
dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
@@ -9,26 +9,16 @@
 #include "mozilla/Types.h"
 #include "prlink.h"
 
 #define AV_LOG_DEBUG    48
 
 namespace mozilla
 {
 
-FFmpegLibWrapper::FFmpegLibWrapper()
-{
-  PodZero(this);
-}
-
-FFmpegLibWrapper::~FFmpegLibWrapper()
-{
-  Unlink();
-}
-
 FFmpegLibWrapper::LinkResult
 FFmpegLibWrapper::Link()
 {
   if (!mAVCodecLib || !mAVUtilLib) {
     Unlink();
     return LinkResult::NoProvidedLib;
   }
 
@@ -170,9 +160,9 @@ FFmpegLibWrapper::Unlink()
     PR_UnloadLibrary(mAVUtilLib);
   }
   if (mAVCodecLib) {
     PR_UnloadLibrary(mAVCodecLib);
   }
   PodZero(this);
 }
 
-} // namespace mozilla
\ No newline at end of file
+} // namespace mozilla
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
@@ -13,20 +13,25 @@ struct AVFrame;
 struct AVPacket;
 struct AVDictionary;
 struct AVCodecParserContext;
 struct PRLibrary;
 
 namespace mozilla
 {
 
-struct FFmpegLibWrapper
+struct MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS FFmpegLibWrapper
 {
-  FFmpegLibWrapper();
-  ~FFmpegLibWrapper();
+  // The class is used only in static storage and so is zero initialized.
+  FFmpegLibWrapper() = default;
+  // The libraries are not unloaded in the destructor, because doing so would
+  // require a static constructor to register the static destructor.  As the
+  // class is in static storage, the destructor would only run on shutdown
+  // anyway.
+  ~FFmpegLibWrapper() = default;
 
   enum class LinkResult
   {
     Success,
     NoProvidedLib,
     NoAVCodecVersion,
     CannotUseLibAV57,
     BlockedOldLibAVVersion,
@@ -86,9 +91,9 @@ struct FFmpegLibWrapper
   PRLibrary* mAVCodecLib;
   PRLibrary* mAVUtilLib;
 
 private:
 };
 
 } // namespace mozilla
 
-#endif // FFmpegLibWrapper
\ No newline at end of file
+#endif // FFmpegLibWrapper