Skip to content

Commit eeed219

Browse files
committed
Media : implement MediaVideoDecoder.change()
1 parent 113f9f6 commit eeed219

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

native/common/ff_av_decoder.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ 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
229+
JNIEXPORT jboolean JNICALL Java_javaforce_media_MediaAudioDecoder_nchange
230230
(JNIEnv *e, jobject c, jlong ctxptr, jint chs, jint freq)
231231
{
232232
//TODO
233+
return JNI_FALSE;
233234
}
234235

235236
//video decoder codebase
@@ -420,10 +421,40 @@ JNIEXPORT jfloat JNICALL Java_javaforce_media_MediaVideoDecoder_ngetFrameRate
420421
return ctx->video_codec_ctx->framerate.num / ctx->video_codec_ctx->framerate.den;
421422
}
422423

423-
JNIEXPORT void JNICALL Java_javaforce_media_MediaVideoDecoder_nchange
424-
(JNIEnv *e, jobject c, jlong ctxptr, jint width, jint height)
424+
JNIEXPORT jboolean JNICALL Java_javaforce_media_MediaVideoDecoder_nchange
425+
(JNIEnv *e, jobject c, jlong ctxptr, jint new_width, jint new_height)
425426
{
426-
//TODO
427-
}
427+
FFContext *ctx = castFFContext(e, c, ctxptr);
428+
if (ctx == NULL) return JNI_FALSE;
429+
430+
if (ctx->video_stream == NULL) return JNI_FALSE; //no video
431+
432+
if (ctx->rgb_video_dst_data[0] != NULL) {
433+
(*_av_free)(ctx->rgb_video_dst_data[0]);
434+
ctx->rgb_video_dst_data[0] = NULL;
435+
}
428436

437+
ctx->rgb_video_dst_bufsize = (*_av_image_alloc)(ctx->rgb_video_dst_data, ctx->rgb_video_dst_linesize
438+
, new_width, new_height, AV_PIX_FMT_BGRA, 1);
439+
if (ctx->rgb_video_dst_bufsize < 0) {
440+
printf("MediaDecoder:av_image_alloc() failed : %d\n", ctx->rgb_video_dst_bufsize);
441+
return JNI_FALSE;
442+
}
429443

444+
if (ctx->jvideo != NULL) {
445+
e->DeleteGlobalRef(ctx->jvideo);
446+
}
447+
ctx->jvideo_length = ctx->rgb_video_dst_bufsize/4;
448+
ctx->jvideo = (jintArray)ctx->e->NewGlobalRef(ctx->e->NewIntArray(ctx->jvideo_length));
449+
450+
if (ctx->sws_ctx != NULL) {
451+
(*_sws_freeContext)(ctx->sws_ctx);
452+
ctx->sws_ctx = NULL;
453+
}
454+
455+
ctx->sws_ctx = (*_sws_getContext)(ctx->video_codec_ctx->width, ctx->video_codec_ctx->height, ctx->video_codec_ctx->pix_fmt
456+
, new_width, new_height, AV_PIX_FMT_BGRA
457+
, SWS_BILINEAR, NULL, NULL, NULL);
458+
459+
return JNI_TRUE;
460+
}

native/common/ffmpeg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +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},
646+
{"nchange", "(JII)Z", (void *)&Java_javaforce_media_MediaAudioDecoder_nchange},
647647
};
648648

649649
static JNINativeMethod javaforce_media_MediaVideoDecoder[] = {
@@ -653,7 +653,7 @@ static JNINativeMethod javaforce_media_MediaVideoDecoder[] = {
653653
{"ngetWidth", "(J)I", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetWidth},
654654
{"ngetHeight", "(J)I", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetHeight},
655655
{"ngetFrameRate", "(J)F", (void *)&Java_javaforce_media_MediaVideoDecoder_ngetFrameRate},
656-
{"nchange", "(JII)V", (void *)&Java_javaforce_media_MediaVideoDecoder_nchange},
656+
{"nchange", "(JII)Z", (void *)&Java_javaforce_media_MediaVideoDecoder_nchange},
657657
};
658658

659659
static JNINativeMethod javaforce_media_MediaAudioEncoder[] = {

src/javaforce/media/MediaAudioDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ 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);
48+
private native boolean nchange(long ctx, int chs, int freq);
4949
/** Changes output chs/freq only. All other fields ignored. */
50-
public void change(CodecInfo info) {
51-
nchange(ctx, info.chs, info.freq);
50+
public boolean change(CodecInfo info) {
51+
return nchange(ctx, info.chs, info.freq);
5252
}
5353
}

src/javaforce/media/MediaVideoDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ 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);
53+
private native boolean nchange(long ctx, int width, int height);
5454
/** Changes output width/height only. All other fields ignored. */
55-
public void change(CodecInfo info) {
56-
nchange(ctx, info.width, info.height);
55+
public boolean change(CodecInfo info) {
56+
return nchange(ctx, info.width, info.height);
5757
}
5858
}

0 commit comments

Comments
 (0)