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;
186 if (*cur < '0' || *cur >
'9')
188 hours = strtol(cur, &end, 10);
189 if (end == cur || *end !=
':' || end[1] <
'0' || end[1] >
'9')
192 minutes = strtol(cur, &end, 10);
197 seconds =
strtod(cur + 1, &end);
208 return c ==
' ' || c ==
'\t' || c ==
'\r';
214 if (m < INT_MIN || m >= INT_MAX) {
286 if (s == p->
end || *s ==
'\n')
300 while (c < p->
end && ((*
c >=
'a' && *
c <=
'z') || (*
c >=
'A' && *
c <=
'Z')
301 || (*
c >=
'0' && *
c <=
'9') || *
c ==
'_' || *
c ==
'-'))
317 #define FORWARD_ERROR(c) \ 321 return errcode ? errcode : AVERROR_INVALIDDATA; \ 327 "immediate sequences not yet implemented");
334 "preprogrammed sequences not yet implemented");
342 "option '%c' requires an argument", o);
359 for (; ostr.
s < ostr.
e; ostr.
s++) {
377 if (oarg.
e != tptr) {
379 "syntax error for option -F");
387 if (oarg.
e != oarg.
s + r) {
389 "syntax error for option -L");
396 if (oarg.
e != oarg.
s + r) {
398 "syntax error for option -T");
407 memcpy(tptr, oarg.
s, oarg.
e - oarg.
s);
408 tptr[oarg.
e - oarg.
s] = 0;
415 if (oarg.
e != tptr) {
417 "syntax error for option -q");
422 "speed factor other than 1 not supported");
428 r = strtol(oarg.
s, &tptr, 10);
429 if (oarg.
e != tptr) {
431 "syntax error for option -r");
436 "invalid sample rate");
443 "unknown option: '%c'", *ostr.
s);
464 int64_t
abs = 0, rel = 0, dt;
539 "relative time without previous absolute time");
577 "waveform definitions not yet implemented");
626 double carrierf, beatf;
627 int carrier, beat, vol;
692 double carrierf, beatf;
693 int carrier, beat, vol;
764 char *cursor_save = p->
cursor;
772 if (name.
e - name.
s == 6 && !memcmp(name.
s,
"wave", 4) &&
773 name.
s[4] >=
'0' && name.
s[4] <=
'9' &&
774 name.
s[5] >=
'0' && name.
s[5] <=
'9') {
775 int wavenum = (name.
s[4] -
'0') * 10 + (name.
s[5] -
'0');
805 .end = script + script_len,
812 .sample_rate = 44100,
846 int lctx = ectx -
ctx;
847 const char *quote =
"\"";
848 if (lctx > 0 && ctx[lctx - 1] ==
'\r')
851 ctx =
"the end of line";
864 int size = 0, bufsize = 0,
r;
867 if (bufsize - size < 1024) {
868 bufsize =
FFMIN(
FFMAX(2 * bufsize, 8192), max_size);
869 if (bufsize - size < 2) {
897 int64_t now, cur_ts,
delta = 0;
899 for (i = 0; i < s->
nb_tseq; i++)
906 "Start time ignored in a purely relative script.\n");
916 struct tm *tm, tmpbuf;
919 "Scripts with mixed absolute and relative timestamps can give " 920 "unexpected results (pause, seeking, time zone change).\n");
924 now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec :
927 (
int)(now / 3600), (
int)(now / 60) % 60, (
int)now % 60);
929 for (i = 0; i < s->
nb_tseq; i++) {
942 if (s->
tseq[i].
ts.
t + delta < cur_ts)
962 for (i = 0; i < s->
nb_def; i++) {
973 if (def->
type ==
'B') {
996 int i,
r, nb_events_max = 0;
999 for (i = 0; i < s->
nb_tseq; i++) {
1024 ri->
f1 == ri->
f2 && ri->
f2 == f1 && f1 == f2 &&
1025 ri->
a1 == ri->
a2 && ri->
a2 == a1 && a1 == a2 &&
1043 i->
phi = ref >= 0 ? ref | 0x80000000 : 0;
1044 return i - inter->
inter;
1064 ts4 =
FFMIN(ts2, ts1 + cpoints[i][0] * dt);
1066 ts3, f, a, ts4, f, cpoints[i][1]);
1077 int64_t
ts1, int64_t
ts2,
1084 if (ts2 <= ts1 || (s1->
vol == 0 && s2->
vol == 0))
1090 if (s1->
beat == 0 && s2->
beat == 0) {
1114 if (transition == 2) {
1123 "using pink noise instead.\n");
1137 ts1, 0, s1->
vol - s1->
vol / 4,
1138 ts2, 0, s2->
vol - s2->
vol / 4);
1148 "Type %d is not implemented\n", s1->
type);
1190 int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1);
1196 for (pass = 0; pass < 2; pass++) {
1204 for (i = 0; i < nb_elements; i++) {
1228 ts1, ts2, &s1mod, &s2mod, 3);
1239 ts1, tsmid, &s1mod, &smid, 1);
1246 tsmid, ts2, &smid, &s2mod, 2);
1282 period =
FFMAX(period, DAY_TS);
1290 : ev2->
ts + (ev1 < ev2 ? 0 : period);
1310 ev1 = i < 0 ? &ev0 : &s->
events[
i];
1320 ev1 = i < 0 ? &ev0 : &s->
events[
i];
1337 int i, edata_size = 4,
ret;
1340 for (i = 0; i < inter->
nb_inter; i++) {
1350 #define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0) 1351 #define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0) 1353 for (i = 0; i < inter->
nb_inter; i++) {
1372 if (edata != par->
extradata + edata_size)
1412 "-m is ignored and mix channels will be silent.\n");
1472 packet->
dts = packet->
pts = ts;
1476 return packet->
size;
1480 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
1482 if (flags || stream_index > 0)
1484 if (stream_index < 0)
1491 int64_t ts,
int flags)
1502 AV_OPT_FLAG_DECODING_PARAM },
1505 AV_OPT_FLAG_DECODING_PARAM },
1525 .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)
#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
int probe_packets
Number of packets to buffer for codec probing.
static int parse_immediate(struct sbg_parser *p)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
const char * av_default_item_name(void *ptr)
Return the context name.
static int parse_timestamp(struct sbg_parser *p, struct sbg_timestamp *rts, int64_t *rrel)
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
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)
This struct describes the properties of an encoded stream.
static int parse_volume(struct sbg_parser *p, int *vol)
static void expand_timestamps(void *log, struct sbg_script *s)
int frame_size
Audio only.
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 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 av_cold int end(AVCodecContext *avctx)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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
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)
enum ws_interval_type type
uint64_t channel_layout
Audio only.
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.
static BenchmarkTimeStamps current_time
struct sbg_script_synth * synth
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)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct ws_interval * inter
enum AVMediaType codec_type
General type of the encoded data.
static int lex_double(struct sbg_parser *p, double *r)
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
static int parse_synth_channel_pink(struct sbg_parser *p, struct sbg_script_synth *synth)
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 const ElemCat * elements[ELEMENT_COUNT]
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 encode_intervals(struct sbg_script *s, AVCodecParameters *par, struct ws_intervals *inter)
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)
struct sbg_script_tseq * tseq
#define AV_LOG_INFO
Standard information.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
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
static int lex_space(struct sbg_parser *p)
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
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.
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.
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
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)
#define flags(name, subs,...)
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.
int sample_rate
Audio only.
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)
static int ref[MAX_W *MAX_W]
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
struct sbg_script_synth::@284 ref
void * priv_data
Format private data.
static int parse_options(struct sbg_parser *p)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
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 array[MAX_W *MAX_W]
static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
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...
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
#define MKTAG(a, b, c, d)
This structure stores compressed data.
mode
Use these values in ebur128_init (or'ed).
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)