Make PlaybackEngine thread-safe to fix FFmpeg segfault
Video and audio threads both pull from the same engine, racing on the MPS demuxer file pointer and feeding corrupted H.264 data to FFmpeg (which segfaults). Synchronize the pull methods and wait for the audio thread before closing the engine.
This commit is contained in:
@@ -75,7 +75,7 @@ public final class PlaybackEngine implements AutoCloseable {
|
||||
* Decodes until the next video frame is available, or end of stream.
|
||||
* Returns {@code null} at end of stream.
|
||||
*/
|
||||
public VideoFrame nextVideoFrame() throws IOException {
|
||||
public synchronized VideoFrame nextVideoFrame() throws IOException {
|
||||
int budget = 1000;
|
||||
while (videoQueue.isEmpty() && budget-- > 0) {
|
||||
if (!routeOne()) {
|
||||
@@ -89,7 +89,7 @@ public final class PlaybackEngine implements AutoCloseable {
|
||||
* Decodes until the next audio chunk is available, or end of stream.
|
||||
* Returns {@code null} at end of stream.
|
||||
*/
|
||||
public AudioChunk nextAudioChunk() throws IOException {
|
||||
public synchronized AudioChunk nextAudioChunk() throws IOException {
|
||||
int budget = 1000;
|
||||
while (audioQueue.isEmpty() && budget-- > 0) {
|
||||
if (!routeOne()) {
|
||||
@@ -100,7 +100,7 @@ public final class PlaybackEngine implements AutoCloseable {
|
||||
}
|
||||
|
||||
/** True once the stream has been fully decoded. */
|
||||
public boolean isEof() {
|
||||
public synchronized boolean isEof() {
|
||||
return eof && videoQueue.isEmpty() && audioQueue.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user