Skip to content

Commit

Permalink
audio player rework
Browse files Browse the repository at this point in the history
  • Loading branch information
salsaman committed Jul 2, 2024
1 parent 40128c7 commit 435c3ca
Show file tree
Hide file tree
Showing 16 changed files with 769 additions and 794 deletions.
901 changes: 416 additions & 485 deletions src/audio.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ weed_error_t lives_aplayer_set_data(lives_obj_t *aplayer, void **data);

// for afbuffer
// per chnnel size in bytes

#define MAX_READAHEAD 120.
#define MIN_READAHEAD 40.

#define ABUF_ARENA_SIZE 32 * 1024 * 1024

#define AREC_BUF_SIZE 2 * 1024 * 1024
Expand Down
7 changes: 2 additions & 5 deletions src/diagnostics.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,11 @@ LIVES_GLOBAL_INLINE double get_inst_fps(boolean get_msg) {
boolean refresh = TRUE;
if (mainw->fps_mini_ticks == last_mini_ticks) {
double tdelta = (currtime - last_curr_time);
g_print("play--- 112221 %f\n", tdelta);
if (tdelta > STATS_MSEC / 1000.) {
mainw->inst_fps = inst_fps = (double)(mainw->fps_mini_measure - last_mm) / tdelta;
g_print("!!!!!!!!!!!!!play--- uuuu112221 %f\n", (double)(mainw->fps_mini_measure - last_mm));
} else refresh = FALSE;
} else last_mini_ticks = mainw->fps_mini_ticks;
if (refresh) {
g_print("play--- 111zzzzn");
last_mm = mainw->fps_mini_measure;
last_curr_time = currtime;
}
Expand Down Expand Up @@ -1289,13 +1286,13 @@ char *get_stats_msg(boolean calc_only) {
fgpal = get_palette_name_for_clip(mainw->current_file);

msg = lives_strdup_printf((tmp3 = _("%sFrame %d / %d / %d, fps %.3f (target: %.3f)\n"
"CPU load %.2f %%\n"
"CPU load %.2f %% (threshold %.2f %%)\n"
"Effort: %d / %d, quality: %d, %s (%s)\n%s\n"
"Fg clip: %d X %d, palette: %s\n%s\n%s")),
audmsg ? audmsg : "",
sfile->frameno, sfile->last_req_frame, sfile->frames,
inst_fps * sig(sfile->pb_fps), sfile->pb_fps,
load, mainw->effort, EFFORT_RANGE_MAX,
load, glob_timing->player.cpu_load_thresh, mainw->effort, EFFORT_RANGE_MAX,
prefs->pb_quality,
tmp = lives_strdup(prefs->pb_quality == PB_QUALITY_LOW ? _("Low")
: prefs->pb_quality == PB_QUALITY_MED ? _("Med") : _("High")),
Expand Down
5 changes: 1 addition & 4 deletions src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,6 @@ void add_quick_fn(lives_funcptr_t func, lives_funcdef_t *fdef) {

const char *get_funcname(lives_funcptr_t func) {
return NULL;
const char *fname;
if (!fn_looker) return NULL;
lives_funcdef_t *fdef = (lives_funcdef_t *)get_from_hash_store_i(fn_looker, (uint64_t)func);
return fdef ? fdef->funcname : NULL;
Expand All @@ -642,14 +641,13 @@ const char *get_funcname(lives_funcptr_t func) {
void dump_fn_notes(void) {
if (fn_looker) {
const char *pfx = lives_index_get_prefix(fn_looker);
size_t pfxlen = lives_strlen(pfx);
char **items = weed_plant_list_leaves(fn_looker, NULL);
for (int i = 0; items[i]; i++) {
if (lives_str_starts_with(items[i], pfx)) {
allvalues_t *allvp = get_databook_item(fn_looker, items[i]);
lives_funcdef_t *fdef;
get_val_from_allvals(&fdef, allvp);
g_print("know abouit %s\n", fdef->funcname);
g_print("know about %s\n", fdef->funcname);
}
_ext_free(items[i]);
}
Expand Down Expand Up @@ -1473,7 +1471,6 @@ static boolean unblock_waiter(void *receipt, void *data) {
// prevent it from pausing and it will clear the request

lives_proc_thread_ensure_resume(adder);

lives_hook_cb_remove(receipt);
return FALSE;
}
Expand Down
8 changes: 4 additions & 4 deletions src/layers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,9 +1448,9 @@ LIVES_GLOBAL_INLINE weed_layer_t *weed_layer_set_audio_asamps(weed_layer_t *laye
}


LIVES_GLOBAL_INLINE weed_layer_t *weed_layer_set_audio_seek(weed_layer_t *layer, double seekto) {
LIVES_GLOBAL_INLINE weed_layer_t *weed_layer_set_audio_seek(weed_layer_t *layer, int64_t seekto) {
if (!WEED_IS_LAYER(layer)) return NULL;
weed_set_double_value(layer, LIVES_LEAF_AUDIO_SEEK, seekto);
weed_set_int64_value(layer, LIVES_LEAF_AUDIO_SEEK, seekto);
return layer;
}

Expand Down Expand Up @@ -1494,9 +1494,9 @@ LIVES_GLOBAL_INLINE double weed_layer_get_audio_vel(weed_layer_t *layer) {
}


LIVES_GLOBAL_INLINE double weed_layer_get_audio_seek(weed_layer_t *layer) {
LIVES_GLOBAL_INLINE int64_t weed_layer_get_audio_seek(weed_layer_t *layer) {
if (!WEED_IS_LAYER(layer)) return 0;
return weed_get_int_value(layer, LIVES_LEAF_AUDIO_SEEK, NULL);
return weed_get_int64_value(layer, LIVES_LEAF_AUDIO_SEEK, NULL);
}


Expand Down
4 changes: 2 additions & 2 deletions src/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ weed_layer_t *weed_layer_set_audio_is_float(weed_layer_t *, boolean isfloat);
weed_layer_t *weed_layer_set_audio_src(weed_layer_t *, int src_type);
int weed_layer_get_audio_src(weed_layer_t *);

weed_layer_t *weed_layer_set_audio_seek(weed_layer_t *, double seekto);
double weed_layer_get_audio_seek(weed_layer_t *);
weed_layer_t *weed_layer_set_audio_seek(weed_layer_t *, int64_t pos);
int64_t weed_layer_get_audio_seek(weed_layer_t *);

weed_layer_t *weed_layer_set_audio_pos(weed_layer_t *, int64_t pos);
int64_t weed_layer_get_audio_pos(weed_layer_t *);
Expand Down
74 changes: 0 additions & 74 deletions src/machinestate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,77 +1191,6 @@ LIVES_GLOBAL_INLINE uint64_t fast_hash64(const char *key) {
return hash64;
}

///////////////// to do - move to performance manager ////

/// estimate the machine load
static boolean inited = FALSE;
static int struggling = 0;
static tab_data_t *force = NULL;

void reset_effort(void) {
if (force) {
free_tabdata(force);
force = NULL;
}
prefs->pb_quality = future_prefs->pb_quality;
inited = TRUE;
struggling = 0;
if ((mainw->is_rendering || (mainw->multitrack
&& mainw->multitrack->is_rendering)) && !mainw->preview_rendering)
mainw->effort = -EFFORT_RANGE_MAX;
else {
if (mainw->effort > EFFORT_LIMIT_MED) mainw->effort = EFFORT_LIMIT_MED;
if (mainw->effort < -EFFORT_LIMIT_MED) mainw->effort = -EFFORT_LIMIT_MED;
}
}


void update_effort(double impulse) {
short pb_quality = prefs->pb_quality;

if (LIVES_IS_RENDERING) {
mainw->effort = -EFFORT_RANGE_MAX;
prefs->pb_quality = PB_QUALITY_HIGH;
return;
}

if (!force) force = init_tab_data(1, EFFORT_RANGE_MAX >> 2);

tabdata_update(force, &impulse);
mainw->effort = (int)force->tots[0];

//g_print("eff is %d\n", mainw->effort);

if (mainw->effort > EFFORT_RANGE_MAX) mainw->effort = EFFORT_RANGE_MAX;
if (mainw->effort < -EFFORT_RANGE_MAX) mainw->effort = -EFFORT_RANGE_MAX;

if (mainw->effort <= 0) struggling--;
else struggling++;

//g_print("strf is %d\n", struggling);

if (struggling > EFFORT_LIMIT_MED) struggling = EFFORT_LIMIT_MED;
if (struggling < -EFFORT_LIMIT_MED) struggling = -EFFORT_LIMIT_MED;

if (mainw->effort > 0) {
if (struggling >= EFFORT_LIMIT_MED && mainw->effort >= EFFORT_LIMIT_MED)
pb_quality = PB_QUALITY_LOW;
else if (struggling > 0 && pb_quality == PB_QUALITY_HIGH)
pb_quality = PB_QUALITY_MED;
}

if (mainw->effort < 0) {
if (struggling <= -EFFORT_LIMIT_MED && mainw->effort <= EFFORT_LIMIT_MED)
pb_quality = PB_QUALITY_HIGH;
else if (struggling > 0 && pb_quality == PB_QUALITY_LOW)
pb_quality = PB_QUALITY_MED;
}

if (pb_quality != future_prefs->pb_quality)
future_prefs->pb_quality = pb_quality;
//g_print("STRG %d and %d %d\n", struggling, mainw->effort, prefs->pb_quality);
}


char *grep_in_cmd(const char *cmd, int mstart, int npieces, const char *mphrase, int ridx, int rlen, boolean partial) {
char **lines, **words, **mwords;
Expand Down Expand Up @@ -3167,9 +3096,6 @@ boolean get_cpu_loads(cpuloadvals_t *loadvals, int ncpus) {
return FALSE;
}

#define N_CPU_MEAS 64
#define CPU_MEAS_THRESH 1000000

static cpuloadvals_t *cpu_stats = NULL;


Expand Down
13 changes: 7 additions & 6 deletions src/maths.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ tab_data_t *init_tab_data(int arsize, int maxsize) {
goto err;
// *INDENT-OFF*
}}}
tabdata->maxsize--;
// *INDENT-ON*
return tabdata;

Expand Down Expand Up @@ -952,19 +953,19 @@ LIVES_GLOBAL_INLINE tab_data_t *free_tabdata(tab_data_t *tabdata) {
void tabdata_update(tab_data_t *tabdata, double * newvals) {
if (!tabdata) return;
if (newvals) {
int nvals = tabdata->nvals;
if (nvals == tabdata->maxsize) {
nvals--;
if (tabdata->nvals >= tabdata->maxsize) {
tabdata->nvals--;
for (int i = tabdata->arsize; i--;) {
tabdata->tots[i] -= tabdata->res[i][0];
lives_memmove(tabdata->res[i], tabdata->res[i] + 1,
(tabdata->maxsize - 1) * sizeof(double));
}
} else tabdata->nvals++;
}
tabdata->nvals++;
for (int i = tabdata->arsize; i--;) {
tabdata->tots[i] += newvals[i];
tabdata->res[i][nvals] = newvals[i];
tabdata->avgs[i] = tabdata->tots[i] / (double)nvals;
tabdata->res[i][tabdata->nvals - 1] = newvals[i];
tabdata->avgs[i] = tabdata->tots[i] / (double)tabdata->nvals;
if (newvals[i] > tabdata->max[i]) tabdata->max[i] = newvals[i];
if (newvals[i] < tabdata->min[i]) tabdata->min[i] = newvals[i];
}
Expand Down
43 changes: 25 additions & 18 deletions src/nodemodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ LIVES_GLOBAL_INLINE double get_cycle_avg_time(double *dets) {
pthread_mutex_lock(&glob_timing->plan.upd_mutex);
ret = glob_timing->plan.avg_duration;
if (dets) {
dets[0] = glob_timing->curr_cpuload;
dets[0] = get_cpu_load();
dets[1] = glob_timing->plan.last_cyc_duration;
dets[2] = glob_timing->plan.tgt_duration;
}
Expand Down Expand Up @@ -7931,16 +7931,33 @@ lives_result_t inst_node_set_flags(inst_node_t *n, uint64_t flags) {



static void free_nodemodel_inner(lives_nodemodel_t *nodemodel) {
if (!nodemodel) return;
//if (nodemodel->clip_index) lives_free(nodemodel->clip_index);
free_all_nodes(nodemodel);
lives_list_free_all(&(nodemodel->node_chains));
lives_free(nodemodel);
}



void free_nodemodel(lives_nodemodel_t **pnodemodel) {
if (!pnodemodel || !*pnodemodel) return;
if ((*pnodemodel)->clip_index) lives_free((*pnodemodel)->clip_index);
free_all_nodes(*pnodemodel);
lives_list_free_all(&(*pnodemodel)->node_chains);
lives_free(*pnodemodel);
*pnodemodel = NULL;
if (!pnodemodel) return;
for (int i = 0; i < 3; i++) {
if (mainw->qnodemodels[i]) {
if (mainw->qnodemodels[i] == *pnodemodel) *pnodemodel = NULL;
free_nodemodel_inner(mainw->qnodemodels[i]);
mainw->qnodemodels[i] = NULL;
}
}
if (*pnodemodel) {
free_nodemodel_inner(*pnodemodel);
*pnodemodel = NULL;
}
}



static void _build_nodemodel(lives_nodemodel_t **pnodemodel, int ntracks, int *clip_index) {
char *tmp;

Expand Down Expand Up @@ -8123,14 +8140,6 @@ void cleanup_nodemodel(lives_nodemodel_t **nodemodel) {
mainw->layers = NULL;
}

for (int i = 0; i < 3; i++) {
if (mainw->qnodemodels[i]) {
if (mainw->qnodemodels[i] == *nodemodel) *nodemodel = NULL;
free_nodemodel(&mainw->qnodemodels[i]);
mainw->qnodemodels[i] = NULL;
}
}

if (*nodemodel) free_nodemodel(nodemodel);

mainw->refresh_model = 1;
Expand Down Expand Up @@ -8275,7 +8284,7 @@ void rebuild_nodemodel(void) {

xtime = lives_get_session_time();
if (!mainw->qnodemodels[prefs->pb_quality - 1]) {
mainw->qnodemodels[prefs->pb_quality - 1] = mainw->nodemodel;
mainw->debug_ptr = mainw->qnodemodels[prefs->pb_quality - 1] = mainw->nodemodel;
mainw->qexec_plans[prefs->pb_quality - 1] = mainw->exec_plan;
}

Expand Down Expand Up @@ -8304,7 +8313,6 @@ void rebuild_nodemodel(void) {
plan_cycle_trigger(mainw->plan_cycle);
if (mainw->plan_cycle) exec_plan_free(STEAL_POINTER(mainw->plan_cycle));


planrunner_lock();
mainw->refresh_model = 0;
mainw->frame_layer = NULL;
Expand Down Expand Up @@ -8343,7 +8351,6 @@ void rebuild_nodemodel(void) {
reset_ext_player_layer(FALSE);

if (mainw->plan_cycle) exec_plan_free(STEAL_POINTER(mainw->plan_cycle));

} else {
cleanup_nodemodel(&mainw->nodemodel);
planrunner_lock();
Expand Down
Loading

0 comments on commit 435c3ca

Please sign in to comment.