32 #define SBG_SCALE (1 << 16)
33 #define DAY (24 * 60 * 60)
34 #define DAY_TS ((int64_t)DAY * AV_TIME_BASE)
159 int *
size,
int *max_size)
163 if (*size == *max_size) {
164 int m =
FFMAX(32,
FFMIN(*max_size, INT_MAX / 2) * 2);
172 ret = (
char *)*array + elsize * *size;
173 memset(ret, 0, elsize);
180 const char *cur = str;
185 if (*cur < '0' || *cur >
'9')
187 hours = strtol(cur, &end, 10);
188 if (end == cur || *end !=
':' || end[1] <
'0' || end[1] >
'9')
191 minutes = strtol(cur, &end, 10);
196 seconds =
strtod(cur + 1, &end);
200 *rtime = (hours * 3600 + minutes * 60 + seconds) *
AV_TIME_BASE;
206 return c ==
' ' || c ==
'\t' || c ==
'\r';
212 if (m < INT_MIN || m >= INT_MAX) {
284 if (s == p->
end || *s ==
'\n')
298 while (c < p->
end && ((*
c >=
'a' && *
c <=
'z') || (*
c >=
'A' && *
c <=
'Z')
299 || (*
c >=
'0' && *
c <=
'9') || *
c ==
'_' || *
c ==
'-'))
315 #define FORWARD_ERROR(c) \
319 return errcode ? errcode : AVERROR_INVALIDDATA; \
325 "immediate sequences not yet implemented");
332 "preprogrammed sequences not yet implemented");
340 "option '%c' requires an argument", o);
357 for (; ostr.
s < ostr.
e; ostr.
s++) {
375 if (oarg.
e != tptr) {
377 "syntax error for option -F");
385 if (oarg.
e != oarg.
s + r) {
387 "syntax error for option -L");
394 if (oarg.
e != oarg.
s + r) {
396 "syntax error for option -T");
405 memcpy(tptr, oarg.
s, oarg.
e - oarg.
s);
406 tptr[oarg.
e - oarg.
s] = 0;
413 if (oarg.
e != tptr) {
415 "syntax error for option -q");
420 "speed factor other than 1 not supported");
426 r = strtol(oarg.
s, &tptr, 10);
427 if (oarg.
e != tptr) {
429 "syntax error for option -r");
434 "invalid sample rate");
441 "unknown option: '%c'", *ostr.
s);
462 int64_t abs = 0, rel = 0, dt;
535 "relative time without previous absolute time");
570 "waveform definitions not yet implemented");
619 double carrierf, beatf;
620 int carrier, beat, vol;
685 double carrierf, beatf;
686 int carrier, beat, vol;
757 char *cursor_save = p->
cursor;
765 if (name.
e - name.
s == 6 && !memcmp(name.
s,
"wave", 4) &&
766 name.
s[4] >=
'0' && name.
s[4] <=
'9' &&
767 name.
s[5] >=
'0' && name.
s[5] <=
'9') {
768 int wavenum = (name.
s[4] -
'0') * 10 + (name.
s[5] -
'0');
798 .end = script + script_len,
805 .sample_rate = 44100,
836 const char *ctx = sp.
cursor;
839 int lctx = ectx - ctx;
840 const char *quote =
"\"";
841 if (lctx > 0 && ctx[lctx - 1] ==
'\r')
844 ctx =
"the end of line";
857 int size = 0, bufsize = 0,
r;
860 if (bufsize - size < 1024) {
861 bufsize =
FFMIN(
FFMAX(2 * bufsize, 8192), max_size);
862 if (bufsize - size < 2) {
890 int64_t now, cur_ts,
delta = 0;
892 for (i = 0; i < s->
nb_tseq; i++)
899 "Start time ignored in a purely relative script.\n");
909 struct tm *tm, tmpbuf;
912 "Scripts with mixed absolute and relative timestamps can give "
913 "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++) {
934 for (i = 0; i < s->
nb_tseq; i++) {
935 if (s->
tseq[i].
ts.
t + delta < cur_ts)
955 for (i = 0; i < s->
nb_def; i++) {
966 if (def->
type ==
'B') {
987 int i,
r, nb_events_max = 0;
990 for (i = 0; i < s->
nb_tseq; i++) {
1012 ri = &inter->
inter[ref];
1015 ri->
f1 == ri->
f2 && ri->
f2 == f1 && f1 == f2 &&
1016 ri->
a1 == ri->
a2 && ri->
a2 == a1 && a1 == a2 &&
1034 i->
phi = ref >= 0 ? ref | 0x80000000 : 0;
1035 return i - inter->
inter;
1055 ts4 =
FFMIN(ts2, ts1 + cpoints[i][0] * dt);
1057 ts3, f, a, ts4, f, cpoints[i][1]);
1068 int64_t
ts1, int64_t
ts2,
1075 if (ts2 <= ts1 || (s1->
vol == 0 && s2->
vol == 0))
1081 if (s1->
beat == 0 && s2->
beat == 0) {
1105 if (transition == 2) {
1114 "using pink noise instead.\n");
1128 ts1, 0, s1->
vol - s1->
vol / 4,
1129 ts2, 0, s2->
vol - s2->
vol / 4);
1139 "Type %d is not implemented\n", s1->
type);
1181 int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1);
1187 for (pass = 0; pass < 2; pass++) {
1195 for (i = 0; i < nb_elements; i++) {
1219 ts1, ts2, &s1mod, &s2mod, 3);
1230 ts1, tsmid, &s1mod, &smid, 1);
1237 tsmid, ts2, &smid, &s2mod, 2);
1273 period =
FFMAX(period, DAY_TS);
1281 : ev2->
ts + (ev1 < ev2 ? 0 : period);
1301 ev1 = i < 0 ? &ev0 : &s->
events[i];
1311 ev1 = i < 0 ? &ev0 : &s->
events[i];
1328 int i, edata_size = 4;
1331 for (i = 0; i < inter->
nb_inter; i++) {
1341 #define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0)
1342 #define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0)
1344 for (i = 0; i < inter->
nb_inter; i++) {
1363 if (edata != avc->
extradata + edata_size)
1403 "-m is ignored and mix channels will be silent.\n");
1457 packet->
dts = packet->
pts = ts;
1461 return packet->
size;
1465 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
1467 if (flags || stream_index > 0)
1469 if (stream_index < 0)
1476 int64_t ts,
int flags)
1488 {
"max_file_size",
"", offsetof(
struct sbg_demuxer, max_file_size),
1510 .extensions =
"sbg",