|
2 | 2 |
|
3 | 3 | import android.graphics.Bitmap; |
4 | 4 | import io.github.deltacv.visionloop.processor.Processor; |
5 | | -import io.github.deltacv.visionloop.tj.TJLoader; |
6 | 5 | import io.javalin.Javalin; |
7 | 6 | import io.javalin.http.Handler; |
| 7 | +import org.deltacv.mackjpeg.JPEGCompressor; |
| 8 | +import org.deltacv.mackjpeg.MackJPEG; |
| 9 | +import org.deltacv.mackjpeg.PixelFormat; |
| 10 | +import org.deltacv.mackjpeg.turbojpeg.TurboJPEGBackend; |
8 | 11 | import org.eclipse.jetty.io.EofException; |
9 | 12 | import org.firstinspires.ftc.robotcore.internal.collections.EvictingBlockingQueue; |
10 | 13 | import org.jetbrains.skia.impl.BufferUtil; |
11 | | -import org.libjpegturbo.turbojpeg.TJ; |
12 | | -import org.libjpegturbo.turbojpeg.TJCompressor; |
13 | 14 | import org.opencv.core.*; |
14 | 15 | import org.opencv.imgproc.Imgproc; |
15 | 16 | import org.openftc.easyopencv.MatRecycler; |
@@ -70,10 +71,6 @@ public class MjpegHttpStreamSink extends CanvasViewportSink { |
70 | 71 | private final BlockingQueue<CompressedFrame> compressedFrames = new ArrayBlockingQueue<>(QUEUE_SIZE); |
71 | 72 | private final AtomicBoolean isRunning = new AtomicBoolean(true); |
72 | 73 |
|
73 | | - static { |
74 | | - TJLoader.load(); |
75 | | - } |
76 | | - |
77 | 74 | /** |
78 | 75 | * Represents a compressed JPEG frame ready to be sent to clients |
79 | 76 | */ |
@@ -147,21 +144,21 @@ private void submitCompressionTask(MatRecycler.RecyclableMat frame) { |
147 | 144 | frameCopy.get(0, 0, frameData); |
148 | 145 | frameCopy.returnMat(); |
149 | 146 |
|
150 | | - TJCompressor compressor = new TJCompressor(); |
| 147 | + JPEGCompressor compressor = MackJPEG.getSupportedBackend().makeCompressor(); |
| 148 | + |
151 | 149 | try { |
152 | 150 | synchronized (qualityLock){ |
153 | | - compressor.setJPEGQuality(quality); |
| 151 | + compressor.setQuality(quality); |
154 | 152 | } |
155 | 153 |
|
156 | | - compressor.setSubsamp(TJ.SAMP_440); |
157 | | - compressor.setSourceImage(frameData, frame.width(), 0, frame.height(), TJ.PF_BGR); |
| 154 | + compressor.setImage(frameData, frame.width(), frame.height(), PixelFormat.RGB); |
158 | 155 |
|
159 | 156 | byte[] buffer = getOrCreateReusableBuffer(2_000_000); // Pre-allocate buffer |
160 | | - compressor.compress(buffer, TJ.FLAG_FASTDCT); |
| 157 | + compressor.compress(buffer); |
161 | 158 |
|
162 | 159 | returnReusableBuffer(frameData); |
163 | 160 |
|
164 | | - int compressedSize = (int) compressor.getCompressedSize(); |
| 161 | + int compressedSize = compressor.getCompressedSize(); |
165 | 162 |
|
166 | 163 | // Add compressed frame to the output queue if we're still running |
167 | 164 | if (isRunning.get()) { |
|
0 commit comments