Skip to content

Commit 4c82af8

Browse files
author
Alexander Matveev
committed
8236832: [macos 10.15] JavaFX Application hangs on video play on Cata…
Reviewed-by: kcr, ghb
1 parent 9cd6f79 commit 4c82af8

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFAudioProcessor.mm

+4
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,8 @@ void ProcessAudioTap(MTAudioProcessingTapRef tapRef,
279279
return;
280280
}
281281
}
282+
283+
if (context->audioSpectrum != nullptr) {
284+
context->audioSpectrum.get()->SetFirstBufferDelivered(true);
285+
}
282286
}

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFAudioSpectrumUnit.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ AVFAudioSpectrumUnit::AVFAudioSpectrumUnit() : mSpectrumCallbackProc(NULL),
4141
mMaxFrames(0),
4242
mSamplesPerInterval(0),
4343
mRebuildCrunch(true),
44+
mFirstBufferDelivered(false),
4445
mSpectrumElement(NULL),
4546
mSpectrum(NULL) {
4647
mMixBuffer.mNumberBuffers = 1;
@@ -191,7 +192,8 @@ void AVFAudioSpectrumUnit::UpdateBands(int size, const float* magnitudes, const
191192
// Call our listener to dispatch the spectrum event
192193
if (mSpectrumCallbackProc) {
193194
double duration = (double) mSamplesPerInterval / (double) 44100;
194-
mSpectrumCallbackProc(mSpectrumCallbackContext, duration);
195+
double timestamp = mFirstBufferDelivered ? -1.0 : 0.0;
196+
mSpectrumCallbackProc(mSpectrumCallbackContext, duration, timestamp);
195197
}
196198

197199
unlockBands();
@@ -214,6 +216,10 @@ void AVFAudioSpectrumUnit::SetSpectrumCallbackProc(AVFSpectrumUnitCallbackProc p
214216
mSpectrumCallbackContext = context;
215217
}
216218

219+
void AVFAudioSpectrumUnit::SetFirstBufferDelivered(bool isFirstBufferDelivered) {
220+
mFirstBufferDelivered = isFirstBufferDelivered;
221+
}
222+
217223
static gboolean PostMessageCallback(GstElement * element, GstMessage * message) {
218224
if (message == NULL) {
219225
return FALSE;

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFAudioSpectrumUnit.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
* timeStamp: the beginning time in seconds of the sample period (from beginning of stream)
5050
* duration: the length of time in seconds of the sample period
5151
*/
52-
typedef void (*AVFSpectrumUnitCallbackProc)(void *callbackContext, double duration);
52+
typedef void (*AVFSpectrumUnitCallbackProc)(void *callbackContext, double duration,
53+
double timestamp);
5354

5455
class AVFAudioSpectrumUnit : public CAudioSpectrum {
5556
public:
@@ -80,6 +81,7 @@ class AVFAudioSpectrumUnit : public CAudioSpectrum {
8081
void SetChannels(UInt32 count);
8182
void SetMaxFrames(UInt32 maxFrames);
8283
void SetSpectrumCallbackProc(AVFSpectrumUnitCallbackProc proc, void *context);
84+
void SetFirstBufferDelivered(bool isFirstBufferDelivered);
8385

8486
private:
8587
AVFSpectrumUnitCallbackProc mSpectrumCallbackProc;
@@ -102,6 +104,7 @@ class AVFAudioSpectrumUnit : public CAudioSpectrum {
102104
UInt32 mSamplesPerInterval;
103105

104106
bool mRebuildCrunch;
107+
bool mFirstBufferDelivered;
105108

106109
// GStreamer
107110
GstElement *mSpectrumElement;

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -87,7 +87,7 @@ static void append_log(NSMutableString *s, NSString *fmt, ...) {
8787

8888
@implementation AVFMediaPlayer
8989

90-
static void SpectrumCallbackProc(void *context, double duration);
90+
static void SpectrumCallbackProc(void *context, double duration, double timestamp);
9191

9292
static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink,
9393
const CVTimeStamp *inNow,
@@ -651,19 +651,21 @@ - (void) sendPixelBuffer:(CVPixelBufferRef)buf frameTime:(double)frameTime hostT
651651
eventHandler->SendNewFrameEvent(frame);
652652
}
653653

654-
- (void) sendSpectrumEventDuration:(double)duration {
654+
- (void) sendSpectrumEventDuration:(double)duration timestamp:(double)timestamp {
655655
if (eventHandler) {
656-
double timestamp = self.currentTime;
656+
if (timestamp < 0) {
657+
timestamp = self.currentTime;
658+
}
657659
eventHandler->SendAudioSpectrumEvent(timestamp, duration);
658660
}
659661
}
660662

661663
@end
662664

663-
static void SpectrumCallbackProc(void *context, double duration) {
665+
static void SpectrumCallbackProc(void *context, double duration, double timestamp) {
664666
if (context) {
665667
AVFMediaPlayer *player = (__bridge AVFMediaPlayer*)context;
666-
[player sendSpectrumEventDuration:duration];
668+
[player sendSpectrumEventDuration:duration timestamp:timestamp];
667669
}
668670
}
669671

0 commit comments

Comments
 (0)