Skip to content

Commit 113f9f6

Browse files
committed
Media - add change() prototype to MediaAudioDecoder and MediaVideoDecoder - set all native fields to private
1 parent 3d022cb commit 113f9f6

File tree

6 files changed

+44
-18
lines changed

6 files changed

+44
-18
lines changed

native/common/ff_av_decoder.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ JNIEXPORT jint JNICALL Java_javaforce_media_MediaAudioDecoder_ngetSampleRate
226226
return ctx->audio_codec_ctx->sample_rate;
227227
}
228228

229+
JNIEXPORT void JNICALL Java_javaforce_media_MediaAudioDecoder_nchange
230+
(JNIEnv *e, jobject c, jlong ctxptr, jint chs, jint freq)
231+
{
232+
//TODO
233+
}
234+
229235
//video decoder codebase
230236

231237
JNIEXPORT jlong JNICALL Java_javaforce_media_MediaVideoDecoder_nstart
@@ -413,3 +419,11 @@ JNIEXPORT jfloat JNICALL Java_javaforce_media_MediaVideoDecoder_ngetFrameRate
413419
if (ctx->video_codec_ctx->framerate.den == 0) return 0;
414420
return ctx->video_codec_ctx->framerate.num / ctx->video_codec_ctx->framerate.den;
415421
}
422+
423+
JNIEXPORT void JNICALL Java_javaforce_media_MediaVideoDecoder_nchange
424+
(JNIEnv *e, jobject c, jlong ctxptr, jint width, jint height)
425+
{
426+
//TODO
427+
}
428+
429+

native/common/ffmpeg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ static JNINativeMethod javaforce_media_MediaAudioDecoder[] = {
643643
{"ndecode", "(J[BII)[S", (void *)&Java_javaforce_media_MediaAudioDecoder_ndecode},
644644
{"ngetChannels", "(J)I", (void *)&Java_javaforce_media_MediaAudioDecoder_ngetChannels},
645645
{"ngetSampleRate", "(J)I", (void *)&Java_javaforce_media_MediaAudioDecoder_ngetSampleRate},
646+
{"nchange", "(JII)V", (void *)&Java_javaforce_media_MediaAudioDecoder_nchange},
646647
};
647648

648649
static JNINativeMethod javaforce_media_MediaVideoDecoder[] = {
@@ -652,6 +653,7 @@ static JNINativeMethod javaforce_media_MediaVideoDecoder[] = {
652653
{"ngetWidth", "(J)I", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetWidth},
653654
{"ngetHeight", "(J)I", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetHeight},
654655
{"ngetFrameRate", "(J)F", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetFrameRate},
656+
{"nchange", "(JII)V", (void *)&Java_javaforce_media_MediaVideoDecoder_nchange},
655657
};
656658

657659
static JNINativeMethod javaforce_media_MediaAudioEncoder[] = {

src/javaforce/media/MediaAudioDecoder.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,39 @@ public MediaAudioDecoder(MediaInput input) {
1515
this.ctx = input.ctx;
1616
shared = true;
1717
}
18-
public native long nstart(int codec_id, int new_chs, int new_freq);
18+
private native long nstart(int codec_id, int new_chs, int new_freq);
1919
public boolean start(int codec_id, int new_chs, int new_freq) {
2020
if (ctx != 0 || shared) return false;
2121
ctx = nstart(codec_id, new_chs, new_freq);
2222
return ctx != 0;
2323
}
24-
public native void nstop(long ctx);
24+
private native void nstop(long ctx);
2525
public void stop() {
2626
if (ctx == 0 || shared) return;
2727
nstop(ctx);
2828
ctx = 0;
2929
}
30-
public native short[] ndecode(long ctx, byte[] data, int offset, int length);
30+
private native short[] ndecode(long ctx, byte[] data, int offset, int length);
3131
public short[] decode(byte[] data, int offset, int length) {
3232
if (ctx == 0) return null;
3333
return ndecode(ctx, data, offset, length);
3434
}
3535
public short[] decode(Packet packet) {
3636
return decode(packet.data, packet.offset, packet.length);
3737
}
38-
public native int ngetChannels(long ctx);
38+
private native int ngetChannels(long ctx);
3939
public int getChannels() {
4040
if (ctx == 0) return -1;
4141
return ngetChannels(ctx);
4242
}
43-
public native int ngetSampleRate(long ctx);
43+
private native int ngetSampleRate(long ctx);
4444
public int getSampleRate() {
4545
if (ctx == 0) return -1;
4646
return ngetSampleRate(ctx);
4747
}
48+
private native void nchange(long ctx, int chs, int freq);
49+
/** Changes output chs/freq only. All other fields ignored. */
50+
public void change(CodecInfo info) {
51+
nchange(ctx, info.chs, info.freq);
52+
}
4853
}

src/javaforce/media/MediaAudioEncoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ public MediaAudioEncoder(MediaOutput output) {
1616
this.ctx = output.ctx;
1717
shared = true;
1818
}
19-
public native long nstart(int codec_id, int bit_rate, int chs, int freq);
19+
private native long nstart(int codec_id, int bit_rate, int chs, int freq);
2020
public boolean start(CodecInfo info) {
2121
if (ctx != 0 || shared) return false;
2222
ctx = nstart(info.audio_codec, info.audio_bit_rate, info.chs, info.freq);
2323
return ctx != 0;
2424
}
25-
public native void nstop(long ctx);
25+
private native void nstop(long ctx);
2626
public void stop() {
2727
if (ctx == 0 || shared) return;
2828
nstop(ctx);
2929
ctx = 0;
3030
}
3131
private Packet packet;
32-
public native byte[] nencode(long ctx, short[] samples, int offset, int length);
32+
private native byte[] nencode(long ctx, short[] samples, int offset, int length);
3333
public Packet encode(short[] samples, int offset, int length) {
3434
if (ctx == 0) {
3535
JFLog.log("MediaAudioEncoder no ctx");
@@ -47,7 +47,7 @@ public Packet encode(short[] samples, int offset, int length) {
4747
packet.length = packet.data.length;
4848
return packet;
4949
}
50-
public native int ngetAudioFramesize(long ctx);
50+
private native int ngetAudioFramesize(long ctx);
5151
public int getAudioFramesize() {
5252
return ngetAudioFramesize(ctx);
5353
}

src/javaforce/media/MediaVideoDecoder.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,44 @@ public MediaVideoDecoder(MediaInput input) {
1515
this.ctx = input.ctx;
1616
shared = true;
1717
}
18-
public native long nstart(int codec_id, int new_width, int new_height);
18+
private native long nstart(int codec_id, int new_width, int new_height);
1919
public boolean start(int codec_id, int new_width, int new_height) {
2020
if (ctx != 0 || shared) return false;
2121
ctx = nstart(codec_id, new_width, new_height);
2222
return ctx != 0;
2323
}
24-
public native void nstop(long ctx);
24+
private native void nstop(long ctx);
2525
public void stop() {
2626
if (ctx == 0 || shared) return;
2727
nstop(ctx);
2828
ctx = 0;
2929
}
30-
public native int[] ndecode(long ctx, byte[] data, int offset, int length);
30+
private native int[] ndecode(long ctx, byte[] data, int offset, int length);
3131
public int[] decode(byte[] data, int offset, int length) {
3232
if (ctx == 0) return null;
3333
return ndecode(ctx, data, offset, length);
3434
}
3535
public int[] decode(Packet packet) {
3636
return decode(packet.data, packet.offset, packet.length);
3737
}
38-
public native int ngetWidth(long ctx);
38+
private native int ngetWidth(long ctx);
3939
public int getWidth() {
4040
if (ctx == 0) return -1;
4141
return ngetWidth(ctx);
4242
}
43-
public native int ngetHeight(long ctx);
43+
private native int ngetHeight(long ctx);
4444
public int getHeight() {
4545
if (ctx == 0) return -1;
4646
return ngetHeight(ctx);
4747
}
48-
public native float ngetFrameRate(long ctx);
48+
private native float ngetFrameRate(long ctx);
4949
public float getFrameRate() {
5050
if (ctx == 0) return -1;
5151
return ngetFrameRate(ctx);
5252
}
53+
private native void nchange(long ctx, int width, int height);
54+
/** Changes output width/height only. All other fields ignored. */
55+
public void change(CodecInfo info) {
56+
nchange(ctx, info.width, info.height);
57+
}
5358
}

src/javaforce/media/MediaVideoEncoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ public MediaVideoEncoder(MediaOutput output) {
1515
this.ctx = output.ctx;
1616
shared = true;
1717
}
18-
public native long nstart(int codec_id, int bit_rate, int width, int height, float fps, int keyFrameInterval);
18+
private native long nstart(int codec_id, int bit_rate, int width, int height, float fps, int keyFrameInterval);
1919
public boolean start(CodecInfo info) {
2020
if (ctx != 0 || shared) return false;
2121
ctx = nstart(info.video_codec, info.video_bit_rate, info.width, info.height, info.fps, info.keyFrameInterval);
2222
return ctx != 0;
2323
}
24-
public native void nstop(long ctx);
24+
private native void nstop(long ctx);
2525
public void stop() {
2626
if (ctx == 0 || shared) return;
2727
nstop(ctx);
2828
ctx = 0;
2929
}
3030
private Packet packet;
31-
public native byte[] nencode(long ctx, int[] px, int offset, int length);
31+
private native byte[] nencode(long ctx, int[] px, int offset, int length);
3232
public Packet encode(int[] px, int offset, int length) {
3333
if (ctx == 0) return null;
3434
if (packet == null) {

0 commit comments

Comments
 (0)