include config.make
-java_MODULES=notzed.jjmpeg #notzed.jjmpeg.fx notzed.jjmpeg.awt notzed.jjmpeg.demo
+java_MODULES=notzed.jjmpeg notzed.jjmpeg.fx notzed.jjmpeg.awt notzed.jjmpeg.demo
notzed.jjmpeg.awt_JDEPMOD=notzed.jjmpeg
notzed.jjmpeg.fx_JDEPMOD=notzed.jjmpeg
package au.notzed.jjmpeg.demo.audio;
import au.notzed.jjmpeg.AVChannelLayout;
+import au.notzed.jjmpeg.AVObject;
import au.notzed.jjmpeg.AVSampleFormat;
import au.notzed.jjmpeg.AVSampleReader;
import au.notzed.jjmpeg.io.JJMediaReader;
import java.io.IOException;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.Arena;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
int outputBits = 16;
long outputLayout = 0;
+ AVObject.init();
+
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "--rate":
return;
}
- try (MemorySession scope = MemorySession.openConfined();
- JJMediaReader mr = new JJMediaReader(path, scope)) {
+ try (Arena arena = Arena.openConfined();
+ JJMediaReader mr = new JJMediaReader(path, arena.scope())) {
JJMediaReader.JJReaderAudio as = mr.openDefaultStream(JJMediaReader.TYPE_AUDIO);
if (as == null)
byte[] buffer = new byte[8192];
System.err.printf("Audio: %s\n", path);
- System.err.printf(" source format: %s %.1f Hz %s\n", AVSampleFormat.toString(fmt), (double) rate, AVChannelLayout.toString(layout));
+ System.err.printf(" source format: %s %.1f Hz %s\n", AVSampleFormat.toString(fmt), (double)rate, AVChannelLayout.toString(layout));
System.err.printf(" output format: %s\n", format);
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss.SSS");
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.Arena;
+import java.lang.foreign.SegmentScope;
import java.util.IllegalFormatException;
import javax.imageio.ImageIO;
System.err.println("Unknown extension");
type = format.substring(dot + 1).toLowerCase();
- try (MemorySession scope = MemorySession.openConfined();
- JJMediaReader mr = new JJMediaReader(path, scope)) {
+ try (Arena arena = Arena.openConfined();
+ JJMediaReader mr = new JJMediaReader(path, arena.scope())) {
int index = 0;
JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
import java.io.FileNotFoundException;
import java.io.IOException;
import static java.lang.Double.min;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.Arena;
import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
* @param path
*/
void reader(String path) {
- try (MemorySession scope = MemorySession.openConfined();
- JJMediaReader mr = new JJMediaReader(path, scope)) {
+ try (Arena arena = Arena.openConfined();
+ JJMediaReader mr = new JJMediaReader(path, arena.scope())) {
JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
if (vs != null) {
import au.notzed.jjmpeg.AVPixelFormat;
import au.notzed.jjmpeg.io.JJMediaReader;
import java.io.IOException;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.Arena;
+import java.lang.foreign.SegmentScope;
/**
* A simple video scanner.
String path = args[0];
- try (MemorySession scope = MemorySession.openConfined();
- JJMediaReader mr = new JJMediaReader(path, scope)) {
+ try (Arena arena = Arena.openConfined();
+ JJMediaReader mr = new JJMediaReader(path, arena.scope())) {
int count = 0;
JJMediaReader.JJReaderVideo vs = mr.openDefaultStream(JJMediaReader.TYPE_VIDEO);
package au.notzed.jjmpeg;
import au.notzed.nativez.*;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
import java.util.logging.Logger;
/**
System.loadLibrary("avutil");
AVUtil.setLogger(AVUtil.createAVLogger(Logger.getLogger("notzed.jjmpeg")),
- MemorySession.global());
+ SegmentScope.global());
}
/**
import java.nio.Buffer;
import java.nio.BufferOverflowException;
import au.notzed.nativez.*;
+import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
-import java.lang.foreign.MemorySession;
public class FramePixelReader implements AVPixelReader {
final int dwidth, dheight, flags;
int dfmt = -1;
- MemorySession scope = MemorySession.openImplicit();
+ Arena arena = Arena.openShared();
MemorySegment seg;
public FramePixelReader(AVFrame frame, int dwidth, int dheight, int flags) {
//Memory.free(seg.baseAddress());
}
//seg = Memory.ofNative(Memory.malloc(size), size);
- seg = MemorySegment.allocateNative(size, 16, scope);
+ seg = arena.allocate(size, 16);
}
return seg;
}
SwsContext ctx = getContext(fmt);
// FIXME: check sizes
- try ( Frame a = Frame.frame()) {
- IntArray stride = IntArray.createArray(4, a);
- PointerArray data = PointerArray.createArray(4, a);
+ try (Frame a = Frame.frame()) {
+ IntArray stride = IntArray.create(4, a);
+ PointerArray data = PointerArray.create(4, a);
int res;
res = AVUtil.av_image_fill_linesizes(stride, fmt, dwidth);
}
public long bufferSize(int h, int fmt) {
- try ( Frame a = Frame.frame()) {
- IntArray stride = IntArray.createArray(4, a);
- PointerArray data = PointerArray.createArray(4, a);
+ try (Frame a = Frame.frame()) {
+ IntArray stride = IntArray.create(4, a);
+ PointerArray data = PointerArray.create(4, a);
int res;
res = AVUtil.av_image_fill_linesizes(stride, fmt, dwidth);
}
public void release() {
- if (scope != null) {
- scope.close();
- scope = null;
+ if (arena != null) {
+ arena.close();
+ arena = null;
}
}
}
import au.notzed.nativez.Frame;
import au.notzed.nativez.HandleArray;
import java.io.FileNotFoundException;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
import java.util.AbstractList;
import java.util.List;
import java.util.logging.Logger;
* @see #getStreams
* @see #readFrame
*/
- public JJMediaReader(String name, MemorySession scope) throws AVIOException, FileNotFoundException {
+ public JJMediaReader(String name, SegmentScope scope) throws AVIOException, FileNotFoundException {
this(name, null, null, scope);
}
- public JJMediaReader(String name, AVInputFormat fmt, HandleArray<AVDictionary> options, MemorySession scope) throws AVIOException, FileNotFoundException {
+ public JJMediaReader(String name, AVInputFormat fmt, HandleArray<AVDictionary> options, SegmentScope scope) throws AVIOException, FileNotFoundException {
this(AVFormatContext.openInput(name, fmt, options, scope));
}
duration = stream.getDuration();
durationms = tb.rescale(duration, 1000);
- try ( Frame f = Frame.frame()) {
+ try (Frame f = Frame.frame()) {
// conservatively assume keyframe every 32 frames
seekOffsetMS = stream.getAverageFrameRate().inv(f).rescale(1000, 32);
import au.notzed.jjmpeg.AVMediaType;
import au.notzed.jjmpeg.AVSampleFormat;
import au.notzed.nativez.Frame;
-import java.lang.foreign.MemorySession;
+import java.lang.foreign.SegmentScope;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
*
* @param filename
*/
- public JJMediaWriter(String filename, MemorySession scope) throws AVIOException {
+ public JJMediaWriter(String filename, SegmentScope scope) throws AVIOException {
this.filename = filename;
oc = AVFormatContext.allocOutputContext(null, null, filename, scope);
code:<inline> {{
// not relly ideal but it'll do
- public void free() { free(segment.address()); }
- public void close() { close(segment.address()); }
+ public void free() { free(segment); }
+ public void close() { close(segment); }
}}
}
}
public void free() {
try (Frame frame = Frame.frame()) {
- PointerArray holder = PointerArray.createArray(1, frame);
- holder.set(0, segment.address());
+ PointerArray holder = PointerArray.create(1, frame);
+ holder.set(0, segment);
freeContext(holder);
}
}
}
public void free() {
try (Frame frame = Frame.frame()) {
- PointerArray holder = PointerArray.createArray(1, frame);
- holder.set(0, segment.address());
+ PointerArray holder = PointerArray.create(1, frame);
+ holder.set(0, segment);
freeFrame(holder);
}
}
code:<inline> {{
public void free() {
try (Frame frame = Frame.frame()) {
- PointerArray holder = PointerArray.createArray(1, frame);
- holder.set(0, segment.address());
+ PointerArray holder = PointerArray.create(1, frame);
+ holder.set(0, segment);
freePacket(holder);
}
}
};
}
- public static void setLogger(AVLogger log, MemorySession scope) {
+ public static void setLogger(AVLogger log, SegmentScope scope) {
AVUtil.av_log_set_callback(AVLogFunc.upcall((avcl, level, fmt, valist) -> {
try (Frame frame = Frame.frame()) {
- ByteArray line = ByteArray.createArray(1024, frame);
+ ByteArray line = ByteArray.create(1024, frame);
IntArray print_prefix = IntArray.create(frame, 1);
AVUtil.av_log_format_line2(avcl, level, fmt, valist, line, print_prefix);
log.log(level, line.toUtf8String());