Пример #1
0
void tc_strfreev(char **pieces)
{
    if (pieces != NULL) {
        int i = 0;
        for (i = 0; pieces[i] != NULL; i++) {
            tc_free(pieces[i]);
        }
        tc_free(pieces);
    }
}
Пример #2
0
int tc_glob_close(TCGlob *tcg)
{
    if (tcg != NULL) {
        if (tcg->pattern != NULL) {
           tc_free((void*)tcg->pattern);
           tcg->pattern = NULL;
        }
        globfree(&(tcg->glob));
        tc_free(tcg);
    }
    return TC_OK;
}
Пример #3
0
/**
 * flogo_yuvbuf_free: Frees a set of YUV frame buffers allocated with
 *                    flogo_yuvbuf_alloc().
 * Parameters:     yuv: a pointer to a set of YUV frames
 *                 num: the number of frames to free
 * Return value:   N/A
 * Preconditions:  yuv was allocated with flogo_yuvbuf_alloc
 *                 num > 0
 * Postconditions: N/A
 */
static void flogo_yuvbuf_free(uint8_t **yuv, int num) {
    int i;

    if (yuv) {
        for (i = 0; i < num; i++) {
            if (yuv[i] != NULL)
                tc_free(yuv[i]);
        }
        tc_free(yuv);
    }

    return;
}
Пример #4
0
void clear(match_line_list *list) {
    match_line_node *node = list->first;
    while (node) {
        match_line_node *next = node->next;
        tc_free(node->line);
        tc_free(node);
        node = next;
    }

    list->first = NULL;
    list->last  = NULL;
    list->max_line_no = 1;
}
Пример #5
0
void tc_module_info_free(TCModuleInfo *info)
{
    if (info != NULL) {
        /*
         * void* casts to silence warning from gcc 4.x (free requires void*,
         * argument is const something*
         */
        tc_free((void*)info->name);
        tc_free((void*)info->version);
        tc_free((void*)info->description);
        tc_free((void*)info->codecs_in);
        tc_free((void*)info->codecs_out);
    }
}
Пример #6
0
TCGlob *tc_glob_open(const char *pattern, uint32_t flags)
{
    TCGlob *tcg = NULL;
    flags = GLOB_ERR; /* flags intentionally overridden */

    if (pattern != NULL && strlen(pattern) > 0) {
        tcg = tc_malloc(sizeof(TCGlob));

        if (tcg != NULL) {
            int err = 0;

            tcg->pattern = NULL;

            err = glob(pattern, flags, NULL, &(tcg->glob));

            switch (err) {
              case GLOB_NOMATCH:
                tcg->pattern = tc_strdup(pattern); // XXX
                tcg->current = -1;
                break;
              case GLOB_NOERROR:
                tcg->current = 0;
                break;
              default: /* any other error: clean it up */
                tc_log_error(__FILE__, "internal glob failed (code=%i)",
                             err);
                tc_free(tcg);
                tcg = NULL;
            }
        }
    }
    return tcg;
}
Пример #7
0
static int vag_fini(TCModuleInstance *self)
{
    TC_MODULE_SELF_CHECK(self, "fini");

    tc_free(self->userdata);
    self->userdata = NULL;
    return TC_OK;
}
Пример #8
0
void tc_list_del(TCList *L, int deepclean)
{
    if (deepclean) {
        foreach_item(L->head,  DIR_FORWARD, free_item_all, NULL);
        /* if !use_cache, this will not hurt anyone */
        foreach_item(L->cache, DIR_FORWARD, free_item_all, NULL);
    }
    tc_free(L);
}
Пример #9
0
/**
 * transform_fini:  Clean up after this instance of the module.  See
 * tcmodule-data.h for function details.
 */
static int transform_fini(TCModuleInstance *self)
{
    FilterData *fd = NULL;
    TC_MODULE_SELF_CHECK(self, "fini");
    fd = self->userdata;
    tc_free(fd);
    self->userdata = NULL;
    return TC_OK;
}
Пример #10
0
/*
 * deshake_fini:  Clean up after this instance of the module.  See
 * tcmodule-data.h for function details.
 */
static int deshake_fini(TCModuleInstance *self)
{
  DeshakeData *sd = NULL;
  TC_MODULE_SELF_CHECK(self, "fini");
  sd = self->userdata;

  tc_free(sd);
  self->userdata = NULL;
  return TC_OK;
}
Пример #11
0
METHOD int pvn_fini(TCModuleInstance *self)
{
    TC_MODULE_SELF_CHECK(self, "fini");

    pvn_stop(self);
    tc_free(self->userdata);
    self->userdata = NULL;

    return TC_OK;
}
Пример #12
0
static int lowpass_stop(TCModuleInstance *self)
{
    LowPassPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "stop");

    pd = self->userdata;
    
    if (pd->array_r) {
        tc_free(pd->array_r);
        pd->array_r = NULL; 
    }
    if (pd->array_l) {
        tc_free(pd->array_l);
        pd->array_l = NULL;
    }

    return TC_OK;
}
Пример #13
0
void chpl_mem_layerInit(void)
{
  void*  heap_base;
  size_t heap_size;

  chpl_comm_desired_shared_heap(&heap_base, &heap_size);

  if (heap_base != NULL && heap_size == 0)
    chpl_internal_error("if heap address is specified, size must be also");

  //
  // Do a first allocation, to allow tcmalloc to set up its internal
  // management structures.
  //
  {
    void* p;

    if ((p = tc_malloc(1)) == NULL)
      chpl_internal_error("cannot init heap: tc_malloc() failed");
    tc_free(p);
  }

  //
  // Initialize our tcmalloc system allocator.
  //
  tcmallocChapelInit_c(heap_base, heap_size);

  //
  // If the heap has to come from the memory supplied to us (say, in
  // order that the comm layer be able to depend on all allocations
  // having come from it), use up all the system memory tcmalloc had
  // acquired before we set up our own system allocator just now.
  // All allocations after this will come from the memory supplied
  // to us.
  //
  // Note that this can waste up to twice INITIAL_USE_UP_SIZE bytes
  // of the memory supplied to us, plus overhead.
  //
  if (heap_base != NULL) {
#define INITIAL_USE_UP_SIZE ((size_t) 4 * 1024)

    size_t size;
    char*  p;

    for (size = INITIAL_USE_UP_SIZE; size > 0; size /= 2) {
      do {
        p = tc_malloc(size);
      } while (p != NULL
               && (p < (char*) heap_base
                   || p > (char*) heap_base + heap_size));

#undef INITIAL_USE_UP_SIZE
    }
  }
}
Пример #14
0
void tc_error(char *fmt, ...) {
	char msg[256];
	va_list args;
	tc_free();
	/* - - - - */
	va_start(args, fmt);
	vsnprintf(msg, sizeof(msg), fmt, args);
	va_end(args);
	printf("error: %s\n", msg);
	exit(1);
}
Пример #15
0
static void del_item(TCList *L, TCListItem *IT)
{
    if (L->use_cache) {
        IT->prev = NULL;
        IT->data = NULL;
        IT->next = L->cache;
        L->cache = IT;
    } else {
        tc_free(IT);
    }
}
Пример #16
0
int tc_list_insert_dup(TCList *L, int pos, void *data, size_t size)
{
    int ret = TC_ERROR;
    void *mem = tc_malloc(size);
    if (mem) {
        memcpy(mem, data, size);
        ret = tc_list_insert(L, pos, mem);
        if (ret == TC_ERROR) {
            tc_free(mem);
        }
    }
    return ret;
}
Пример #17
0
/** 
 * calulcates the cleaned maximum and minimum of an array of transforms,
 * considerung only x and y
 * It cuts off the upper and lower x-th percentil
 *
 * Parameters:
 *    transforms: array of transforms.
 *           len: length  of array
 *     percentil: the x-th percentil to cut off
 *           min: pointer to min (return value)
 *           max: pointer to max (return value)
 * Return value:
 *     call by reference in min and max
 * Preconditions:
 *     len>0, 0<=percentil<50
 * Side effects:
 *     only on min and max
 */
void cleanmaxmin_xy_transform(const Transform* transforms, int len, 
                              int percentil, 
                              Transform* min, Transform* max){
    Transform* ts = tc_malloc(sizeof(Transform) * len);
    int cut = len * percentil / 100;
    memcpy(ts, transforms, sizeof(Transform) * len); 
    qsort(ts,len, sizeof(Transform), cmp_trans_x);
    min->x = ts[cut].x;
    max->x = ts[len-cut-1].x;
    qsort(ts, len, sizeof(Transform), cmp_trans_y);
    min->y = ts[cut].y;
    max->y = ts[len-cut-1].y;
    tc_free(ts);
}
Пример #18
0
static int fields_stop(TCModuleInstance *self)
{
    FieldsPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "stop");

    pd = self->userdata;

    if (pd->buffer) {
        tc_free(pd->buffer);
        pd->buffer = NULL;
    }
    return TC_OK;
}
static int template_fini(TCModuleInstance *self)
{
    PrivateData *pd;

    TC_MODULE_SELF_CHECK(self, "fini");

    pd = self->userdata;

    /* free data allocated in _init */

    tc_free(self->userdata);
    self->userdata = NULL;
    return TC_OK;
}
Пример #20
0
/**
 * median_xy_transform: calulcates the median of an array 
 * of transforms, considering only x and y
 *
 * Parameters:
 *    transforms: array of transforms.
 *           len: length  of array
 * Return value:
 *     A new transform with x and y beeing the median of 
 *     all transforms. alpha and other fields are 0.
 * Preconditions:
 *     len>0
 * Side effects:
 *     None
 */
Transform median_xy_transform(const Transform* transforms, int len)
{
    Transform* ts = tc_malloc(sizeof(Transform) * len);
    Transform t;
    memcpy(ts,transforms, sizeof(Transform)*len ); 
    int half = len/2;
    qsort(ts, len, sizeof(Transform), cmp_trans_x);
    t.x = len % 2 == 0 ? ts[half].x : (ts[half].x + ts[half+1].x)/2;
    qsort(ts, len, sizeof(Transform), cmp_trans_y);
    t.y = len % 2 == 0 ? ts[half].y : (ts[half].y + ts[half+1].y)/2;
    t.alpha = 0;
    t.zoom = 0;
    t.extra = 0;
    tc_free(ts);
    return t;
}
Пример #21
0
static int nuv_fini(TCModuleInstance *self)
{
    PrivateData *pd;

    TC_MODULE_SELF_CHECK(self, "fini");

    pd = self->userdata;

    if (pd->fd) {
        close(pd->fd);
        pd->fd = -1;
    }

    tc_free(self->userdata);
    self->userdata = NULL;
    return TC_OK;
}
Пример #22
0
static int astat_stop(TCModuleInstance *self)
{
    int ret = TC_OK; /* optimistism... */
    AStatPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "stop");

    pd = self->userdata;

    /* stats summary */
    if (pd->min >= pd->silence_limit && pd->max <= pd->silence_limit) {
        tc_log_info(MOD_NAME, "audio track seems only silence");
    } else if (pd->min == 0 || pd->max == 0) {
        tc_log_warn(MOD_NAME, "bad minimum/maximum value,"
                              " unable to find scale value");
        ret = TC_ERROR;
    } else {
        double fmin = -((double) pd->min)/TCA_S16LE_MAX;
        double fmax =  ((double) pd->max)/TCA_S16LE_MAX;
        /* FIXME: constantize in libtcaudio */
        double vol = (fmin < fmax) ? 1./fmax : 1./fmin;

        if (pd->filepath == NULL) {
            tc_log_info(MOD_NAME, "(min=%.3f/max=%.3f), "
                                  "normalize volume with \"-s %.3f\"",
                                  -fmin, fmax, vol);
        } else {
            FILE *fh = fopen(pd->filepath, "w");
            if (fh == NULL) {
                tc_log_perror(MOD_NAME, "unable to open scale value file");
                ret = TC_ERROR;
            } else {
                fprintf(fh, "%.3f\n", vol);
                fclose(fh); // XXX
                if (verbose) {
                    tc_log_info(MOD_NAME, "wrote audio scale value to '%s'", pd->filepath);
                }
            }

            tc_free(pd->filepath);
            pd->filepath = NULL;
        }
    }

    return TC_OK;
}
static int doublefps_fini(TCModuleInstance *self)
{
    DfpsPrivateData *pd;

    TC_MODULE_SELF_CHECK(self, "fini");

    pd = self->userdata;

    if (pd->tcvhandle) {
        tcv_free(pd->tcvhandle);
        pd->tcvhandle = 0;
    }

    tc_free(self->userdata);
    self->userdata = NULL;
    return TC_OK;
}
Пример #24
0
static int tc_sync_adjust_fini(TCSynchronizer *sy)
{
    if (sy) {
        AdjustContext *ctx = sy->privdata;
        if (ctx) {
            adjust_print(ctx, TC_INFO); /* last summary */

            if (ctx->saved) {
                tc_del_video_frame(ctx->saved);
                ctx->saved = NULL;
            }
            tc_free(ctx);
            sy->privdata = NULL;
        }
    }
    return TC_OK;
}
Пример #25
0
/**
 * cleanmean_xy_transform: calulcates the cleaned mean of an array 
 * of transforms, considering only x and y
 *
 * Parameters:
 *    transforms: array of transforms.
 *           len: length  of array
 * Return value:
 *     A new transform with x and y beeing the cleaned mean 
 *     (meaning upper and lower pentile are removed) of 
 *     all transforms. alpha and other fields are 0.
 * Preconditions:
 *     len>0
 * Side effects:
 *     None
 */
Transform cleanmean_xy_transform(const Transform* transforms, int len)
{
    Transform* ts = tc_malloc(sizeof(Transform) * len);
    Transform t = null_transform();
    int i, cut = len / 5;
    memcpy(ts, transforms, sizeof(Transform) * len); 
    qsort(ts,len, sizeof(Transform), cmp_trans_x);
    for (i = cut; i < len - cut; i++){ // all but cutted
        t.x += ts[i].x;
    }
    qsort(ts, len, sizeof(Transform), cmp_trans_y);
    for (i = cut; i < len - cut; i++){ // all but cutted
        t.y += ts[i].y;
    }
    tc_free(ts);
    return mult_transform(&t, 1.0 / (len - (2.0 * cut)));
}
Пример #26
0
char *grow_buf_if_shortage(size_t *cur_buf_size,
                           size_t need_size,
                           int buf_offset,
                           char *copy_buf,
                           char *current_buf)
{
    char *new_buf;
    if (*cur_buf_size < need_size + buf_offset + NMAX) {
        *cur_buf_size += need_size + (NMAX - need_size % NMAX);
        new_buf = (char *)hw_calloc(*cur_buf_size, SIZE_OF_CHAR);
        memcpy(new_buf, copy_buf, need_size);
        tc_free(current_buf);
    } else {
        new_buf = copy_buf;
    }

    return new_buf;
}
Пример #27
0
void user_free(void *ptr, uint32_t handle, uint32_t *op_time) {
    unsigned long size = g_handles[ptr];
    g_memory_usage -= size;

    g_count[ptr] -= 1;
    g_free++;

#ifdef DEBUG
    //sanity();
#endif

    TIMER_DECL;

    TIMER_START;
    tc_free(ptr);
    TIMER_END;
    if (op_time)
        *op_time = TIMER_ELAPSED;
}
Пример #28
0
static int tc_sync_adjust_init(TCSynchronizer *sy, vob_t *vob, int master)
{
    AdjustContext *ctx = NULL;
    
    if (master != TC_AUDIO) {
        tc_log_error(__FILE__, 
                     "(adjust) only audio master source supported yet");
        /* can't yet use method_name */
        return TC_ERROR;
    }
    
    ctx = tc_zalloc(sizeof(AdjustContext));
    if (!ctx) {
        goto no_context;
    }
    ctx->saved = tc_new_video_frame(vob->im_v_width, vob->im_v_height,
                                    vob->im_v_codec, 0);
    if (!ctx->saved) {
        goto no_frame;
    }
    ctx->method_name     = "adjust";
    ctx->op              = AdjustNone;
    ctx->frames_margin   = vob->resync_frame_margin;
    ctx->frames_interval = vob->resync_frame_interval;
    /* vertical alignement intentionally changed */
    sy->method_name = ctx->method_name; /* let's recycle some bytes */
    sy->privdata    = ctx;
    sy->audio_shift = vob->sync;
    sy->verbose     = vob->verbose;
    sy->get_video   = tc_sync_adjust_get_video;
    sy->get_audio   = tc_sync_adjust_get_audio;
    sy->fini        = tc_sync_adjust_fini;

    tc_log_info(__FILE__, "(%s) resync frames: interval=%i/margin=%i",
                sy->method_name,
                ctx->frames_interval, ctx->frames_margin);
    return TC_OK;

no_frame:
    tc_free(ctx);
no_context:
    return TC_ERROR;
}
Пример #29
0
static int deshake_stop(TCModuleInstance *self)
{
  DeshakeData *sd = NULL;
  TC_MODULE_SELF_CHECK(self, "stop");
  sd = self->userdata;
  // print transs
  if (sd->f) {
    fclose(sd->f);
    sd->f = NULL;
  }

  cleanupMotionDetection(&sd->md);
  if (sd->result) {
    tc_free(sd->result);
    sd->result = NULL;
  }

  cleanupTransformData(&sd->td);

  return TC_OK;
}
Пример #30
0
int main(int argc, char *argv[])
{
	tc_init();

	int rc;
	enum tc_opt_mode mode = tc_opt_init(&tc.opt, argc, argv);
	switch (mode) {
	case TC_OPT_USAGE:
		tc_opt_usage();
		break;
	case TC_OPT_RPL:
		tc_connect();
		rc = tc_wal_remote();
		break;
	case TC_OPT_WAL_CAT:
		rc = tc_wal_cat();
		break;
	case TC_OPT_WAL_PLAY:
		tc_connect();
		rc = tc_wal_play();
		break;
	case TC_OPT_CMD:
		tc_connect();
		tc_connect_admin();
		rc = tc_cli_cmdv();
		break;
	case TC_OPT_INTERACTIVE:
		tc_connect();
		tc_connect_admin();
		rc = tc_cli();
		break;
	}

	tc_free();
	return rc;
}