FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
sbgdec.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/time_internal.h"
#include "avformat.h"
#include "demux.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  sbg_demuxer
 
struct  sbg_string
 
struct  sbg_fade
 
struct  sbg_timestamp
 
struct  sbg_script_definition
 
struct  sbg_script_synth
 
struct  sbg_script_tseq
 
struct  sbg_script_event
 
struct  sbg_script
 
struct  sbg_parser
 
struct  ws_interval
 
struct  ws_intervals
 

Macros

#define SBG_SCALE   (1 << 16)
 
#define DAY   (24 * 60 * 60)
 
#define DAY_TS   ((int64_t)DAY * AV_TIME_BASE)
 
#define FORWARD_ERROR(c)
 
#define ADD_EDATA32(v)   do { AV_WL32(edata, (v)); edata += 4; } while(0)
 
#define ADD_EDATA64(v)   do { AV_WL64(edata, (v)); edata += 8; } while(0)
 

Enumerations

enum  sbg_fade_type { SBG_FADE_SILENCE = 0, SBG_FADE_SAME = 1, SBG_FADE_ADAPT = 3 }
 
enum  sbg_synth_type {
  SBG_TYPE_NONE, SBG_TYPE_SINE, SBG_TYPE_NOISE, SBG_TYPE_BELL,
  SBG_TYPE_MIX, SBG_TYPE_SPIN
}
 
enum  ws_interval_type { WS_SINE = MKTAG('S','I','N','E'), WS_NOISE = MKTAG('N','O','I','S'), WS_SINE = MKTAG('S','I','N','E'), WS_NOISE = MKTAG('N','O','I','S') }
 

Functions

static void * alloc_array_elem (void **array, size_t elsize, int *size, int *max_size)
 
static int str_to_time (const char *str, int64_t *rtime)
 
static int is_space (char c)
 
static int scale_double (void *log, double d, double m, int *r)
 
static int lex_space (struct sbg_parser *p)
 
static int lex_char (struct sbg_parser *p, char c)
 
static int lex_double (struct sbg_parser *p, double *r)
 
static int lex_fixed (struct sbg_parser *p, const char *t, int l)
 
static int lex_line_end (struct sbg_parser *p)
 
static int lex_wsword (struct sbg_parser *p, struct sbg_string *rs)
 
static int lex_name (struct sbg_parser *p, struct sbg_string *rs)
 
static int lex_time (struct sbg_parser *p, int64_t *rt)
 
static int parse_immediate (struct sbg_parser *p)
 
static int parse_preprogrammed (struct sbg_parser *p)
 
static int parse_optarg (struct sbg_parser *p, char o, struct sbg_string *r)
 
static int parse_options (struct sbg_parser *p)
 
static int parse_timestamp (struct sbg_parser *p, struct sbg_timestamp *rts, int64_t *rrel)
 
static int parse_fade (struct sbg_parser *p, struct sbg_fade *fr)
 
static int parse_time_sequence (struct sbg_parser *p, int inblock)
 
static int parse_wave_def (struct sbg_parser *p, int wavenum)
 
static int parse_block_def (struct sbg_parser *p, struct sbg_script_definition *def)
 
static int parse_volume (struct sbg_parser *p, int *vol)
 
static int parse_synth_channel_sine (struct sbg_parser *p, struct sbg_script_synth *synth)
 
static int parse_synth_channel_pink (struct sbg_parser *p, struct sbg_script_synth *synth)
 
static int parse_synth_channel_bell (struct sbg_parser *p, struct sbg_script_synth *synth)
 
static int parse_synth_channel_mix (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_synth_channel (struct sbg_parser *p)
 
static int parse_synth_def (struct sbg_parser *p, struct sbg_script_definition *def)
 
static int parse_named_def (struct sbg_parser *p)
 
static void free_script (struct sbg_script *s)
 
static int parse_script (void *log, char *script, int script_len, struct sbg_script *rscript)
 
static int read_whole_file (AVIOContext *io, int max_size, AVBPrint *rbuf)
 
static int expand_timestamps (void *log, struct sbg_script *s)
 
static int expand_tseq (void *log, struct sbg_script *s, int *nb_ev_max, int64_t t0, struct sbg_script_tseq *tseq)
 
static int expand_script (void *log, struct sbg_script *s)
 
static int add_interval (struct ws_intervals *inter, enum ws_interval_type type, uint32_t channels, int ref, int64_t ts1, int32_t f1, int32_t a1, int64_t ts2, int32_t f2, int32_t a2)
 
static int add_bell (struct ws_intervals *inter, struct sbg_script *s, int64_t ts1, int64_t ts2, int32_t f, int32_t a)
 
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 generate_plateau (void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1)
 
static int generate_transition (void *log, struct sbg_script *s, struct ws_intervals *inter, struct sbg_script_event *ev1, struct sbg_script_event *ev2)
 
static int generate_intervals (void *log, struct sbg_script *s, int sample_rate, struct ws_intervals *inter)
 
static int encode_intervals (struct sbg_script *s, AVCodecParameters *par, struct ws_intervals *inter)
 
static av_cold int sbg_read_probe (const AVProbeData *p)
 
static av_cold int sbg_read_header (AVFormatContext *avf)
 
static int sbg_read_packet (AVFormatContext *avf, AVPacket *packet)
 
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 sbg_read_seek (AVFormatContext *avf, int stream_index, int64_t ts, int flags)
 

Variables

static const AVOption sbg_options []
 
static const AVClass sbg_demuxer_class
 
const FFInputFormat ff_sbg_demuxer
 

Macro Definition Documentation

◆ SBG_SCALE

#define SBG_SCALE   (1 << 16)

Definition at line 36 of file sbgdec.c.

◆ DAY

#define DAY   (24 * 60 * 60)

Definition at line 37 of file sbgdec.c.

◆ DAY_TS

#define DAY_TS   ((int64_t)DAY * AV_TIME_BASE)

Definition at line 38 of file sbgdec.c.

◆ FORWARD_ERROR

#define FORWARD_ERROR (   c)
Value:
do { \
int errcode = c; \
if (errcode <= 0) \
return errcode ? errcode : AVERROR_INVALIDDATA; \
} while (0)

Definition at line 321 of file sbgdec.c.

◆ ADD_EDATA32

#define ADD_EDATA32 (   v)    do { AV_WL32(edata, (v)); edata += 4; } while(0)

◆ ADD_EDATA64

#define ADD_EDATA64 (   v)    do { AV_WL64(edata, (v)); edata += 8; } while(0)

Enumeration Type Documentation

◆ sbg_fade_type

Enumerator
SBG_FADE_SILENCE 
SBG_FADE_SAME 
SBG_FADE_ADAPT 

Definition at line 52 of file sbgdec.c.

◆ sbg_synth_type

Enumerator
SBG_TYPE_NONE 
SBG_TYPE_SINE 
SBG_TYPE_NOISE 
SBG_TYPE_BELL 
SBG_TYPE_MIX 
SBG_TYPE_SPIN 

Definition at line 62 of file sbgdec.c.

◆ ws_interval_type

Enumerator
WS_SINE 
WS_NOISE 
WS_SINE 
WS_NOISE 

Definition at line 142 of file sbgdec.c.

Function Documentation

◆ alloc_array_elem()

static void* alloc_array_elem ( void **  array,
size_t  elsize,
int size,
int max_size 
)
static

◆ str_to_time()

static int str_to_time ( const char *  str,
int64_t *  rtime 
)
static

Definition at line 182 of file sbgdec.c.

Referenced by lex_time(), and parse_options().

◆ is_space()

static int is_space ( char  c)
inlinestatic

Definition at line 210 of file sbgdec.c.

Referenced by lex_double(), lex_space(), and lex_wsword().

◆ scale_double()

static int scale_double ( void *  log,
double  d,
double  m,
int r 
)
inlinestatic

◆ lex_space()

static int lex_space ( struct sbg_parser p)
static

◆ lex_char()

static int lex_char ( struct sbg_parser p,
char  c 
)
static

◆ lex_double()

static int lex_double ( struct sbg_parser p,
double r 
)
static

◆ lex_fixed()

static int lex_fixed ( struct sbg_parser p,
const char *  t,
int  l 
)
static

◆ lex_line_end()

static int lex_line_end ( struct sbg_parser p)
static

◆ lex_wsword()

static int lex_wsword ( struct sbg_parser p,
struct sbg_string rs 
)
static

Definition at line 286 of file sbgdec.c.

Referenced by parse_optarg(), and parse_options().

◆ lex_name()

static int lex_name ( struct sbg_parser p,
struct sbg_string rs 
)
static

Definition at line 300 of file sbgdec.c.

Referenced by parse_named_def(), and parse_time_sequence().

◆ lex_time()

static int lex_time ( struct sbg_parser p,
int64_t *  rt 
)
static

Definition at line 314 of file sbgdec.c.

Referenced by parse_timestamp().

◆ parse_immediate()

static int parse_immediate ( struct sbg_parser p)
static

Definition at line 328 of file sbgdec.c.

Referenced by parse_options().

◆ parse_preprogrammed()

static int parse_preprogrammed ( struct sbg_parser p)
static

Definition at line 335 of file sbgdec.c.

Referenced by parse_options().

◆ parse_optarg()

static int parse_optarg ( struct sbg_parser p,
char  o,
struct sbg_string r 
)
static

Definition at line 342 of file sbgdec.c.

Referenced by parse_options().

◆ parse_options()

static int parse_options ( struct sbg_parser p)
static

Definition at line 352 of file sbgdec.c.

Referenced by parse_script().

◆ parse_timestamp()

static int parse_timestamp ( struct sbg_parser p,
struct sbg_timestamp rts,
int64_t *  rrel 
)
static

Definition at line 465 of file sbgdec.c.

Referenced by parse_time_sequence().

◆ parse_fade()

static int parse_fade ( struct sbg_parser p,
struct sbg_fade fr 
)
static

Definition at line 498 of file sbgdec.c.

Referenced by parse_time_sequence().

◆ parse_time_sequence()

static int parse_time_sequence ( struct sbg_parser p,
int  inblock 
)
static

Definition at line 522 of file sbgdec.c.

Referenced by parse_block_def(), and parse_script().

◆ parse_wave_def()

static int parse_wave_def ( struct sbg_parser p,
int  wavenum 
)
static

Definition at line 578 of file sbgdec.c.

Referenced by parse_named_def().

◆ parse_block_def()

static int parse_block_def ( struct sbg_parser p,
struct sbg_script_definition def 
)
static

Definition at line 585 of file sbgdec.c.

Referenced by parse_named_def().

◆ parse_volume()

static int parse_volume ( struct sbg_parser p,
int vol 
)
static

◆ parse_synth_channel_sine()

static int parse_synth_channel_sine ( struct sbg_parser p,
struct sbg_script_synth synth 
)
static

Definition at line 627 of file sbgdec.c.

Referenced by parse_synth_channel().

◆ parse_synth_channel_pink()

static int parse_synth_channel_pink ( struct sbg_parser p,
struct sbg_script_synth synth 
)
static

Definition at line 648 of file sbgdec.c.

Referenced by parse_synth_channel().

◆ parse_synth_channel_bell()

static int parse_synth_channel_bell ( struct sbg_parser p,
struct sbg_script_synth synth 
)
static

Definition at line 661 of file sbgdec.c.

Referenced by parse_synth_channel().

◆ parse_synth_channel_mix()

static int parse_synth_channel_mix ( struct sbg_parser p,
struct sbg_script_synth synth 
)
static

Definition at line 680 of file sbgdec.c.

Referenced by parse_synth_channel().

◆ parse_synth_channel_spin()

static int parse_synth_channel_spin ( struct sbg_parser p,
struct sbg_script_synth synth 
)
static

Definition at line 693 of file sbgdec.c.

Referenced by parse_synth_channel().

◆ parse_synth_channel()

static int parse_synth_channel ( struct sbg_parser p)
static

Definition at line 716 of file sbgdec.c.

Referenced by parse_synth_def().

◆ parse_synth_def()

static int parse_synth_def ( struct sbg_parser p,
struct sbg_script_definition def 
)
static

Definition at line 742 of file sbgdec.c.

Referenced by parse_named_def().

◆ parse_named_def()

static int parse_named_def ( struct sbg_parser p)
static

Definition at line 766 of file sbgdec.c.

Referenced by parse_script().

◆ free_script()

static void free_script ( struct sbg_script s)
static

Definition at line 793 of file sbgdec.c.

Referenced by parse_script(), sbg_read_header(), and sbg_read_probe().

◆ parse_script()

static int parse_script ( void *  log,
char *  script,
int  script_len,
struct sbg_script rscript 
)
static

Definition at line 803 of file sbgdec.c.

Referenced by sbg_read_header(), and sbg_read_probe().

◆ read_whole_file()

static int read_whole_file ( AVIOContext io,
int  max_size,
AVBPrint *  rbuf 
)
static

Definition at line 865 of file sbgdec.c.

Referenced by sbg_read_header().

◆ expand_timestamps()

static int expand_timestamps ( void *  log,
struct sbg_script s 
)
static

Definition at line 881 of file sbgdec.c.

Referenced by expand_script().

◆ expand_tseq()

static int expand_tseq ( void *  log,
struct sbg_script s,
int nb_ev_max,
int64_t  t0,
struct sbg_script_tseq tseq 
)
static

Definition at line 941 of file sbgdec.c.

Referenced by expand_script().

◆ expand_script()

static int expand_script ( void *  log,
struct sbg_script s 
)
static

Definition at line 990 of file sbgdec.c.

Referenced by sbg_read_header().

◆ add_interval()

static int add_interval ( struct ws_intervals inter,
enum ws_interval_type  type,
uint32_t  channels,
int  ref,
int64_t  ts1,
int32_t  f1,
int32_t  a1,
int64_t  ts2,
int32_t  f2,
int32_t  a2 
)
static

Definition at line 1011 of file sbgdec.c.

Referenced by add_bell(), and generate_interval().

◆ add_bell()

static int add_bell ( struct ws_intervals inter,
struct sbg_script s,
int64_t  ts1,
int64_t  ts2,
int32_t  f,
int32_t  a 
)
static

Definition at line 1045 of file sbgdec.c.

Referenced by generate_interval().

◆ generate_interval()

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

Definition at line 1073 of file sbgdec.c.

Referenced by generate_plateau(), and generate_transition().

◆ generate_plateau()

static int generate_plateau ( void *  log,
struct sbg_script s,
struct ws_intervals inter,
struct sbg_script_event ev1 
)
static

Definition at line 1152 of file sbgdec.c.

Referenced by generate_intervals().

◆ generate_transition()

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

Definition at line 1181 of file sbgdec.c.

Referenced by generate_intervals().

◆ generate_intervals()

static int generate_intervals ( void *  log,
struct sbg_script s,
int  sample_rate,
struct ws_intervals inter 
)
static

Definition at line 1267 of file sbgdec.c.

Referenced by sbg_read_header().

◆ encode_intervals()

static int encode_intervals ( struct sbg_script s,
AVCodecParameters par,
struct ws_intervals inter 
)
static

Definition at line 1341 of file sbgdec.c.

Referenced by sbg_read_header().

◆ sbg_read_probe()

static av_cold int sbg_read_probe ( const AVProbeData p)
static

Definition at line 1384 of file sbgdec.c.

◆ sbg_read_header()

static av_cold int sbg_read_header ( AVFormatContext avf)
static

Definition at line 1396 of file sbgdec.c.

◆ sbg_read_packet()

static int sbg_read_packet ( AVFormatContext avf,
AVPacket packet 
)
static

Definition at line 1476 of file sbgdec.c.

◆ sbg_read_seek2()

static int sbg_read_seek2 ( AVFormatContext avf,
int  stream_index,
int64_t  min_ts,
int64_t  ts,
int64_t  max_ts,
int  flags 
)
static

Definition at line 1497 of file sbgdec.c.

Referenced by sbg_read_seek().

◆ sbg_read_seek()

static int sbg_read_seek ( AVFormatContext avf,
int  stream_index,
int64_t  ts,
int  flags 
)
static

Definition at line 1508 of file sbgdec.c.

Variable Documentation

◆ sbg_options

const AVOption sbg_options[]
static
Initial value:
= {
{ "sample_rate", "", 0x42,
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
{ "frame_size", "", 0x42,
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
{ "max_file_size", "", 0x42,
AV_OPT_TYPE_INT, { .i64 = 5000000 }, 0, INT_MAX,
{ NULL },
}

Definition at line 1514 of file sbgdec.c.

◆ sbg_demuxer_class

const AVClass sbg_demuxer_class
static
Initial value:
= {
.class_name = "sbg_demuxer",
.item_name = av_default_item_name,
.option = sbg_options,
}

Definition at line 1527 of file sbgdec.c.

◆ ff_sbg_demuxer

const FFInputFormat ff_sbg_demuxer
Initial value:
= {
.p.name = "sbg",
.p.long_name = NULL_IF_CONFIG_SMALL("SBaGen binaural beats script"),
.p.extensions = "sbg",
.p.priv_class = &sbg_demuxer_class,
.priv_data_size = sizeof(struct sbg_demuxer),
.read_header = sbg_read_header,
.read_packet = sbg_read_packet,
.read_seek = sbg_read_seek,
.read_seek2 = sbg_read_seek2,
}

Definition at line 1534 of file sbgdec.c.

sbg_read_seek2
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:1497
sbg_read_packet
static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet)
Definition: sbgdec.c:1476
sbg_options
static const AVOption sbg_options[]
Definition: sbgdec.c:1514
sbg_read_seek
static int sbg_read_seek(AVFormatContext *avf, int stream_index, int64_t ts, int flags)
Definition: sbgdec.c:1508
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
sbg_demuxer
Definition: sbgdec.c:40
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
sbg_demuxer_class
static const AVClass sbg_demuxer_class
Definition: sbgdec.c:1527
c
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
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
sbg_read_header
static av_cold int sbg_read_header(AVFormatContext *avf)
Definition: sbgdec.c:1396
sbg_read_probe
static av_cold int sbg_read_probe(const AVProbeData *p)
Definition: sbgdec.c:1384
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:273
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:30
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61