FFmpeg
sbgdec.c
Go to the documentation of this file.
1 /*
2  * SBG (SBaGen) file format decoder
3  * Copyright (c) 2011 Nicolas George
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include "libavutil/intreadwrite.h"
26 #include "libavutil/log.h"
27 #include "libavutil/opt.h"
29 #include "avformat.h"
30 #include "internal.h"
31 
32 #define SBG_SCALE (1 << 16)
33 #define DAY (24 * 60 * 60)
34 #define DAY_TS ((int64_t)DAY * AV_TIME_BASE)
35 
36 struct sbg_demuxer {
37  AVClass *class;
41 };
42 
43 struct sbg_string {
44  char *s;
45  char *e;
46 };
47 
52 };
53 
54 struct sbg_fade {
55  int8_t in, out, slide;
56 };
57 
65 };
66 
67 /* bell: freq constant, ampl decreases exponentially, can be approx lin */
68 
69 struct sbg_timestamp {
70  int64_t t;
71  char type; /* 0 for relative, 'N' for now, 'T' for absolute */
72 };
73 
75  char *name;
76  int name_len;
78  char type; /* 'S' or 'B' */
79 };
80 
82  int carrier;
83  int beat;
84  int vol;
86  struct {
87  int l, r;
88  } ref;
89 };
90 
92  struct sbg_timestamp ts;
93  char *name;
94  int name_len;
95  int lock;
96  struct sbg_fade fade;
97 };
98 
100  int64_t ts;
101  int64_t ts_int, ts_trans, ts_next;
103  struct sbg_fade fade;
104 };
105 
106 struct sbg_script {
112  int nb_def;
113  int nb_tseq;
115  int nb_synth;
116  int64_t start_ts;
117  int64_t end_ts;
118  int64_t opt_fade_time;
119  int64_t opt_duration;
120  char *opt_mix;
124 };
125 
126 struct sbg_parser {
127  void *log;
128  char *script, *end;
129  char *cursor;
130  struct sbg_script scs;
133  int nb_def_max, nb_synth_max, nb_tseq_max, nb_block_tseq_max;
134  int line_no;
135  char err_msg[128];
136 };
137 
139  WS_SINE = MKTAG('S','I','N','E'),
140  WS_NOISE = MKTAG('N','O','I','S'),
141 };
142 
143 struct ws_interval {
144  int64_t ts1, ts2;
145  enum ws_interval_type type;
146  uint32_t channels;
147  int32_t f1, f2;
149  uint32_t phi;
150 };
151 
152 struct ws_intervals {
154  int nb_inter;
156 };
157 
158 static void *alloc_array_elem(void **array, size_t elsize,
159  int *size, int *max_size)
160 {
161  void *ret;
162 
163  if (*size == *max_size) {
164  int m = FFMAX(32, FFMIN(*max_size, INT_MAX / 2) * 2);
165  if (*size >= m)
166  return NULL;
167  *array = av_realloc_f(*array, m, elsize);
168  if (!*array)
169  return NULL;
170  *max_size = m;
171  }
172  ret = (char *)*array + elsize * *size;
173  memset(ret, 0, elsize);
174  (*size)++;
175  return ret;
176 }
177 
178 static int str_to_time(const char *str, int64_t *rtime)
179 {
180  const char *cur = str;
181  char *end;
182  int hours, minutes;
183  double seconds = 0;
184 
185  if (*cur < '0' || *cur > '9')
186  return 0;
187  hours = strtol(cur, &end, 10);
188  if (end == cur || *end != ':' || end[1] < '0' || end[1] > '9')
189  return 0;
190  cur = end + 1;
191  minutes = strtol(cur, &end, 10);
192  if (end == cur)
193  return 0;
194  cur = end;
195  if (*end == ':'){
196  seconds = strtod(cur + 1, &end);
197  if (end > cur + 1)
198  cur = end;
199  }
200  *rtime = (hours * 3600LL + minutes * 60LL + seconds) * AV_TIME_BASE;
201  return cur - str;
202 }
203 
204 static inline int is_space(char c)
205 {
206  return c == ' ' || c == '\t' || c == '\r';
207 }
208 
209 static inline int scale_double(void *log, double d, double m, int *r)
210 {
211  m *= d * SBG_SCALE;
212  if (m < INT_MIN || m >= INT_MAX) {
213  if (log)
214  av_log(log, AV_LOG_ERROR, "%g is too large\n", d);
215  return AVERROR(EDOM);
216  }
217  *r = m;
218  return 0;
219 }
220 
221 static int lex_space(struct sbg_parser *p)
222 {
223  char *c = p->cursor;
224 
225  while (p->cursor < p->end && is_space(*p->cursor))
226  p->cursor++;
227  return p->cursor > c;
228 }
229 
230 static int lex_char(struct sbg_parser *p, char c)
231 {
232  int r = p->cursor < p->end && *p->cursor == c;
233 
234  p->cursor += r;
235  return r;
236 }
237 
238 static int lex_double(struct sbg_parser *p, double *r)
239 {
240  double d;
241  char *end;
242 
243  if (p->cursor == p->end || is_space(*p->cursor) || *p->cursor == '\n')
244  return 0;
245  d = strtod(p->cursor, &end);
246  if (end > p->cursor) {
247  *r = d;
248  p->cursor = end;
249  return 1;
250  }
251  return 0;
252 }
253 
254 static int lex_fixed(struct sbg_parser *p, const char *t, int l)
255 {
256  if (p->end - p->cursor < l || memcmp(p->cursor, t, l))
257  return 0;
258  p->cursor += l;
259  return 1;
260 }
261 
262 static int lex_line_end(struct sbg_parser *p)
263 {
264  if (p->cursor < p->end && *p->cursor == '#') {
265  p->cursor++;
266  while (p->cursor < p->end && *p->cursor != '\n')
267  p->cursor++;
268  }
269  if (p->cursor == p->end)
270  /* simulate final LF for files lacking it */
271  return 1;
272  if (*p->cursor != '\n')
273  return 0;
274  p->cursor++;
275  p->line_no++;
276  lex_space(p);
277  return 1;
278 }
279 
280 static int lex_wsword(struct sbg_parser *p, struct sbg_string *rs)
281 {
282  char *s = p->cursor, *c = s;
283 
284  if (s == p->end || *s == '\n')
285  return 0;
286  while (c < p->end && *c != '\n' && !is_space(*c))
287  c++;
288  rs->s = s;
289  rs->e = p->cursor = c;
290  lex_space(p);
291  return 1;
292 }
293 
294 static int lex_name(struct sbg_parser *p, struct sbg_string *rs)
295 {
296  char *s = p->cursor, *c = s;
297 
298  while (c < p->end && ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z')
299  || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-'))
300  c++;
301  if (c == s)
302  return 0;
303  rs->s = s;
304  rs->e = p->cursor = c;
305  return 1;
306 }
307 
308 static int lex_time(struct sbg_parser *p, int64_t *rt)
309 {
310  int r = str_to_time(p->cursor, rt);
311  p->cursor += r;
312  return r > 0;
313 }
314 
315 #define FORWARD_ERROR(c) \
316  do { \
317  int errcode = c; \
318  if (errcode <= 0) \
319  return errcode ? errcode : AVERROR_INVALIDDATA; \
320  } while (0)
321 
322 static int parse_immediate(struct sbg_parser *p)
323 {
324  snprintf(p->err_msg, sizeof(p->err_msg),
325  "immediate sequences not yet implemented");
326  return AVERROR_PATCHWELCOME;
327 }
328 
329 static int parse_preprogrammed(struct sbg_parser *p)
330 {
331  snprintf(p->err_msg, sizeof(p->err_msg),
332  "preprogrammed sequences not yet implemented");
333  return AVERROR_PATCHWELCOME;
334 }
335 
336 static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r)
337 {
338  if (!lex_wsword(p, r)) {
339  snprintf(p->err_msg, sizeof(p->err_msg),
340  "option '%c' requires an argument", o);
341  return AVERROR_INVALIDDATA;
342  }
343  return 1;
344 }
345 
346 static int parse_options(struct sbg_parser *p)
347 {
348  struct sbg_string ostr, oarg;
349  char mode = 0;
350  int r;
351  char *tptr;
352  double v;
353 
354  if (p->cursor == p->end || *p->cursor != '-')
355  return 0;
356  while (lex_char(p, '-') && lex_wsword(p, &ostr)) {
357  for (; ostr.s < ostr.e; ostr.s++) {
358  char opt = *ostr.s;
359  switch (opt) {
360  case 'S':
361  p->scs.opt_start_at_first = 1;
362  break;
363  case 'E':
364  p->scs.opt_end_at_last = 1;
365  break;
366  case 'i':
367  mode = 'i';
368  break;
369  case 'p':
370  mode = 'p';
371  break;
372  case 'F':
373  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
374  v = strtod(oarg.s, &tptr);
375  if (oarg.e != tptr) {
376  snprintf(p->err_msg, sizeof(p->err_msg),
377  "syntax error for option -F");
378  return AVERROR_INVALIDDATA;
379  }
380  p->scs.opt_fade_time = v * AV_TIME_BASE / 1000;
381  break;
382  case 'L':
383  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
384  r = str_to_time(oarg.s, &p->scs.opt_duration);
385  if (oarg.e != oarg.s + r) {
386  snprintf(p->err_msg, sizeof(p->err_msg),
387  "syntax error for option -L");
388  return AVERROR_INVALIDDATA;
389  }
390  break;
391  case 'T':
392  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
393  r = str_to_time(oarg.s, &p->scs.start_ts);
394  if (oarg.e != oarg.s + r) {
395  snprintf(p->err_msg, sizeof(p->err_msg),
396  "syntax error for option -T");
397  return AVERROR_INVALIDDATA;
398  }
399  break;
400  case 'm':
401  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
402  tptr = av_malloc(oarg.e - oarg.s + 1);
403  if (!tptr)
404  return AVERROR(ENOMEM);
405  memcpy(tptr, oarg.s, oarg.e - oarg.s);
406  tptr[oarg.e - oarg.s] = 0;
407  av_free(p->scs.opt_mix);
408  p->scs.opt_mix = tptr;
409  break;
410  case 'q':
411  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
412  v = strtod(oarg.s, &tptr);
413  if (oarg.e != tptr) {
414  snprintf(p->err_msg, sizeof(p->err_msg),
415  "syntax error for option -q");
416  return AVERROR_INVALIDDATA;
417  }
418  if (v != 1) {
419  snprintf(p->err_msg, sizeof(p->err_msg),
420  "speed factor other than 1 not supported");
421  return AVERROR_PATCHWELCOME;
422  }
423  break;
424  case 'r':
425  FORWARD_ERROR(parse_optarg(p, opt, &oarg));
426  r = strtol(oarg.s, &tptr, 10);
427  if (oarg.e != tptr) {
428  snprintf(p->err_msg, sizeof(p->err_msg),
429  "syntax error for option -r");
430  return AVERROR_INVALIDDATA;
431  }
432  if (r < 40) {
433  snprintf(p->err_msg, sizeof(p->err_msg),
434  "invalid sample rate");
435  return AVERROR_PATCHWELCOME;
436  }
437  p->scs.sample_rate = r;
438  break;
439  default:
440  snprintf(p->err_msg, sizeof(p->err_msg),
441  "unknown option: '%c'", *ostr.s);
442  return AVERROR_INVALIDDATA;
443  }
444  }
445  }
446  switch (mode) {
447  case 'i':
448  return parse_immediate(p);
449  case 'p':
450  return parse_preprogrammed(p);
451  case 0:
452  if (!lex_line_end(p))
453  return AVERROR_INVALIDDATA;
454  return 1;
455  }
456  return AVERROR_BUG;
457 }
458 
459 static int parse_timestamp(struct sbg_parser *p,
460  struct sbg_timestamp *rts, int64_t *rrel)
461 {
462  int64_t abs = 0, rel = 0, dt;
463  char type = 0;
464  int r;
465 
466  if (lex_fixed(p, "NOW", 3)) {
467  type = 'N';
468  r = 1;
469  } else {
470  r = lex_time(p, &abs);
471  if (r)
472  type = 'T';
473  }
474  while (lex_char(p, '+')) {
475  if (!lex_time(p, &dt))
476  return AVERROR_INVALIDDATA;
477  if (av_sat_add64(rel, dt) - dt != rel)
478  return AVERROR_INVALIDDATA;
479  rel += dt;
480  r = 1;
481  }
482  if (r) {
483  if (!lex_space(p))
484  return AVERROR_INVALIDDATA;
485  rts->type = type;
486  rts->t = abs;
487  *rrel = rel;
488  }
489  return r;
490 }
491 
492 static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr)
493 {
494  struct sbg_fade f = {0};
495 
496  if (lex_char(p, '<'))
497  f.in = SBG_FADE_SILENCE;
498  else if (lex_char(p, '-'))
499  f.in = SBG_FADE_SAME;
500  else if (lex_char(p, '='))
501  f.in = SBG_FADE_ADAPT;
502  else
503  return 0;
504  if (lex_char(p, '>'))
505  f.out = SBG_FADE_SILENCE;
506  else if (lex_char(p, '-'))
507  f.out = SBG_FADE_SAME;
508  else if (lex_char(p, '='))
509  f.out = SBG_FADE_ADAPT;
510  else
511  return AVERROR_INVALIDDATA;
512  *fr = f;
513  return 1;
514 }
515 
516 static int parse_time_sequence(struct sbg_parser *p, int inblock)
517 {
518  struct sbg_timestamp ts;
519  int64_t rel_ts;
520  int r;
521  struct sbg_fade fade = { SBG_FADE_SAME, SBG_FADE_SAME, 0 };
522  struct sbg_string name;
523  struct sbg_script_tseq *tseq;
524 
525  r = parse_timestamp(p, &ts, &rel_ts);
526  if (!r)
527  return 0;
528  if (r < 0)
529  return r;
530  if (ts.type) {
531  if (inblock)
532  return AVERROR_INVALIDDATA;
533  p->current_time.type = ts.type;
534  p->current_time.t = ts.t;
535  } else if(!inblock && !p->current_time.type) {
536  snprintf(p->err_msg, sizeof(p->err_msg),
537  "relative time without previous absolute time");
538  return AVERROR_INVALIDDATA;
539  }
540  ts.type = p->current_time.type;
541  ts.t = p->current_time.t + rel_ts;
542  r = parse_fade(p, &fade);
543  if (r < 0)
544  return r;
545  lex_space(p);
546  if (!lex_name(p, &name))
547  return AVERROR_INVALIDDATA;
548  lex_space(p);
549  if (lex_fixed(p, "->", 2)) {
550  fade.slide = SBG_FADE_ADAPT;
551  lex_space(p);
552  }
553  if (!lex_line_end(p))
554  return AVERROR_INVALIDDATA;
555  tseq = inblock ?
556  alloc_array_elem((void **)&p->scs.block_tseq, sizeof(*tseq),
557  &p->nb_block_tseq, &p->nb_block_tseq_max) :
558  alloc_array_elem((void **)&p->scs.tseq, sizeof(*tseq),
559  &p->scs.nb_tseq, &p->nb_tseq_max);
560  if (!tseq)
561  return AVERROR(ENOMEM);
562  tseq->ts = ts;
563  tseq->name = name.s;
564  tseq->name_len = name.e - name.s;
565  tseq->fade = fade;
566  return 1;
567 }
568 
569 static int parse_wave_def(struct sbg_parser *p, int wavenum)
570 {
571  snprintf(p->err_msg, sizeof(p->err_msg),
572  "waveform definitions not yet implemented");
573  return AVERROR_PATCHWELCOME;
574 }
575 
576 static int parse_block_def(struct sbg_parser *p,
577  struct sbg_script_definition *def)
578 {
579  int r, tseq;
580 
581  lex_space(p);
582  if (!lex_line_end(p))
583  return AVERROR_INVALIDDATA;
584  tseq = p->nb_block_tseq;
585  while (1) {
586  r = parse_time_sequence(p, 1);
587  if (r < 0)
588  return r;
589  if (!r)
590  break;
591  }
592  if (!lex_char(p, '}'))
593  return AVERROR_INVALIDDATA;
594  lex_space(p);
595  if (!lex_line_end(p))
596  return AVERROR_INVALIDDATA;
597  def->type = 'B';
598  def->elements = tseq;
599  def->nb_elements = p->nb_block_tseq - tseq;
600  if (!def->nb_elements)
601  return AVERROR_INVALIDDATA;
602  return 1;
603 }
604 
605 static int parse_volume(struct sbg_parser *p, int *vol)
606 {
607  double v;
608 
609  if (!lex_char(p, '/'))
610  return 0;
611  if (!lex_double(p, &v))
612  return AVERROR_INVALIDDATA;
613  if (scale_double(p->log, v, 0.01, vol))
614  return AVERROR(ERANGE);
615  return 1;
616 }
617 
619  struct sbg_script_synth *synth)
620 {
621  double carrierf, beatf;
622  int carrier, beat, vol;
623 
624  if (!lex_double(p, &carrierf))
625  return 0;
626  if (!lex_double(p, &beatf))
627  beatf = 0;
628  FORWARD_ERROR(parse_volume(p, &vol));
629  if (scale_double(p->log, carrierf, 1, &carrier) < 0 ||
630  scale_double(p->log, beatf, 1, &beat) < 0)
631  return AVERROR(EDOM);
632  synth->type = SBG_TYPE_SINE;
633  synth->carrier = carrier;
634  synth->beat = beat;
635  synth->vol = vol;
636  return 1;
637 }
638 
640  struct sbg_script_synth *synth)
641 {
642  int vol;
643 
644  if (!lex_fixed(p, "pink", 4))
645  return 0;
646  FORWARD_ERROR(parse_volume(p, &vol));
647  synth->type = SBG_TYPE_NOISE;
648  synth->vol = vol;
649  return 1;
650 }
651 
653  struct sbg_script_synth *synth)
654 {
655  double carrierf;
656  int carrier, vol;
657 
658  if (!lex_fixed(p, "bell", 4))
659  return 0;
660  if (!lex_double(p, &carrierf))
661  return AVERROR_INVALIDDATA;
662  FORWARD_ERROR(parse_volume(p, &vol));
663  if (scale_double(p->log, carrierf, 1, &carrier) < 0)
664  return AVERROR(EDOM);
665  synth->type = SBG_TYPE_BELL;
666  synth->carrier = carrier;
667  synth->vol = vol;
668  return 1;
669 }
670 
671 static int parse_synth_channel_mix(struct sbg_parser *p,
672  struct sbg_script_synth *synth)
673 {
674  int vol;
675 
676  if (!lex_fixed(p, "mix", 3))
677  return 0;
678  FORWARD_ERROR(parse_volume(p, &vol));
679  synth->type = SBG_TYPE_MIX;
680  synth->vol = vol;
681  return 1;
682 }
683 
685  struct sbg_script_synth *synth)
686 {
687  double carrierf, beatf;
688  int carrier, beat, vol;
689 
690  if (!lex_fixed(p, "spin:", 5))
691  return 0;
692  if (!lex_double(p, &carrierf))
693  return AVERROR_INVALIDDATA;
694  if (!lex_double(p, &beatf))
695  return AVERROR_INVALIDDATA;
696  FORWARD_ERROR(parse_volume(p, &vol));
697  if (scale_double(p->log, carrierf, 1, &carrier) < 0 ||
698  scale_double(p->log, beatf, 1, &beat) < 0)
699  return AVERROR(EDOM);
700  synth->type = SBG_TYPE_SPIN;
701  synth->carrier = carrier;
702  synth->beat = beat;
703  synth->vol = vol;
704  return 1;
705 }
706 
707 static int parse_synth_channel(struct sbg_parser *p)
708 {
709  int r;
710  struct sbg_script_synth *synth;
711 
712  synth = alloc_array_elem((void **)&p->scs.synth, sizeof(*synth),
713  &p->scs.nb_synth, &p->nb_synth_max);
714  if (!synth)
715  return AVERROR(ENOMEM);
716  r = lex_char(p, '-');
717  if (!r)
718  r = parse_synth_channel_pink(p, synth);
719  if (!r)
720  r = parse_synth_channel_bell(p, synth);
721  if (!r)
722  r = parse_synth_channel_mix(p, synth);
723  if (!r)
724  r = parse_synth_channel_spin(p, synth);
725  /* Unimplemented: wave%d:%f%f/vol (carrier, beat) */
726  if (!r)
727  r = parse_synth_channel_sine(p, synth);
728  if (r <= 0)
729  p->scs.nb_synth--;
730  return r;
731 }
732 
733 static int parse_synth_def(struct sbg_parser *p,
734  struct sbg_script_definition *def)
735 {
736  int r, synth;
737 
738  synth = p->scs.nb_synth;
739  while (1) {
740  r = parse_synth_channel(p);
741  if (r < 0)
742  return r;
743  if (!r || !lex_space(p))
744  break;
745  }
746  lex_space(p);
747  if (synth == p->scs.nb_synth)
748  return AVERROR_INVALIDDATA;
749  if (!lex_line_end(p))
750  return AVERROR_INVALIDDATA;
751  def->type = 'S';
752  def->elements = synth;
753  def->nb_elements = p->scs.nb_synth - synth;
754  return 1;
755 }
756 
757 static int parse_named_def(struct sbg_parser *p)
758 {
759  char *cursor_save = p->cursor;
760  struct sbg_string name;
761  struct sbg_script_definition *def;
762 
763  if (!lex_name(p, &name) || !lex_char(p, ':') || !lex_space(p)) {
764  p->cursor = cursor_save;
765  return 0;
766  }
767  if (name.e - name.s == 6 && !memcmp(name.s, "wave", 4) &&
768  name.s[4] >= '0' && name.s[4] <= '9' &&
769  name.s[5] >= '0' && name.s[5] <= '9') {
770  int wavenum = (name.s[4] - '0') * 10 + (name.s[5] - '0');
771  return parse_wave_def(p, wavenum);
772  }
773  def = alloc_array_elem((void **)&p->scs.def, sizeof(*def),
774  &p->scs.nb_def, &p->nb_def_max);
775  if (!def)
776  return AVERROR(ENOMEM);
777  def->name = name.s;
778  def->name_len = name.e - name.s;
779  if (lex_char(p, '{'))
780  return parse_block_def(p, def);
781  return parse_synth_def(p, def);
782 }
783 
784 static void free_script(struct sbg_script *s)
785 {
786  av_freep(&s->def);
787  av_freep(&s->synth);
788  av_freep(&s->tseq);
789  av_freep(&s->block_tseq);
790  av_freep(&s->events);
791  av_freep(&s->opt_mix);
792 }
793 
794 static int parse_script(void *log, char *script, int script_len,
795  struct sbg_script *rscript)
796 {
797  struct sbg_parser sp = {
798  .log = log,
799  .script = script,
800  .end = script + script_len,
801  .cursor = script,
802  .line_no = 1,
803  .err_msg = "",
804  .scs = {
805  /* default values */
806  .start_ts = AV_NOPTS_VALUE,
807  .sample_rate = 44100,
808  .opt_fade_time = 60 * AV_TIME_BASE,
809  },
810  };
811  int r;
812 
813  lex_space(&sp);
814  while (sp.cursor < sp.end) {
815  r = parse_options(&sp);
816  if (r < 0)
817  goto fail;
818  if (!r && !lex_line_end(&sp))
819  break;
820  }
821  while (sp.cursor < sp.end) {
822  r = parse_named_def(&sp);
823  if (!r)
824  r = parse_time_sequence(&sp, 0);
825  if (!r)
826  r = lex_line_end(&sp) ? 1 : AVERROR_INVALIDDATA;
827  if (r < 0)
828  goto fail;
829  }
830  *rscript = sp.scs;
831  return 1;
832 fail:
833  free_script(&sp.scs);
834  if (!*sp.err_msg)
835  if (r == AVERROR_INVALIDDATA)
836  snprintf(sp.err_msg, sizeof(sp.err_msg), "syntax error");
837  if (log && *sp.err_msg) {
838  const char *ctx = sp.cursor;
839  const char *ectx = av_x_if_null(memchr(ctx, '\n', sp.end - sp.cursor),
840  sp.end);
841  int lctx = ectx - ctx;
842  const char *quote = "\"";
843  if (lctx > 0 && ctx[lctx - 1] == '\r')
844  lctx--;
845  if (lctx == 0) {
846  ctx = "the end of line";
847  lctx = strlen(ctx);
848  quote = "";
849  }
850  av_log(log, AV_LOG_ERROR, "Error line %d: %s near %s%.*s%s.\n",
851  sp.line_no, sp.err_msg, quote, lctx, ctx, quote);
852  }
853  return r;
854 }
855 
856 static int read_whole_file(AVIOContext *io, int max_size, char **rbuf)
857 {
858  char *buf = NULL;
859  int size = 0, bufsize = 0, r;
860 
861  while (1) {
862  if (bufsize - size < 1024) {
863  bufsize = FFMIN(FFMAX(2 * bufsize, 8192), max_size);
864  if (bufsize - size < 2) {
865  size = AVERROR(EFBIG);
866  goto fail;
867  }
868  buf = av_realloc_f(buf, bufsize, 1);
869  if (!buf) {
870  size = AVERROR(ENOMEM);
871  goto fail;
872  }
873  }
874  r = avio_read(io, buf, bufsize - size - 1);
875  if (r == AVERROR_EOF)
876  break;
877  if (r < 0)
878  goto fail;
879  size += r;
880  }
881  buf[size] = 0;
882  *rbuf = buf;
883  return size;
884 fail:
885  av_free(buf);
886  return size;
887 }
888 
889 static void expand_timestamps(void *log, struct sbg_script *s)
890 {
891  int i, nb_rel = 0;
892  int64_t now, cur_ts, delta = 0;
893 
894  for (i = 0; i < s->nb_tseq; i++)
895  nb_rel += s->tseq[i].ts.type == 'N';
896  if (nb_rel == s->nb_tseq) {
897  /* All ts are relative to NOW: consider NOW = 0 */
898  now = 0;
899  if (s->start_ts != AV_NOPTS_VALUE)
900  av_log(log, AV_LOG_WARNING,
901  "Start time ignored in a purely relative script.\n");
902  } else if (nb_rel == 0 && s->start_ts != AV_NOPTS_VALUE ||
903  s->opt_start_at_first) {
904  /* All ts are absolute and start time is specified */
905  if (s->start_ts == AV_NOPTS_VALUE)
906  s->start_ts = s->tseq[0].ts.t;
907  now = s->start_ts;
908  } else {
909  /* Mixed relative/absolute ts: expand */
910  time_t now0;
911  struct tm *tm, tmpbuf;
912 
913  av_log(log, AV_LOG_WARNING,
914  "Scripts with mixed absolute and relative timestamps can give "
915  "unexpected results (pause, seeking, time zone change).\n");
916 #undef time
917  time(&now0);
918  tm = localtime_r(&now0, &tmpbuf);
919  now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec :
920  now0 % DAY;
921  av_log(log, AV_LOG_INFO, "Using %02d:%02d:%02d as NOW.\n",
922  (int)(now / 3600), (int)(now / 60) % 60, (int)now % 60);
923  now *= AV_TIME_BASE;
924  for (i = 0; i < s->nb_tseq; i++) {
925  if (s->tseq[i].ts.type == 'N') {
926  s->tseq[i].ts.t += now;
927  s->tseq[i].ts.type = 'T'; /* not necessary */
928  }
929  }
930  }
931  if (s->start_ts == AV_NOPTS_VALUE)
932  s->start_ts = (s->opt_start_at_first && s->tseq) ? s->tseq[0].ts.t : now;
933  s->end_ts = s->opt_duration ? s->start_ts + s->opt_duration :
934  AV_NOPTS_VALUE; /* may be overridden later by -E option */
935  cur_ts = now;
936  for (i = 0; i < s->nb_tseq; i++) {
937  if (s->tseq[i].ts.t + delta < cur_ts)
938  delta += DAY_TS;
939  cur_ts = s->tseq[i].ts.t += delta;
940  }
941 }
942 
943 static int expand_tseq(void *log, struct sbg_script *s, int *nb_ev_max,
944  int64_t t0, struct sbg_script_tseq *tseq)
945 {
946  int i, r;
947  struct sbg_script_definition *def;
948  struct sbg_script_tseq *be;
949  struct sbg_script_event *ev;
950 
951  if (tseq->lock++) {
952  av_log(log, AV_LOG_ERROR, "Recursion loop on \"%.*s\"\n",
953  tseq->name_len, tseq->name);
954  return AVERROR(EINVAL);
955  }
956  t0 += tseq->ts.t;
957  for (i = 0; i < s->nb_def; i++) {
958  if (s->def[i].name_len == tseq->name_len &&
959  !memcmp(s->def[i].name, tseq->name, tseq->name_len))
960  break;
961  }
962  if (i >= s->nb_def) {
963  av_log(log, AV_LOG_ERROR, "Tone-set \"%.*s\" not defined\n",
964  tseq->name_len, tseq->name);
965  return AVERROR(EINVAL);
966  }
967  def = &s->def[i];
968  if (def->type == 'B') {
969  be = s->block_tseq + def->elements;
970  for (i = 0; i < def->nb_elements; i++) {
971  r = expand_tseq(log, s, nb_ev_max, t0, &be[i]);
972  if (r < 0)
973  return r;
974  }
975  } else {
976  ev = alloc_array_elem((void **)&s->events, sizeof(*ev),
977  &s->nb_events, nb_ev_max);
978  if (!ev)
979  return AVERROR(ENOMEM);
980  ev->ts = tseq->ts.t;
981  ev->elements = def->elements;
982  ev->nb_elements = def->nb_elements;
983  ev->fade = tseq->fade;
984  }
985  tseq->lock--;
986  return 0;
987 }
988 
989 static int expand_script(void *log, struct sbg_script *s)
990 {
991  int i, r, nb_events_max = 0;
992 
993  expand_timestamps(log, s);
994  for (i = 0; i < s->nb_tseq; i++) {
995  r = expand_tseq(log, s, &nb_events_max, 0, &s->tseq[i]);
996  if (r < 0)
997  return r;
998  }
999  if (!s->nb_events) {
1000  av_log(log, AV_LOG_ERROR, "No events in script\n");
1001  return AVERROR_INVALIDDATA;
1002  }
1003  if (s->opt_end_at_last)
1004  s->end_ts = s->events[s->nb_events - 1].ts;
1005  return 0;
1006 }
1007 
1008 static int add_interval(struct ws_intervals *inter,
1009  enum ws_interval_type type, uint32_t channels, int ref,
1010  int64_t ts1, int32_t f1, int32_t a1,
1011  int64_t ts2, int32_t f2, int32_t a2)
1012 {
1013  struct ws_interval *i, *ri;
1014 
1015  if (ref >= 0) {
1016  ri = &inter->inter[ref];
1017  /* ref and new intervals are constant, identical and adjacent */
1018  if (ri->type == type && ri->channels == channels &&
1019  ri->f1 == ri->f2 && ri->f2 == f1 && f1 == f2 &&
1020  ri->a1 == ri->a2 && ri->a2 == a1 && a1 == a2 &&
1021  ri->ts2 == ts1) {
1022  ri->ts2 = ts2;
1023  return ref;
1024  }
1025  }
1026  i = alloc_array_elem((void **)&inter->inter, sizeof(*i),
1027  &inter->nb_inter, &inter->max_inter);
1028  if (!i)
1029  return AVERROR(ENOMEM);
1030  i->ts1 = ts1;
1031  i->ts2 = ts2;
1032  i->type = type;
1033  i->channels = channels;
1034  i->f1 = f1;
1035  i->f2 = f2;
1036  i->a1 = a1;
1037  i->a2 = a2;
1038  i->phi = ref >= 0 ? ref | 0x80000000 : 0;
1039  return i - inter->inter;
1040 }
1041 
1042 static int add_bell(struct ws_intervals *inter, struct sbg_script *s,
1043  int64_t ts1, int64_t ts2, int32_t f, int32_t a)
1044 {
1045  /* SBaGen uses an exponential decrease every 50ms.
1046  We approximate it with piecewise affine segments. */
1047  int32_t cpoints[][2] = {
1048  { 2, a },
1049  { 4, a - a / 4 },
1050  { 8, a / 2 },
1051  { 16, a / 4 },
1052  { 25, a / 10 },
1053  { 50, a / 80 },
1054  { 75, 0 },
1055  };
1056  int i, r;
1057  int64_t dt = s->sample_rate / 20, ts3 = ts1, ts4;
1058  for (i = 0; i < FF_ARRAY_ELEMS(cpoints); i++) {
1059  ts4 = FFMIN(ts2, ts1 + cpoints[i][0] * dt);
1060  r = add_interval(inter, WS_SINE, 3, -1,
1061  ts3, f, a, ts4, f, cpoints[i][1]);
1062  if (r < 0)
1063  return r;
1064  ts3 = ts4;
1065  a = cpoints[i][1];
1066  }
1067  return 0;
1068 }
1069 
1070 static int generate_interval(void *log, struct sbg_script *s,
1071  struct ws_intervals *inter,
1072  int64_t ts1, int64_t ts2,
1073  struct sbg_script_synth *s1,
1074  struct sbg_script_synth *s2,
1075  int transition)
1076 {
1077  int r;
1078 
1079  if (ts2 <= ts1 || (s1->vol == 0 && s2->vol == 0))
1080  return 0;
1081  switch (s1->type) {
1082  case SBG_TYPE_NONE:
1083  break;
1084  case SBG_TYPE_SINE:
1085  if (s1->beat == 0 && s2->beat == 0) {
1086  r = add_interval(inter, WS_SINE, 3, s1->ref.l,
1087  ts1, s1->carrier, s1->vol,
1088  ts2, s2->carrier, s2->vol);
1089  if (r < 0)
1090  return r;
1091  s2->ref.l = s2->ref.r = r;
1092  } else {
1093  r = add_interval(inter, WS_SINE, 1, s1->ref.l,
1094  ts1, s1->carrier + s1->beat / 2, s1->vol,
1095  ts2, s2->carrier + s2->beat / 2, s2->vol);
1096  if (r < 0)
1097  return r;
1098  s2->ref.l = r;
1099  r = add_interval(inter, WS_SINE, 2, s1->ref.r,
1100  ts1, s1->carrier - s1->beat / 2, s1->vol,
1101  ts2, s2->carrier - s2->beat / 2, s2->vol);
1102  if (r < 0)
1103  return r;
1104  s2->ref.r = r;
1105  }
1106  break;
1107 
1108  case SBG_TYPE_BELL:
1109  if (transition == 2) {
1110  r = add_bell(inter, s, ts1, ts2, s1->carrier, s2->vol);
1111  if (r < 0)
1112  return r;
1113  }
1114  break;
1115 
1116  case SBG_TYPE_SPIN:
1117  av_log(log, AV_LOG_WARNING, "Spinning noise not implemented, "
1118  "using pink noise instead.\n");
1119  /* fall through */
1120  case SBG_TYPE_NOISE:
1121  /* SBaGen's pink noise generator uses:
1122  - 1 band of white noise, mean square: 1/3;
1123  - 9 bands of subsampled white noise with linear
1124  interpolation, mean square: 2/3 each;
1125  with 1/10 weight each: the total mean square is 7/300.
1126  Our pink noise generator uses 8 bands of white noise with
1127  rectangular subsampling: the total mean square is 1/24.
1128  Therefore, to match SBaGen's volume, we must multiply vol by
1129  sqrt((7/300) / (1/24)) = sqrt(14/25) =~ 0.748
1130  */
1131  r = add_interval(inter, WS_NOISE, 3, s1->ref.l,
1132  ts1, 0, s1->vol - s1->vol / 4,
1133  ts2, 0, s2->vol - s2->vol / 4);
1134  if (r < 0)
1135  return r;
1136  s2->ref.l = s2->ref.r = r;
1137  break;
1138 
1139  case SBG_TYPE_MIX:
1140  /* Unimplemented: silence; warning present elsewhere */
1141  default:
1142  av_log(log, AV_LOG_ERROR,
1143  "Type %d is not implemented\n", s1->type);
1144  return AVERROR_PATCHWELCOME;
1145  }
1146  return 0;
1147 }
1148 
1149 static int generate_plateau(void *log, struct sbg_script *s,
1150  struct ws_intervals *inter,
1151  struct sbg_script_event *ev1)
1152 {
1153  int64_t ts1 = ev1->ts_int, ts2 = ev1->ts_trans;
1154  int i, r;
1155  struct sbg_script_synth *s1;
1156 
1157  for (i = 0; i < ev1->nb_elements; i++) {
1158  s1 = &s->synth[ev1->elements + i];
1159  r = generate_interval(log, s, inter, ts1, ts2, s1, s1, 0);
1160  if (r < 0)
1161  return r;
1162  }
1163  return 0;
1164 }
1165 
1166 /*
1167 
1168  ts1 ts2 ts1 tsmid ts2
1169  | | | | |
1170  v v v | v
1171 ____ ____ v ____
1172  ''''.... ''.. ..''
1173  ''''....____ ''....''
1174 
1175  compatible transition incompatible transition
1176  */
1177 
1178 static int generate_transition(void *log, struct sbg_script *s,
1179  struct ws_intervals *inter,
1180  struct sbg_script_event *ev1,
1181  struct sbg_script_event *ev2)
1182 {
1183  int64_t ts1 = ev1->ts_trans, ts2 = ev1->ts_next;
1184  /* (ts1 + ts2) / 2 without overflow */
1185  int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1);
1186  enum sbg_fade_type type = ev1->fade.slide | (ev1->fade.out & ev2->fade.in);
1187  int nb_elements = FFMAX(ev1->nb_elements, ev2->nb_elements);
1188  struct sbg_script_synth *s1, *s2, s1mod, s2mod, smid;
1189  int pass, i, r;
1190 
1191  for (pass = 0; pass < 2; pass++) {
1192  /* pass = 0 -> compatible and first half of incompatible
1193  pass = 1 -> second half of incompatible
1194  Using two passes like that ensures that the intervals are generated
1195  in increasing order according to their start timestamp.
1196  Otherwise it would be necessary to sort them
1197  while keeping the mutual references.
1198  */
1199  for (i = 0; i < nb_elements; i++) {
1200  s1 = i < ev1->nb_elements ? &s->synth[ev1->elements + i] : &s1mod;
1201  s2 = i < ev2->nb_elements ? &s->synth[ev2->elements + i] : &s2mod;
1202  s1mod = s1 != &s1mod ? *s1 : (struct sbg_script_synth){ 0 };
1203  s2mod = s2 != &s2mod ? *s2 : (struct sbg_script_synth){ 0 };
1204  if (ev1->fade.slide) {
1205  /* for slides, and only for slides, silence ("-") is equivalent
1206  to anything with volume 0 */
1207  if (s1mod.type == SBG_TYPE_NONE) {
1208  s1mod = s2mod;
1209  s1mod.vol = 0;
1210  } else if (s2mod.type == SBG_TYPE_NONE) {
1211  s2mod = s1mod;
1212  s2mod.vol = 0;
1213  }
1214  }
1215  if (s1mod.type == s2mod.type &&
1216  s1mod.type != SBG_TYPE_BELL &&
1217  (type == SBG_FADE_ADAPT ||
1218  (s1mod.carrier == s2mod.carrier &&
1219  s1mod.beat == s2mod.beat))) {
1220  /* compatible: single transition */
1221  if (!pass) {
1222  r = generate_interval(log, s, inter,
1223  ts1, ts2, &s1mod, &s2mod, 3);
1224  if (r < 0)
1225  return r;
1226  s2->ref = s2mod.ref;
1227  }
1228  } else {
1229  /* incompatible: silence at midpoint */
1230  if (!pass) {
1231  smid = s1mod;
1232  smid.vol = 0;
1233  r = generate_interval(log, s, inter,
1234  ts1, tsmid, &s1mod, &smid, 1);
1235  if (r < 0)
1236  return r;
1237  } else {
1238  smid = s2mod;
1239  smid.vol = 0;
1240  r = generate_interval(log, s, inter,
1241  tsmid, ts2, &smid, &s2mod, 2);
1242  if (r < 0)
1243  return r;
1244  s2->ref = s2mod.ref;
1245  }
1246  }
1247  }
1248  }
1249  return 0;
1250 }
1251 
1252 /*
1253  ev1 trats ev2 intts endts ev3
1254  | | | | | |
1255  v v v v v v
1256  ________________
1257 .... .... ....
1258  '''....________________....''' '''...._______________
1259 
1260 \_________/\______________/\_________/\______________/\_________/\_____________/
1261  tr x->1 int1 tr 1->2 int2 tr 2->3 int3
1262  */
1263 
1264 static int generate_intervals(void *log, struct sbg_script *s, int sample_rate,
1265  struct ws_intervals *inter)
1266 {
1267  int64_t trans_time = s->opt_fade_time / 2;
1268  struct sbg_script_event ev0, *ev1, *ev2;
1269  int64_t period;
1270  int i, r;
1271 
1272  /* SBaGen handles the time before and after the extremal events,
1273  and the corresponding transitions, as if the sequence were cyclic
1274  with a 24-hours period. */
1275  period = s->events[s->nb_events - 1].ts - s->events[0].ts;
1276  period = (period + (DAY_TS - 1)) / DAY_TS * DAY_TS;
1277  period = FFMAX(period, DAY_TS);
1278 
1279  /* Prepare timestamps for transitions */
1280  for (i = 0; i < s->nb_events; i++) {
1281  ev1 = &s->events[i];
1282  ev2 = &s->events[(i + 1) % s->nb_events];
1283  ev1->ts_int = ev1->ts;
1284  ev1->ts_trans = ev1->fade.slide ? ev1->ts
1285  : ev2->ts + (ev1 < ev2 ? 0 : period);
1286  }
1287  for (i = 0; i < s->nb_events; i++) {
1288  ev1 = &s->events[i];
1289  ev2 = &s->events[(i + 1) % s->nb_events];
1290  if (!ev1->fade.slide) {
1291  ev1->ts_trans = FFMAX(ev1->ts_int, ev1->ts_trans - trans_time);
1292  ev2->ts_int = FFMIN(ev2->ts_trans, ev2->ts_int + trans_time);
1293  }
1294  ev1->ts_next = ev2->ts_int + (ev1 < ev2 ? 0 : period);
1295  }
1296 
1297  /* Pseudo event before the first one */
1298  ev0 = s->events[s->nb_events - 1];
1299  ev0.ts_int -= period;
1300  ev0.ts_trans -= period;
1301  ev0.ts_next -= period;
1302 
1303  /* Convert timestamps */
1304  for (i = -1; i < s->nb_events; i++) {
1305  ev1 = i < 0 ? &ev0 : &s->events[i];
1306  ev1->ts_int = av_rescale(ev1->ts_int, sample_rate, AV_TIME_BASE);
1307  ev1->ts_trans = av_rescale(ev1->ts_trans, sample_rate, AV_TIME_BASE);
1308  ev1->ts_next = av_rescale(ev1->ts_next, sample_rate, AV_TIME_BASE);
1309  }
1310 
1311  /* Generate intervals */
1312  for (i = 0; i < s->nb_synth; i++)
1313  s->synth[i].ref.l = s->synth[i].ref.r = -1;
1314  for (i = -1; i < s->nb_events; i++) {
1315  ev1 = i < 0 ? &ev0 : &s->events[i];
1316  ev2 = &s->events[(i + 1) % s->nb_events];
1317  r = generate_plateau(log, s, inter, ev1);
1318  if (r < 0)
1319  return r;
1320  r = generate_transition(log, s, inter, ev1, ev2);
1321  if (r < 0)
1322  return r;
1323  }
1324  if (!inter->nb_inter)
1325  av_log(log, AV_LOG_WARNING, "Completely silent script.\n");
1326  return 0;
1327 }
1328 
1330  struct ws_intervals *inter)
1331 {
1332  int i, edata_size = 4, ret;
1333  uint8_t *edata;
1334 
1335  for (i = 0; i < inter->nb_inter; i++) {
1336  edata_size += inter->inter[i].type == WS_SINE ? 44 :
1337  inter->inter[i].type == WS_NOISE ? 32 : 0;
1338  if (edata_size < 0)
1339  return AVERROR(ENOMEM);
1340  }
1341  if ((ret = ff_alloc_extradata(par, edata_size)) < 0)
1342  return ret;
1343  edata = par->extradata;
1344 
1345 #define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0)
1346 #define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0)
1347  ADD_EDATA32(inter->nb_inter);
1348  for (i = 0; i < inter->nb_inter; i++) {
1349  ADD_EDATA64(inter->inter[i].ts1);
1350  ADD_EDATA64(inter->inter[i].ts2);
1351  ADD_EDATA32(inter->inter[i].type);
1352  ADD_EDATA32(inter->inter[i].channels);
1353  switch (inter->inter[i].type) {
1354  case WS_SINE:
1355  ADD_EDATA32(inter->inter[i].f1);
1356  ADD_EDATA32(inter->inter[i].f2);
1357  ADD_EDATA32(inter->inter[i].a1);
1358  ADD_EDATA32(inter->inter[i].a2);
1359  ADD_EDATA32(inter->inter[i].phi);
1360  break;
1361  case WS_NOISE:
1362  ADD_EDATA32(inter->inter[i].a1);
1363  ADD_EDATA32(inter->inter[i].a2);
1364  break;
1365  }
1366  }
1367  if (edata != par->extradata + edata_size)
1368  return AVERROR_BUG;
1369  return 0;
1370 }
1371 
1372 static av_cold int sbg_read_probe(const AVProbeData *p)
1373 {
1374  int r, score;
1375  struct sbg_script script = { 0 };
1376 
1377  r = parse_script(NULL, p->buf, p->buf_size, &script);
1378  score = r < 0 || !script.nb_def || !script.nb_tseq ? 0 :
1379  AVPROBE_SCORE_MAX / 3;
1380  free_script(&script);
1381  return score;
1382 }
1383 
1385 {
1386  struct sbg_demuxer *sbg = avf->priv_data;
1387  int r;
1388  char *buf = NULL;
1389  struct sbg_script script = { 0 };
1390  AVStream *st;
1391  struct ws_intervals inter = { 0 };
1392 
1393  r = read_whole_file(avf->pb, sbg->max_file_size, &buf);
1394  if (r < 0)
1395  goto fail;
1396  r = parse_script(avf, buf, r, &script);
1397  if (r < 0)
1398  goto fail;
1399  if (!sbg->sample_rate)
1400  sbg->sample_rate = script.sample_rate;
1401  else
1402  script.sample_rate = sbg->sample_rate;
1403  if (!sbg->frame_size)
1404  sbg->frame_size = FFMAX(1, sbg->sample_rate / 10);
1405  if (script.opt_mix)
1406  av_log(avf, AV_LOG_WARNING, "Mix feature not implemented: "
1407  "-m is ignored and mix channels will be silent.\n");
1408  r = expand_script(avf, &script);
1409  if (r < 0)
1410  goto fail;
1411  av_freep(&buf);
1412  r = generate_intervals(avf, &script, sbg->sample_rate, &inter);
1413  if (r < 0)
1414  goto fail;
1415 
1416  st = avformat_new_stream(avf, NULL);
1417  if (!st)
1418  return AVERROR(ENOMEM);
1421  st->codecpar->channels = 2;
1423  st->codecpar->sample_rate = sbg->sample_rate;
1424  st->codecpar->frame_size = sbg->frame_size;
1425  avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
1426  st->probe_packets = 0;
1427  st->start_time = av_rescale(script.start_ts,
1428  sbg->sample_rate, AV_TIME_BASE);
1429  st->duration = script.end_ts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE :
1430  av_rescale(script.end_ts - script.start_ts,
1431  sbg->sample_rate, AV_TIME_BASE);
1432  st->cur_dts = st->start_time;
1433  r = encode_intervals(&script, st->codecpar, &inter);
1434  if (r < 0)
1435  goto fail;
1436 
1437  av_free(inter.inter);
1438  free_script(&script);
1439  return 0;
1440 
1441 fail:
1442  av_free(inter.inter);
1443  free_script(&script);
1444  av_free(buf);
1445  return r;
1446 }
1447 
1448 static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
1449 {
1450  int64_t ts, end_ts;
1451  int ret;
1452 
1453  ts = avf->streams[0]->cur_dts;
1454  end_ts = ts + avf->streams[0]->codecpar->frame_size;
1455  if (avf->streams[0]->duration != AV_NOPTS_VALUE)
1456  end_ts = FFMIN(avf->streams[0]->start_time + avf->streams[0]->duration,
1457  end_ts);
1458  if (end_ts <= ts)
1459  return AVERROR_EOF;
1460  if ((ret = av_new_packet(packet, 12)) < 0)
1461  return ret;
1462  packet->dts = packet->pts = ts;
1463  packet->duration = end_ts - ts;
1464  AV_WL64(packet->data + 0, ts);
1465  AV_WL32(packet->data + 8, packet->duration);
1466  return packet->size;
1467 }
1468 
1469 static int sbg_read_seek2(AVFormatContext *avf, int stream_index,
1470  int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
1471 {
1472  if (flags || stream_index > 0)
1473  return AVERROR(EINVAL);
1474  if (stream_index < 0)
1475  ts = av_rescale_q(ts, AV_TIME_BASE_Q, avf->streams[0]->time_base);
1476  avf->streams[0]->cur_dts = ts;
1477  return 0;
1478 }
1479 
1480 static int sbg_read_seek(AVFormatContext *avf, int stream_index,
1481  int64_t ts, int flags)
1482 {
1483  return sbg_read_seek2(avf, stream_index, ts, ts, ts, 0);
1484 }
1485 
1486 static const AVOption sbg_options[] = {
1487  { "sample_rate", "", offsetof(struct sbg_demuxer, sample_rate),
1488  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
1490  { "frame_size", "", offsetof(struct sbg_demuxer, frame_size),
1491  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
1492  AV_OPT_FLAG_DECODING_PARAM },
1493  { "max_file_size", "", offsetof(struct sbg_demuxer, max_file_size),
1494  AV_OPT_TYPE_INT, { .i64 = 5000000 }, 0, INT_MAX,
1495  AV_OPT_FLAG_DECODING_PARAM },
1496  { NULL },
1497 };
1498 
1499 static const AVClass sbg_demuxer_class = {
1500  .class_name = "sbg_demuxer",
1501  .item_name = av_default_item_name,
1502  .option = sbg_options,
1503  .version = LIBAVUTIL_VERSION_INT,
1504 };
1505 
1507  .name = "sbg",
1508  .long_name = NULL_IF_CONFIG_SMALL("SBaGen binaural beats script"),
1509  .priv_data_size = sizeof(struct sbg_demuxer),
1510  .read_probe = sbg_read_probe,
1511  .read_header = sbg_read_header,
1512  .read_packet = sbg_read_packet,
1513  .read_seek = sbg_read_seek,
1514  .read_seek2 = sbg_read_seek2,
1515  .extensions = "sbg",
1516  .priv_class = &sbg_demuxer_class,
1517 };
int64_t ts_trans
Definition: sbgdec.c:101
char * cursor
Definition: sbgdec.c:129
#define NULL
Definition: coverity.c:32
char * opt_mix
Definition: sbgdec.c:120
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int sample_rate
Definition: sbgdec.c:121
static int parse_synth_channel_bell(struct sbg_parser *p, struct sbg_script_synth *synth)
Definition: sbgdec.c:652
static av_cold int sbg_read_header(AVFormatContext *avf)
Definition: sbgdec.c:1384
#define av_realloc_f(p, o, n)
AVOption.
Definition: opt.h:248
static int generate_transition(void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1, struct sbg_script_event *ev2)
Definition: sbgdec.c:1178
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int64_t end_ts
Definition: sbgdec.c:117
struct sbg_script_event * events
Definition: sbgdec.c:111
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4869
uint32_t channels
Definition: ffwavesynth.c:87
uint8_t opt_start_at_first
Definition: sbgdec.c:122
int probe_packets
Number of packets to buffer for codec probing.
Definition: avformat.h:1086
static int parse_immediate(struct sbg_parser *p)
Definition: sbgdec.c:322
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
ws_interval_type
Definition: ffwavesynth.c:77
int nb_synth_max
Definition: sbgdec.c:133
int size
Definition: packet.h:364
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
static int parse_timestamp(struct sbg_parser *p, struct sbg_timestamp *rts, int64_t *rrel)
Definition: sbgdec.c:459
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:36
static const AVOption sbg_options[]
Definition: sbgdec.c:1486
static int add_bell(struct ws_intervals *inter, struct sbg_script *s, int64_t ts1, int64_t ts2, int32_t f, int32_t a)
Definition: sbgdec.c:1042
char type
Definition: sbgdec.c:71
GLint GLenum type
Definition: opengl_enc.c:104
#define a1
Definition: regdef.h:47
#define AV_CH_LAYOUT_STEREO
char * script
Definition: sbgdec.c:128
static int expand_tseq(void *log, struct sbg_script *s, int *nb_ev_max, int64_t t0, struct sbg_script_tseq *tseq)
Definition: sbgdec.c:943
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
static int parse_volume(struct sbg_parser *p, int *vol)
Definition: sbgdec.c:605
int8_t in
Definition: sbgdec.c:55
#define DAY
Definition: sbgdec.c:33
static void expand_timestamps(void *log, struct sbg_script *s)
Definition: sbgdec.c:889
int frame_size
Audio only.
Definition: codec_par.h:181
static int parse_synth_channel(struct sbg_parser *p)
Definition: sbgdec.c:707
Format I/O context.
Definition: avformat.h:1351
static int scale_double(void *log, double d, double m, int *r)
Definition: sbgdec.c:209
int64_t cur_dts
Definition: avformat.h:1079
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define SBG_SCALE
Definition: sbgdec.c:32
uint8_t
#define av_cold
Definition: attributes.h:88
#define av_malloc(s)
static av_cold int sbg_read_probe(const AVProbeData *p)
Definition: sbgdec.c:1372
float delta
AVOptions.
int32_t f1
Definition: sbgdec.c:147
#define f(width, name)
Definition: cbs_vp9.c:255
static int sbg_read_seek(AVFormatContext *avf, int stream_index, int64_t ts, int flags)
Definition: sbgdec.c:1480
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
int nb_events
Definition: sbgdec.c:114
int64_t ts1
Definition: sbgdec.c:144
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:381
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:4450
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1419
int nb_tseq
Definition: sbgdec.c:113
#define t0
Definition: regdef.h:28
double strtod(const char *, char **)
static int parse_named_def(struct sbg_parser *p)
Definition: sbgdec.c:757
uint8_t * data
Definition: packet.h:363
#define AVERROR_EOF
End of file.
Definition: error.h:55
int64_t opt_duration
Definition: sbgdec.c:119
static int lex_wsword(struct sbg_parser *p, struct sbg_string *rs)
Definition: sbgdec.c:280
ptrdiff_t size
Definition: opengl_enc.c:100
int nb_block_tseq
Definition: sbgdec.c:132
enum ws_interval_type type
Definition: ffwavesynth.c:88
channels
Definition: aptx.h:33
uint64_t channel_layout
Audio only.
Definition: codec_par.h:162
#define av_log(a,...)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:637
sbg_synth_type
Definition: sbgdec.c:58
int nb_def
Definition: sbgdec.c:112
static void free_script(struct sbg_script *s)
Definition: sbgdec.c:784
struct sbg_timestamp ts
Definition: sbgdec.c:92
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
struct sbg_fade fade
Definition: sbgdec.c:103
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:88
#define AV_WL64(p, v)
Definition: intreadwrite.h:440
int line_no
Definition: sbgdec.c:134
int nb_synth
Definition: sbgdec.c:115
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define s2
Definition: regdef.h:39
int frame_size
Definition: sbgdec.c:39
static BenchmarkTimeStamps current_time
Definition: ffmpeg.c:142
struct sbg_script_synth * synth
Definition: sbgdec.c:108
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)
Definition: vp8.c:488
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
const char * r
Definition: vf_curves.c:114
struct sbg_script_synth::@286 ref
struct ws_interval * inter
Definition: sbgdec.c:153
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
static int lex_double(struct sbg_parser *p, double *r)
Definition: sbgdec.c:238
int nb_block_tseq_max
Definition: sbgdec.c:133
int max_inter
Definition: sbgdec.c:155
int32_t a1
Definition: sbgdec.c:148
int64_t start_ts
Definition: sbgdec.c:116
#define FFMAX(a, b)
Definition: common.h:94
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option keep it simple and lowercase description are in without period
#define fail()
Definition: checkasm.h:123
static int parse_synth_channel_pink(struct sbg_parser *p, struct sbg_script_synth *synth)
Definition: sbgdec.c:639
#define pass
Definition: fft_template.c:619
int64_t ts
Definition: sbgdec.c:100
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:444
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:443
int64_t opt_fade_time
Definition: sbgdec.c:118
static int read_whole_file(AVIOContext *io, int max_size, char **rbuf)
Definition: sbgdec.c:856
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0...
Definition: utils.c:3259
uint64_t phi
Definition: ffwavesynth.c:86
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
struct sbg_script_definition * def
Definition: sbgdec.c:107
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
#define FFMIN(a, b)
Definition: common.h:96
static int parse_block_def(struct sbg_parser *p, struct sbg_script_definition *def)
Definition: sbgdec.c:576
static const ElemCat * elements[ELEMENT_COUNT]
Definition: signature.h:566
static int parse_synth_channel_mix(struct sbg_parser *p, struct sbg_script_synth *synth)
Definition: sbgdec.c:671
struct sbg_fade fade
Definition: sbgdec.c:96
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
#define a2
Definition: regdef.h:48
static void * alloc_array_elem(void **array, size_t elsize, int *size, int *max_size)
Definition: sbgdec.c:158
#define s(width, name)
Definition: cbs_vp9.c:257
enum sbg_synth_type type
Definition: sbgdec.c:85
struct sbg_timestamp current_time
Definition: sbgdec.c:131
#define DAY_TS
Definition: sbgdec.c:34
char * end
Definition: sbgdec.c:128
#define FF_ARRAY_ELEMS(a)
static int encode_intervals(struct sbg_script *s, AVCodecParameters *par, struct ws_intervals *inter)
Definition: sbgdec.c:1329
if(ret)
static int generate_intervals(void *log, struct sbg_script *s, int sample_rate, struct ws_intervals *inter)
Definition: sbgdec.c:1264
Stream structure.
Definition: avformat.h:876
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
Definition: sbgdec.c:1448
static int parse_synth_def(struct sbg_parser *p, struct sbg_script_definition *def)
Definition: sbgdec.c:733
static int parse_wave_def(struct sbg_parser *p, int wavenum)
Definition: sbgdec.c:569
struct sbg_script_tseq * tseq
Definition: sbgdec.c:109
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AVIOContext * pb
I/O context.
Definition: avformat.h:1393
static int is_space(char c)
Definition: sbgdec.c:204
int nb_tseq_max
Definition: sbgdec.c:133
char * s
Definition: sbgdec.c:44
static int lex_char(struct sbg_parser *p, char c)
Definition: sbgdec.c:230
struct sbg_script_tseq * block_tseq
Definition: sbgdec.c:110
#define abs(x)
Definition: cuda_runtime.h:35
static int lex_space(struct sbg_parser *p)
Definition: sbgdec.c:221
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it be(in the first position) for now.Options-------Then comes the options array.This is what will define the user accessible options.For example
int max_file_size
Definition: sbgdec.c:40
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)
Definition: sbgdec.c:1008
int64_t ts_next
Definition: sbgdec.c:101
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:279
#define FORWARD_ERROR(c)
Definition: sbgdec.c:315
int sample_rate
Definition: sbgdec.c:38
#define s1
Definition: regdef.h:38
#define snprintf
Definition: snprintf.h:34
int8_t out
Definition: sbgdec.c:55
int64_t t
Definition: sbgdec.c:70
This structure contains the data a format has to probe a file.
Definition: avformat.h:441
int nb_def_max
Definition: sbgdec.c:133
static const AVClass sbg_demuxer_class
Definition: sbgdec.c:1499
static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr)
Definition: sbgdec.c:492
char err_msg[128]
Definition: sbgdec.c:135
#define flags(name, subs,...)
Definition: cbs_av1.c:560
static int parse_preprogrammed(struct sbg_parser *p)
Definition: sbgdec.c:329
static int generate_plateau(void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1)
Definition: sbgdec.c:1149
uint32_t phi
Definition: sbgdec.c:149
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:925
int sample_rate
Audio only.
Definition: codec_par.h:170
static int parse_synth_channel_sine(struct sbg_parser *p, struct sbg_script_synth *synth)
Definition: sbgdec.c:618
#define ADD_EDATA32(v)
struct sbg_script scs
Definition: sbgdec.c:130
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:453
static int parse_synth_channel_spin(struct sbg_parser *p, struct sbg_script_synth *synth)
Definition: sbgdec.c:684
int name_len
Definition: sbgdec.c:94
static int parse_time_sequence(struct sbg_parser *p, int inblock)
Definition: sbgdec.c:516
Main libavformat public API header.
static int sbg_read_seek2(AVFormatContext *avf, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Definition: sbgdec.c:1469
static int str_to_time(const char *str, int64_t *rtime)
Definition: sbgdec.c:178
static int lex_line_end(struct sbg_parser *p)
Definition: sbgdec.c:262
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int nb_inter
Definition: sbgdec.c:154
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:915
static int expand_script(void *log, struct sbg_script *s)
Definition: sbgdec.c:989
sbg_fade_type
Definition: sbgdec.c:48
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)
Definition: sbgdec.c:1070
#define localtime_r
Definition: time_internal.h:46
void * log
Definition: sbgdec.c:127
static int parse_script(void *log, char *script, int script_len, struct sbg_script *rscript)
Definition: sbgdec.c:794
#define ADD_EDATA64(v)
AVInputFormat ff_sbg_demuxer
Definition: sbgdec.c:1506
int32_t f2
Definition: sbgdec.c:147
int64_t ts_int
Definition: sbgdec.c:101
#define av_free(p)
uint8_t opt_end_at_last
Definition: sbgdec.c:123
void * priv_data
Format private data.
Definition: avformat.h:1379
static int parse_options(struct sbg_parser *p)
Definition: sbgdec.c:346
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
int channels
Audio only.
Definition: codec_par.h:166
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:362
int32_t a2
Definition: sbgdec.c:148
FILE * out
Definition: movenc.c:54
#define av_freep(p)
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:650
static int lex_name(struct sbg_parser *p, struct sbg_string *rs)
Definition: sbgdec.c:294
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r)
Definition: sbgdec.c:336
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1023
static int lex_fixed(struct sbg_parser *p, const char *t, int l)
Definition: sbgdec.c:254
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:905
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int64_t ts2
Definition: sbgdec.c:144
#define MKTAG(a, b, c, d)
Definition: common.h:406
This structure stores compressed data.
Definition: packet.h:340
char * name
Definition: sbgdec.c:93
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:356
for(j=16;j >0;--j)
int i
Definition: input.c:407
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
static int lex_time(struct sbg_parser *p, int64_t *rt)
Definition: sbgdec.c:308
int8_t slide
Definition: sbgdec.c:55
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
char * e
Definition: sbgdec.c:45