Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include "libavutil/avstring.h" #include "libavutil/eval.h" #include "libavutil/opt.h" #include "libavutil/samplefmt.h" #include "avfilter.h" #include "audio.h" #include "filters.h" #include "internal.h" typedef struct ChanDelay { int64_t delay; size_t delay_index; size_t index; unsigned int samples_size; uint8_t *samples; } ChanDelay; typedef struct AudioDelayContext { const AVClass *class; int all; char *delays; ChanDelay *chandelay; int nb_delays; int block_align; int64_t padding; int64_t max_delay; int64_t next_pts; int eof; void (*delay_channel)(ChanDelay *d, int nb_samples, const uint8_t *src, uint8_t *dst); int (*resize_channel_samples)(ChanDelay *d, int64_t new_delay); } AudioDelayContext; #define OFFSET(x) offsetof(AudioDelayContext, x) #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM static const AVOption adelay_options[] = { { "delays", "set list of delays for each channel", OFFSET(delays), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, A | AV_OPT_FLAG_RUNTIME_PARAM }, { "all", "use last available delay for remained channels", OFFSET(all), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A }, { NULL } }; AVFILTER_DEFINE_CLASS(adelay); #define DELAY(name, type, fill) \ static void delay_channel_## name ##p(ChanDelay *d, int nb_samples, \ const uint8_t *ssrc, uint8_t *ddst) \ { \ const type *src = (type *)ssrc; \ type *dst = (type *)ddst; \ type *samples = (type *)d->samples; \ \ while (nb_samples) { \ if (d->delay_index < d->delay) { \ const int len = FFMIN(nb_samples, d->delay - d->delay_index); \ \ memcpy(&samples[d->delay_index], src, len * sizeof(type)); \ memset(dst, fill, len * sizeof(type)); \ d->delay_index += len; \ src += len; \ dst += len; \ nb_samples -= len; \ } else { \ *dst = samples[d->index]; \ samples[d->index] = *src; \ nb_samples--; \ d->index++; \ src++, dst++; \ d->index = d->index >= d->delay ? 0 : d->index; \ } \ } \ } DELAY(u8, uint8_t, 0x80) DELAY(s16, int16_t, 0) DELAY(s32, int32_t, 0) DELAY(flt, float, 0) DELAY(dbl, double, 0) #define CHANGE_DELAY(name, type, fill) \ static int resize_samples_## name ##p(ChanDelay *d, int64_t new_delay) \ { \ type *samples = (type *)d->samples; \ \ if (new_delay == 0) { \ av_freep(&d->samples); \ d->samples_size = 0; \ d->delay = 0; \ d->index = 0; \ return 0; \ } \ \ d->samples = av_fast_realloc(d->samples, &d->samples_size, new_delay * sizeof(type)); \ if (!d->samples) { \ av_freep(samples); \ return AVERROR(ENOMEM); \ } \ samples = (type *)d->samples; \ if (new_delay < d->delay) { \ if (d->index > new_delay) { \ d->index -= new_delay; \ memmove(samples, &samples[new_delay], d->index * sizeof(type)); \ } else if (d->delay_index > d->index) { \ memmove(&samples[d->index], &samples[d->index+(d->delay-new_delay)], \ (new_delay - d->index) * sizeof(type)); \ } \ d->delay_index = new_delay; \ } else { \ size_t block_size; \ if (d->delay_index >= d->delay) { \ block_size = (d->delay - d->index) * sizeof(type); \ memmove(&samples[d->index+(new_delay - d->delay)], &samples[d->index], block_size); \ d->delay_index = new_delay; \ } else { \ d->delay_index += new_delay - d->delay; \ } \ block_size = (new_delay - d->delay) * sizeof(type); \ memset(&samples[d->index], fill, block_size); \ } \ d->delay = new_delay; \ d->samples = (void *) samples; \ return 0; \ } CHANGE_DELAY(u8, uint8_t, 0x80) CHANGE_DELAY(s16, int16_t, 0) CHANGE_DELAY(s32, int32_t, 0) CHANGE_DELAY(flt, float, 0) CHANGE_DELAY(dbl, double, 0) static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; AudioDelayContext *s = ctx->priv; char *p, *arg, *saveptr = NULL; int i; s->chandelay = av_calloc(inlink->channels, sizeof(*s->chandelay)); if (!s->chandelay) return AVERROR(ENOMEM); s->nb_delays = inlink->channels; s->block_align = av_get_bytes_per_sample(inlink->format); p = s->delays; for (i = 0; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; float delay, div; char type = 0; int ret; if (!(arg = av_strtok(p, "|", &saveptr))) break; p = NULL; ret = av_sscanf(arg, "%"SCNd64"%c", &d->delay, &type); if (ret != 2 || type != 'S') { div = type == 's' ? 1.0 : 1000.0; if (av_sscanf(arg, "%f", &delay) != 1) { av_log(ctx, AV_LOG_ERROR, "Invalid syntax for delay.\n"); return AVERROR(EINVAL); } d->delay = delay * inlink->sample_rate / div; } if (d->delay < 0) { av_log(ctx, AV_LOG_ERROR, "Delay must be non negative number.\n"); return AVERROR(EINVAL); } } if (s->all && i) { for (int j = i; j < s->nb_delays; j++) s->chandelay[j].delay = s->chandelay[i-1].delay; } s->padding = s->chandelay[0].delay; for (i = 1; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; s->padding = FFMIN(s->padding, d->delay); } if (s->padding) { for (i = 0; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; d->delay -= s->padding; } } for (i = 0; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; if (!d->delay) continue; if (d->delay > SIZE_MAX) { av_log(ctx, AV_LOG_ERROR, "Requested delay is too big.\n"); return AVERROR(EINVAL); } d->samples = av_malloc_array(d->delay, s->block_align); if (!d->samples) return AVERROR(ENOMEM); d->samples_size = d->delay * s->block_align; s->max_delay = FFMAX(s->max_delay, d->delay); } switch (inlink->format) { case AV_SAMPLE_FMT_U8P : s->delay_channel = delay_channel_u8p ; s->resize_channel_samples = resize_samples_u8p; break; case AV_SAMPLE_FMT_S16P: s->delay_channel = delay_channel_s16p; s->resize_channel_samples = resize_samples_s16p; break; case AV_SAMPLE_FMT_S32P: s->delay_channel = delay_channel_s32p; s->resize_channel_samples = resize_samples_s32p; break; case AV_SAMPLE_FMT_FLTP: s->delay_channel = delay_channel_fltp; s->resize_channel_samples = resize_samples_fltp; break; case AV_SAMPLE_FMT_DBLP: s->delay_channel = delay_channel_dblp; s->resize_channel_samples = resize_samples_dblp; break; } return 0; } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags) { int ret = AVERROR(ENOSYS); AVFilterLink *inlink = ctx->inputs[0]; AudioDelayContext *s = ctx->priv; if (!strcmp(cmd, "delays")) { // if(flags & AVFILTER_CMD_FLAG_ONE) { // return 0; // } int64_t delay; av_sscanf(args, "%"SCNd64, &delay); if (delay > SIZE_MAX) { av_log(ctx, AV_LOG_ERROR, "Requested delay is too big.\n"); return AVERROR(EINVAL); } s->max_delay = 0; delay = delay * inlink->sample_rate / 1000.0; for (int i = 0; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; av_log(ctx, AV_LOG_INFO, "old delay: %ld\n", d->delay); ret = s->resize_channel_samples(d, delay); s->max_delay = FFMAX(s->max_delay, d->delay); av_log(ctx, AV_LOG_INFO, "new delay: %ld\n", d->delay); } } return ret; } static int filter_frame(AVFilterLink *inlink, AVFrame *frame) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; AudioDelayContext *s = ctx->priv; AVFrame *out_frame; int i; if (ctx->is_disabled || !s->delays) return ff_filter_frame(outlink, frame); out_frame = ff_get_audio_buffer(outlink, frame->nb_samples); if (!out_frame) { av_frame_free(&frame); return AVERROR(ENOMEM); } av_frame_copy_props(out_frame, frame); for (i = 0; i < s->nb_delays; i++) { ChanDelay *d = &s->chandelay[i]; const uint8_t *src = frame->extended_data[i]; uint8_t *dst = out_frame->extended_data[i]; if (!d->delay) memcpy(dst, src, frame->nb_samples * s->block_align); else s->delay_channel(d, frame->nb_samples, src, dst); } out_frame->pts = s->next_pts; s->next_pts += av_rescale_q(frame->nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); av_frame_free(&frame); return ff_filter_frame(outlink, out_frame); } static int activate(AVFilterContext *ctx) { AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; AudioDelayContext *s = ctx->priv; AVFrame *frame = NULL; int ret, status; int64_t pts; FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); if (s->padding) { int nb_samples = FFMIN(s->padding, 2048); frame = ff_get_audio_buffer(outlink, nb_samples); if (!frame) return AVERROR(ENOMEM); s->padding -= nb_samples; av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->channels, frame->format); frame->pts = s->next_pts; if (s->next_pts != AV_NOPTS_VALUE) s->next_pts += av_rescale_q(nb_samples, (AVRational){1, outlink->sample_rate}, outlink->time_base); return ff_filter_frame(outlink, frame); } ret = ff_inlink_consume_frame(inlink, &frame); if (ret < 0) return ret; if (ret > 0) return filter_frame(inlink, frame); if (ff_inlink_acknowledge_status(inlink, &status, &pts)) { if (status == AVERROR_EOF) s->eof = 1; } if (s->eof && s->max_delay) { int nb_samples = FFMIN(s->max_delay, 2048); frame = ff_get_audio_buffer(outlink, nb_samples); if (!frame) return AVERROR(ENOMEM); s->max_delay -= nb_samples; av_samples_set_silence(frame->extended_data, 0, frame->nb_samples, outlink->channels, frame->format); frame->pts = s->next_pts; return filter_frame(inlink, frame); } if (s->eof && s->max_delay == 0) { ff_outlink_set_status(outlink, AVERROR_EOF, s->next_pts); return 0; } if (!s->eof) FF_FILTER_FORWARD_WANTED(outlink, inlink); return FFERROR_NOT_READY; } static av_cold void uninit(AVFilterContext *ctx) { AudioDelayContext *s = ctx->priv; if (s->chandelay) { for (int i = 0; i < s->nb_delays; i++) av_freep(&s->chandelay[i].samples); } av_freep(&s->chandelay); } static const AVFilterPad adelay_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_input, }, }; static const AVFilterPad adelay_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, }, }; const AVFilter ff_af_adelay = { .name = "adelay", .description = NULL_IF_CONFIG_SMALL("Delay one or more audio channels."), .priv_size = sizeof(AudioDelayContext), .priv_class = &adelay_class, .activate = activate, .uninit = uninit, FILTER_INPUTS(adelay_inputs), FILTER_OUTPUTS(adelay_outputs), FILTER_SAMPLEFMTS(AV_SAMPLE_FMT_U8P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_DBLP), .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL, .process_command = process_command, };
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
25 min ago | 14.56 KB
py_PYTHON-FROM-CLI-RUN-HIDDEN-PYW
1 hour ago | 0.05 KB
Untitled
2 hours ago | 14.19 KB
Untitled
4 hours ago | 13.68 KB
Untitled
6 hours ago | 14.74 KB
Untitled
8 hours ago | 16.88 KB
Warum Systeme scheitern
8 hours ago | 33.75 KB
supahffej
8 hours ago | 7.50 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!