Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Issue 3009383002: Enhance RTCUIApplicationStatusObserver thread safety. (Closed)

Created:
3 years, 3 months ago by andersc
Modified:
3 years, 3 months ago
CC:
webrtc-reviews_webrtc.org, tterriberry_mozilla.com
Target Ref:
refs/heads/master
Project:
webrtc
Visibility:
Public.

Description

Enhance RTCUIApplicationStatusObserver thread safety. Add locking around waiting for initialization to finish, since calling dispatch_block_wait from multiple threads leads to undefined behavior. Initialize RTCUIApplicationStatusObserver earlier to give the initialization block more time to run on the main thread before starting to query the application state. http://www.dailymotion.com/video/x2mckmh BUG=b/65558688 Review-Url: https://codereview.webrtc.org/3009383002 Cr-Commit-Position: refs/heads/master@{#19822} Committed: https://chromium.googlesource.com/external/webrtc/+/9a85f0782ea4647d77515b48b4bd2e1b0826210a

Patch Set 1 #

Total comments: 8

Patch Set 2 : Better name for the method to prepare the singleton for use. #

Patch Set 3 : Add note to explain the waiting logic in `isApplicationActive`. #

Patch Set 4 : Rebase #

Total comments: 6
Unified diffs Side-by-side diffs Delta from patch set Stats (+35 lines, -3 lines) Patch
M webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m View 1 2 3 4 chunks +20 lines, -3 lines 6 comments Download
M webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoDecoderH264.mm View 1 1 chunk +10 lines, -0 lines 0 comments Download
M webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm View 1 1 chunk +4 lines, -0 lines 0 comments Download

Messages

Total messages: 22 (9 generated)
andersc
Please take a look
3 years, 3 months ago (2017-09-13 08:03:52 UTC) #5
andersc
On 2017/09/13 08:03:52, andersc wrote: > Please take a look There is more information about ...
3 years, 3 months ago (2017-09-13 08:05:20 UTC) #6
kthelgason
https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm File webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm (right): https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm#newcode308 webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm:308: #endif I think this needs a comment to explain ...
3 years, 3 months ago (2017-09-13 08:20:09 UTC) #7
andersc
https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm File webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm (right): https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm#newcode308 webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm:308: #endif On 2017/09/13 08:20:09, kthelgason wrote: > I think ...
3 years, 3 months ago (2017-09-13 08:46:22 UTC) #8
daniela-webrtc
lgtm with two comments to be addressed https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m File webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m (right): https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m#newcode68 webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:68: dispatch_semaphore_wait(_waitForInitializeSemaphore, DISPATCH_TIME_FOREVER); ...
3 years, 3 months ago (2017-09-13 09:02:51 UTC) #9
kthelgason
lgtm
3 years, 3 months ago (2017-09-13 09:05:50 UTC) #10
andersc
https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m File webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m (right): https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m#newcode68 webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:68: dispatch_semaphore_wait(_waitForInitializeSemaphore, DISPATCH_TIME_FOREVER); On 2017/09/13 09:02:50, daniela-webrtc wrote: > This ...
3 years, 3 months ago (2017-09-13 09:19:51 UTC) #11
daniela-webrtc
https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m File webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m (right): https://codereview.webrtc.org/3009383002/diff/1/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m#newcode69 webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:69: if (!_initialized) { On 2017/09/13 09:19:51, andersc wrote: > ...
3 years, 3 months ago (2017-09-13 09:30:49 UTC) #12
Chuck
lgtm
3 years, 3 months ago (2017-09-13 13:44:29 UTC) #13
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/3009383002/60001
3 years, 3 months ago (2017-09-13 14:08:57 UTC) #16
commit-bot: I haz the power
Committed patchset #4 (id:60001) as https://chromium.googlesource.com/external/webrtc/+/9a85f0782ea4647d77515b48b4bd2e1b0826210a
3 years, 3 months ago (2017-09-13 14:31:54 UTC) #19
tkchin_webrtc
https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m File webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m (right): https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m#newcode22 webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:22: @property(nonatomic, assign) UIApplicationState state; State is read and written ...
3 years, 3 months ago (2017-09-13 18:32:03 UTC) #21
andersc
3 years, 3 months ago (2017-09-14 08:08:46 UTC) #22
Message was sent while issue was closed.
https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework...
File webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m
(right):

https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework...
webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:22:
@property(nonatomic, assign) UIApplicationState state;
On 2017/09/13 18:32:02, tkchin_webrtc wrote:
> State is read and written to from multiple threads. It should be atomic, and
> only accessed via property accessor instead of directly through _state. 

Acknowledged.

https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework...
webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:51: +
(void)prepareForUse {
On 2017/09/13 18:32:02, tkchin_webrtc wrote:
> This class feels more complex than it needs to be.
> I suspect that if we constructed multiple instances instead of a singleton,
> created the instance in encoder / decoder ctors, provided an isReady method,
> ignored frames until main queue initialization is complete, we'd have the same
> thing working. I'd guess there'd be sufficient time between encoder / decoder
> ctor and the first encode/decode method call to complete init in most cases
> because it will take time for capture to begin.
> 

I agree, and I mentioned a solution similar to that in b/65558688#comment4

The reason I did it this way was that it is a logically smaller change than from
what we had before, and I'm not confident that returning OK from the
encoder/decoder without performing the work doesn't impact any other record
keeping made by WebRTC. But it should be easy to try out and see if it works as
expected. Let me know if you think we should spend time on trying such a
solution out instead.

https://codereview.webrtc.org/3009383002/diff/60001/webrtc/sdk/objc/Framework...
webrtc/sdk/objc/Framework/Classes/Common/RTCUIApplicationStatusObserver.m:104:
dispatch_time(DISPATCH_TIME_NOW, 10.0 * NSEC_PER_SEC));
On 2017/09/13 18:32:02, tkchin_webrtc wrote:
> What's the benefit of setting a short timeout here? It seems to introduce bad
> behavior if the timeout isn't met, and it seems hard to guarantee that this
> number works for all iOS hardware. DISPATCH_TIME_FOREVER seems more
appropriate.

10 seconds was picked to be a long timeout. A test deadlocked (because the main
queue was blocked on something else), so added the DCHECK to make it easier to
debug similar issues in the future, rather than the test just hanging.

Powered by Google App Engine
This is Rietveld 408576698