|
|
|
@ -217,11 +217,18 @@ static int config_input(AVFilterLink *inlink) |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void flush(AVFrame *out, AVFilterLink *outlink, |
|
|
|
|
static void flush(SilenceRemoveContext *s, |
|
|
|
|
AVFrame *out, AVFilterLink *outlink, |
|
|
|
|
int *nb_samples_written, int *ret) |
|
|
|
|
{ |
|
|
|
|
if (*nb_samples_written) { |
|
|
|
|
out->nb_samples = *nb_samples_written / outlink->channels; |
|
|
|
|
|
|
|
|
|
out->pts = s->next_pts; |
|
|
|
|
s->next_pts += av_rescale_q(out->nb_samples, |
|
|
|
|
(AVRational){1, outlink->sample_rate}, |
|
|
|
|
outlink->time_base); |
|
|
|
|
|
|
|
|
|
*ret = ff_filter_frame(outlink, out); |
|
|
|
|
*nb_samples_written = 0; |
|
|
|
|
} else { |
|
|
|
@ -297,6 +304,12 @@ silence_trim_flush: |
|
|
|
|
|
|
|
|
|
memcpy(out->data[0], &s->start_holdoff[s->start_holdoff_offset], |
|
|
|
|
nbs * sizeof(double)); |
|
|
|
|
|
|
|
|
|
out->pts = s->next_pts; |
|
|
|
|
s->next_pts += av_rescale_q(out->nb_samples, |
|
|
|
|
(AVRational){1, outlink->sample_rate}, |
|
|
|
|
outlink->time_base); |
|
|
|
|
|
|
|
|
|
s->start_holdoff_offset += nbs; |
|
|
|
|
|
|
|
|
|
ret = ff_filter_frame(outlink, out); |
|
|
|
@ -330,7 +343,7 @@ silence_copy: |
|
|
|
|
|
|
|
|
|
if (threshold && s->stop_holdoff_end && !s->leave_silence) { |
|
|
|
|
s->mode = SILENCE_COPY_FLUSH; |
|
|
|
|
flush(out, outlink, &nb_samples_written, &ret); |
|
|
|
|
flush(s, out, outlink, &nb_samples_written, &ret); |
|
|
|
|
goto silence_copy_flush; |
|
|
|
|
} else if (threshold) { |
|
|
|
|
for (j = 0; j < inlink->channels; j++) { |
|
|
|
@ -358,7 +371,7 @@ silence_copy: |
|
|
|
|
|
|
|
|
|
if (!s->restart) { |
|
|
|
|
s->mode = SILENCE_STOP; |
|
|
|
|
flush(out, outlink, &nb_samples_written, &ret); |
|
|
|
|
flush(s, out, outlink, &nb_samples_written, &ret); |
|
|
|
|
goto silence_stop; |
|
|
|
|
} else { |
|
|
|
|
s->stop_found_periods = 0; |
|
|
|
@ -367,19 +380,25 @@ silence_copy: |
|
|
|
|
s->start_holdoff_end = 0; |
|
|
|
|
clear_window(s); |
|
|
|
|
s->mode = SILENCE_TRIM; |
|
|
|
|
flush(out, outlink, &nb_samples_written, &ret); |
|
|
|
|
flush(s, out, outlink, &nb_samples_written, &ret); |
|
|
|
|
goto silence_trim; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
s->mode = SILENCE_COPY_FLUSH; |
|
|
|
|
flush(out, outlink, &nb_samples_written, &ret); |
|
|
|
|
flush(s, out, outlink, &nb_samples_written, &ret); |
|
|
|
|
goto silence_copy_flush; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
flush(out, outlink, &nb_samples_written, &ret); |
|
|
|
|
flush(s, out, outlink, &nb_samples_written, &ret); |
|
|
|
|
} else { |
|
|
|
|
memcpy(obuf, ibuf, sizeof(double) * nbs * inlink->channels); |
|
|
|
|
|
|
|
|
|
out->pts = s->next_pts; |
|
|
|
|
s->next_pts += av_rescale_q(out->nb_samples, |
|
|
|
|
(AVRational){1, outlink->sample_rate}, |
|
|
|
|
outlink->time_base); |
|
|
|
|
|
|
|
|
|
ret = ff_filter_frame(outlink, out); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -401,6 +420,11 @@ silence_copy_flush: |
|
|
|
|
nbs * sizeof(double)); |
|
|
|
|
s->stop_holdoff_offset += nbs; |
|
|
|
|
|
|
|
|
|
out->pts = s->next_pts; |
|
|
|
|
s->next_pts += av_rescale_q(out->nb_samples, |
|
|
|
|
(AVRational){1, outlink->sample_rate}, |
|
|
|
|
outlink->time_base); |
|
|
|
|
|
|
|
|
|
ret = ff_filter_frame(outlink, out); |
|
|
|
|
|
|
|
|
|
if (s->stop_holdoff_offset == s->stop_holdoff_end) { |
|
|
|
@ -439,6 +463,12 @@ static int request_frame(AVFilterLink *outlink) |
|
|
|
|
|
|
|
|
|
memcpy(frame->data[0], &s->stop_holdoff[s->stop_holdoff_offset], |
|
|
|
|
nbs * sizeof(double)); |
|
|
|
|
|
|
|
|
|
frame->pts = s->next_pts; |
|
|
|
|
s->next_pts += av_rescale_q(frame->nb_samples, |
|
|
|
|
(AVRational){1, outlink->sample_rate}, |
|
|
|
|
outlink->time_base); |
|
|
|
|
|
|
|
|
|
ret = ff_filter_frame(ctx->inputs[0], frame); |
|
|
|
|
} |
|
|
|
|
s->mode = SILENCE_STOP; |
|
|
|
|