[tbb-commits] [Git][tpo/applications/tor-browser][tor-browser-102.12.0esr-12.0-1] Bug 1832832 - protect encoder accesses in Java callbacks. r=media-playback-reviewers, alwu a=pascalc

richard (@richard) git at gitlab.torproject.org
Tue Jun 6 16:35:08 UTC 2023



richard pushed to branch tor-browser-102.12.0esr-12.0-1 at The Tor Project / Applications / Tor Browser


Commits:
d661761c by John Lin at 2023-06-06T16:34:36+00:00
Bug 1832832 - protect encoder accesses in Java callbacks. r=media-playback-reviewers,alwu a=pascalc

Differential Revision: https://phabricator.services.mozilla.com/D178564
- - - - -


2 changed files:

- dom/media/platforms/android/AndroidDataEncoder.cpp
- dom/media/platforms/android/AndroidDataEncoder.h


Changes:

=====================================
dom/media/platforms/android/AndroidDataEncoder.cpp
=====================================
@@ -494,7 +494,10 @@ void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleInput(
 template <typename ConfigType>
 void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleOutput(
     java::Sample::Param aSample, java::SampleBuffer::Param aBuffer) {
-  mEncoder->ProcessOutput(std::move(aSample), std::move(aBuffer));
+  MutexAutoLock lock(mMutex);
+  if (mEncoder) {
+    mEncoder->ProcessOutput(std::move(aSample), std::move(aBuffer));
+  }
 }
 
 template <typename ConfigType>
@@ -504,7 +507,10 @@ void AndroidDataEncoder<ConfigType>::CallbacksSupport::
 template <typename ConfigType>
 void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleError(
     const MediaResult& aError) {
-  mEncoder->Error(aError);
+  MutexAutoLock lock(mMutex);
+  if (mEncoder) {
+    mEncoder->Error(aError);
+  }
 }
 
 // Force compiler to generate code.


=====================================
dom/media/platforms/android/AndroidDataEncoder.h
=====================================
@@ -13,6 +13,7 @@
 
 #include "mozilla/Maybe.h"
 #include "mozilla/Monitor.h"
+#include "mozilla/Mutex.h"
 
 namespace mozilla {
 
@@ -36,7 +37,15 @@ class AndroidDataEncoder final : public MediaDataEncoder {
   class CallbacksSupport final : public JavaCallbacksSupport {
    public:
     explicit CallbacksSupport(AndroidDataEncoder* aEncoder)
-        : mEncoder(aEncoder) {}
+        : mMutex("AndroidDataEncoder::CallbacksSupport") {
+      MutexAutoLock lock(mMutex);
+      mEncoder = aEncoder;
+    }
+
+    ~CallbacksSupport() {
+      MutexAutoLock lock(mMutex);
+      mEncoder = nullptr;
+    }
 
     void HandleInput(int64_t aTimestamp, bool aProcessed) override;
     void HandleOutput(java::Sample::Param aSample,
@@ -46,7 +55,8 @@ class AndroidDataEncoder final : public MediaDataEncoder {
     void HandleError(const MediaResult& aError) override;
 
    private:
-    AndroidDataEncoder* mEncoder;
+    Mutex mMutex;
+    AndroidDataEncoder* mEncoder MOZ_GUARDED_BY(mMutex);
   };
   friend class CallbacksSupport;
 



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d661761cf03d6fd4f8b28004c88bdcd93a381814

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/d661761cf03d6fd4f8b28004c88bdcd93a381814
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20230606/43efbf66/attachment-0001.htm>


More information about the tbb-commits mailing list