mirror of
https://github.com/androidx/media.git
synced 2025-05-06 23:20:42 +08:00
Avoid possibility of leaking an activity/service context
The bug here was that we'd create a VideoFrameReleaseTimeHelper using whatever context DefaultRenderersFactory has, and it would then hold a reference to that context via DisplayManager. A leak could then occur if the player outlived the life of the context used to create it (which would be strange/unusual, but not impossible). Issue: #4249 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198747599
This commit is contained in:
parent
4ecce9802b
commit
7d0769249f
@ -205,7 +205,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
this.allowedJoiningTimeMs = allowedJoiningTimeMs;
|
this.allowedJoiningTimeMs = allowedJoiningTimeMs;
|
||||||
this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
|
this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(context);
|
frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
|
||||||
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
|
eventDispatcher = new EventDispatcher(eventHandler, eventListener);
|
||||||
deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
|
deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
|
||||||
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
|
||||||
|
@ -72,8 +72,12 @@ public final class VideoFrameReleaseTimeHelper {
|
|||||||
* @param context A context from which information about the default display can be retrieved.
|
* @param context A context from which information about the default display can be retrieved.
|
||||||
*/
|
*/
|
||||||
public VideoFrameReleaseTimeHelper(@Nullable Context context) {
|
public VideoFrameReleaseTimeHelper(@Nullable Context context) {
|
||||||
windowManager = context == null ? null
|
if (context != null) {
|
||||||
: (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
context = context.getApplicationContext();
|
||||||
|
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
} else {
|
||||||
|
windowManager = null;
|
||||||
|
}
|
||||||
if (windowManager != null) {
|
if (windowManager != null) {
|
||||||
displayListener = Util.SDK_INT >= 17 ? maybeBuildDefaultDisplayListenerV17(context) : null;
|
displayListener = Util.SDK_INT >= 17 ? maybeBuildDefaultDisplayListenerV17(context) : null;
|
||||||
vsyncSampler = VSyncSampler.getInstance();
|
vsyncSampler = VSyncSampler.getInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user