/* * cfg_open * Open the current configuration file * Sets file descriptor in cfp->cf_fd for use by other routines */ cfp_t * localcf_open(cfp_t *cfp, char *name) { struct stat sb; int rc; if (name == NULL) { cfg_perror_str = dgettext("cfg", "cfg_open: unable to open configuration location"); cfg_severity = CFG_EFATAL; return (NULL); } cfp->cf_fd = open(name, O_RDWR|O_CREAT|O_DSYNC|O_RSYNC, 0640); if (cfp->cf_fd == -1) { if ((cfp->cf_fd = open(name, O_RDONLY, 0640)) == -1) { cfg_perror_str = dgettext("cfg", "cfg_open: unable to open configuration location"); cfg_severity = CFG_EFATAL; return (NULL); } cfp->cf_flag |= CFG_RDONLY; } if (fstat(cfp->cf_fd, &sb) == -1) { close(cfp->cf_fd); cfg_perror_str = dgettext("cfg", "cfg_open: unable to stat configuration location"); cfg_severity = CFG_EFATAL; return (NULL); } if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { cfp->cf_size = get_bsize(cfp, name); /* skip the vtoc if necessary */ if (cfp->cf_flag & CFG_NOWRVTOC) { do { rc = lseek(cfp->cf_fd, CFG_VTOC_SKIP, SEEK_SET); } while (rc == -1 && errno == EINTR); if (rc == -1) { cfg_perror_str = dgettext("cfg", strerror(errno)); cfg_severity = CFG_EFATAL; close(cfp->cf_fd); return (NULL); } } } else if (S_ISREG(sb.st_mode)) { cfp->cf_flag |= CFG_FILE; cfp->cf_size = FBA_NUM(FBA_SIZE(1) - 1 + sb.st_size); } else { cfg_perror_str = dgettext("cfg", "cfg_open: unknown file type"); cfg_severity = CFG_EFATAL; close(cfp->cf_fd); cfp->cf_fd = NULL; return (NULL); } return (cfp); }
static inline void plot_freq(ShowFreqsContext *s, int ch, double a, int f, uint8_t fg[4], int *prev_y, AVFrame *out, AVFilterLink *outlink) { const int w = s->w; const float avg = s->avg_data[ch][f]; const float bsize = get_bsize(s, f); const int sx = get_sx(s, f); int end = outlink->h; int x, y, i; switch(s->ascale) { case AS_SQRT: a = 1.0 - sqrt(a); break; case AS_CBRT: a = 1.0 - cbrt(a); break; case AS_LOG: a = log(av_clipd(a, 1e-6, 1)) / log(1e-6); break; case AS_LINEAR: a = 1.0 - a; break; } switch (s->cmode) { case COMBINED: y = a * outlink->h - 1; break; case SEPARATE: end = (outlink->h / s->nb_channels) * (ch + 1); y = (outlink->h / s->nb_channels) * ch + a * (outlink->h / s->nb_channels) - 1; break; } if (y < 0) return; switch (s->avg) { case 0: y = s->avg_data[ch][f] = !outlink->frame_count ? y : FFMIN(avg, y); break; case 1: break; default: s->avg_data[ch][f] = avg + y * (y - avg) / (FFMIN(outlink->frame_count + 1, s->avg) * y); y = s->avg_data[ch][f]; break; } switch(s->mode) { case LINE: if (*prev_y == -1) { *prev_y = y; } if (y <= *prev_y) { for (x = sx + 1; x < sx + bsize && x < w; x++) draw_dot(out, x, y, fg); for (i = y; i <= *prev_y; i++) draw_dot(out, sx, i, fg); } else { for (i = *prev_y; i <= y; i++) draw_dot(out, sx, i, fg); for (x = sx + 1; x < sx + bsize && x < w; x++) draw_dot(out, x, i - 1, fg); } *prev_y = y; break; case BAR: for (x = sx; x < sx + bsize && x < w; x++) for (i = y; i < end; i++) draw_dot(out, x, i, fg); break; case DOT: for (x = sx; x < sx + bsize && x < w; x++) draw_dot(out, x, y, fg); break; } }