fix: can't exit
authoryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 14:52:06 +0000 (22:52 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 11 Apr 2023 14:52:06 +0000 (22:52 +0800)
simp_ffmpeg_output.c
simp_filter.c

index de3004d4b73ec93c7c0ca721a9e00b59f80b2830..ab38f256e8b7344ed2a74dac132e82583d1d9156 100644 (file)
@@ -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) {
index 826e3d60861f6d39719478a7c74220864a022bc9..91fe4e8a622415e6eac896a1f3e3b0eac3286fbc 100644 (file)
@@ -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);