Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions webrtc-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<maven.deploy.skip>true</maven.deploy.skip>
<maven.install.skip>true</maven.install.skip>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>12.0.23</jetty.version>
</properties>

<build>
Expand Down Expand Up @@ -48,6 +49,13 @@
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<targetPath>resources</targetPath>
</resource>
</resources>
</build>

<dependencies>
Expand All @@ -56,5 +64,34 @@
<artifactId>webrtc-java</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>

<!-- JSON Processing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.17</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 WebRTC Java Contributors
* Copyright 2025 Alex Andres
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 WebRTC Java Contributors
* Copyright 2025 Alex Andres
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 WebRTC Java Contributors
* Copyright 2025 Alex Andres
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/*
* Example application that demonstrates how to set up a WebRTC peer connection,
* create an offer, and accept a remote answer.
* Copyright 2025 Alex Andres
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.onvoid.webrtc.examples;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2025 Alex Andres
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.onvoid.webrtc.examples.util;

import dev.onvoid.webrtc.media.audio.AudioTrackSink;
import dev.onvoid.webrtc.media.video.VideoFrame;
import dev.onvoid.webrtc.media.video.VideoTrackSink;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Utility class for logging audio and video frame information.
*
* @author Alex Andres
*/
public class MediaFrameLogger {

private static final Logger LOG = LoggerFactory.getLogger(MediaFrameLogger.class);


/**
* Creates a new audio track sink that logs information about received audio data.
*
* @return An AudioTrackSink that logs audio frame information.
*/
public static AudioTrackSink createAudioLogger() {
return new AudioFrameLogger();
}

/**
* Creates a new video track sink that logs information about received video frames.
*
* @return A VideoTrackSink that logs video frame information.
*/
public static VideoTrackSink createVideoLogger() {
return new VideoFrameLogger();
}



/**
* A simple implementation of AudioTrackSink that logs information about received audio data.
*/
private static class AudioFrameLogger implements AudioTrackSink {

private static final long LOG_INTERVAL_MS = 1000; // Log every second
private int frameCount = 0;
private long lastLogTime = System.currentTimeMillis();

@Override
public void onData(byte[] data, int bitsPerSample, int sampleRate, int channels, int frames) {
frameCount++;

long now = System.currentTimeMillis();
if (now - lastLogTime >= LOG_INTERVAL_MS) {
LOG.info(String.format("Received %d audio frames in the last %.1f seconds",
frameCount, (now - lastLogTime) / 1000.0));
LOG.info(String.format("Last audio data: %d bytes, %d bits/sample, %d Hz, %d channels, %d frames",
data.length, bitsPerSample, sampleRate, channels, frames));

frameCount = 0;
lastLogTime = now;
}
}
}



/**
* A simple implementation of VideoTrackSink that logs information about received frames.
*/
private static class VideoFrameLogger implements VideoTrackSink {

private static final long LOG_INTERVAL_MS = 1000; // Log every second
private int frameCount = 0;
private long lastLogTime = System.currentTimeMillis();

@Override
public void onVideoFrame(VideoFrame frame) {
frameCount++;

long now = System.currentTimeMillis();
if (now - lastLogTime >= LOG_INTERVAL_MS) {
LOG.info(String.format("Received %d video frames in the last %.1f seconds",
frameCount, (now - lastLogTime) / 1000.0));
LOG.info(String.format("Last frame: %dx%d, rotation: %d, timestamp: %dms",
frame.buffer.getWidth(), frame.buffer.getHeight(), frame.rotation,
frame.timestampNs / 1000000));

frameCount = 0;
lastLogTime = now;
}

// Release the native resources associated with this frame to prevent memory leaks.
frame.release();
}
}
}
Loading
Loading