From 12a683f45fac1e6e3d8b17b62bdacf59d98d04f7 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Sun, 18 Jul 2021 18:44:54 +0800 Subject: [PATCH] adjust free order --- app/src/main/cpp/video_filter.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/src/main/cpp/video_filter.c b/app/src/main/cpp/video_filter.c index dbf762c..e84b0f3 100644 --- a/app/src/main/cpp/video_filter.c +++ b/app/src/main/cpp/video_filter.c @@ -344,7 +344,7 @@ VIDEO_PLAYER_FUNC(jint, filter, jstring filePath, jobject surface, jstring filte } //is video stream or not if (packet.stream_index == video_stream_index) { - //对该帧进行解码 + // decode frame by frame avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet); if (frameFinished) { @@ -389,22 +389,21 @@ VIDEO_PLAYER_FUNC(jint, filter, jstring filePath, jobject surface, jstring filte end: is_playing = 0; av_free(buffer); - av_free(pFrameRGBA); - av_free(filter_frame); - av_free(pFrame); - avcodec_close(pCodecCtx); - avformat_close_input(&pFormatCtx); + av_free(out_buffer); + sws_freeContext(sws_ctx); + swr_free(&audio_swr_ctx); avfilter_free(buffersrc_ctx); avfilter_free(buffersink_ctx); avfilter_graph_free(&filter_graph); - avcodec_close(audioCodecCtx); - free(buffer); - free(sws_ctx); - free(&windowBuffer); - free(out_buffer); - free(audio_swr_ctx); + avcodec_free_context(&pCodecCtx); + avcodec_free_context(&audioCodecCtx); + avformat_close_input(&pFormatCtx); + av_free(pFrameRGBA); + av_free(filter_frame); + av_free(pFrame); + free(audio_track); - free(audio_track_write_mid); + free(&windowBuffer); ANativeWindow_release(nativeWindow); (*env)->ReleaseStringUTFChars(env, filePath, file_name); (*env)->ReleaseStringUTFChars(env, filterDescr, filter_descr);