@@ -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+ }
0 commit comments