From: Michael Zucchi Date: Wed, 16 Oct 2019 22:10:46 +0000 (+1030) Subject: Add FrameSideData api. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=1d8c9b0c70170a340dff111e218ab761c4d57577;p=jjmpeg Add FrameSideData api. Some minor medieareader tweaks. --- diff --git a/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/AVFrame.java b/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/AVFrame.java index 3a8ad2d..ca2032e 100644 --- a/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/AVFrame.java +++ b/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/AVFrame.java @@ -59,6 +59,8 @@ public class AVFrame extends AVObject { */ public native void unref(); + public native AVFrameSideData getSideData(int type); + /* * Data stuff. *

diff --git a/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/io/JJMediaReader.java b/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/io/JJMediaReader.java index 6c3d6b2..9892eaf 100644 --- a/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/io/JJMediaReader.java +++ b/src/notzed.jjmpeg/classes/au/notzed/jjmpeg/io/JJMediaReader.java @@ -24,7 +24,6 @@ import au.notzed.jjmpeg.AVCodecID; import au.notzed.jjmpeg.AVCodecParameters; import au.notzed.jjmpeg.AVDictionary; import au.notzed.jjmpeg.AVDiscardBits; -import au.notzed.jjmpeg.AVError; import au.notzed.jjmpeg.AVFormatContext; import au.notzed.jjmpeg.AVFrame; import au.notzed.jjmpeg.AVIOException; @@ -37,6 +36,7 @@ import au.notzed.jjmpeg.AVSampleFormat; import au.notzed.jjmpeg.AVStream; import java.io.FileNotFoundException; import java.util.Iterator; +import java.util.List; import java.util.logging.Logger; /** @@ -127,7 +127,7 @@ public class JJMediaReader implements AutoCloseable { * @throws AVIOException */ public T openDefaultStream(Class type) throws AVIOException { - for (JJReaderStream rs : streams) { + for (JJReaderStream rs: streams) { if (type.isInstance(rs)) { T m = type.cast(rs); if (!m.isOpened()) @@ -138,6 +138,10 @@ public class JJMediaReader implements AutoCloseable { return null; } + public List getStreams() { + return List.of(streams); + } + public Iterable streams() { return () -> { return new Iterator() { @@ -157,7 +161,7 @@ public class JJMediaReader implements AutoCloseable { } public void release() { - for (JJReaderStream m : streams) { + for (JJReaderStream m: streams) { m.release(); } format.release(); @@ -196,13 +200,13 @@ public class JJMediaReader implements AutoCloseable { * e.g. after a seek. */ public void flushCodec() { - for (JJReaderStream rs : streams) { + for (JJReaderStream rs: streams) { rs.flushCodec(); } } private long currentVideoMS() { - for (JJReaderStream r : streams) { + for (JJReaderStream r: streams) { if (r instanceof JJReaderVideo) { return r.convertPTS(getPTS()); } @@ -374,8 +378,10 @@ public class JJMediaReader implements AutoCloseable { this.cp = cp; // Hmm, what if i want to override CodedID? codec = AVCodec.findDecoder(cp.getCodecID()); - if (codec == null) - throw new AVIOException(AVError.AVERROR_DECODER_NOT_FOUND); + if (codec == null) { + frame = null; + return; + } c = AVCodecContext.allocContext(codec); @@ -467,7 +473,17 @@ public class JJMediaReader implements AutoCloseable { * @return */ public long convertPTS(long pts) { - return tb.rescale(pts, 1000) - startms; + return tb.rescale(pts - startpts, 1000); + } + + /** + * Convert the 'pts' to milliseconds as presented in the stream. + * + * @param pts + * @return + */ + public long absolutePTS(long pts) { + return tb.rescale(pts, 1000); } /** @@ -538,7 +554,7 @@ public class JJMediaReader implements AutoCloseable { @Override public void open() throws AVIOException { - throw new AVIOException(AVError.AVERROR_UNKNOWN, "Unknown stream type"); + //throw new AVIOException(AVError.AVERROR_UNKNOWN, "Unknown stream type"); } @Override @@ -559,9 +575,9 @@ public class JJMediaReader implements AutoCloseable { @Override public void open() throws AVIOException { - if (cp.getPixelFormat() == AVPixelFormat.AV_PIX_FMT_NONE) { - throw new AVIOException(AVError.AVERROR_INVALIDDATA, "No decodable video present"); - } + //if (cp.getPixelFormat() == AVPixelFormat.AV_PIX_FMT_NONE) { + // throw new AVIOException(AVError.AVERROR_INVALIDDATA, "No decodable video present"); + //} Logger.getLogger("jjmpeg.io") .fine(() -> { diff --git a/src/notzed.jjmpeg/gen/gen.make b/src/notzed.jjmpeg/gen/gen.make index 76b758b..296573b 100644 --- a/src/notzed.jjmpeg/gen/gen.make +++ b/src/notzed.jjmpeg/gen/gen.make @@ -28,6 +28,7 @@ notzed.jjmpeg_JAVA_GENERATED = \ au/notzed/jjmpeg/AVCodecIDBits.java \ au/notzed/jjmpeg/AVDiscardBits.java \ au/notzed/jjmpeg/AVErrorBits.java \ + au/notzed/jjmpeg/AVFrameSideDataTypeBits.java \ au/notzed/jjmpeg/AVIOContextBits.java \ au/notzed/jjmpeg/AVMediaTypeBits.java \ au/notzed/jjmpeg/AVOptionsBits.java \ @@ -68,6 +69,10 @@ $(tmp)/AVDiscardBits-gen.c: $(extract_enum) $(dep) @install -d $(@D) perl $(extract_enum) -I$(FFMPEG_HOME)/include AVDiscard AVDISCARD_ $(FFMPEG_HOME)/include/libavcodec/avcodec.h $@ +$(tmp)/AVFrameSideDataTypeBits-gen.c: $(extract_defines) $(dep) + @install -d $(@D) + perl $(extract_enum) -I$(FFMPEG_HOME)/include AVFrameSideDataType AV_FRAME_ $(FFMPEG_HOME)/include/libavutil/frame.h $@ + $(tmp)/AVChannelLayoutBits-gen.c: $(extract_enum) $(dep) @install -d $(@D) perl $(extract_defines) -f $(FFMPEG_HOME) -interface AVChannelLayoutBits -header libavutil/channel_layout.h -type long -d AV_CH_LAYOUT_ $@ diff --git a/src/notzed.jjmpeg/jni/jj-avframe.c b/src/notzed.jjmpeg/jni/jj-avframe.c index d2eb767..a5f97be 100644 --- a/src/notzed.jjmpeg/jni/jj-avframe.c +++ b/src/notzed.jjmpeg/jni/jj-avframe.c @@ -30,7 +30,8 @@ #define MAX(a, b) ((a)>(b)?(a):(b)) jint AVFrame_OnLoad(JavaVM *vmi, JNIEnv *env) { - return nativez_ResolveFunctions(env, jj_libtable, fn_names, &fn); + return nativez_ResolveReferences(env, java_names, &java) + || nativez_ResolveFunctions(env, jj_libtable, fn_names, &fn); } /* ********************************************************************** */ @@ -248,6 +249,18 @@ JNIEXPORT void JNICALL Java_au_notzed_jjmpeg_AVFrame_unref DLCALL(av_frame_unref)(frame); } +JNIEXPORT jobject JNICALL Java_au_notzed_jjmpeg_AVFrame_getSideData +(JNIEnv *env, jobject jo, jint type) { + AVFrame *frame = NativeZ_getP(env, jo); + AVFrameSideData *sd; + + printf("get side data len=%d type=%d\n", frame->nb_side_data, type); + fflush(stdout); + + sd = DLCALL(av_frame_get_side_data)(frame, type); + return NativeZ_refer(env, AVFrameSideData_classid, sd); +} + /* ********************************************************************** */ /* FrameReader */ diff --git a/src/notzed.jjmpeg/jni/jj-avframe.def b/src/notzed.jjmpeg/jni/jj-avframe.def index a409b7e..5a251b8 100644 --- a/src/notzed.jjmpeg/jni/jj-avframe.def +++ b/src/notzed.jjmpeg/jni/jj-avframe.def @@ -8,6 +8,7 @@ header avutil libavutil/frame.h { av_frame_unref av_frame_get_buffer + av_frame_get_side_data } header avutil libavutil/imgutils.h { @@ -38,4 +39,7 @@ header swresample libswresample/swresample.h { swr_init swr_convert swr_get_out_samples -} \ No newline at end of file +} + +java AVFrameSideData au/notzed/jjmpeg/AVFrameSideData { +} diff --git a/src/notzed.jjmpeg/jni/jni.make b/src/notzed.jjmpeg/jni/jni.make index a712c73..ef0fc36 100644 --- a/src/notzed.jjmpeg/jni/jni.make +++ b/src/notzed.jjmpeg/jni/jni.make @@ -28,6 +28,7 @@ jjmpeg_SOURCES = \ jj-avdevice.c \ jj-avformatcontext.c \ jj-avframe.c \ + jj-avframesidedata.c \ jj-aviocontext.c \ jj-avmisc.c \ jj-avoptions.c \