mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Revert to mjpeg (#645)
* Reverted to front end using MJPEG streams. Added FPS limiting to the stream. * formatting * fixup - got handlers getting called on error to reload * revised architecture to let a click open a new tab Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ import java.util.function.Consumer;
|
||||
import org.opencv.core.MatOfByte;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.imgcodecs.Imgcodecs;
|
||||
import org.photonvision.common.util.math.MathUtils;
|
||||
import org.photonvision.vision.frame.Frame;
|
||||
import org.photonvision.vision.frame.consumer.MJPGFrameConsumer;
|
||||
|
||||
@@ -39,11 +40,14 @@ public class SocketVideoStream implements Consumer<Frame> {
|
||||
|
||||
// Synclock around manipulating the jpeg bytes from multiple threads
|
||||
Lock jpegBytesLock = new ReentrantLock();
|
||||
|
||||
MJPGFrameConsumer oldSchoolServer;
|
||||
|
||||
private int userCount = 0;
|
||||
|
||||
// FPS-limited MJPEG sender
|
||||
private final double FPS_MAX = 30.0;
|
||||
private final long minFramePeriodNanos = Math.round(1000000000.0 / FPS_MAX);
|
||||
private long nextFrameSendTime = MathUtils.wpiNanoTime() + minFramePeriodNanos;
|
||||
MJPGFrameConsumer oldSchoolServer;
|
||||
|
||||
public SocketVideoStream(int portID) {
|
||||
this.portID = portID;
|
||||
oldSchoolServer =
|
||||
@@ -73,7 +77,13 @@ public class SocketVideoStream implements Consumer<Frame> {
|
||||
}
|
||||
}
|
||||
}
|
||||
oldSchoolServer.accept(frame);
|
||||
|
||||
// Send the frame in an FPS-limited fashion
|
||||
var now = MathUtils.wpiNanoTime();
|
||||
if (now > nextFrameSendTime) {
|
||||
oldSchoolServer.accept(frame);
|
||||
nextFrameSendTime = now + minFramePeriodNanos;
|
||||
}
|
||||
}
|
||||
|
||||
public ByteBuffer getJPEGByteBuffer() {
|
||||
|
||||
Reference in New Issue
Block a user