]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/af_afade.c
avfilter/af_arnndn: reduce size of second_check[] table
[ffmpeg] / libavfilter / af_afade.c
index 751db7da4d6715bea9ab259429d24d4dcbb1e8b1..4edfd27a3c610484480f63ce409bba76101f0ed2 100644 (file)
@@ -51,7 +51,7 @@ typedef struct AudioFadeContext {
                               int curve0, int curve1);
 } AudioFadeContext;
 
-enum CurveType { TRI, QSIN, ESIN, HSIN, LOG, IPAR, QUA, CUB, SQU, CBR, PAR, EXP, IQSIN, IHSIN, DESE, DESI, LOSI, NB_CURVES };
+enum CurveType { TRI, QSIN, ESIN, HSIN, LOG, IPAR, QUA, CUB, SQU, CBR, PAR, EXP, IQSIN, IHSIN, DESE, DESI, LOSI, NONE, NB_CURVES };
 
 #define OFFSET(x) offsetof(AudioFadeContext, x)
 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
@@ -153,6 +153,9 @@ static double fade_gain(int curve, int64_t index, int64_t range)
                    gain = (A - B) / (C - B);
                }
         break;
+    case NONE:
+        gain = 1.0;
+        break;
     }
 
     return gain;
@@ -260,6 +263,7 @@ static const AVOption afade_options[] = {
     { "dese",         "double-exponential seat",                     0,                    AV_OPT_TYPE_CONST,  {.i64 = DESE }, 0, 0, FLAGS, "curve" },
     { "desi",         "double-exponential sigmoid",                  0,                    AV_OPT_TYPE_CONST,  {.i64 = DESI }, 0, 0, FLAGS, "curve" },
     { "losi",         "logistic sigmoid",                            0,                    AV_OPT_TYPE_CONST,  {.i64 = LOSI }, 0, 0, FLAGS, "curve" },
+    { "nofade",       "no fade; keep audio as-is",                   0,                    AV_OPT_TYPE_CONST,  {.i64 = NONE }, 0, 0, FLAGS, "curve" },
     { NULL }
 };
 
@@ -380,6 +384,7 @@ static const AVOption acrossfade_options[] = {
     {     "dese",     "double-exponential seat",                       0,                    AV_OPT_TYPE_CONST,  {.i64 = DESE }, 0, 0, FLAGS, "curve" },
     {     "desi",     "double-exponential sigmoid",                    0,                    AV_OPT_TYPE_CONST,  {.i64 = DESI }, 0, 0, FLAGS, "curve" },
     {     "losi",     "logistic sigmoid",                              0,                    AV_OPT_TYPE_CONST,  {.i64 = LOSI }, 0, 0, FLAGS, "curve" },
+    {     "nofade",   "no fade; keep audio as-is",                     0,                    AV_OPT_TYPE_CONST,  {.i64 = NONE }, 0, 0, FLAGS, "curve" },
     { "curve2",       "set fade curve type for 2nd stream",            OFFSET(curve2),       AV_OPT_TYPE_INT,    {.i64 = TRI  }, 0, NB_CURVES - 1, FLAGS, "curve" },
     { "c2",           "set fade curve type for 2nd stream",            OFFSET(curve2),       AV_OPT_TYPE_INT,    {.i64 = TRI  }, 0, NB_CURVES - 1, FLAGS, "curve" },
     { NULL }
@@ -449,21 +454,22 @@ static int activate(AVFilterContext *ctx)
 
     if (s->crossfade_is_over) {
         ret = ff_inlink_consume_frame(ctx->inputs[1], &in);
-        if (ret < 0) {
+        if (ret > 0) {
+            in->pts = s->pts;
+            s->pts += av_rescale_q(in->nb_samples,
+                      (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
+            return ff_filter_frame(outlink, in);
+        } else if (ret < 0) {
             return ret;
         } else if (ff_inlink_acknowledge_status(ctx->inputs[1], &status, &pts)) {
             ff_outlink_set_status(ctx->outputs[0], status, pts);
             return 0;
-        } else {
-            if (ff_outlink_frame_wanted(ctx->outputs[0]) && !in) {
+        } else if (!ret) {
+            if (ff_outlink_frame_wanted(ctx->outputs[0])) {
                 ff_inlink_request_frame(ctx->inputs[1]);
                 return 0;
             }
         }
-        in->pts = s->pts;
-        s->pts += av_rescale_q(in->nb_samples,
-            (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
-        return ff_filter_frame(outlink, in);
     }
 
     if (ff_inlink_queued_samples(ctx->inputs[0]) > s->nb_samples) {
@@ -478,7 +484,8 @@ static int activate(AVFilterContext *ctx)
         s->pts += av_rescale_q(in->nb_samples,
             (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
         return ff_filter_frame(outlink, in);
-    } else if (ff_inlink_queued_samples(ctx->inputs[1]) >= s->nb_samples) {
+    } else if (ff_inlink_queued_samples(ctx->inputs[0]) >= s->nb_samples &&
+               ff_inlink_queued_samples(ctx->inputs[1]) >= s->nb_samples && s->cf0_eof) {
         if (s->overlap) {
             out = ff_get_audio_buffer(outlink, s->nb_samples);
             if (!out)