Skip to content

Commit

Permalink
Make some internal implementations final and apply some cleanup on th…
Browse files Browse the repository at this point in the history
…e media recorder classes
  • Loading branch information
besidev committed Jan 12, 2024
1 parent ae62ff5 commit 1c4e6d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,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 @@ -117,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 @@ -132,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 @@ -119,12 +119,17 @@ public NativeMediaRecorder() {
}));
}

ImageView getCameraView() {
/**
* Returns the {@link ImageView} instance used to display video frames captured from the camera.
*
* @return <code>ImageView</code> instance showing the captured video frames
*/
public final ImageView getCameraView() {
return cameraView;
}

@Override
public void enable() {
public final void enable() {
if (recorderReady) {
logger.info("Media recorder is already enabled.");
} else {
Expand Down Expand Up @@ -243,7 +248,7 @@ private void enableAudioCapture() {
/**
* Records a single video frame.
*
* @param frame the video frame to be recorded.
* @param frame the video frame to be recorded
*/
private void writeVideoFrame(Frame frame) {
if (recorder != null && recording) {
Expand Down Expand Up @@ -271,7 +276,7 @@ private void writeAudioSamples(ShortBuffer audioSamples) {
}

@Override
public void start() {
public final void start() {
if (getStatus().equals(Status.INACTIVE) || getStatus().equals(Status.READY)) {
final Runnable startRecordingRunnable = () -> {
// Start the recording if the camera is enabled
Expand Down Expand Up @@ -336,7 +341,7 @@ public void start() {
}

@Override
public void pause() {
public final void pause() {
// Disable recording
recording = false;

Expand All @@ -350,7 +355,7 @@ public void pause() {
}

@Override
public void stop() {
public final void stop() {
final Runnable startRecordingRunnable = () -> {
stopRecording();

Expand Down Expand Up @@ -390,7 +395,7 @@ private void stopRecording() {
/**
* Stop the acquisition from the camera and microphone and release all the resources.
*/
public void release() {
public final void release() {
recorderReady = false;
recording = false;
releaseVideoResources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public NativeMediaRecorderView(NativeMediaRecorder mediaRecorder) {
}

@Override
public ObjectProperty<MediaEngine> mediaEngineProperty() {
public final ObjectProperty<MediaEngine> mediaEngineProperty() {
if (mediaEngine == null) {
mediaEngine = new SimpleObjectProperty<>(this, "mediaEngine") {

Expand Down Expand Up @@ -60,7 +60,7 @@ protected void invalidated() {
}

@Override
public DoubleProperty fitHeightProperty() {
public final DoubleProperty fitHeightProperty() {
if (fitHeight == null) {
fitHeight = new SimpleDoubleProperty(this, "fitHeight") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @author Besmir Beqiri
*/
public final class WebMediaRecorder extends BaseMediaRecorder implements WebMediaEngine {
public class WebMediaRecorder extends BaseMediaRecorder implements WebMediaEngine {

private static final String DEFAULT_MIME_TYPE = "video/webm";

Expand Down Expand Up @@ -118,12 +118,12 @@ public WebMediaRecorder(WebAPI webAPI) {
}

@Override
public WebAPI getWebAPI() {
public final WebAPI getWebAPI() {
return webAPI;
}

@Override
public JSVariable getVideoElement() {
public final JSVariable getVideoElement() {
return recorderVideoElement;
}

Expand All @@ -138,7 +138,7 @@ public JSVariable getVideoElement() {
* specified format.
* @throws Exception
*/
public boolean isTypeSupported(String mimeType) throws Exception {
public final boolean isTypeSupported(String mimeType) throws Exception {
return Boolean.getBoolean(webAPI.executeScriptWithReturn("""
MediaRecorder.isTypeSupported("%s")
""".formatted(mimeType)));
Expand All @@ -147,15 +147,15 @@ public boolean isTypeSupported(String mimeType) throws Exception {
// mimeType property (read-only)
private ReadOnlyStringWrapper mimeType;

public String getMimeType() {
public final String getMimeType() {
return (mimeType == null) ? DEFAULT_MIME_TYPE : mimeType.get();
}

private void setMimeType(String value) {
mimeTypePropertyImpl().set(value);
}

public ReadOnlyStringProperty mimeTypeProperty() {
public final ReadOnlyStringProperty mimeTypeProperty() {
return mimeTypePropertyImpl().getReadOnlyProperty();
}

Expand All @@ -168,7 +168,7 @@ private ReadOnlyStringWrapper mimeTypePropertyImpl() {

// Recorder controller methods
@Override
public void enable() {
public final void enable() {
final var mediaRecorderOptions = new MediaRecorderOptions().mimeType(getMimeType());
webAPI.executeScript("""
$blobsRecorded = []; // stream buffer
Expand Down Expand Up @@ -218,7 +218,7 @@ public void enable() {
}

@Override
public void start() {
public final void start() {
if (recorderReady) {
if (getStatus().equals(Status.INACTIVE) || getStatus().equals(Status.READY)) {
webAPI.executeScript("""
Expand All @@ -238,7 +238,7 @@ public void start() {
}

@Override
public void pause() {
public final void pause() {
if (recorderReady) {
webAPI.executeScript("""
if ($mediaRecorder.state === "recording") {
Expand All @@ -249,7 +249,7 @@ public void pause() {
}

@Override
public void stop() {
public final void stop() {
if (recorderReady) {
webAPI.executeScript("""
$mediaRecorder.stop();
Expand Down

0 comments on commit 1c4e6d3

Please sign in to comment.