Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix media recorder audio/video delay on the native implementation #32

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ all while utilizing the same codebase.
<!-- since the platform related libraries are no more needed-->
<!-- <scope>compile</scope>-->
</dependency>

<!-- when running on desktop/device only-->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>flandmark-platform</artifactId>
<version>1.07-1.5.8</version>
<scope>runtime</scope>
</dependency>
</dependencies>
```

Expand All @@ -192,7 +184,6 @@ plugins {
dependencies {
implementation("one.jpro.platform:jpro-media:0.2.11-SNAPSHOT")
implementation "org.bytedeco:javacv-platform:1.5.9" // use compileOnly configuration when running/deploying with JPro
runtimeOnly 'org.bytedeco:flandmark-platform:1.07-1.5.8' // when running on desktop/device only
}
```

Expand Down
1 change: 0 additions & 1 deletion jpro-media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ plugins {

dependencies {
implementation 'one.jpro.platform:jpro-media:0.2.11-SNAPSHOT'
runtimeOnly 'org.bytedeco:flandmark-platform:1.07-1.5.8' // when running on desktop/device only

// use compileOnly configuration when running/deploying with JPro,
// since the platform specific libraries are no more needed
Expand Down
2 changes: 1 addition & 1 deletion jpro-media/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
dependencies {
implementation "com.sandec.jpro:jpro-webapi:$JPRO_VERSION"
compileOnly "org.bytedeco:javacv-platform:$JAVACV_VERSION"
runtimeOnly 'org.bytedeco:flandmark-platform:1.07-1.5.8'
api "org.slf4j:slf4j-api:$SLF4J_API_VERSION"
api "org.json:json:$JSON_VERSION"

testImplementation "org.testfx:testfx-junit5:$TESTFX_VERSION"
testImplementation "org.bytedeco:javacv-platform:$JAVACV_VERSION"
testRuntimeOnly 'org.bytedeco:flandmark-platform:1.07-1.5.8'
}

compileJava {
Expand Down
1 change: 0 additions & 1 deletion jpro-media/example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {

implementation "org.bytedeco:javacv-platform:$JAVACV_VERSION"
// compileOnly "org.bytedeco:javacv-platform:$JAVACV_VERSION" // when running on JPro
runtimeOnly 'org.bytedeco:flandmark-platform:1.07-1.5.8' // when running on desktop/device only
implementation "io.github.mkpaz:atlantafx-base:$ATLANTAFX_VERSION"
runtimeOnly "ch.qos.logback:logback-classic:$LOGBACK_VERSION"
}
Expand Down
12 changes: 6 additions & 6 deletions jpro-media/src/main/java/one/jpro/platform/media/MediaView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import one.jpro.platform.media.player.impl.WebMediaPlayer;
import one.jpro.platform.media.player.impl.WebMediaPlayerView;
import one.jpro.platform.media.recorder.MediaRecorder;
import one.jpro.platform.media.recorder.impl.FXMediaRecorder;
import one.jpro.platform.media.recorder.impl.FXMediaRecorderView;
import one.jpro.platform.media.recorder.impl.WebMediaRecorder;
import one.jpro.platform.media.recorder.impl.WebMediaRecorderView;
import one.jpro.platform.media.recorder.NativeMediaRecorder;
import one.jpro.platform.media.recorder.NativeMediaRecorderView;
import one.jpro.platform.media.recorder.WebMediaRecorder;
import one.jpro.platform.media.recorder.WebMediaRecorderView;

/**
* Provides a view of {@link MediaSource} being played by a {@link MediaPlayer}
Expand Down Expand Up @@ -136,8 +136,8 @@ public static MediaView create(MediaPlayer mediaPlayer) {
* @return a {@link MediaView} object.
*/
public static MediaView create(MediaRecorder mediaRecorder) {
if (mediaRecorder instanceof FXMediaRecorder fxMediaRecorder) {
return new FXMediaRecorderView(fxMediaRecorder);
if (mediaRecorder instanceof NativeMediaRecorder fxMediaRecorder) {
return new NativeMediaRecorderView(fxMediaRecorder);
} else if (mediaRecorder instanceof WebMediaRecorder webMediaRecorder) {
return new WebMediaRecorderView(webMediaRecorder);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import one.jpro.platform.media.recorder.impl.WebMediaRecorder;
import one.jpro.platform.media.recorder.WebMediaRecorder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package one.jpro.platform.media.recorder.impl;
package one.jpro.platform.media.recorder;

import com.sun.javafx.event.EventHandlerManager;
import javafx.application.Platform;
Expand All @@ -12,8 +12,6 @@
import javafx.util.Duration;
import one.jpro.platform.media.MediaSource;
import one.jpro.platform.media.event.MediaRecorderEvent;
import one.jpro.platform.media.recorder.MediaRecorder;
import one.jpro.platform.media.recorder.MediaRecorderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -28,14 +26,14 @@
*/
abstract class BaseMediaRecorder implements MediaRecorder {

private static final Logger logger = LoggerFactory.getLogger(BaseMediaRecorder.class);

private RecorderTimerTask recorderTimerTask;
volatile boolean recorderReady;
volatile boolean isUpdateDurationEnabled;
long startRecordingTime = 0;
private double pauseDurationTime = 0;

private final Logger log = LoggerFactory.getLogger(BaseMediaRecorder.class);

// media source property (read-only)
ReadOnlyObjectWrapper<MediaSource> mediaSource;

Expand Down Expand Up @@ -119,12 +117,12 @@ public Duration getDuration() {
return (duration == null) ? Duration.ZERO : duration.get();
}

void setDuration(Duration value) {
final void setDuration(Duration value) {
durationPropertyImpl().set(value);
}

@Override
public ReadOnlyObjectProperty<Duration> durationProperty() {
public final ReadOnlyObjectProperty<Duration> durationProperty() {
return durationPropertyImpl().getReadOnlyProperty();
}

Expand All @@ -134,7 +132,7 @@ private ReadOnlyObjectWrapper<Duration> durationPropertyImpl() {

@Override
protected void invalidated() {
log.trace("Recording duration: {} s", get().toSeconds());
logger.trace("Recording duration: {} s", get().toSeconds());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import one.jpro.platform.media.MediaSource;
import one.jpro.platform.media.MediaView;
import one.jpro.platform.media.event.MediaRecorderEvent;
import one.jpro.platform.media.recorder.impl.FXMediaRecorder;
import one.jpro.platform.media.recorder.impl.WebMediaRecorder;

import java.util.Optional;

Expand Down Expand Up @@ -60,7 +58,7 @@ static MediaRecorder create(Stage stage) {
final WebAPI webAPI = WebAPI.getWebAPI(stage);
return new WebMediaRecorder(webAPI);
}
return new FXMediaRecorder();
return new NativeMediaRecorder();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package one.jpro.platform.media.recorder.impl;
package one.jpro.platform.media.recorder;

import org.json.JSONObject;

Expand Down
Loading