|
|
Chromium Code Reviews|
Created:
4 years, 7 months ago by nisse-webrtc Modified:
4 years, 6 months ago CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com Base URL:
https://chromium.googlesource.com/external/webrtc.git@master Target Ref:
refs/pending/heads/master Project:
webrtc Visibility:
Public. |
DescriptionCall java SurfaceTextureHelper.dispose from the corresponding C++ destructor.
This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it.
In addition, arrange so that the SurfaceTextureHelper.stopListening
method (in java) can be called from any thread.
BUG=
Committed: https://crrev.com/a44e72c44f4dcc2332819ffd089f182385aea08c
Cr-Commit-Position: refs/heads/master@{#12941}
Patch Set 1 #Patch Set 2 : Improve comment. #Patch Set 3 : Use stopListening, and make it thread safe. #
Total comments: 9
Patch Set 4 : Define a helper invokeAtFrontUninterruptibly, and use it. #Patch Set 5 : Rebase. #Patch Set 6 : Make invokeAtFrontUninterruptibly work also on the handler's own thread. #Patch Set 7 : Delete non-AtFront method. #Patch Set 8 : Break a long line. #
Total comments: 2
Patch Set 9 : Indentation tweak. #
Messages
Total messages: 37 (15 generated)
nisse@webrtc.org changed reviewers: + magjed@webrtc.org, perkj@webrtc.org
I don't quite understand the required ordering in this code.
The method MediaCodecVideoDecoder.TextureListener.release used to look like
this,
surfaceTextureHelper.dispose();
synchronized (newFrameLock) {
if (renderedBuffer != null) {
surfaceTextureHelper.returnTextureFrame();
renderedBuffer = null;
}
}
I.e., first call surfaceTextureHelper.dispose, and then conditinally call
surfaceTextureHelper.returnTextureFrame. This looks a bit strange.
Maybe SurfaceTextureHelper.dispose ought to do that? The comments on that method
(and the related stopListening), are a bit confusing.
And if it really is important that dispose complete before other things are
cleaned up, it seems a bit brittle to do it in the C++ destructor of a
ref-counted object. It would perhaps be better with a wrapper dispose method
that can be called explicitly.
Description was changed from ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. BUG= ========== to ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. BUG= ==========
lgtm It's ok to call SurfaceTextureHelper.returnTextureFrame() after SurfaceTextureHelper.dispose(). The only important thing to make sure is that all frames are eventually returned with returnTextureFrame(), otherwise the resources in SurfaceTextureHelper will not be released.
The CQ bit was checked by nisse@webrtc.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1988043002/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1988043002/20001
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
I'm looking into how to support calling stopListening on any thread.
The simplest approach would be to use a lock and use for synchronizing all of
startListening, stopListening, and listener.onTextureFrameAvailable.
But maybe it's better to use a similar trick as dispose uses? I.e., something
like
if (on handler thread) {
listener = null;
} else {
handler.postAtFrontOfQueue(... { listener = null; barrier.countDown() });
wait(barrier)
}
Tried to make stopListening work on any thread, using the same post-and-barrier trick as dispose. https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (left): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:380: handler.removeCallbacks(setListenerRunnable); Is it correct to make this call up-front, regardless of which thread we're on?
https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (left): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:380: handler.removeCallbacks(setListenerRunnable); On 2016/05/23 13:31:57, nisse-webrtc wrote: > Is it correct to make this call up-front, regardless of which thread we're on? Yes? |setListenerRunnable| is not allowed to execute after stopListening(), because calling startListening() followed by stopListening() should be guaranteed to stop. https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { Please add a helper method invokeAtFrontUninterruptibly() in ThreadUtils that does exactly this, and replace the use case here and in dispose(). dispose() currently avoids waiting for release() to finish, but you can ignore that and wait for the whole Runnable to finish instead. public static void invokeUninterruptibly(final Handler handler, final Runnable runnable) { if (handler.getLooper().getThread() == Thread.currentThread()) { runnable.run(); return; } final CountDownLatch barrier = new CountDownLatch(1); handler.postAtFrontOfQueue(new Runnable() { @Override public void run() { runnable.run(); barrier.countDown(); } }); awaitUninterruptibly(barrier); }
https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (left): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:380: handler.removeCallbacks(setListenerRunnable); On 2016/05/24 09:09:55, magjed_webrtc wrote: > On 2016/05/23 13:31:57, nisse-webrtc wrote: > > Is it correct to make this call up-front, regardless of which thread we're on? > > Yes? |setListenerRunnable| is not allowed to execute after stopListening(), > because calling startListening() followed by stopListening() should be > guaranteed to stop. Good. It used to only be called on the handler thread. https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { On 2016/05/24 09:09:55, magjed_webrtc wrote: > Please add a helper method invokeAtFrontUninterruptibly() in ThreadUtils that > does exactly this, and replace the use case here and in dispose(). dispose() > currently avoids waiting for release() to finish, but you can ignore that and > wait for the whole Runnable to finish instead. > > public static void invokeUninterruptibly(final Handler handler, final Runnable > runnable) { > if (handler.getLooper().getThread() == Thread.currentThread()) { > runnable.run(); > return; > } > final CountDownLatch barrier = new CountDownLatch(1); > handler.postAtFrontOfQueue(new Runnable() { > @Override > public void run() { > runnable.run(); > barrier.countDown(); > } > }); > awaitUninterruptibly(barrier); > } Done, except that I don't do the currentThread case. The other invoke methods appear to not to do that, so I try to stay consistent and leave that check with the caller, even if that's a somewhat ugly duplication of the code block. Not sure what's best, should all ThreadUtils.invoke* check for this case?
https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { > Not sure what's best, should all ThreadUtils.invoke* check for this case? At least invokeAtFront() should have it. Otherwise it will surely deadlock. The other invoke* should probably have a check, but I'm not sure if we should execute the Runnable immediately or throw a RuntimeException. If we have code like: handler.post(A); invokeUninterruptibly(handler, B); A should probably be executed before B, so we can't execute the Runnable immediately in B.
https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { On 2016/05/24 14:29:56, magjed_webrtc wrote: > > Not sure what's best, should all ThreadUtils.invoke* check for this case? > At least invokeAtFront() should have it. I'll add that. > Otherwise it will surely deadlock. The alternative would be to require the caller to do that check, so I think it's a matter of style. As far as I see, invokeInterruptibly will deadlock in the same way if called on the handler's own thread. > The other invoke* should probably have a check, I'm a little concerned about consistency, but maybe it makes sense to have the atFront variant be special and try run it as soon as possible.
lgtm https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { On 2016/05/25 07:35:59, nisse-webrtc wrote: > On 2016/05/24 14:29:56, magjed_webrtc wrote: > The alternative would be to require the caller to do that check, so I think it's > a matter of style. Yes, but in the case of invokeAtFront, the util function can handle if it's the same thread, so I don't see any reason not to handle it. > As far as I see, invokeInterruptibly will deadlock in the > same way if called on the handler's own thread. Yes they will, so throwing an exception might facilitate debugging. The invoke functions are only used from this class, so if you want, you can even remove the non-at-front invoke functions and only use invokeAtFront.
I'll try to land this now. https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/40001/webrtc/api/java/android/o... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:377: if (handler.getLooper().getThread() == Thread.currentThread()) { On 2016/05/25 09:03:07, magjed_webrtc wrote: > On 2016/05/25 07:35:59, nisse-webrtc wrote: > > On 2016/05/24 14:29:56, magjed_webrtc wrote: > > The alternative would be to require the caller to do that check, so I think > it's > > a matter of style. > Yes, but in the case of invokeAtFront, the util function can handle if it's the > same thread, so I don't see any reason not to handle it. > > > As far as I see, invokeInterruptibly will deadlock in the > > same way if called on the handler's own thread. > Yes they will, so throwing an exception might facilitate debugging. > > The invoke functions are only used from this class, so if you want, you can even > remove the non-at-front invoke functions and only use invokeAtFront. Deleted the non-AtFront method. Renamed the variant with return value, made to post at front, and work on the handler's thread. Also updated tests.
The CQ bit was checked by nisse@webrtc.org
The patchset sent to the CQ was uploaded after l-g-t-m from magjed@webrtc.org Link to the patchset: https://codereview.webrtc.org/1988043002/#ps120001 (title: "Delete non-AtFront method.")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1988043002/120001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1988043002/120001
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: presubmit on tryserver.webrtc (JOB_FAILED, http://build.chromium.org/p/tryserver.webrtc/builders/presubmit/builds/5843)
Description was changed from ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. BUG= ========== to ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. In addition, arrange so that the SurfaceTextureHelper.stopListening method (in java) can be called from any thread. BUG= ==========
nisse@webrtc.org changed reviewers: + tommi@webrtc.org - perkj@webrtc.org
Hi tommi, I need owners approval, primarily for ThreadUtils.java and MediaCodecVideoDecoder.java. I Per's absense, can you take a look?
lgtm https://codereview.webrtc.org/1988043002/diff/140001/webrtc/api/java/android/... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/140001/webrtc/api/java/android/... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:382: @Override public void run() { is the indent off?
Fixed indent now. https://codereview.webrtc.org/1988043002/diff/140001/webrtc/api/java/android/... File webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java (right): https://codereview.webrtc.org/1988043002/diff/140001/webrtc/api/java/android/... webrtc/api/java/android/org/webrtc/SurfaceTextureHelper.java:382: @Override public void run() { On 2016/05/26 13:36:58, tommi-webrtc wrote: > is the indent off? Possibly, the current code and cl format don't agree at all, so I'm not sure how it's supposed to be indented. I'll check with Magnus before landing.
The CQ bit was checked by nisse@webrtc.org
The patchset sent to the CQ was uploaded after l-g-t-m from magjed@webrtc.org, tommi@webrtc.org Link to the patchset: https://codereview.webrtc.org/1988043002/#ps160001 (title: "Indentation tweak.")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1988043002/160001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1988043002/160001
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: android_arm64_rel on tryserver.webrtc (JOB_TIMED_OUT, no build URL)
The CQ bit was checked by nisse@webrtc.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1988043002/160001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1988043002/160001
Message was sent while issue was closed.
Description was changed from ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. In addition, arrange so that the SurfaceTextureHelper.stopListening method (in java) can be called from any thread. BUG= ========== to ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. In addition, arrange so that the SurfaceTextureHelper.stopListening method (in java) can be called from any thread. BUG= ==========
Message was sent while issue was closed.
Committed patchset #9 (id:160001)
Message was sent while issue was closed.
Description was changed from ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. In addition, arrange so that the SurfaceTextureHelper.stopListening method (in java) can be called from any thread. BUG= ========== to ========== Call java SurfaceTextureHelper.dispose from the corresponding C++ destructor. This makes it clearer that the C++ SurfaceTextureHelper owns its associated java object it. In addition, arrange so that the SurfaceTextureHelper.stopListening method (in java) can be called from any thread. BUG= Committed: https://crrev.com/a44e72c44f4dcc2332819ffd089f182385aea08c Cr-Commit-Position: refs/heads/master@{#12941} ==========
Message was sent while issue was closed.
Patchset 9 (id:??) landed as https://crrev.com/a44e72c44f4dcc2332819ffd089f182385aea08c Cr-Commit-Position: refs/heads/master@{#12941} |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
