From cf1095675c0118ad0e4b2969c4638cedd473cb75 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 11 Apr 2023 22:52:06 +0800 Subject: [PATCH] fix: can't exit --- simp_ffmpeg_output.c | 21 ++++++++++----------- simp_filter.c | 9 +++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/simp_ffmpeg_output.c b/simp_ffmpeg_output.c index de3004d..ab38f25 100644 --- a/simp_ffmpeg_output.c +++ b/simp_ffmpeg_output.c @@ -392,7 +392,6 @@ static void* __ffmpeg_output_run(void* arg) } } - pthread_mutex_lock(&io->mutex); while(!scf_list_empty(&io->vout)) { l = scf_list_head(&io->vout); @@ -436,19 +435,19 @@ static void* __ffmpeg_output_run(void* arg) while (av_audio_fifo_size(priv->afifo) > 0) { - if (0 == io->error && io->flush) { + ret = av_audio_fifo_read(priv->afifo, (void**)priv->aframe->data, 1024); + if (ret < 0) { + scf_loge("ret: %d\n", ret); + io->error = ret; + break; + } - ret = av_audio_fifo_read(priv->afifo, (void**)priv->aframe->data, 1024); - if (ret < 0) { - scf_loge("ret: %d\n", ret); - io->error = ret; - break; - } + priv->nb_samples += priv->aframe->nb_samples; + priv->aframe->pts = priv->nb_samples; - priv->nb_samples += priv->aframe->nb_samples; - priv->aframe->pts = priv->nb_samples; + scf_logd("aframe->pts: %ld\n", priv->aframe->pts); - scf_logd("aframe->pts: %ld\n", priv->aframe->pts); + if (0 == io->error && io->flush) { ret = __ffmpeg_encode(io, priv->acodec_ctx, priv->apkt, priv->aframe, priv->aidx); if (ret < 0) { diff --git a/simp_filter.c b/simp_filter.c index 826e3d6..91fe4e8 100644 --- a/simp_filter.c +++ b/simp_filter.c @@ -243,6 +243,9 @@ int simp_filter_close(simp_filter_t* f, int flush) io->abuffersrc_ctx = NULL; io->vbuffersrc_ctx = NULL; + if (flush) + io->flush = 1; + simp_avio_close(io); io = NULL; } @@ -251,6 +254,9 @@ int simp_filter_close(simp_filter_t* f, int flush) io = scf_list_data(l, simp_avio_t, list); l = scf_list_next(l); + if (flush) + io->flush = 1; + scf_list_del(&io->list); simp_avio_close(io); io = NULL; @@ -477,6 +483,9 @@ static void* __filter_run(void* arg) pthread_mutex_unlock(&io->mutex); vf = NULL; } + + if (f->flush) + io->flush = 1; } av_frame_unref(f->vframe); -- 2.25.1