0
私は簡単なライブ壁紙アプリケーションを開発しました。その中で私はcaptureWallpaperとDrawWallpaperという2つのネイティブ関数を使用しました。その中でキャプチャの壁紙機能は以下のようなものですjni-Androidで可変反射を削除する
void Java_com_sample_NativeCalls_ captureWallpaper(JNIEnv * env, jobject this){
struct SwsContext *img_convert_ctx;
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) { avcodec_decode_video(pCodecCtx,
pFrame,
&frameFinished,
packet.data,
packet.size);
if(frameFinished) {
if(img_convert_ctx == NULL) {
w = pCodecCtx->width;
h = pCodecCtx->height;
__android_log_print(ANDROID_LOG_DEBUG,
"video.c",
"NDK: Cannot initialize the conversion context!"
);
img_convert_ctx =
sws_getContext(
w, h,
pCodecCtx->pix_fmt,
textureWidth,textureHeight,textureFormat,
SWS_FAST_BILINEAR,
NULL, NULL, NULL
);
if(img_convert_ctx == NULL) {
return;
}
}
sws_scale(img_convert_ctx,
pFrame->data,
pFrame->linesize,
0, pCodecCtx->height,
pFrameConverted->data,
pFrameConverted->linesize);
av_free_packet(&packet);
return;
}
}
av_free_packet(&packet);
}
av_seek_frame(pFormatCtx,videoStream,0,AVSEEK_FLAG_ANY);
}
その後、私はそれらの関数をJavaコードのonDraw関数で使用します。このメソッドを何度も呼び出すと、私のRAMメモリが増え続けます。私はいずれかのオブジェクトの参照が作成され、破壊されていないと思う。これを知っている人は、私がこれから出てくるのを助けてください。