Fix potential crash during SimulcastEncoderAdapter tear down.

On the Android and iOS platforms, occasionally crash when using the SimulcastEncoderAdapter.

The Android platform reverted,
In function `SimulcastEncoderAdapter::EncoderContext::Release`,
After executing `encoder_->RegisterEncodeCompleteCallback(nullptr)`
before execute `encoder_->Release()`

If the encoder thread is executed here,
```
// out/xxx/xxx/gen/sdk/android/generated_video_jni/VideoEncoderWrapper_jni.h
JNI_GENERATOR_EXPORT void Java_org_webrtc_VideoEncoderWrapper_nativeOnEncodedFrame(
    JNIEnv* env,
    jclass jcaller,
    jlong nativeVideoEncoderWrapper,
    jobject frame) {
  VideoEncoderWrapper* native = reinterpret_cast<VideoEncoderWrapper*>(nativeVideoEncoderWrapper);
  CHECK_NATIVE_PTR(env, jcaller, native, "OnEncodedFrame");
  return native->OnEncodedFrame(env, base::android::JavaParamRef<jobject>(env, frame)); // HERE
}
```
it will cause `native` to nullptr.

iOS also.

Bug: webrtc:13156
Change-Id: Id5563b3fa2c11606ae7b35de56bbaa6adba59b14
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/231780
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34989}
This commit is contained in:
Johnny 2021-09-14 11:28:17 +08:00 committed by WebRTC LUCI CQ
parent 99c6ca0e66
commit dc8fc72204
2 changed files with 2 additions and 1 deletions

View File

@ -58,6 +58,7 @@ Jesús Leganés-Combarro <piranna@gmail.com>
Jiawei Ou <jiawei.ou@gmail.com>
Jie Mao <maojie0924@gmail.com>
Jiwon Kim <jwkim0000@gmail.com>
Johnny Wong <hellojinqiang@gmail.com>
Jose Antonio Olivera Ortega <josea.olivera@gmail.com>
Keiichi Enomoto <enm10k@gmail.com>
Kiran Thind <kiran.thind@gmail.com>

View File

@ -159,8 +159,8 @@ SimulcastEncoderAdapter::EncoderContext::EncoderContext(
void SimulcastEncoderAdapter::EncoderContext::Release() {
if (encoder_) {
encoder_->RegisterEncodeCompleteCallback(nullptr);
encoder_->Release();
encoder_->RegisterEncodeCompleteCallback(nullptr);
}
}