Bug 878449 - Fixed mismatched CoInitialize call causing crash in JumpList. r=padenot.
authorBrian R. Bondy <netzen@gmail.com>
Thu, 20 Jun 2013 08:57:46 -0400
changeset 147268 a67425aa4728b9a1ab301f023ac7427e1b91ed3a
parent 147267 ac7663828c8823ccadc73614671309eb7e9f9d06
child 147283 3a32e60568f6a516a6b0fe306b9afe1b14aca03e
child 147323 58a97d6ad3be5c1c86d7855048389b01d126fc0c
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs878449
milestone24.0a1
first release with
nightly mac
a67425aa4728 / 24.0a1 / 20130620113202 / files
nightly linux32
nightly linux64
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly mac
Bug 878449 - Fixed mismatched CoInitialize call causing crash in JumpList. r=padenot.
content/media/wmf/WMFReader.cpp
content/media/wmf/WMFReader.h
--- a/content/media/wmf/WMFReader.cpp
+++ b/content/media/wmf/WMFReader.cpp
@@ -49,17 +49,18 @@ WMFReader::WMFReader(AbstractMediaDecode
     mVideoHeight(0),
     mVideoStride(0),
     mAudioFrameSum(0),
     mAudioFrameOffset(0),
     mHasAudio(false),
     mHasVideo(false),
     mUseHwAccel(false),
     mMustRecaptureAudioPosition(true),
-    mIsMP3Enabled(WMFDecoder::IsMP3Supported())
+    mIsMP3Enabled(WMFDecoder::IsMP3Supported()),
+    mCOMInitialized(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
   MOZ_COUNT_CTOR(WMFReader);
 }
 
 WMFReader::~WMFReader()
 {
   NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
@@ -74,25 +75,32 @@ WMFReader::~WMFReader()
   NS_ASSERTION(SUCCEEDED(hr), "MFShutdown failed");
   MOZ_COUNT_DTOR(WMFReader);
 }
 
 void
 WMFReader::OnDecodeThreadStart()
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
-  HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
-  NS_ENSURE_TRUE_VOID(SUCCEEDED(hr));
+
+  // XXX WebAudio will call this on the main thread so CoInit will definitely
+  // fail. You cannot change the concurrency model once already set.
+  // The main thread will continue to be STA, which seems to work, but MSDN
+  // recommends that MTA be used.
+  mCOMInitialized = SUCCEEDED(CoInitializeEx(0, COINIT_MULTITHREADED));
+  NS_ENSURE_TRUE_VOID(mCOMInitialized);
 }
 
 void
 WMFReader::OnDecodeThreadFinish()
 {
   NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
-  CoUninitialize();
+  if (mCOMInitialized) {
+    CoUninitialize();
+  }
 }
 
 bool
 WMFReader::InitializeDXVA()
 {
   if (!Preferences::GetBool("media.windows-media-foundation.use-dxva", false)) {
     return false;
   }
--- a/content/media/wmf/WMFReader.h
+++ b/content/media/wmf/WMFReader.h
@@ -110,13 +110,15 @@ private:
   bool mHasAudio;
   bool mHasVideo;
   bool mUseHwAccel;
 
   // We can't call WMFDecoder::IsMP3Supported() on non-main threads, since it
   // checks a pref, so we cache its value in mIsMP3Enabled and use that on
   // the decode thread.
   const bool mIsMP3Enabled;
+
+  bool mCOMInitialized;
 };
 
 } // namespace mozilla
 
 #endif