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

Side by Side Diff: webrtc/sdk/android/src/jni/androidmediaencoder_jni.cc

Issue 2627973004: Fix JNI reference leak in MediaCodecVideoEncoder (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 jni->NewObject(*j_media_codec_video_encoder_class_, 307 jni->NewObject(*j_media_codec_video_encoder_class_,
308 GetMethodID(jni, 308 GetMethodID(jni,
309 *j_media_codec_video_encoder_class_, 309 *j_media_codec_video_encoder_class_,
310 "<init>", 310 "<init>",
311 "()V"))), 311 "()V"))),
312 inited_(false), 312 inited_(false),
313 use_surface_(false), 313 use_surface_(false),
314 picture_id_(0), 314 picture_id_(0),
315 egl_context_(egl_context), 315 egl_context_(egl_context),
316 sw_fallback_required_(false) { 316 sw_fallback_required_(false) {
317 ScopedLocalRefFrame local_ref_frame(jni);
318 // It would be nice to avoid spinning up a new thread per MediaCodec, and 317 // It would be nice to avoid spinning up a new thread per MediaCodec, and
319 // instead re-use e.g. the PeerConnectionFactory's |worker_thread_|, but bug 318 // instead re-use e.g. the PeerConnectionFactory's |worker_thread_|, but bug
320 // 2732 means that deadlocks abound. This class synchronously trampolines 319 // 2732 means that deadlocks abound. This class synchronously trampolines
321 // to |codec_thread_|, so if anything else can be coming to _us_ from 320 // to |codec_thread_|, so if anything else can be coming to _us_ from
322 // |codec_thread_|, or from any thread holding the |_sendCritSect| described 321 // |codec_thread_|, or from any thread holding the |_sendCritSect| described
323 // in the bug, we have a problem. For now work around that with a dedicated 322 // in the bug, we have a problem. For now work around that with a dedicated
324 // thread. 323 // thread.
325 codec_thread_->SetName("MediaCodecVideoEncoder", NULL); 324 codec_thread_->SetName("MediaCodecVideoEncoder", NULL);
326 RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoEncoder"; 325 RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoEncoder";
327 codec_thread_checker_.DetachFromThread(); 326 codec_thread_checker_.DetachFromThread();
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 } 1259 }
1261 1260
1262 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder( 1261 webrtc::VideoEncoder* MediaCodecVideoEncoderFactory::CreateVideoEncoder(
1263 const cricket::VideoCodec& codec) { 1262 const cricket::VideoCodec& codec) {
1264 if (supported_codecs_.empty()) { 1263 if (supported_codecs_.empty()) {
1265 ALOGW << "No HW video encoder for codec " << codec.name; 1264 ALOGW << "No HW video encoder for codec " << codec.name;
1266 return nullptr; 1265 return nullptr;
1267 } 1266 }
1268 if (FindMatchingCodec(supported_codecs_, codec)) { 1267 if (FindMatchingCodec(supported_codecs_, codec)) {
1269 ALOGD << "Create HW video encoder for " << codec.name; 1268 ALOGD << "Create HW video encoder for " << codec.name;
1270 return new MediaCodecVideoEncoder(AttachCurrentThreadIfNeeded(), codec, 1269 JNIEnv* jni = AttachCurrentThreadIfNeeded();
1271 egl_context_); 1270 ScopedLocalRefFrame local_ref_frame(jni);
1271 return new MediaCodecVideoEncoder(jni, codec, egl_context_);
1272 } 1272 }
1273 ALOGW << "Can not find HW video encoder for type " << codec.name; 1273 ALOGW << "Can not find HW video encoder for type " << codec.name;
1274 return nullptr; 1274 return nullptr;
1275 } 1275 }
1276 1276
1277 const std::vector<cricket::VideoCodec>& 1277 const std::vector<cricket::VideoCodec>&
1278 MediaCodecVideoEncoderFactory::supported_codecs() const { 1278 MediaCodecVideoEncoderFactory::supported_codecs() const {
1279 return supported_codecs_; 1279 return supported_codecs_;
1280 } 1280 }
1281 1281
1282 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder( 1282 void MediaCodecVideoEncoderFactory::DestroyVideoEncoder(
1283 webrtc::VideoEncoder* encoder) { 1283 webrtc::VideoEncoder* encoder) {
1284 ALOGD << "Destroy video encoder."; 1284 ALOGD << "Destroy video encoder.";
1285 delete encoder; 1285 delete encoder;
1286 } 1286 }
1287 1287
1288 } // namespace webrtc_jni 1288 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698