changeset 10842:d4c0f65a3bbb

8198316: MediaPlayer crashes when playing m3u8 files on macOS High Sierra 10.13.2 Reviewed-by: kcr
author almatvee
date Fri, 16 Feb 2018 15:58:52 -0800
parents f8b0d53d9542
children 03d6c4487f90
files modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.h modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm
diffstat 2 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.h	Thu Feb 15 07:41:05 2018 -0800
+++ b/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.h	Fri Feb 16 15:58:52 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -84,5 +84,6 @@
 
 - (id) initWithURL:(NSURL *)source eventHandler:(CJavaPlayerEventDispatcher*)hdlr;
 - (void) setPlayerState:(int)newState;
+- (void) hlsBugReset;
 
 @end
--- a/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm	Thu Feb 15 07:41:05 2018 -0800
+++ b/modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm	Fri Feb 16 15:58:52 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -278,6 +278,25 @@
     }
 }
 
+- (void) hlsBugReset {
+    // schedule this to be done when we're not buried inside the AVPlayer callback
+    dispatch_async(dispatch_get_main_queue(), ^{
+        LOGGER_DEBUGMSG(([[NSString stringWithFormat:@"hlsBugReset()"] UTF8String]));
+
+        if (_playerOutput) {
+            _playerOutput.suppressesPlayerRendering = YES;
+
+            CVDisplayLinkStop(_displayLink);
+            [_player.currentItem removeOutput:_playerOutput];
+
+            [_playerOutput requestNotificationOfMediaDataChangeWithAdvanceInterval:ADVANCE_INTERVAL_IN_SECONDS];
+            [_player.currentItem addOutput:_playerOutput];
+
+            self.hlsBugResetCount = 0;
+        }
+    });
+}
+
 - (void) observeValueForKeyPath:(NSString *)keyPath
                        ofObject:(id)object
                          change:(NSDictionary *)change
@@ -680,11 +699,9 @@
                      * than not playing at all, and this should not happen once
                      * the bug is fixed in AVFoundation.
                      */
-                    [self.player.currentItem removeOutput:playerItemVideoOutput];
-                    [self.player.currentItem addOutput:playerItemVideoOutput];
-                    self.hlsBugResetCount = 0;
+                    [self hlsBugReset];
                     self.lastHostTime = inNow->hostTime;
-                    // fall through to allow it to stop the display link
+                    return kCVReturnSuccess; // hlsBugReset() will stop display link
                 } else {
                     self.hlsBugResetCount++;
                     self.lastHostTime = inNow->hostTime;