37#define SBG_SCALE (1 << 16)
38#define DAY (24 * 60 * 60)
39#define DAY_TS ((int64_t)DAY * AV_TIME_BASE)
40#define SBG_MAX_CHANNELS 16
165 int *
size,
int *max_size)
169 if (*
size == *max_size) {
170 int m =
FFMAX(32,
FFMIN(*max_size, INT_MAX / 2) * 2);
179 memset(
ret, 0, elsize);
186 const char *cur = str;
192 if (*cur <
'0' || *cur >
'9')
194 hours = strtol(cur, &end, 10);
195 if (end == cur || *end !=
':' || end[1] <
'0' || end[1] >
'9')
198 minutes = strtol(cur, &end, 10);
203 seconds =
strtod(cur + 1, &end);
214 return c ==
' ' ||
c ==
'\t' ||
c ==
'\r';
220 if (isnan(m) || m < INT_MIN || m >= INT_MAX) {
222 av_log(log,
AV_LOG_ERROR,
"%g is %s\n", d, isnan(m) ?
"not a valid number" :
"too large");
233 while (p->cursor < p->end &&
is_space(*p->cursor))
235 return p->cursor >
c;
240 int r = p->cursor < p->end && *p->cursor ==
c;
251 if (p->cursor == p->end ||
is_space(*p->cursor) || *p->cursor ==
'\n')
253 d =
strtod(p->cursor, &end);
254 if (end > p->cursor) {
264 if (p->end - p->cursor < l || memcmp(p->cursor, t, l))
272 if (p->cursor < p->end && *p->cursor ==
'#') {
274 while (p->cursor < p->end && *p->cursor !=
'\n')
277 if (p->cursor == p->end)
280 if (*p->cursor !=
'\n')
290 char *
s = p->cursor, *
c =
s;
292 if (
s == p->end || *
s ==
'\n')
297 rs->
e = p->cursor =
c;
304 char *
s = p->cursor, *
c =
s;
306 while (
c < p->end && ((*
c >=
'a' && *
c <=
'z') || (*
c >=
'A' && *
c <=
'Z')
307 || (*
c >=
'0' && *
c <=
'9') || *
c ==
'_' || *
c ==
'-'))
312 rs->
e = p->cursor =
c;
323#define FORWARD_ERROR(c) \
327 return errcode ? errcode : AVERROR_INVALIDDATA; \
332 snprintf(p->err_msg,
sizeof(p->err_msg),
333 "immediate sequences not yet implemented");
339 snprintf(p->err_msg,
sizeof(p->err_msg),
340 "preprogrammed sequences not yet implemented");
347 snprintf(p->err_msg,
sizeof(p->err_msg),
348 "option '%c' requires an argument", o);
362 if (p->cursor == p->end || *p->cursor !=
'-')
365 for (; ostr.
s < ostr.
e; ostr.
s++) {
369 p->scs.opt_start_at_first = 1;
372 p->scs.opt_end_at_last = 1;
383 if (oarg.
e != tptr) {
384 snprintf(p->err_msg,
sizeof(p->err_msg),
385 "syntax error for option -F");
393 if (oarg.
e != oarg.
s +
r || p->scs.opt_duration < 0) {
394 snprintf(p->err_msg,
sizeof(p->err_msg),
395 "syntax error for option -L");
402 if (oarg.
e != oarg.
s +
r) {
403 snprintf(p->err_msg,
sizeof(p->err_msg),
404 "syntax error for option -T");
413 memcpy(tptr, oarg.
s, oarg.
e - oarg.
s);
414 tptr[oarg.
e - oarg.
s] = 0;
416 p->scs.opt_mix = tptr;
421 if (oarg.
e != tptr) {
422 snprintf(p->err_msg,
sizeof(p->err_msg),
423 "syntax error for option -q");
427 snprintf(p->err_msg,
sizeof(p->err_msg),
428 "speed factor other than 1 not supported");
434 r = strtol(oarg.
s, &tptr, 10);
435 if (oarg.
e != tptr) {
436 snprintf(p->err_msg,
sizeof(p->err_msg),
437 "syntax error for option -r");
441 snprintf(p->err_msg,
sizeof(p->err_msg),
442 "invalid sample rate");
445 p->scs.sample_rate =
r;
448 snprintf(p->err_msg,
sizeof(p->err_msg),
449 "unknown option: '%c'", *ostr.
s);
541 p->current_time.type =
ts.
type;
542 p->current_time.t =
ts.
t;
543 }
else if(!inblock && !p->current_time.type) {
544 snprintf(p->err_msg,
sizeof(p->err_msg),
545 "relative time without previous absolute time");
548 ts.
type = p->current_time.type;
550 if (
av_sat_add64(p->current_time.t, rel_ts) != p->current_time.t + (uint64_t)rel_ts)
552 ts.
t = inblock ? rel_ts : p->current_time.t + rel_ts;
568 &p->nb_block_tseq, &p->nb_block_tseq_max) :
570 &p->scs.nb_tseq, &p->nb_tseq_max);
582 snprintf(p->err_msg,
sizeof(p->err_msg),
583 "waveform definitions not yet implemented");
595 tseq = p->nb_block_tseq;
632 double carrierf, beatf;
633 int carrier, beat, vol;
698 double carrierf, beatf;
699 int carrier, beat, vol;
724 &p->scs.nb_synth, &p->nb_synth_max);
749 synth = p->scs.nb_synth;
758 if (synth == p->scs.nb_synth)
761 snprintf(p->err_msg,
sizeof(p->err_msg),
762 "too many channels in tone-set");
775 char *cursor_save = p->cursor;
780 p->cursor = cursor_save;
783 if (
name.e -
name.s == 6 && !memcmp(
name.s,
"wave", 4) &&
784 name.s[4] >=
'0' &&
name.s[4] <=
'9' &&
785 name.s[5] >=
'0' &&
name.s[5] <=
'9') {
786 int wavenum = (
name.s[4] -
'0') * 10 + (
name.s[5] -
'0');
790 &p->scs.nb_def, &p->nb_def_max);
816 .end =
script + script_len,
823 .sample_rate = 44100,
857 int lctx = ectx -
ctx;
858 const char *quote =
"\"";
859 if (lctx > 0 &&
ctx[lctx - 1] ==
'\r')
862 ctx =
"the end of line";
893 for (
i = 0;
i <
s->nb_tseq;
i++)
894 nb_rel +=
s->tseq[
i].ts.type ==
'N';
895 if (nb_rel ==
s->nb_tseq) {
900 "Start time ignored in a purely relative script.\n");
902 s->opt_start_at_first) {
905 s->start_ts =
s->tseq[0].ts.t;
910 struct tm *tm, tmpbuf;
913 "Scripts with mixed absolute and relative timestamps can give "
914 "unexpected results (pause, seeking, time zone change).\n");
917 now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec :
920 (
int)(now / 3600), (
int)(now / 60) % 60, (
int)now % 60);
922 for (
i = 0;
i <
s->nb_tseq;
i++) {
923 if (
s->tseq[
i].ts.type ==
'N') {
924 s->tseq[
i].ts.t += now;
925 s->tseq[
i].ts.type =
'T';
930 s->start_ts = (
s->opt_start_at_first &&
s->tseq) ?
s->tseq[0].ts.t : now;
931 if (
s->start_ts > INT64_MAX -
s->opt_duration)
934 s->end_ts =
s->opt_duration ?
s->start_ts +
s->opt_duration :
937 for (
i = 0;
i <
s->nb_tseq;
i++) {
940 if (
s->tseq[
i].ts.t +
delta < cur_ts)
942 cur_ts =
s->tseq[
i].ts.t +=
delta;
965 for (
i = 0;
i <
s->nb_def;
i++) {
970 if (
i >=
s->nb_def) {
976 if (def->
type ==
'B') {
984 if (
s->nb_events >= max_events) {
989 &
s->nb_events, nb_ev_max);
1003 int i,
r, nb_events_max = 0;
1008 for (
i = 0;
i <
s->nb_tseq;
i++) {
1013 if (!
s->nb_events) {
1017 if (
s->opt_end_at_last)
1018 s->end_ts =
s->events[
s->nb_events - 1].ts;
1052 i->phi =
ref >= 0 ?
ref | 0x80000000 : 0;
1075 ts3,
f,
a, ts4,
f, cpoints[
i][1]);
1099 if (s1->
beat == 0 && s2->
beat == 0) {
1132 "using pink noise instead.\n");
1157 "Type %d is not implemented\n", s1->
type);
1199 int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1);
1205 for (pass = 0; pass < 2; pass++) {
1213 for (
i = 0;
i < nb_elements;
i++) {
1237 ts1, ts2, &s1mod, &s2mod, 3);
1248 ts1, tsmid, &s1mod, &smid, 1);
1255 tsmid, ts2, &smid, &s2mod, 2);
1281 int64_t trans_time =
s->opt_fade_time / 2;
1289 period =
s->events[
s->nb_events - 1].ts - (uint64_t)
s->events[0].ts;
1297 for (
i = 0;
i <
s->nb_events;
i++) {
1298 ev1 = &
s->events[
i];
1299 ev2 = &
s->events[(
i + 1) %
s->nb_events];
1302 if (!ev1->
fade.
slide && ev1 >= ev2 && ev2->
ts > INT64_MAX - period)
1306 : ev2->
ts + (ev1 < ev2 ? 0 : period);
1308 for (
i = 0;
i <
s->nb_events;
i++) {
1309 ev1 = &
s->events[
i];
1310 ev2 = &
s->events[(
i + 1) %
s->nb_events];
1319 ev0 =
s->events[
s->nb_events - 1];
1327 for (
i = -1;
i <
s->nb_events;
i++) {
1328 ev1 =
i < 0 ? &ev0 : &
s->events[
i];
1335 for (
i = 0;
i <
s->nb_synth;
i++)
1336 s->synth[
i].ref.l =
s->synth[
i].ref.r = -1;
1337 for (
i = -1;
i <
s->nb_events;
i++) {
1338 ev1 =
i < 0 ? &ev0 : &
s->events[
i];
1339 ev2 = &
s->events[(
i + 1) %
s->nb_events];
1362 if (edata_size > INT_MAX)
1368#define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0)
1369#define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0)
1390 if (edata != par->
extradata + edata_size)
1433 "-m is ignored and mix channels will be silent.\n");
1503 packet->
dts = packet->
pts = ts;
1507 return packet->
size;
1513 if (
flags || stream_index > 0)
1515 if (stream_index < 0)
1528 {
"sample_rate",
"", offsetof(
struct sbg_demuxer, sample_rate),
1534 {
"max_file_size",
"", offsetof(
struct sbg_demuxer, max_file_size),
1541 .class_name =
"sbg_demuxer",
1550 .p.extensions =
"sbg",
static AVFormatContext * ctx
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
Public libavutil channel layout APIs header.
static void transition(ID3D12GraphicsCommandList *cl, ID3D12Resource *res, UINT subresource, D3D12_RESOURCE_STATES before, D3D12_RESOURCE_STATES after)
static const uint8_t frame_size[4]
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_CODEC_ID_FFWAVESYNTH
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_STEREO
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
static void fade(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, int width, int height, int alpha, int beta)
Macro definitions for various function/variable attributes.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MKTAG(a, b, c, d)
Memory handling functions.
static void free_script(struct sbg_script *s)
static int parse_synth_def(struct sbg_parser *p, struct sbg_script_definition *def)
static int parse_preprogrammed(struct sbg_parser *p)
static av_cold int sbg_read_header(AVFormatContext *avf)
static int lex_name(struct sbg_parser *p, struct sbg_string *rs)
static int parse_volume(struct sbg_parser *p, int *vol)
static int encode_intervals(struct sbg_script *s, AVCodecParameters *par, struct ws_intervals *inter)
static int parse_timestamp(struct sbg_parser *p, struct sbg_timestamp *rts, int64_t *rrel)
static int parse_synth_channel_bell(struct sbg_parser *p, struct sbg_script_synth *synth)
static int lex_wsword(struct sbg_parser *p, struct sbg_string *rs)
static int generate_transition(void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1, struct sbg_script_event *ev2)
static int expand_tseq(void *log, struct sbg_script *s, int *nb_ev_max, int64_t max_events, int64_t t0, struct sbg_script_tseq *tseq)
static int expand_script(void *log, struct sbg_script *s, int64_t max_events)
static int lex_char(struct sbg_parser *p, char c)
static int parse_synth_channel_pink(struct sbg_parser *p, struct sbg_script_synth *synth)
static int expand_timestamps(void *log, struct sbg_script *s)
static int parse_block_def(struct sbg_parser *p, struct sbg_script_definition *def)
static int parse_options(struct sbg_parser *p)
static int str_to_time(const char *str, int64_t *rtime)
static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr)
static int parse_immediate(struct sbg_parser *p)
static int scale_double(void *log, double d, double m, int *r)
static int lex_line_end(struct sbg_parser *p)
static int sbg_read_seek2(AVFormatContext *avf, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static int generate_intervals(void *log, struct sbg_script *s, int sample_rate, struct ws_intervals *inter)
static int parse_time_sequence(struct sbg_parser *p, int inblock)
static int parse_wave_def(struct sbg_parser *p, int wavenum)
static av_cold int sbg_read_probe(const AVProbeData *p)
static int sbg_read_seek(AVFormatContext *avf, int stream_index, int64_t ts, int flags)
static int lex_fixed(struct sbg_parser *p, const char *t, int l)
static int add_interval(struct ws_intervals *inter, enum ws_interval_type type, uint32_t channels, int ref, int64_t ts1, int32_t f1, int32_t a1, int64_t ts2, int32_t f2, int32_t a2)
static int generate_interval(void *log, struct sbg_script *s, struct ws_intervals *inter, int64_t ts1, int64_t ts2, struct sbg_script_synth *s1, struct sbg_script_synth *s2, int transition)
static int lex_space(struct sbg_parser *p)
static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r)
static int parse_synth_channel_mix(struct sbg_parser *p, struct sbg_script_synth *synth)
static int parse_synth_channel(struct sbg_parser *p)
static int lex_double(struct sbg_parser *p, double *r)
static void * alloc_array_elem(void **array, size_t elsize, int *size, int *max_size)
static int lex_time(struct sbg_parser *p, int64_t *rt)
static int read_whole_file(AVIOContext *io, int max_size, AVBPrint *rbuf)
static int add_bell(struct ws_intervals *inter, struct sbg_script *s, int64_t ts1, int64_t ts2, int32_t f, int32_t a)
static int parse_script(void *log, char *script, int script_len, struct sbg_script *rscript)
static int parse_named_def(struct sbg_parser *p)
static const AVOption sbg_options[]
static const AVClass sbg_demuxer_class
static int is_space(char c)
static int parse_synth_channel_spin(struct sbg_parser *p, struct sbg_script_synth *synth)
static int generate_plateau(void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1)
static int parse_synth_channel_sine(struct sbg_parser *p, struct sbg_script_synth *synth)
#define FF_ARRAY_ELEMS(a)
double strtod(const char *, char **)
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
This struct describes the properties of an encoded stream.
int frame_size
Audio frame size, if known.
AVChannelLayout ch_layout
The channel layout and number of channels.
enum AVMediaType codec_type
General type of the encoded data.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
AVIOContext * pb
I/O context.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
int eof_reached
true if was unable to read due to error or eof
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int64_t duration
Decoding: duration of the stream, in stream time base.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int probe_packets
Number of packets to buffer for codec probing.
struct sbg_timestamp current_time
struct sbg_script_synth::@063010234066362206263163064344241116375044362047 ref
struct sbg_script_tseq * tseq
struct sbg_script_tseq * block_tseq
uint8_t opt_start_at_first
struct sbg_script_event * events
struct sbg_script_synth * synth
struct sbg_script_definition * def
enum ws_interval_type type
struct ws_interval * inter
#define av_realloc_f(p, o, n)
static int ref[MAX_W *MAX_W]
static int array[MAX_W *MAX_W]
static double a2(void *priv, double x, double y)
static double a1(void *priv, double x, double y)