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') {
989 int i,
r, nb_events_max = 0;
992 for (i = 0; i < s->
nb_tseq; i++) {
1014 ri = &inter->
inter[ref];
1017 ri->
f1 == ri->
f2 && ri->
f2 == f1 && f1 == f2 &&
1018 ri->
a1 == ri->
a2 && ri->
a2 == a1 && a1 == a2 &&
1036 i->
phi = ref >= 0 ? ref | 0x80000000 : 0;
1037 return i - inter->
inter;
1057 ts4 =
FFMIN(ts2, ts1 + cpoints[i][0] * dt);
1059 ts3, f, a, ts4, f, cpoints[i][1]);
1070 int64_t
ts1, int64_t
ts2,
1077 if (ts2 <= ts1 || (s1->
vol == 0 && s2->
vol == 0))
1083 if (s1->
beat == 0 && s2->
beat == 0) {
1107 if (transition == 2) {
1116 "using pink noise instead.\n");
1130 ts1, 0, s1->
vol - s1->
vol / 4,
1131 ts2, 0, s2->
vol - s2->
vol / 4);
1141 "Type %d is not implemented\n", s1->
type);
1183 int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1);
1189 for (pass = 0; pass < 2; pass++) {
1197 for (i = 0; i < nb_elements; i++) {
1221 ts1, ts2, &s1mod, &s2mod, 3);
1232 ts1, tsmid, &s1mod, &smid, 1);
1239 tsmid, ts2, &smid, &s2mod, 2);
1275 period =
FFMAX(period, DAY_TS);
1283 : ev2->
ts + (ev1 < ev2 ? 0 : period);
1303 ev1 = i < 0 ? &ev0 : &s->
events[i];
1313 ev1 = i < 0 ? &ev0 : &s->
events[i];
1330 int i, edata_size = 4;
1333 for (i = 0; i < inter->
nb_inter; i++) {
1343 #define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0)
1344 #define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0)
1346 for (i = 0; i < inter->
nb_inter; i++) {
1365 if (edata != avc->
extradata + edata_size)
1405 "-m is ignored and mix channels will be silent.\n");
1459 packet->
dts = packet->
pts = ts;
1463 return packet->
size;
1467 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
1469 if (flags || stream_index > 0)
1471 if (stream_index < 0)
1478 int64_t ts,
int flags)
1490 {
"max_file_size",
"", offsetof(
struct sbg_demuxer, max_file_size),
1512 .extensions =
"sbg",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int parse_synth_channel_bell(struct sbg_parser *p, struct sbg_script_synth *synth)
static av_cold int sbg_read_header(AVFormatContext *avf)
#define av_realloc_f(p, o, n)
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 av_cold int sbg_read_probe(AVProbeData *p)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
struct sbg_script_event * events
uint8_t opt_start_at_first
static int parse_immediate(struct sbg_parser *p)
static int parse_timestamp(struct sbg_parser *p, struct sbg_timestamp *rts, int64_t *rrel)
static const AVOption sbg_options[]
static int add_bell(struct ws_intervals *inter, struct sbg_script *s, int64_t ts1, int64_t ts2, int32_t f, int32_t a)
#define FF_ARRAY_ELEMS(a)
#define AV_CH_LAYOUT_STEREO
static int expand_tseq(void *log, struct sbg_script *s, int *nb_ev_max, int64_t t0, struct sbg_script_tseq *tseq)
static int parse_volume(struct sbg_parser *p, int *vol)
static void expand_timestamps(void *log, struct sbg_script *s)
static int parse_synth_channel(struct sbg_parser *p)
static int scale_double(void *log, double d, double m, int *r)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int sbg_read_seek(AVFormatContext *avf, int stream_index, int64_t ts, int flags)
static av_cold int end(AVCodecContext *avctx)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
double strtod(const char *, char **)
static int parse_named_def(struct sbg_parser *p)
#define AVERROR_EOF
End of file.
static int lex_wsword(struct sbg_parser *p, struct sbg_string *rs)
static void fade(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int width, int height, int alpha, int beta)
enum ws_interval_type type
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
static void free_script(struct sbg_script *s)
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
struct sbg_script_synth * synth
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct ws_interval * inter
static int lex_double(struct sbg_parser *p, double *r)
uint64_t channel_layout
Audio channel layout.
static int parse_synth_channel_pink(struct sbg_parser *p, struct sbg_script_synth *synth)
AVCodecContext * codec
Codec context associated with this stream.
int buf_size
Size of buf except extra allocated bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static int read_whole_file(AVIOContext *io, int max_size, char **rbuf)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
struct sbg_script_definition * def
#define AV_TIME_BASE
Internal time base represented as integer.
static int parse_block_def(struct sbg_parser *p, struct sbg_script_definition *def)
static struct tm * localtime_r(const time_t *clock, struct tm *result)
static int parse_synth_channel_mix(struct sbg_parser *p, struct sbg_script_synth *synth)
static void * alloc_array_elem(void **array, size_t elsize, int *size, int *max_size)
struct sbg_timestamp current_time
static int generate_intervals(void *log, struct sbg_script *s, int sample_rate, struct ws_intervals *inter)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
static int parse_synth_def(struct sbg_parser *p, struct sbg_script_definition *def)
static int parse_wave_def(struct sbg_parser *p, int wavenum)
int frame_size
Number of samples per channel in an audio frame.
struct sbg_script_tseq * tseq
#define AV_LOG_INFO
Standard information.
enum AVMediaType codec_type
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
AVIOContext * pb
I/O context.
static int is_space(char c)
static int lex_char(struct sbg_parser *p, char c)
struct sbg_script_tseq * block_tseq
main external API structure.
static int lex_space(struct sbg_parser *p)
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)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Describe the class of an AVClass context structure.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
static int encode_intervals(struct sbg_script *s, AVCodecContext *avc, struct ws_intervals *inter)
This structure contains the data a format has to probe a file.
static const AVClass sbg_demuxer_class
static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr)
static int parse_preprogrammed(struct sbg_parser *p)
static int generate_plateau(void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1)
int64_t duration
Decoding: duration of the stream, in stream time base.
static int parse_synth_channel_sine(struct sbg_parser *p, struct sbg_script_synth *synth)
static int parse_synth_channel_spin(struct sbg_parser *p, struct sbg_script_synth *synth)
static int parse_time_sequence(struct sbg_parser *p, int inblock)
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 str_to_time(const char *str, int64_t *rtime)
static int lex_line_end(struct sbg_parser *p)
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
static int expand_script(void *log, struct sbg_script *s)
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 parse_script(void *log, char *script, int script_len, struct sbg_script *rscript)
AVInputFormat ff_sbg_demuxer
int channels
number of audio channels
void * priv_data
Format private data.
static int parse_options(struct sbg_parser *p)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int lex_name(struct sbg_parser *p, struct sbg_string *rs)
static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r)
static int lex_fixed(struct sbg_parser *p, const char *t, int l)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
struct sbg_script_synth::@171 ref
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int lex_time(struct sbg_parser *p, int64_t *rt)