LiVES  3.2.0
diagnostics.c
Go to the documentation of this file.
1 // diagnostics.h
2 // LiVES
3 // (c) G. Finch 2003 - 2020 <salsaman+lives@gmail.com>
4 // released under the GNU GPL 3 or later
5 // see file ../COPYING for licensing details
6 
7 #ifndef _DIAGNOSTICS_H
8 #define _DIAGNOSTICS_H
9 
10 #include "diagnostics.h"
11 #include "callbacks.h"
12 
13 #define STATS_TC (TICKS_PER_SECOND_DBL)
14 static double inst_fps = 0.;
15 
18  return inst_fps;
19 }
20 
21 
22 char *get_stats_msg(boolean calc_only) {
23  double avsync = 1.0;
24  static int last_play_sequence = -1;
25  static ticks_t last_curr_tc = 0, currticks;
26  static ticks_t last_mini_ticks = 0;
27  static frames_t last_mm = 0;
28  boolean have_avsync = FALSE;
29  char *msg, *audmsg = NULL, *bgmsg = NULL, *fgpal = NULL;
30  char *tmp, *tmp2;
31 
32  if (!LIVES_IS_PLAYING) return NULL;
33  //currticks = lives_get_current_playback_ticks(mainw->origsecs, mainw->orignsecs, NULL);
34  currticks = mainw->clock_ticks;
35 
37 #ifdef ENABLE_JACK
38  if (prefs->audio_player == AUD_PLAYER_JACK && mainw->jackd && mainw->jackd->in_use &&
39  IS_VALID_CLIP(mainw->jackd->playing_file) && mainw->files[mainw->jackd->playing_file]->arate != 0) {
40  avsync = (double)mainw->jackd->seek_pos
41  / (double)mainw->files[mainw->jackd->playing_file]->arate / 4.; //lives_pulse_get_pos(mainw->jackd);
42  avsync -= ((double)mainw->files[mainw->jackd->playing_file]->frameno - 1.) / mainw->files[mainw->jackd->playing_file]->fps
44  have_avsync = TRUE;
45  }
46 #endif
47 #ifdef HAVE_PULSE_AUDIO
48  if (prefs->audio_player == AUD_PLAYER_PULSE && mainw->pulsed && mainw->pulsed->in_use &&
49  IS_VALID_CLIP(mainw->pulsed->playing_file) && mainw->files[mainw->pulsed->playing_file]->arate != 0) {
50  avsync = (double)mainw->pulsed->seek_pos
51  / (double)mainw->files[mainw->pulsed->playing_file]->arate / 4.; //lives_pulse_get_pos(mainw->pulsed);
52  avsync -= ((double)mainw->files[mainw->pulsed->playing_file]->frameno - 1.) / mainw->files[mainw->pulsed->playing_file]->fps
54  have_avsync = TRUE;
55  }
56 #endif
57  }
58  //currticks = lives_get_current_ticks();
59 
60  if (mainw->play_sequence > last_play_sequence) {
61  last_curr_tc = currticks;
62  last_play_sequence = mainw->play_sequence;
63  inst_fps = cfile->pb_fps;
64  return NULL;
65  }
66 
67  if (currticks > last_curr_tc + STATS_TC) {
68  if (mainw->fps_mini_ticks == last_mini_ticks) {
69  inst_fps = (double)(mainw->fps_mini_measure - last_mm
70  + (double)(mainw->currticks - mainw->startticks) / TICKS_PER_SECOND_DBL / cfile->pb_fps)
71  / ((double)(currticks - last_curr_tc) / TICKS_PER_SECOND_DBL);
72  mainw->inst_fps = inst_fps;
73  }
74  last_curr_tc = currticks;
75  last_mini_ticks = mainw->fps_mini_ticks;
76  last_mm = mainw->fps_mini_measure;
77  }
78 
79  if (calc_only) return NULL;
80 
81  if (have_avsync) {
82  audmsg = lives_strdup_printf(_("Audio is %s video by %.4f secs.\n"),
83  tmp = lives_strdup(avsync >= 0. ? _("ahead of") : _("behind")), fabs(avsync));
84  lives_free(tmp);
85  } else {
86  if (prefs->audio_src == AUDIO_SRC_INT) audmsg = (_("Clip has no audio.\n"));
87  else audmsg = (_("Audio source external.\n"));
88  }
89 
92  bgmsg = lives_strdup_printf(_("Bg clip: %d X %d, frame: %d / %d, palette: %s\n"),
97  bgpal);
98  lives_free(bgpal);
99  }
100 
102 
103  msg = lives_strdup_printf(_("%sFrame %d / %d, fps %.3f (target: %.3f)\n"
104  "Effort: %d / %d, quality: %d, %s (%s)\n%s\n"
105  "Fg clip: %d X %d, palette: %s\n%s"),
106  audmsg ? audmsg : "",
107  mainw->actual_frame, cfile->frames,
108  inst_fps * sig(cfile->pb_fps), cfile->pb_fps,
110  prefs->pb_quality,
111  tmp = lives_strdup(prefs->pb_quality == 1 ? _("Low") : prefs->pb_quality == 2 ? _("Med") : _("High")),
112  tmp2 = lives_strdup(prefs->pbq_adaptive ? _("adaptive") : _("fixed")),
113  get_cache_stats(),
114  cfile->hsize, cfile->vsize,
115  fgpal, bgmsg ? bgmsg : "");
116 
117  lives_freep((void **)&bgmsg); lives_freep((void **)&audmsg);
118  lives_freep((void **)&tmp); lives_freep((void **)&tmp2);
119 
120  return msg;
121 }
122 
123 
124 #ifdef WEED_STARTUP_TESTS
125 
126 #define NITERS 1024
127 #define DTHRESH 8
128 #define PMISS 0.99609375
129 void check_random(void) {
130  int counter[64];
131  int last[64];
132  int buckets[64][4];
133  int dist[8][256];
134  int bval, dval;
135  double prob;
136  register int d, x;
137  uint64_t tt, r;
140 
141  lives_memset(counter, 0, 256);
142  lives_memset(last, 0, 256);
143  lives_memset(buckets, 0, 1024);
144  lives_memset(dist, 0, 8192);
145 
146  for (x = 0; x < NITERS; x++) {
147  uint64_t uu = 1;
148  tt = fastrand();
149  bval = 0;
150  dval = 0;
151  for (d = 0; d < 64; d++) {
152  bval <<= 1;
153  r = tt & uu;
154  if (!r) {
155  if (x && !(x & 1)) buckets[d][last[d] << 1]++;
156  counter[d]--;
157  last[d] = 0;
158  } else {
159  if (x && !(x & 1)) buckets[d][(last[d] << 1) + 1]++;
160  counter[d]++;
161  last[d] = 1;
162  bval++;
163  }
164  uu <<= 1;
165  if ((d & 7) == 7) {
166  dist[dval++][bval]++;
167  bval = 0;
168  }
169  }
170  }
171 
172  prob = PMISS;
173  fprintf(stderr, "Checking statistical probabilities\n");
174  for (x = 0; x < NITERS; x++) {
175  fprintf(stderr, "%d %.4f ", x, 1. - prob);
176  prob *= prob;
177  }
178  fprintf(stderr, "\n");
179 
180 
182  for (d = 0; d < 64; d++) {
183  fprintf(stderr, "digit %d: score %d (%.2f%% 1s)\n", d, counter[d],
184  ((double)counter[d] + (double)NITERS) / (double)NITERS * 50.);
185  fprintf(stderr, "buckets: ");
186  for (x = 0; x < 4; x++) fprintf(stderr, "[%d]: %d ", x, buckets[d][x]);
187  fprintf(stderr, "\n");
188  }
189  for (d = 0; d < 8; d++) {
190  fprintf(stderr, "segment %d: ", d);
191  for (x = 0; x < 256; x++) {
192  dval = dist[d][x];
193  if (dval >= DTHRESH) fprintf(stderr, "val %d / %d hit %d times ", d, x, dist[d][x]);
194  }
195  fprintf(stderr, "\n");
196  }
197 }
198 
199 
200 ticks_t timerinfo;
201 
202 static void show_timer_info(void) {
203  g_print("\n\nTest completed in %.4f seconds\n\n",
204  ((double)lives_get_current_ticks() - (double)timerinfo) / TICKS_PER_SECOND_DBL);
205  timerinfo = lives_get_current_ticks();
206 }
207 
208 static char *randstrg(size_t len) {
209  char *strg = lives_calloc(1, len), *ptr = strg;
210  for (int i = 1; i < len; i++) *(ptr++) = ((lives_random() & 63) + 32);
211  return strg;
212 }
213 
214 
215 
216 void hash_test(void) {
217  char *str;
218  int i;
219  uint32_t val;
220  int nr = 100000000;
221  timerinfo = lives_get_current_ticks();
222  for (i = 0; i < nr; i++) {
223  str = randstrg(fastrand_int(20));
224  val = fast_hash(str) / 7;
225  lives_free(str);
226  }
227  show_timer_info();
228  for (i = 0; i < nr; i++) {
229  str = randstrg(fastrand_int(20));
230  lives_string_hash(str) / 7;
231  lives_free(str);
232  }
233  show_timer_info();
234 }
235 
236 #include "lsd.h"
237 
238 typedef struct {
239  lives_struct_def_t lsd;
240  char buff[100000];
241  char *strg;
242  uint64_t num0, num1;
243  void *p;
244  char **strgs;
245 } lives_test_t;
246 
247 
248 void benchmark(void) {
249  int nruns = 1000000;
250  char *strg = randstrg(400);
251  char *strg2 = randstrg(500);
252  volatile size_t sz = 1;
253  int i, j;
254  memcpy(strg2, strg, 400);
255  for (j = 0; j < 5; j++) {
256  sz++;
257  fprintf(stderr, "test %d runs with lives_strlen()", nruns);
258  timerinfo = lives_get_current_ticks();
259  for (i = 0; i < nruns; i++) {
260  sz = lives_strcmp(strg, strg2);
261  //sz += lives_strlen(strg2);
262  }
263  show_timer_info();
264  sz++;
265  fprintf(stderr, "test %d runs with strlen()", nruns);
266  timerinfo = lives_get_current_ticks();
267  for (i = 0; i < nruns; i++) {
268  sz = strcmp(strg, strg2);
269  //sz += strlen(strg2);
270  }
271  show_timer_info();
272  sz++;
273  }
274  lives_free(strg2);
275 }
276 
277 
278 void lives_struct_test(void) {
279  const lives_struct_def_t *lsd;
280 
281  lives_test_t *tt = (lives_test_t *)lives_calloc(1, sizeof(lives_test_t)), *tt2;
282 
283  lsd = lsd_create("lives_test_t", sizeof(lives_test_t), "strgs", 1);
284 
285  lsd->special_fields[0] = make_special_field(LIVES_FIELD_CHARPTR, tt,
286  &tt->strg, "strg", 0,
287  NULL, NULL, NULL);
288  lives_struct_init(lsd, tt, &tt->lsd);
289  lives_free(tt);
290 
291  timerinfo = lives_get_current_ticks();
292  for (int i = 0; i < 1000000; i++) {
293  tt = lives_struct_create(lsd);
294  tt->strg = strdup("a string to be copied !");
295 
296  /* //g_print("done\n"); */
297  /* //g_print("fields: struct ^%p lsd: %s %p, id %08lX uid: %08lX self %p type %s " */
298  /* "top %p len %lu last field %s spcl %p user_data %p \n", tt, tt->strg, &tt->lsd, */
299  /* tt->lsd.identifier, */
300  /* tt->lsd.unique_id, tt->lsd.self_fields, tt->lsd.structtype, tt->lsd.top, */
301  /* tt->lsd.structsize, tt->lsd.last_field, tt->lsd.special_fields, tt->lsd.user_data); */
302 
303  //g_print("copy struct 1\n");
304  tt2 = lives_struct_copy(&tt->lsd);
306  //g_print("done\n");
307  //g_print("fields: struct ^%p lsd: %s, %p id %08lX uid: %08lX self %p type %s "
308  //"top %p len %lu last field %s spcl %p user_data %p \n", tt2, tt2->strg, &tt2->lsd, tt2->lsd.identifier,
309  //tt2->lsd.unique_id, tt2->lsd.self_fields, tt2->lsd.structtype, tt2->lsd.top,
310  //tt2->lsd.structsize, tt2->lsd.last_field, tt2->lsd.special_fields, tt2->lsd.user_data);
311 
312  lives_struct_free(&tt->lsd);
313  lives_struct_free(&tt2->lsd);
314  }
315  show_timer_info();
316 }
317 
318 LIVES_LOCAL_INLINE void show_quadstate(weed_plant_t *p) {
319  // do nothing
320 }
321 
322 int run_weed_startup_tests(void) {
323  weed_plant_t *plant;
324  int a, type, ne, st, flags;
325  int *intpr;
326  char *str;
327  int pint[4];//, zint[4];
328  weed_error_t werr;
329  char **keys;
330  void *ptr, *ptr2;
331  void *ptra[4];
332  char *s[4];
333  int n;
334  weed_size_t nleaves;
335 
336  g_print("Testing libweed functionality:\n\n");
337 
338  timerinfo = lives_get_current_ticks();
339 
340  // run some tests..
341  plant = weed_plant_new(WEED_PLANT_HOST_INFO);
342  fprintf(stderr, "plant is %p\n", plant);
343 
344  fprintf(stderr, "\n");
345  show_quadstate(plant);
346  fprintf(stderr, "\n");
347 
348  type = weed_get_int_value(plant, WEED_LEAF_TYPE, &werr);
349  fprintf(stderr, "type is %d, err was %d\n", type, werr);
350 
351  ne = weed_leaf_num_elements(plant, WEED_LEAF_TYPE);
352  fprintf(stderr, "ne was %d\n", ne);
353 
354  st = weed_leaf_seed_type(plant, "type");
355  fprintf(stderr, "seedtype is %d\n", st);
356 
357  flags = weed_leaf_get_flags(plant, WEED_LEAF_TYPE);
358  fprintf(stderr, "flags is %d\n", flags);
359 
361 
362  keys = weed_plant_list_leaves(plant, &nleaves);
363  n = 0;
364  while (keys[n] != NULL) {
365  fprintf(stderr, "key %d is %s\n", n, keys[n]);
366  free(keys[n]);
367  n++;
368  }
369  free(keys);
370  fprintf(stderr, "\n");
371  show_quadstate(plant);
372  fprintf(stderr, "\n");
373 
374 
375  fprintf(stderr, "check NULL plant\n");
376  type = weed_get_int_value(NULL, WEED_LEAF_TYPE, &werr);
377 
378  fprintf(stderr, "type is %d, err was %d\n", type, werr);
379  ne = weed_leaf_num_elements(NULL, WEED_LEAF_TYPE);
380 
381  fprintf(stderr, "ne was %d\n", ne);
382  st = weed_leaf_seed_type(NULL, "type");
383 
384  fprintf(stderr, "seedtype is %d\n", st);
385  flags = weed_leaf_get_flags(NULL, WEED_LEAF_TYPE);
386 
387  fprintf(stderr, "flags is %d\n", flags);
388 
389  keys = weed_plant_list_leaves(NULL, NULL);
390  n = 0;
391  while (keys[n] != NULL) {
392  fprintf(stderr, "key %d is %s\n", n, keys[n]);
393  free(keys[n]);
394  n++;
395  }
396  free(keys);
397  fprintf(stderr, "\n");
398  show_quadstate(plant);
399  fprintf(stderr, "\n");
400 
401  // flags ok here
402 
403 
404  fprintf(stderr, "zzztype setfff\n");
405  werr = weed_leaf_set_flags(plant, "type", 0);
406  fprintf(stderr, "zzztype setflags %d\n", werr);
407 
408 
409  fprintf(stderr, "Check NULL key \n");
410 
411  type = weed_get_int_value(plant, NULL, &werr);
412  fprintf(stderr, "type is %d, err was %d\n", type, werr);
413 
414  fprintf(stderr, "\n");
415  show_quadstate(plant);
416  fprintf(stderr, "\n");
417 
419 
420  ne = weed_leaf_num_elements(plant, NULL);
421  fprintf(stderr, "ne was %d\n", ne);
422 
423  fprintf(stderr, "\n");
424  show_quadstate(plant);
425  fprintf(stderr, "\n");
426 
427 
429 
430  st = weed_leaf_seed_type(plant, NULL);
431  fprintf(stderr, "seedtype is %d\n", st);
432 
433  fprintf(stderr, "\n");
434  show_quadstate(plant);
435  fprintf(stderr, "\n");
436 
437 
438  flags = weed_leaf_get_flags(plant, NULL);
439  fprintf(stderr, "flags is %d\n", flags);
440 
441  fprintf(stderr, "\n");
442  show_quadstate(plant);
443  fprintf(stderr, "\n");
444 
445  fprintf(stderr, "Check zero key \n");
446  type = weed_get_int_value(plant, "", &werr);
447 
448  fprintf(stderr, "\n");
449  show_quadstate(plant);
450  fprintf(stderr, "\n");
451 
453 
454  fprintf(stderr, "type is %d, err was %d\n", type, werr);
455  ne = weed_leaf_num_elements(plant, "");
456 
457  fprintf(stderr, "\n");
458  show_quadstate(plant);
459  fprintf(stderr, "\n");
460 
461  fprintf(stderr, "ne was %d\n", ne);
462  st = weed_leaf_seed_type(plant, "");
463 
464  fprintf(stderr, "seedtype is %d\n", st);
465  flags = weed_leaf_get_flags(plant, "");
466  fprintf(stderr, "flags is %d\n", flags);
467 
468  fprintf(stderr, "\n");
469  show_quadstate(plant);
470  fprintf(stderr, "\n");
471 
472  fprintf(stderr, "checking get / set values\n");
473 
474  weed_set_int_value(plant, "Test", 99);
475  fprintf(stderr, "Set 'Test' = 99\n");
476 
477  fprintf(stderr, "\n");
478  show_quadstate(plant);
479  fprintf(stderr, "\n");
480 
481  a = weed_get_int_value(plant, "Test", &werr);
482 
483  fprintf(stderr, "value read was %d, err was %d\n", a, werr);
484 
485  fprintf(stderr, "\n");
486  show_quadstate(plant);
487  fprintf(stderr, "\n");
488 
489  keys = weed_plant_list_leaves(plant, &nleaves);
490  n = 0;
491  while (keys[n] != NULL) {
492  fprintf(stderr, "key %d is %s\n", n, keys[n]);
493  free(keys[n]);
494  n++;
495  }
496  free(keys);
497 
498  fprintf(stderr, "\n");
499  show_quadstate(plant);
500  fprintf(stderr, "\n");
501 
502  weed_set_int_value(plant, "Test", 143);
503  a = weed_get_int_value(plant, "Test", &werr);
504 
505  fprintf(stderr, "value read was %d, err was %d\n", a, werr);
506 
507  keys = weed_plant_list_leaves(plant, &nleaves);
508  n = 0;
509  while (keys[n] != NULL) {
510  fprintf(stderr, "key %d is %s\n", n, keys[n]);
511  free(keys[n]);
512  n++;
513  }
514  free(keys);
515  fprintf(stderr, "\n");
516  show_quadstate(plant);
517  fprintf(stderr, "\n");
518 
519  weed_set_string_value(plant, "Test2", "abc");
520  str = weed_get_string_value(plant, "Test2", &werr);
521 
522  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
523 
524  keys = weed_plant_list_leaves(plant, &nleaves);
525  n = 0;
526  while (keys[n] != NULL) {
527  fprintf(stderr, "key %d is %s\n", n, keys[n]);
528  free(keys[n]);
529  n++;
530  }
531  free(keys);
532 
533  weed_set_string_value(plant, "Test2", "12345");
534  str = weed_get_string_value(plant, "Test2", &werr);
535 
536  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
537 
538  keys = weed_plant_list_leaves(plant, &nleaves);
539  n = 0;
540  while (keys[n] != NULL) {
541  fprintf(stderr, "key %d is %s\n", n, keys[n]);
542  free(keys[n]);
543  n++;
544  }
545  free(keys);
546  fprintf(stderr, "\n");
547  show_quadstate(plant);
548  fprintf(stderr, "\n");
549 
550  weed_set_string_value(plant, "Test2", "");
551  str = weed_get_string_value(plant, "Test2", &werr);
552 
553  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
554 
555  keys = weed_plant_list_leaves(plant, &nleaves);
556  n = 0;
557  while (keys[n] != NULL) {
558  fprintf(stderr, "key %d is %s\n", n, keys[n]);
559  free(keys[n]);
560  n++;
561  }
562  free(keys);
563 
564  weed_set_string_value(plant, "Test2", NULL);
565  str = weed_get_string_value(plant, "Test2", &werr);
566 
567  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
568 
569  keys = weed_plant_list_leaves(plant, &nleaves);
570  n = 0;
571  while (keys[n] != NULL) {
572  fprintf(stderr, "key %d is %s\n", n, keys[n]);
573  free(keys[n]);
574  n++;
575  }
576  free(keys);
577  fprintf(stderr, "\n");
578  show_quadstate(plant);
579  fprintf(stderr, "\n");
580 
581  weed_set_string_value(plant, "Test3", NULL);
582  str = weed_get_string_value(plant, "Test3", &werr);
583 
584  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
585 
586  keys = weed_plant_list_leaves(plant, &nleaves);
587  n = 0;
588  while (keys[n] != NULL) {
589  fprintf(stderr, "key %d is %s\n", n, keys[n]);
590  free(keys[n]);
591  n++;
592  }
593  free(keys);
594  fprintf(stderr, "\n");
595  show_quadstate(plant);
596  fprintf(stderr, "\n");
597 
598  weed_set_string_value(plant, NULL, NULL);
599  str = weed_get_string_value(NULL, NULL, &werr);
600 
601  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
602 
603  keys = weed_plant_list_leaves(plant, &nleaves);
604  n = 0;
605  while (keys[n] != NULL) {
606  fprintf(stderr, "key %d is %s\n", n, keys[n]);
607  free(keys[n]);
608  n++;
609  }
610  free(keys);
611  fprintf(stderr, "\n");
612  show_quadstate(plant);
613  fprintf(stderr, "\n");
614 
615  pint[0] = 10000000;
616  pint[1] = 1;
617  pint[2] = 5;
618  pint[3] = -199;
619 
620  werr = weed_set_int_array(plant, "intarray", 4, pint);
621  fprintf(stderr, "int array set, err was %d\n", werr);
622 
623  intpr = weed_get_int_array(plant, "intarray", &werr);
624  fprintf(stderr, "int array got %d %d %d %d , err was %d\n", intpr[0], intpr[1], intpr[2], intpr[3], werr);
625 
626  intpr = weed_get_int_array(plant, "xintarray", &werr);
627  fprintf(stderr, "int array got %p, err was %d\n", intpr, werr);
628 
629  intpr = weed_get_int_array(NULL, "xintarray", &werr);
630  fprintf(stderr, "int array got %p , err was %d\n", intpr, werr);
631 
632  fprintf(stderr, "\n");
633  show_quadstate(plant);
634  fprintf(stderr, "\n");
635 
636  fprintf(stderr, "\n\nflag tests\n");
637 
638  flags = weed_leaf_get_flags(plant, "type");
639  fprintf(stderr, "type flags (0) are %d\n", flags);
640 
641  fprintf(stderr, "\n");
642  show_quadstate(plant);
643  fprintf(stderr, "\n");
644 
645  a = weed_get_int_value(plant, "type", &werr);
646  fprintf(stderr, "get type returned %d %d\n", a, werr);
647 
648  fprintf(stderr, "\n");
649  show_quadstate(plant);
650  fprintf(stderr, "\n");
651 
652  werr = weed_set_int_value(plant, "type", 99);
653  fprintf(stderr, "set type returned %d\n", werr);
654 
655  fprintf(stderr, "\n");
656  show_quadstate(plant);
657  fprintf(stderr, "\n");
658 
659  a = weed_get_int_value(plant, "type", &werr);
660  fprintf(stderr, "get type returned %d %d\n", a, werr);
661 
662  fprintf(stderr, "\n");
663  show_quadstate(plant);
664  fprintf(stderr, "\n");
665 
666  flags = weed_leaf_get_flags(plant, "type");
667  fprintf(stderr, "type flags (1) are %d\n", flags);
668 
669  fprintf(stderr, "\n");
670  show_quadstate(plant);
671  fprintf(stderr, "\n");
672 
673  werr = weed_leaf_set_flags(plant, "type", 0);
674  fprintf(stderr, "type setflags %d\n", werr);
675 
676  fprintf(stderr, "\n");
677  show_quadstate(plant);
678  fprintf(stderr, "\n");
679 
680  flags = weed_leaf_get_flags(plant, "type");
681  fprintf(stderr, "type flags (1a) are %d\n", flags);
682 
683  fprintf(stderr, "\n");
684  show_quadstate(plant);
685  fprintf(stderr, "\n");
686 
687 
688 
689 
690  werr = weed_set_int_value(plant, "type", 123);
691  fprintf(stderr, "set type returned %d\n", werr);
692 
693  fprintf(stderr, "\n");
694  show_quadstate(plant);
695  fprintf(stderr, "\n");
696 
697 
698 
699 
700  a = weed_get_int_value(plant, "type", &werr);
701  fprintf(stderr, "get type returned %d %d\n", a, werr);
702 
703 
704  fprintf(stderr, "\n");
705  show_quadstate(plant);
706  fprintf(stderr, "\n");
707 
708 
709 
710  flags = weed_leaf_get_flags(plant, "type");
711  fprintf(stderr, "type flags (2) are %d\n", flags);
712 
713  fprintf(stderr, "\n");
714  show_quadstate(plant);
715  fprintf(stderr, "\n");
717 
718 
719  werr = weed_leaf_set_flags(plant, "type", WEED_FLAG_IMMUTABLE);
720  fprintf(stderr, "type setflags %d\n", werr);
721 
722  werr = weed_set_int_value(plant, "type", 200);
723  fprintf(stderr, "set type returned %d\n", werr);
724 
725  flags = weed_leaf_get_flags(plant, "type");
726  fprintf(stderr, "type flags (3) are %d\n", flags);
727 
728  flags = weed_leaf_get_flags(plant, "Test2");
729  fprintf(stderr, "test getflags %d\n", flags);
730 
731  weed_set_string_value(plant, "Test2", "abcde");
732  str = weed_get_string_value(plant, "Test2", &werr);
733 
734  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
735 
736  keys = weed_plant_list_leaves(plant, &nleaves);
737  n = 0;
738  while (keys[n] != NULL) {
739  fprintf(stderr, "key %d is %s\n", n, keys[n]);
740  free(keys[n]);
741  n++;
742  }
743  free(keys);
744 
745  weed_set_string_value(plant, "Test2", "888888");
746  str = weed_get_string_value(plant, "Test2", &werr);
747 
748  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
749 
750  weed_leaf_set_flags(plant, "Test2", WEED_FLAG_IMMUTABLE);
751 
752  werr = weed_set_string_value(plant, "Test2", "hello");
753  fprintf(stderr, "set immutable returned %d\n", werr);
754 
755  str = weed_get_string_value(plant, "Test2", &werr);
756 
757  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
758 
759  weed_leaf_set_flags(plant, "Test2", 0);
760 
761  weed_set_string_value(plant, "Test2", "OK");
762  str = weed_get_string_value(plant, "Test2", &werr);
763 
764  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
765 
766  weed_set_string_value(plant, "string1", "abccc");
767  weed_set_string_value(plant, "string2", "xyyyyzz");
768  weed_set_string_value(plant, "string3", "11111 11111");
769 
770  werr = weed_set_string_value(plant, "string2", "xxxxx");
771  str = weed_get_string_value(plant, "string2", &werr);
772  fprintf(stderr, "value read was %s, err was %d\n", str, werr);
773 
774 
775  fprintf(stderr, "\n");
776  show_quadstate(plant);
777  fprintf(stderr, "\n");
778 
779 
780  keys = weed_plant_list_leaves(plant, &nleaves);
781  n = 0;
782  while (keys[n] != NULL) {
783  fprintf(stderr, "key %d is %s\n", n, keys[n]);
784  free(keys[n]);
785  n++;
786  }
787  free(keys);
788 
790  werr = weed_leaf_delete(plant, "string1");
791  fprintf(stderr, "del leaf returned %d\n", werr);
792 
793  if (werr) abort();
794 
795  keys = weed_plant_list_leaves(plant, &nleaves);
796  n = 0;
797  while (keys[n] != NULL) {
798  fprintf(stderr, "key %d is %s\n", n, keys[n]);
799  free(keys[n]);
800  n++;
801  }
802  free(keys);
803 
804  str = weed_get_string_value(plant, "string1", &werr);
805  fprintf(stderr, "del leaf returned %s %d\n", str, werr);
806 
807  flags = weed_leaf_get_flags(plant, "string2");
808  fprintf(stderr, "get flags returned %d\n", flags);
809  weed_leaf_set_flags(plant, "string2", WEED_FLAG_UNDELETABLE);
810  flags = weed_leaf_get_flags(plant, "string2");
811  fprintf(stderr, "get flags returned %d\n", flags);
812 
813  werr = weed_leaf_delete(plant, "string2");
814  fprintf(stderr, "del aaa leaf returned %d\n", werr);
815  str = weed_get_string_value(plant, "string2", &werr);
816  fprintf(stderr, "del zzz leaf returned %s %d\n", str, werr);
817 
818 
819  weed_leaf_set_flags(plant, "string2", 0);
820  flags = weed_leaf_get_flags(plant, "string2");
821  fprintf(stderr, "set flags returned %d\n", flags);
822  werr = weed_leaf_delete(plant, "string2");
823  fprintf(stderr, "del yyy leaf returned %d\n", werr);
824 
825  str = weed_get_string_value(plant, "string2", &werr);
826  fprintf(stderr, "del xxx leaf val returned %s %d\n", str, werr);
827 
828 
829 
830  werr = weed_leaf_set_flags(plant, "Test2", WEED_FLAG_UNDELETABLE);
831 
832  flags = weed_leaf_get_flags(plant, "string2");
833  fprintf(stderr, "get flags returned %d\n", flags);
834 
835  werr = weed_plant_free(plant);
836  fprintf(stderr, "wpf returned %d\n", werr);
837 
839 
840  keys = weed_plant_list_leaves(plant, &nleaves);
841  n = 0;
842  while (keys[n] != NULL) {
843  fprintf(stderr, "key %d is %s\n", n, keys[n]);
844  free(keys[n]);
845  n++;
846  }
847  free(keys);
848 
849 
850 
851  werr = weed_set_voidptr_value(plant, "nullptr", NULL);
852  fprintf(stderr, "set null void * returned %d\n", werr);
853 
854  ptr = weed_get_voidptr_value(plant, "nullptr", &werr);
855  fprintf(stderr, "get null vooid * returned (%p) %d\n", ptr, werr);
856 
857  ptr = weed_get_voidptr_value(plant, "nullptrxx", &werr);
858  fprintf(stderr, "get nonexist void * returned (%p) %d\n", ptr, werr);
859 
861 
862  /* werr = weed_leaf_set(plant, "nullbasic", WEED_SEED_VOIDPTR, 0, NULL); */
863  /* fprintf(stderr, "set null basic voidptr zero returned %d\n", werr); */
864 
865  ptr = weed_get_voidptr_value(plant, "nullbasic", &werr);
866  fprintf(stderr, "get null basic voidptr 0 returned (%p) %d\n", ptr, werr);
867 
869 
870  keys = weed_plant_list_leaves(plant, &nleaves);
871  n = 0;
872  while (keys[n] != NULL) {
873  fprintf(stderr, "key %d is %s\n", n, keys[n]);
874  free(keys[n]);
875  n++;
876  }
877  free(keys);
878 
880  /* werr = weed_leaf_set(plant, "nullbasic", WEED_SEED_VOIDPTR, 1, NULL); */
881  /* fprintf(stderr, "set null string returned %d\n", werr); */
882 
883  ptr = weed_get_voidptr_value(plant, "nullbasic", &werr);
884  fprintf(stderr, "get null string returned (%p) %d\n", ptr, werr);
885 
886  /* ptr2 = NULL; */
887  /* werr = weed_leaf_set(plant, "indirect", WEED_SEED_VOIDPTR, 1, &ptr2); */
888  /* fprintf(stderr, "set null ptr returned %d\n", werr); */
889 
890  ptr = weed_get_voidptr_value(plant, "indirect", &werr);
891  fprintf(stderr, "get null string returned (%p) %d\n", ptr, werr);
892 
893  ptra[0] = &werr;
894  ptra[1] = &keys;
895  ptra[2] = NULL;
896  ptra[3] = &ptra[3];
897 
898  weed_leaf_set(plant, "ptrs", WEED_SEED_VOIDPTR, 4, &ptra);
899  fprintf(stderr, "set null array elem ptra returned %d\n", werr);
900 
901  void **ptrb = weed_get_voidptr_array(plant, "ptrs", &werr);
902  fprintf(stderr, "get void ** returned (%p %p %p %p) %d\n", ptrb[0], ptrb[1], ptrb[2], ptrb[3], werr);
903 
904  s[0] = "okok";
905  s[1] = "1ok2ok";
906  s[2] = NULL;
907  s[3] = "1ok2ok";
908 
909  weed_leaf_set(plant, "ptrs", WEED_SEED_VOIDPTR, 4, &ptra);
910  fprintf(stderr, "set null array elem ptra returned %d\n", werr);
911 
912  ptrb = weed_get_voidptr_array(plant, "ptrs", &werr);
913  fprintf(stderr, "get void ** returned (%p %p %p %p) %d\n", ptrb[0], ptrb[1], ptrb[2], ptrb[3], werr);
914 
915  weed_leaf_set(plant, "strings", WEED_SEED_STRING, 4, &s);
916  fprintf(stderr, "set char ** %d\n", werr);
917 
918  char **stng2;
919  stng2 = weed_get_string_array(plant, "strings", &werr);
920  fprintf(stderr, "get char ** returned (%s %s %s %s) %d\n", stng2[0], stng2[1], stng2[2], stng2[3], werr);
921 
922  werr = weed_leaf_set(plant, "arrawn", WEED_SEED_VOIDPTR, 4, ptra);
923  fprintf(stderr, "set null array returned %d\n", werr);
924 
925  keys = weed_plant_list_leaves(plant, &nleaves);
926  n = 0;
927  while (keys[n] != NULL) {
928  fprintf(stderr, "key %d is %s\n", n, keys[n]);
929  free(keys[n]);
930  n++;
931  }
932  free(keys);
933 
934  flags = weed_leaf_get_flags(plant, "Test2");
935  fprintf(stderr, "get flags for Test2returned %d\n", flags);
936 
937  werr = weed_leaf_set_flags(plant, "Test2", WEED_FLAG_UNDELETABLE);
938  flags = weed_leaf_get_flags(plant, "string2");
939 
940  fprintf(stderr, "get flags for Test2returned %d\n", flags);
941 
942  werr = weed_leaf_set_flags(plant, "Test2", 0);
943  flags = weed_leaf_get_flags(plant, "string2");
944 
945  fprintf(stderr, "get flags for Test2returned %d\n", flags);
946 
947  werr = weed_leaf_set_flags(plant, "type", WEED_FLAG_UNDELETABLE | WEED_FLAG_IMMUTABLE);
948  fprintf(stderr, "wlsf for type returned %d\n", werr);
949 
950 
951 
952  flags = weed_leaf_get_flags(plant, "type");
953  fprintf(stderr, "get type flags returned %d\n", flags);
954 
955  werr = weed_plant_free(plant);
956  fprintf(stderr, "wpf returned %d\n", werr);
957 
958  keys = weed_plant_list_leaves(plant, &nleaves);
959  n = 0;
960  while (keys[n] != NULL) {
961  fprintf(stderr, "key %d is %s\n", n, keys[n]);
962  free(keys[n]);
963  n++;
964  }
965  free(keys);
966 
967  werr = weed_leaf_set_flags(plant, "type", WEED_FLAG_IMMUTABLE);
968  flags = weed_leaf_get_flags(plant, "type");
969  fprintf(stderr, "get flags returned %d\n", flags);
970 
971  werr = weed_leaf_set_flags(plant, "arrawn", WEED_FLAG_UNDELETABLE);
972  fprintf(stderr, "set flags returned %d\n", werr);
973 
974  flags = weed_leaf_get_flags(plant, "arrawn");
975  fprintf(stderr, "get flags returned %d\n", flags);
976 
977  werr = weed_leaf_set_flags(plant, "indirect", WEED_FLAG_UNDELETABLE);
978  werr = weed_leaf_set_flags(plant, "Test2", WEED_FLAG_UNDELETABLE);
979 
980  werr = weed_plant_free(plant);
981  fprintf(stderr, "wpf returned %d\n", werr);
982 
983  keys = weed_plant_list_leaves(plant, &nleaves);
984  n = 0;
985  while (keys[n] != NULL) {
986  fprintf(stderr, "key %d is %s\n", n, keys[n]);
987  free(keys[n]);
988  n++;
989  }
990  free(keys);
991 
992  werr = weed_leaf_set_flags(plant, "arrawn", 0);
993  fprintf(stderr, "set flags returned %d\n", werr);
994  flags = weed_leaf_get_flags(plant, "arrawn");
995  fprintf(stderr, "get flags returned %d\n", flags);
996 
997  werr = weed_leaf_set_flags(plant, "indirect", WEED_FLAG_IMMUTABLE);
998  werr = weed_leaf_set_flags(plant, "Test2", 0);
999 
1000  werr = weed_plant_free(plant);
1001  fprintf(stderr, "wpf returned %d\n", werr);
1002 
1004 
1005  /* keys = weed_plant_list_leaves(plant, &nleaves); */
1006  /* n = 0; */
1007  /* while (keys[n] != NULL) { */
1008  /* fprintf(stderr, "key %d is %s\n", n, keys[n]); */
1009  /* free(keys[n]); */
1010  /* n++; */
1011  /* } */
1012  /* free(keys); */
1013 
1014  show_timer_info();
1015 
1016 #define BPLANT_LEAVES 10000
1017  g_print("Big plant test: \n");
1018  g_print("adding %d leaves\n", BPLANT_LEAVES);
1019  plant = weed_plant_new(WEED_PLANT_EVENT);
1020  for (int i = 0; i < BPLANT_LEAVES; i++) {
1021  int num = fastrand() >> 32;
1022  char *key = lives_strdup_printf("leaf_number_%d", i);
1023  weed_set_int_value(plant, key, num);
1024  free(key);
1025  }
1026  g_print("done\n");
1027  g_print("test %d random reads\n", BPLANT_LEAVES * 10);
1028  n = 0;
1029  for (int i = 0; i < BPLANT_LEAVES * 10; i++) {
1030  char *key = lives_strdup_printf("leaf_number_%d", (int)((double)fastrand() / (double)LIVES_MAXUINT64 * BPLANT_LEAVES * 2.));
1031  weed_get_int_value(plant, key, &werr);
1032  if (werr == WEED_SUCCESS) n++;
1033  free(key);
1034  }
1035  g_print("done, hit percentage was %.2f\n", (double)n / (double)BPLANT_LEAVES * 10);
1036  show_timer_info();
1037 
1038  g_print("test %d last-leaf reads\n", BPLANT_LEAVES * 10);
1039  n = 0;
1040  for (int i = 0; i < BPLANT_LEAVES * 10; i++) {
1041  const char *key = "leaf_number_0";
1042  weed_get_int_value(plant, key, &werr);
1043  if (werr == WEED_SUCCESS) n++;
1044  }
1045  g_print("done, hit percentage was %.2f\n", (double)n / (double)BPLANT_LEAVES * 10);
1046  show_timer_info();
1047 
1048  g_print("freeing big plant\n");
1049  weed_plant_free(plant);
1050  g_print("done\n");
1051 
1053  plant = weed_plant_new(0);
1054  if (weed_leaf_set_private_data(plant, WEED_LEAF_TYPE, NULL) == WEED_ERROR_CONCURRENCY) {
1056  g_print("libweed built with FULL threadsafety\n");
1057  } else {
1059  g_print("libweed built with PARTIAL threadsafety\n");
1060  }
1061  weed_plant_free(plant);
1062 
1063  //g_print
1064 
1065  return 0;
1066 }
1067 
1068 #endif
1069 
1070 #define SCALE_FACT 65793.
1071 
1073  double val;
1074  int inval, outval;
1075  for (val = 0.; val < 256.; val += .1) {
1076  inval = val * SCALE_FACT;
1077  outval = round_special(inval);
1078  if (fabs((float)outval - val) > .51)
1079  g_print("in val was %.6f, stored as %d, returned as %d\n", val, inval, outval);
1080  }
1081  return 0;
1082 }
1083 
1084 #endif
lives_freep
boolean lives_freep(void **ptr)
Definition: utils.c:1411
LIVES_GLOBAL_INLINE
#define LIVES_GLOBAL_INLINE
Definition: main.h:239
mainwindow::jackd
void * jackd
jack audio player / transport
Definition: mainwindow.h:1453
mainwindow::startticks
volatile ticks_t startticks
effective ticks when current frame was (should have been) displayed
Definition: mainwindow.h:997
LIVES_IS_PLAYING
#define LIVES_IS_PLAYING
Definition: main.h:840
LIVES_LOCAL_INLINE
#define LIVES_LOCAL_INLINE
Definition: main.h:246
EFFORT_RANGE_MAX
#define EFFORT_RANGE_MAX
if set to TRUE during playback then a new frame (or possibly the current one) will be displayed ASAP
Definition: mainwindow.h:1770
hash_test
void hash_test(void)
lives_struct_def_t
112 bytes
Definition: lsd.h:241
fastrand_int
LIVES_GLOBAL_INLINE uint32_t fastrand_int(uint32_t range)
pick a pseudo random uint between 0 and range (inclusive)
Definition: machinestate.c:54
lives_free
#define lives_free
Definition: machinestate.h:52
get_cache_stats
const char * get_cache_stats(void)
Definition: dialogs.c:68
mainwindow::current_file
int current_file
Definition: mainwindow.h:727
IS_VALID_CLIP
#define IS_VALID_CLIP(clip)
Definition: main.h:808
lives_string_hash
LIVES_GLOBAL_INLINE uint32_t lives_string_hash(const char *st)
Definition: machinestate.c:1585
cfile
#define cfile
Definition: main.h:1833
lives_clip_t::frames
frames_t frames
number of video frames
Definition: main.h:890
prefs
_prefs * prefs
Definition: preferences.h:847
lives_strcmp
LIVES_GLOBAL_INLINE boolean lives_strcmp(const char *st1, const char *st2)
returns FALSE if strings match
Definition: machinestate.c:1506
get_inst_fps
LIVES_GLOBAL_INLINE double get_inst_fps(void)
Definition: diagnostics.c:16
_prefs::audio_player
short audio_player
Definition: preferences.h:40
LIVES_FIELD_CHARPTR
#define LIVES_FIELD_CHARPTR
Definition: lsd.h:171
TICKS_PER_SECOND_DBL
#define TICKS_PER_SECOND_DBL
actually microseconds / 100.
Definition: mainwindow.h:37
mainwindow::actual_frame
frames_t actual_frame
actual / last frame being displayed
Definition: mainwindow.h:959
lives_random
LIVES_GLOBAL_INLINE uint64_t lives_random(void)
Definition: machinestate.c:58
round_special
LIVES_GLOBAL_INLINE int32_t round_special(int32_t val)
Definition: colourspace.c:544
fastrand
LIVES_GLOBAL_INLINE uint64_t fastrand(void)
Definition: machinestate.c:40
ticks_t
int64_t ticks_t
Definition: main.h:97
TRUE
#define TRUE
Definition: videoplugin.h:59
lives_memset
#define lives_memset
Definition: machinestate.h:61
check_random
void check_random(void)
CURRENT_CLIP_HAS_AUDIO
#define CURRENT_CLIP_HAS_AUDIO
Definition: main.h:818
lives_clip_t::fps
double fps
Definition: main.h:893
test_palette_conversions
int test_palette_conversions(void)
Definition: diagnostics.c:1072
callbacks.h
_prefs::audio_src
int audio_src
Definition: preferences.h:204
lives_clip_t::frameno
frames_t frameno
Definition: main.h:934
mainwindow::fps_mini_measure
frames_t fps_mini_measure
show fps stats during playback
Definition: mainwindow.h:779
mainwindow::blend_file
int blend_file
background clip details
Definition: mainwindow.h:976
mainwindow::clock_ticks
volatile ticks_t clock_ticks
unadjusted system time since pb start, measured concurrently with currticks
Definition: mainwindow.h:1003
SCALE_FACT
#define SCALE_FACT
Definition: diagnostics.c:1070
mainwindow::files
lives_clip_t * files[MAX_FILES+1]
+1 for the clipboard
Definition: mainwindow.h:729
mainwindow::pulsed
void * pulsed
pulseaudio player
Definition: mainwindow.h:1463
diagnostics.h
weed_threadsafe
boolean weed_threadsafe
Definition: main.h:634
mainwindow::play_sequence
int play_sequence
currticks when last display was shown (used for fixed fps)
Definition: mainwindow.h:1013
lives_get_current_ticks
LIVES_GLOBAL_INLINE ticks_t lives_get_current_ticks(void)
Definition: machinestate.c:835
benchmark
void benchmark(void)
lives_strdup_printf
#define lives_strdup_printf(fmt,...)
Definition: support.c:27
lives_calloc
#define lives_calloc
Definition: machinestate.h:67
lives_clip_t::hsize
int hsize
frame width (horizontal) in pixels (NOT macropixels !)
Definition: main.h:896
get_stats_msg
char * get_stats_msg(boolean calc_only)
Definition: diagnostics.c:22
mainwindow::inst_fps
double inst_fps
Definition: mainwindow.h:781
fast_hash
LIVES_GLOBAL_INLINE uint32_t fast_hash(const char *key)
Definition: machinestate.c:1596
AUDIO_SRC_INT
#define AUDIO_SRC_INT
Definition: preferences.h:205
mainwindow::effort
int effort
Definition: mainwindow.h:1773
sig
#define sig(a)
Definition: main.h:268
mainw
mainwindow * mainw
Definition: main.c:103
get_palette_name_for_clip
char * get_palette_name_for_clip(int clipno)
Definition: callbacks.c:11272
mainwindow::lockstats
boolean lockstats
Definition: mainwindow.h:1774
frames_t
int frames_t
Definition: main.h:99
lives_struct_test
void lives_struct_test(void)
lives_struct_def_t::special_fields
lives_special_field_t ** special_fields
user_data for delete_struct_callback
Definition: lsd.h:263
_prefs::pb_quality
short pb_quality
Definition: preferences.h:31
lives_clip_t::vsize
int vsize
frame height (vertical) in pixels
Definition: main.h:897
AUD_PLAYER_PULSE
#define AUD_PLAYER_PULSE
Definition: preferences.h:44
mainwindow::fps_mini_ticks
ticks_t fps_mini_ticks
Definition: mainwindow.h:780
AUD_PLAYER_JACK
#define AUD_PLAYER_JACK
Definition: preferences.h:43
_prefs::pbq_adaptive
boolean pbq_adaptive
Definition: preferences.h:36
lsd.h
STATS_TC
#define STATS_TC
Definition: diagnostics.c:13
mainwindow::currticks
volatile ticks_t currticks
wall clock time, updated whenever lives_get_*_ticks is called
Definition: mainwindow.h:1005
lives_clip_t::arate
int arate
current audio playback rate (varies if the clip rate is changed)
Definition: main.h:906
FALSE
#define FALSE
Definition: videoplugin.h:60
_
#define _(String)
Definition: support.h:44