Exemplo n.º 1
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
    }
  }
}
Exemplo n.º 2
0
static int sdlview_init(TCModuleInstance *self, uint32_t features)
{
    int err = 0;
    SDLPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    err = SDL_Init(SDL_INIT_VIDEO);
    if (err) {
        tc_log_error(MOD_NAME, "SDL initialization failed: %s", SDL_GetError());
        return TC_ERROR;
    }

    pd = tc_malloc(sizeof(SDLPrivateData));
    if (pd == NULL) {
        tc_log_error(MOD_NAME, "init: out of memory!");
        return TC_ERROR;
    }

    pd->surface = NULL;
    pd->overlay = NULL;

    pd->w = 0;
    pd->h = 0;

    self->userdata = pd;

    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }
    return TC_OK;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
static int tc_y4m_init(TCModuleInstance *self, uint32_t features)
{
    Y4MPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    pd = tc_malloc(sizeof(Y4MPrivateData));
    if (pd == NULL) {
        return TC_ERROR;
    }

    pd->width  = 0;
    pd->height = 0;
    pd->fd_vid = -1;

    y4m_init_stream_info(&(pd->streaminfo));
    /* frameinfo will be initialized at each multiplex call  */

    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }

    self->userdata = pd;
    return TC_OK;
}
Exemplo n.º 5
0
static int faac_init(TCModuleInstance *self, uint32_t features)
{
    PrivateData *pd;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    self->userdata = pd = tc_malloc(sizeof(PrivateData));
    if (!pd) {
        tc_log_error(MOD_NAME, "init: out of memory!");
        return TC_ERROR;
    }
    pd->handle = 0;
    pd->audiobuf = NULL;
    pd->need_flush = TC_FALSE;

    /* FIXME: shouldn't this test a specific flag? */
    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
        if (verbose >= TC_INFO) {
            char *id, *copyright;
            faacEncGetVersion(&id, &copyright);
            tc_log_info(MOD_NAME, "Using FAAC %s", id);
        }
    }
    return TC_OK;
}
Exemplo n.º 6
0
static int write_tmpfile(char* header, char* content, int content_size, int slot_id){
	FILE* 	tmp = NULL;
	int 	i = 0;
	char*	filename = NULL;

	filename = tc_malloc(sizeof(char)*(strlen(TMP_FILE) + TMP_STRING_SIZE));
	if (!filename){
		tc_log_error(MOD_NAME, "Out of memory !!!");
		return -1;
	}

	if (verbose & TC_DEBUG)
		tc_log_info(MOD_NAME, "Temporary filename correctly allocated.");
	tc_snprintf(filename, strlen(TMP_FILE) + TMP_STRING_SIZE, "%s-%d.tmp", TMP_FILE, slot_id);

	tmp = fopen(filename, "w");
	if (!tmp){
		tc_log_error(MOD_NAME, "Cannot write temporary file !");
		return -1;
	}
	for(i=0; i<strlen(header); i++)
		fputc(header[i], tmp);

	for(i=0; i< content_size; i++)
		fputc(content[i], tmp);

	fclose(tmp);
	free(filename);
	return 0;
}
Exemplo n.º 7
0
file_queue_node *enqueue_file(file_queue *queue, const char *filename)
{
    file_queue_node *node = (file_queue_node *)tc_malloc(sizeof(file_queue_node));
    node->next        = NULL;
    node->prev        = NULL;
    node->match_lines = NULL;
    node->searched    = false;
    node->matched     = false;
    strcpy(node->filename, filename);

    if (queue->first) {
        node->prev = queue->last;
        queue->last->next = node;
        queue->last = node;

        if (!queue->current_for_search) {
            queue->current_for_search = node;
        }
    } else {
        queue->first   = node;
        queue->last    = node;
        queue->current_for_search = node;
    }

    return node;
}
Exemplo n.º 8
0
static void deNoise(unsigned char *Frame,        // mpi->planes[x]
                    unsigned char *FrameDest,    // dmpi->planes[x]
                    unsigned int *LineAnt,      // vf->priv->Line (width bytes)
		    unsigned short **FrameAntPtr,
                    int W, int H, int sStride, int dStride,
                    int *Horizontal, int *Vertical, int *Temporal)
{
    int X, Y;
    int sLineOffs = 0, dLineOffs = 0;
    unsigned int PixelAnt;
    int PixelDst;
    unsigned short* FrameAnt=(*FrameAntPtr);

    if(!FrameAnt){
	(*FrameAntPtr)=FrameAnt=tc_malloc(W*H*sizeof(unsigned short));
	for (Y = 0; Y < H; Y++){
	    unsigned short* dst=&FrameAnt[Y*W];
	    unsigned char* src=Frame+Y*sStride;
	    for (X = 0; X < W; X++) dst[X]=src[X]<<8;
	}
    }

    /* First pixel has no left nor top neightbour. Only previous frame */
    LineAnt[0] = PixelAnt = Frame[0]<<16;
    PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal);
    FrameAnt[0] = ((PixelDst+0x1000007F)/256);
    FrameDest[0]= ((PixelDst+0x10007FFF)/65536);

    /* Fist line has no top neightbour. Only left one for each pixel and
     * last frame */
    for (X = 1; X < W; X++){
        LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
        PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal);
	FrameAnt[X] = ((PixelDst+0x1000007F)/256);
	FrameDest[X]= ((PixelDst+0x10007FFF)/65536);
    }

    for (Y = 1; Y < H; Y++){
	unsigned int PixelAnt;
	unsigned short* LinePrev=&FrameAnt[Y*W];
	sLineOffs += sStride, dLineOffs += dStride;
        /* First pixel on each line doesn't have previous pixel */
        PixelAnt = Frame[sLineOffs]<<16;
        LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
	PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal);
	LinePrev[0] = ((PixelDst+0x1000007F)/256);
	FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)/65536);

        for (X = 1; X < W; X++){
	    int PixelDst;
            /* The rest are normal */
            PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
            LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
	    PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal);
	    LinePrev[X] = ((PixelDst+0x1000007F)/256);
	    FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)/65536);
        }
    }
}
Exemplo n.º 9
0
match_line_list *create_match_line_list()
{
    match_line_list *list = (match_line_list *)tc_malloc(sizeof(match_line_list));
    list->first = NULL;
    list->last  = NULL;
    list->max_line_no = 1;
    return list;
}
Exemplo n.º 10
0
TCList *tc_list_new(int usecache)
{
    TCList *L = tc_malloc(sizeof(TCList));
    if (L) {
        tc_list_init(L, usecache);
    }
    return L;
}
Exemplo n.º 11
0
file_queue *create_file_queue()
{
    file_queue *queue = (file_queue *)tc_malloc(sizeof(file_queue));
    queue->first   = NULL;
    queue->last    = NULL;
    queue->current_for_search = NULL;
    return queue;
}
Exemplo n.º 12
0
int tc_ogg_dup_packet(ogg_packet *dst, const ogg_packet *src)
{
    int ret = TC_ERROR;

    ac_memcpy(dst, src, sizeof(ogg_packet));
    dst->packet = tc_malloc(src->bytes);
    if (dst->packet) {
        ac_memcpy(dst->packet, src->packet, src->bytes);
        ret = TC_OK;
    }
    return ret;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
seq_list_t *seq_register(int id)
{

  /* objectives:
     ===========

     register new seq

     allocate space for new seq and establish backward reference


  */

  seq_list_t *ptr;

  pthread_mutex_lock(&seq_list_lock);

  // retrive a valid pointer from the pool

  if((ptr = tc_malloc(sizeof(seq_list_t))) == NULL) {
    pthread_mutex_unlock(&seq_list_lock);
    return(NULL);
  }

  memset(ptr, 0, sizeof(seq_list_t));

  ptr->status = BUFFER_EMPTY;

  ptr->next = NULL;
  ptr->prev = NULL;

  ptr->id  = id;

  if(seq_list_tail != NULL)
  {
      seq_list_tail->next = ptr;
      ptr->prev = seq_list_tail;
  }

  seq_list_tail = ptr;

  /* first seq registered must set seq_list_head */

  if(seq_list_head == NULL) seq_list_head = ptr;

  pthread_mutex_unlock(&seq_list_lock);

  return(ptr);

}
Exemplo n.º 15
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);
}
Exemplo n.º 16
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;
}
Exemplo n.º 17
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)));
}
Exemplo n.º 18
0
static int tc_x11_init(TCModuleInstance *self, uint32_t features)
{
    TCX11PrivateData *priv = NULL;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }
    priv = tc_malloc(sizeof(TCX11PrivateData));
    if (priv == NULL) {
        return TC_ERROR;
    }

    self->userdata = priv;    
    return TC_OK;
}
Exemplo n.º 19
0
static int nuv_init(TCModuleInstance *self, uint32_t features)
{
    PrivateData *pd;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    self->userdata = pd = tc_malloc(sizeof(PrivateData));
    if (!pd) {
        tc_log_error(MOD_NAME, "init: out of memory!");
        return TC_ERROR;
    }
    pd->fd = -1;
    pd->dec_initted = 0;

    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }

    return TC_OK;
}
Exemplo n.º 20
0
static int raw_init(TCModuleInstance *self, uint32_t features)
{
    RawPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    pd = tc_malloc(sizeof(RawPrivateData));
    if (pd == NULL) {
        return TC_ERROR;
    }

    pd->fd_aud = -1;
    pd->fd_vid = -1;

    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }

    self->userdata = pd;
    return TC_OK;
}
Exemplo n.º 21
0
static int doublefps_init(TCModuleInstance *self, uint32_t features)
{
    DfpsPrivateData *pd;
    vob_t *vob = tc_get_vob();

    TC_MODULE_SELF_CHECK(self, "init");
    TC_MODULE_INIT_CHECK(self, MOD_FEATURES, features);

    self->userdata = pd = tc_malloc(sizeof(DfpsPrivateData));
    if (!pd) {
        tc_log_error(MOD_NAME, "init: out of memory!");
        return TC_ERROR;
    }
    pd->topfirst = -1;
    pd->fullheight = 0;
    pd->have_first_frame = pd->saved_width = pd->saved_height = 0;

    /* FIXME: we need a proper way for filters to tell the core that
     * they're changing the export parameters */
    if (!(vob->export_attributes
          & (TC_EXPORT_ATTRIBUTE_FPS | TC_EXPORT_ATTRIBUTE_FRC))
    ) {
        vob->ex_fps *= 2;
        switch (vob->ex_frc) {
            case  3: vob->ex_frc =  6; break;
            case  4: vob->ex_frc =  7; break;
            case  5: vob->ex_frc =  8; break;
            case 10: vob->ex_frc = 11; break;
            case 12: vob->ex_frc =  2; break;
            case 13: vob->ex_frc =  5; break;
            default: vob->ex_frc =  0; break;
        }
    }
    if (verbose) {
        tc_log_info(MOD_NAME, "%s %s", MOD_VERSION, MOD_CAP);
    }
    return TC_OK;
}
Exemplo n.º 22
0
void *user_malloc(int size, uint32_t handle, uint32_t *op_time, void **memaddress) {
    g_memory_usage += size*0.9; // XXX: *0.9 is bogus, should be just size. for plot testing purposes!

    TIMER_DECL;

    TIMER_START;
    void *ptr = tc_malloc(size);
    TIMER_END;
    if (op_time)
        *op_time = TIMER_ELAPSED;
    if (ptr == NULL)
        return ptr;

    //printf("|| h == (void *)0x%X // MALLOC, heap start %x, heap end %x\n", (uint32_t)ptr, (uint32_t)g_heap, (uint32_t)g_heap_end);
    g_handles[ptr] = size;

    g_handle_pointer[ptr] = handle;

    if (g_count.find(ptr) == g_count.end())
        g_count[ptr] = 1;
    else {
        g_count[ptr] += 1;
        if (g_count[ptr] > 1)
            fprintf(stderr, "Double malloc for handle %d\n", handle); // FIXME: this test should be here.
    }

#ifdef DEBUG
    //sanity();
#endif
    
    g_malloc++;

    if (memaddress != NULL)
        *memaddress = (void *)((ptr_t)ptr);

    return ptr;
}
Exemplo n.º 23
0
void* operator new[](size_t size, const std::nothrow_t& nt) {
	return tc_malloc(size);
}
Exemplo n.º 24
0
ZoomInfo *zoom_init(int old_w, int old_h, int new_w, int new_h, int Bpp,
                    int old_stride, int new_stride, TCVZoomFilter filter)
{
    ZoomInfo *zi;
    struct clist *x_contrib = NULL, *y_contrib = NULL;

    /* Sanity check */
    if (old_w <= 0 || old_h <= 0 || new_w <= 0 || new_h <= 0 || Bpp <= 0
     || old_stride <= 0 || new_stride <= 0)
        return NULL;

    /* Allocate structure */
    zi = tc_malloc(sizeof(*zi));
    if (!zi)
        return NULL;

    /* Set up scalar members, and check filter value */
    zi->old_w = old_w;
    zi->old_h = old_h;
    zi->new_w = new_w;
    zi->new_h = new_h;
    zi->Bpp = Bpp;
    zi->old_stride = old_stride;
    zi->new_stride = new_stride;
    switch (filter) {
      case TCV_ZOOM_BOX:
        zi->filter = box_filter;
        zi->fwidth = box_support;
        break;
      case TCV_ZOOM_TRIANGLE:
        zi->filter = triangle_filter;
        zi->fwidth = triangle_support;
        break;
      case TCV_ZOOM_HERMITE:
        zi->filter = hermite_filter;
        zi->fwidth = hermite_support;
        break;
      case TCV_ZOOM_BELL:
        zi->filter = bell_filter;
        zi->fwidth = bell_support;
        break;
      case TCV_ZOOM_B_SPLINE:
        zi->filter = B_spline_filter;
        zi->fwidth = B_spline_support;
        break;
      case TCV_ZOOM_MITCHELL:
        zi->filter = mitchell_filter;
        zi->fwidth = mitchell_support;
        break;
      case TCV_ZOOM_LANCZOS3:
        zi->filter = lanczos3_filter;
        zi->fwidth = lanczos3_support;
        break;
      case TCV_ZOOM_CUBIC_KEYS4:
        zi->filter = cubic_keys4_filter;
        zi->fwidth = cubic_keys4_support;
        break;
      case TCV_ZOOM_SINC8:
        zi->filter = sinc8_filter;
        zi->fwidth = sinc8_support;
        break;
      default:
        free(zi);
        return NULL;
    }

    /* Generate contributor lists and allocate temporary image buffer */
    zi->x_contrib = NULL;
    zi->y_contrib = NULL;
    zi->tmpimage = tc_malloc(new_w * old_h * Bpp);
    if (!zi->tmpimage)
        goto error_out;
    if (old_w != new_w) {
        x_contrib = gen_contrib(old_w, new_w, Bpp, zi->filter, zi->fwidth);
        if (!x_contrib)
            goto error_out;
    }
    if (old_h != new_h) {
        /* Calculate the correct stride--if the width isn't changing,
         * this will just be old_stride */
        int stride = (old_w==new_w) ? old_stride : Bpp*new_w;
        y_contrib = gen_contrib(old_h, new_h, stride, zi->filter,
                                zi->fwidth);
        if (!y_contrib)
            goto error_out;
    }

    /* Convert contributor lists into flat arrays and fixed-point values.
     * The flat array consists of a contributor count plus two values per
     * contributor (index and fixed-point weight) for each output pixel.
     * Note that for the horizontal direction, we make `Bpp' copies of the
     * contributors, adjusting the offset for each byte of the pixel. */

    if (x_contrib) {
        int count = 0, i;
        int32_t *ptr;

        for (i = 0; i < new_w; i++)
            count += 1 + 2 * x_contrib[i].n;
        zi->x_contrib = tc_malloc(sizeof(int32_t) * count * Bpp);
        if (!zi->x_contrib)
            goto error_out;
        for (ptr = zi->x_contrib, i = 0; i < new_w * Bpp; i++) {
            int j;
            *ptr++ = x_contrib[i/Bpp].n;
            for (j = 0; j < x_contrib[i/Bpp].n; j++) {
                *ptr++ = x_contrib[i/Bpp].list[j].pixel + i%Bpp;
                *ptr++ = DOUBLE_TO_FIXED(x_contrib[i/Bpp].list[j].weight);
            }
        }
        /* Free original contributor list */
        for (i = 0; i < new_w; i++)
            free(x_contrib[i].list);
        free(x_contrib);
        x_contrib = NULL;
    }

    if (y_contrib) {
        int count = 0, i;
        int32_t *ptr;

        for (i = 0; i < new_h; i++)
            count += 1 + 2 * y_contrib[i].n;
        zi->y_contrib = tc_malloc(sizeof(int32_t) * count);
        if (!zi->y_contrib)
            goto error_out;
        for (ptr = zi->y_contrib, i = 0; i < new_h; i++) {
            int j;
            *ptr++ = y_contrib[i].n;
            for (j = 0; j < y_contrib[i].n; j++) {
                *ptr++ = y_contrib[i].list[j].pixel;
                *ptr++ = DOUBLE_TO_FIXED(y_contrib[i].list[j].weight);
            }
        }
        for (i = 0; i < new_h; i++)
            free(y_contrib[i].list);
        free(y_contrib);
        y_contrib = NULL;
    }

    /* Done */
    return zi;

  error_out:
    {
        if (x_contrib) {
            int i;
            for (i = 0; i < new_w; i++)
                free(x_contrib[i].list);
            free(x_contrib);
        }
        if (y_contrib) {
            int i;
            for (i = 0; i < new_w; i++)
                free(x_contrib[i].list);
            free(x_contrib);
        }
        zoom_free(zi);
        return NULL;
    }
}
Exemplo n.º 25
0
void* operator new[](size_t size) {
	return tc_malloc(size);
}
Exemplo n.º 26
0
void decode_mov(decode_t *decode)
{

    quicktime_t *qt_handle=NULL;
    unsigned char **p_raw_buffer;
    char *p_v_codec=NULL,*p_a_codec=NULL,*p_buffer=NULL,*p_tmp=NULL;
    int s_width=0,s_height=0,s_channel=0,s_bits=0,s_buff_size=0,s_audio_size=0,s_video_size=0,s_sample=0;
    int s_cont,s_frames;
    double s_fps=0;
    long s_audio_rate,s_qt_pos;
    uint16_t *p_mask1, *p_mask2;
    char msgbuf[TC_BUF_MIN];


    qt_handle = quicktime_open((char * )decode->name, 1, 0);
    if (qt_handle == NULL) {
        QT_ABORT("can't open quicktime!");
    }
    quicktime_set_preload(qt_handle, 10240000);
    s_fps = quicktime_frame_rate(qt_handle, 0);
    if (decode->format == TC_CODEC_PCM) {
        if (quicktime_audio_tracks(qt_handle) == 0) {
            QT_ABORT("no audio track in quicktime found!");
        }
        s_channel = quicktime_track_channels(qt_handle, 0);
        s_audio_rate = quicktime_sample_rate(qt_handle, 0);
        s_bits = quicktime_audio_bits(qt_handle, 0);
        s_audio_size = quicktime_audio_length(qt_handle,0);
        p_a_codec = quicktime_audio_compressor(qt_handle, 0);

        if (decode->frame_limit[1] < s_audio_size) {
            s_audio_size = decode->frame_limit[1] - decode->frame_limit[0];
        } else {
            s_audio_size -= decode->frame_limit[0];
        }

        if (decode->verbose) {
            tc_log_info(__FILE__, "Audio codec=%s, rate=%ld Hz, bits=%d, channels=%d",
                                  p_a_codec, s_audio_rate, s_bits, s_channel);
        }

        if ((s_bits != 8) && (s_bits != 16)) {
            tc_snprintf(msgbuf, sizeof(msgbuf), "unsupported %d bit rate"
                        " in quicktime!", s_bits);
            QT_ABORT(msgbuf);
        }
        if (s_channel > 2) {
            tc_snprintf(msgbuf, sizeof(msgbuf), "too many audio tracks "
                        "(%d) found in quicktime!", s_channel);
            QT_ABORT(msgbuf);
        }
        if (strlen(p_a_codec) == 0) {
            QT_ABORT("unsupported codec (empty!) in quicktime!");
        }
        if (quicktime_supported_audio(qt_handle, 0) != 0) {
            s_qt_pos = quicktime_audio_position(qt_handle,0);
            s_sample = (1.00 * s_channel * s_bits *s_audio_rate)/(s_fps * 8);
            s_buff_size = s_sample * sizeof(uint16_t);
            p_buffer = tc_malloc(s_buff_size);
            if (s_bits == 16)
                s_sample /= 2;
            if (s_channel == 1) {
                p_mask1=(uint16_t *)p_buffer;
                quicktime_set_audio_position(qt_handle, s_qt_pos + decode->frame_limit[0], 0);
                for (; s_audio_size > 0; s_audio_size -= s_sample) {
                    if (quicktime_decode_audio(qt_handle, p_mask1, NULL, s_sample, 0) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    QT_WRITE(decode->fd_out, p_buffer, s_buff_size);
                }
            } else {
                s_sample /= 2;
                p_mask1 = (uint16_t *)p_buffer;
                p_mask2 = tc_malloc(s_sample * sizeof(uint16_t));
                s_qt_pos += decode->frame_limit[0];
                quicktime_set_audio_position(qt_handle, s_qt_pos, 0);
                for (; s_audio_size > 0; s_audio_size -= s_sample) {
                    if (quicktime_decode_audio(qt_handle, p_mask1, NULL, s_sample, 0) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    quicktime_set_audio_position(qt_handle, s_qt_pos, 0);
                    if (quicktime_decode_audio(qt_handle,p_mask2, NULL,s_sample, 1) < 0) {
                        QT_ABORT("error reading quicktime audio frame");
                    }
                    for (s_cont = s_sample - 1; s_cont >= 0; s_cont--)
                        p_mask1[s_cont<<1] = p_mask1[s_cont];
                    for (s_cont = 0; s_cont < s_sample; s_cont++)
                        p_mask1[1+(s_cont<<1)] = p_mask2[s_cont];
                    s_qt_pos += s_sample;
                    QT_WRITE(decode->fd_out, p_buffer, s_buff_size >> 1);
                }
                free(p_mask2);
            }
            free(p_buffer);
        }
#if !defined(LIBQUICKTIME_000904)
        else if ((strcasecmp(p_a_codec, QUICKTIME_RAW) == 0)
Exemplo n.º 27
0
                        p_mask1[s_cont<<1] = p_mask1[s_cont];
                    for (s_cont = 0; s_cont < s_sample; s_cont++)
                        p_mask1[1+(s_cont<<1)] = p_mask2[s_cont];
                    s_qt_pos += s_sample;
                    QT_WRITE(decode->fd_out, p_buffer, s_buff_size >> 1);
                }
                free(p_mask2);
            }
            free(p_buffer);
        }
#if !defined(LIBQUICKTIME_000904)
        else if ((strcasecmp(p_a_codec, QUICKTIME_RAW) == 0)
              || (strcasecmp(p_a_codec, QUICKTIME_TWOS) == 0)) {
            s_sample = (1.00 * s_channel * s_bits *s_audio_rate)/(s_fps * 8);
            s_buff_size = s_sample * sizeof(uint16_t);
            p_buffer = tc_malloc(s_buff_size);
            s_qt_pos = quicktime_audio_position(qt_handle, 0);
            quicktime_set_audio_position(qt_handle, s_qt_pos + decode->frame_limit[0], 0);
            for (; s_audio_size > 0; s_audio_size -= s_buff_size) {
                if (quicktime_read_audio(qt_handle,p_buffer, s_buff_size, 0) < 0) {
                    QT_ABORT("error reading quicktime audio frame");
                }
                QT_WRITE(decode->fd_out, p_buffer, s_buff_size);
            }
            quicktime_close(qt_handle);
            free(p_buffer);
        }
#endif
        else {
            tc_snprintf(msgbuf, sizeof(msgbuf), "quicktime audio codec '%s'"
                        " not supported!", p_a_codec);
Exemplo n.º 28
0
#include <dirent.h>


#ifndef DIR_NAME
    #define DIR_NAME "./knowledge/"
#endif

#define FILE_BUFFER 1024

TEXTCAT_SAVE(default)
{
    uchar * fname, * content;
    long i, ret, offset;
    int fd;

    fname = tc_malloc(strlen(id) + strlen(DIR_NAME) + 2);
    sprintf(fname, "%s/%s", DIR_NAME, id);
    mkdir(DIR_NAME, 0777);

    fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0644);
    if (fd == -1) {
        return TC_FALSE;
    }
    content = tc_malloc(FILE_BUFFER); 
    if (content == NULL) {
        return TC_FALSE;
    }

    /* sort by freq */
    textcat_ngram_sort_by_freq(result);
Exemplo n.º 29
0
void probe_ogg(info_t *ipipe)
{
    ogg_sync_state    sync;
    ogg_page          page;
    ogg_packet        pack;
    char             *buf;
    int               nread, np, sno, nvtracks = 0, natracks = 0, i, idx;
    //int               endofstream = 0, k, n;
    struct demux_t    streams[MAX_AUDIO_TRACKS + MAX_VIDEO_TRACKS];
    int               fdin = -1;
    char vid_codec[5];
    ogm_stream_header *sth;

    fdin = ipipe->fd_in;

    if (fdin == -1) {
	tc_log_error(__FILE__, "Could not open file.");
	goto ogg_out;
    }

    ipipe->probe_info->magic=TC_MAGIC_OGG;

    memset(streams, 0, sizeof(streams));
    for (i = 0; i < (MAX_AUDIO_TRACKS + MAX_VIDEO_TRACKS); i++)
	streams[i].serial = -1;

    ogg_sync_init(&sync);

    while (1) {
	np = ogg_sync_pageseek(&sync, &page);
	if (np < 0) {
	    tc_log_error(__FILE__, "ogg_sync_pageseek failed");
	    goto ogg_out;
	}
	if (np == 0) {
	    buf = ogg_sync_buffer(&sync, BLOCK_SIZE);
	    if (!buf) {
		tc_log_error(__FILE__, "ogg_sync_buffer failed");
		goto ogg_out;
	    }

	    if ((nread = read(fdin, buf, BLOCK_SIZE)) <= 0) {
	    }
	    ogg_sync_wrote(&sync, nread);
	    continue;
	}

	if (!ogg_page_bos(&page)) {
	    break;
	} else {
	    ogg_stream_state sstate;
	    vorbis_info *inf = tc_malloc (sizeof(vorbis_info));
	    vorbis_comment *com = tc_malloc (sizeof(vorbis_comment));

	    if (!inf || !com) {
		tc_log_error(__FILE__, "Out of Memory at %d", __LINE__);
		goto ogg_out;
	    }
	    sno = ogg_page_serialno(&page);
	    if (ogg_stream_init(&sstate, sno)) {
		tc_log_error(__FILE__, "ogg_stream_init failed");
		goto ogg_out;
	    }
	    ogg_stream_pagein(&sstate, &page);
	    ogg_stream_packetout(&sstate, &pack);

	    switch (ogm_packet_type(pack))
	    {
		case Vorbis:
		    vorbis_info_init(inf);
		    vorbis_comment_init(com);

		    if(vorbis_synthesis_headerin(inf, com, &pack) < 0) {
			tc_log_warn(__FILE__, "Could not decode vorbis header "
				    "packet - invalid vorbis stream ()");
		    } else {
#ifdef OGM_DEBUG
			tc_log_msg(__FILE__, "(a%d/%d) Vorbis audio; "
				"rate: %ldHz, channels: %d, bitrate %3.2f kb/s",
				natracks + 1, natracks + nvtracks + 1, inf->rate,
				inf->channels, (double)inf->bitrate_nominal/1000.0);
#endif

			ipipe->probe_info->track[natracks].samplerate = inf->rate;
			ipipe->probe_info->track[natracks].chan = inf->channels;
			ipipe->probe_info->track[natracks].bits = 0; /* XXX --tibit*/
			ipipe->probe_info->track[natracks].format = TC_CODEC_VORBIS;
			ipipe->probe_info->track[natracks].bitrate = (double)inf->bitrate_nominal/1000.0;

			ipipe->probe_info->track[natracks].tid=natracks;
			if(ipipe->probe_info->track[natracks].chan>0) ++ipipe->probe_info->num_tracks;

			streams[natracks].serial = sno;
			streams[natracks].vorbis = 1;
			ac_memcpy(&streams[natracks].state, &sstate, sizeof(sstate));
			natracks++;
		    }
		    break;
#ifdef HAVE_THEORA
		case Theora:
		{
		    theora_info ti;
		    theora_comment tc;

		    theora_decode_header(&ti, &tc, &pack);

		    ipipe->probe_info->width  =  ti.width;
		    ipipe->probe_info->height =  ti.height;
		    ipipe->probe_info->fps    =  (double)ti.fps_numerator/ti.fps_denominator;
		    tc_frc_code_from_ratio(&(ipipe->probe_info->frc),
		    	    		   ti.fps_numerator, ti.fps_denominator);

		    ipipe->probe_info->codec=TC_CODEC_THEORA;

		    idx = natracks + MAX_AUDIO_TRACKS;

		    streams[idx].serial = sno;
		    ac_memcpy(&streams[idx].state, &sstate, sizeof(sstate));
		    nvtracks++;
		    break;
	        }
#endif
		case DirectShow:
		    if ((*(int32_t*)(pack.packet+96) == 0x05589f80) &&
			    (pack.bytes >= 184)) {
			tc_log_warn(__FILE__, "(v%d/%d) Found old video "
				    "header. Not supported.", nvtracks + 1,
				    natracks + nvtracks + 1);
		    } else if (*(int32_t*)pack.packet+96 == 0x05589F81) {
			tc_log_warn(__FILE__, "(a%d/%d) Found old audio "
				    "header. Not supported.", natracks + 1,
				    natracks + nvtracks + 1);
		    }
		    break;
		case StreamHeader:
		    sth = (ogm_stream_header *)(pack.packet + 1);

		    if (!strncmp(sth->streamtype, "video", 5)) {
#ifdef OGM_DEBUG
			unsigned long codec;
			codec = (sth->subtype[0] << 24) +
			    (sth->subtype[1] << 16) + (sth->subtype[2] << 8) + sth->subtype[3];
			tc_log_msg(__FILE__, "(v%d/%d) video; fps: %.3f width height: %dx%d "
				"codec: %p (%c%c%c%c)", nvtracks + 1,
				natracks + nvtracks + 1,
				(double)10000000 / (double)sth->time_unit,
				sth->sh.video.width, sth->sh.video.height, (void *)codec,
				sth->subtype[0], sth->subtype[1], sth->subtype[2],
				sth->subtype[3]);
#endif
			vid_codec[0] = sth->subtype[0];
			vid_codec[1] = sth->subtype[1];
			vid_codec[2] = sth->subtype[2];
			vid_codec[3] = sth->subtype[3];
			vid_codec[4] = '\0';

			//ipipe->probe_info->frames = AVI_video_frames(avifile);

			ipipe->probe_info->width  =  sth->sh.video.width;
			ipipe->probe_info->height =  sth->sh.video.height;
			ipipe->probe_info->fps    =  (double)10000000 / (double)sth->time_unit;
			tc_frc_code_from_value(&(ipipe->probe_info->frc),
  						  ipipe->probe_info->fps);

			ipipe->probe_info->codec=TC_CODEC_UNKNOWN; // gets rewritten

			if(strlen(vid_codec)==0) {
			    ipipe->probe_info->codec=TC_CODEC_RGB24;
			} else {

			    if(strcasecmp(vid_codec,"dvsd")==0)
				ipipe->probe_info->codec=TC_CODEC_DV;

			    if(strcasecmp(vid_codec,"DIV3")==0)
				ipipe->probe_info->codec=TC_CODEC_DIVX3;

			    if(strcasecmp(vid_codec,"DIVX")==0)
				ipipe->probe_info->codec=TC_CODEC_DIVX4;

			    if(strcasecmp(vid_codec,"DX50")==0)
				ipipe->probe_info->codec=TC_CODEC_DIVX5;

			    if(strcasecmp(vid_codec,"XVID")==0)
				ipipe->probe_info->codec=TC_CODEC_XVID;

			    if(strcasecmp(vid_codec,"MJPG")==0)
				ipipe->probe_info->codec=TC_CODEC_MJPEG;
			}

			idx = natracks + MAX_AUDIO_TRACKS;

			streams[idx].serial = sno;
			ac_memcpy(&streams[idx].state, &sstate, sizeof(sstate));
			nvtracks++;
		    } else if (!strncmp(sth->streamtype, "audio", 5)) {
			int codec;
			char buf[5];
			ac_memcpy(buf, sth->subtype, 4);
			buf[4] = 0;
			codec = strtoul(buf, NULL, 16);
#ifdef OGM_DEBUG
			tc_log_msg(__FILE__, "(a%d/%d) codec: %d (0x%04x) (%s) bits per "
				   "sample: %d channels: %hd  samples per second: %ld "
				   "avgbytespersec: %hd blockalign: %d",
				   natracks + 1, natracks + nvtracks + 1,
				   codec, codec,
				   codec == 0x1 ? "PCM" : codec == 55 ? "MP3" :
				   codec == 0x55 ? "MP3" :
				   codec == 0x2000 ? "AC3" : "unknown",
				   sth->bits_per_sample, sth->sh.audio.channels,
				   (long)sth->samples_per_unit,
				   sth->sh.audio.avgbytespersec,
				   sth->sh.audio.blockalign);
#endif
			idx = natracks;

			ipipe->probe_info->track[natracks].samplerate = sth->samples_per_unit;
			ipipe->probe_info->track[natracks].chan = sth->sh.audio.channels;
			ipipe->probe_info->track[natracks].bits =
			    (sth->bits_per_sample<4)?sth->bits_per_sample*8:sth->bits_per_sample;
			ipipe->probe_info->track[natracks].format = codec;
			ipipe->probe_info->track[natracks].bitrate = 0;

			ipipe->probe_info->track[natracks].tid=natracks;


			if(ipipe->probe_info->track[natracks].chan>0) ++ipipe->probe_info->num_tracks;

			streams[idx].serial = sno;
			ac_memcpy(&streams[idx].state, &sstate, sizeof(sstate));
			natracks++;
		    } else {
			tc_log_warn(__FILE__, "(%d) found new header of unknown/"
				"unsupported type\n", nvtracks + natracks + 1);
		    }
		    break;
		case none:
		    tc_log_warn(__FILE__, "OGG stream %d is of an unknown type "
			"(bad header?)", nvtracks + natracks + 1);
		    break;
	    } /* switch type */
	    free(inf);
	    free(com);
	    ogg_stream_clear(&sstate);
	} /* beginning of page */
    } /* while (1) */
ogg_out:
    //close(fdin);
    return;
}
Exemplo n.º 30
0
int tc_filter(frame_list_t *ptr_, char *options)
{
  vframe_list_t *ptr = (vframe_list_t *)ptr_;
  static vob_t *vob=NULL;
  /* FIXME: these use the filter ID as an index--the ID can grow
   * arbitrarily large, so this needs to be fixed */
  static int cdiff[100], ldiff[100], range[100];
  static float strength[100];
  int instance = ptr->filter_id;


  //----------------------------------
  //
  // filter print configure
  //
  //----------------------------------

  if(ptr->tag & TC_FILTER_GET_CONFIG) {

      char buf[32];
      optstr_filter_desc (options, MOD_NAME, MOD_CAP, MOD_VERSION, MOD_AUTHOR, "VYEM", "1");

      // buf, name, comment, format, val, from, to
      tc_snprintf (buf, 32, "%.2f", strength[instance]);
      optstr_param (options, "strength", "Blending factor",                 "%f", buf, "0.0", "0.9");

      tc_snprintf (buf, 32, "%d", cdiff[instance]);
      optstr_param (options, "cdiff",    "Max difference in chroma values", "%d", buf, "0", "16");

      tc_snprintf (buf, 32, "%d", ldiff[instance]);
      optstr_param (options, "ldiff",    "Max difference in luma value",    "%d", buf, "0", "16");

      tc_snprintf (buf, 32, "%d", range[instance]);
      optstr_param (options, "range",    "Search Range",                    "%d", buf, "0", "16");

	return 0;
  }

  //----------------------------------
  //
  // filter init
  //
  //----------------------------------

  if(ptr->tag & TC_FILTER_INIT) {

    if((vob = tc_get_vob())==NULL) return(-1);

    // filter init ok.

    // set defaults

    strength[instance] = 0.25;	/* Blending factor.  Do not exceed 2 ever */
    cdiff[instance] = 6;		/* Max difference in UV values */
    ldiff[instance] = 8;		/* Max difference in Y value */
    range[instance] = 4;		/* Search range */

    if (options != NULL) {
    	if(verbose) tc_log_info(MOD_NAME, "options=%s", options);

	optstr_get (options, "strength",  "%f", &strength[instance]);
	optstr_get (options, "cdiff",  "%d", &cdiff[instance]);
	optstr_get (options, "ldiff",  "%d", &ldiff[instance]);
	optstr_get (options, "range",  "%d", &range[instance]);
    }

    tbuf[instance] = tc_malloc(SIZE_RGB_FRAME);
    if (strength[instance]> 0.9) strength[instance] = 0.9;
    memset(tbuf[instance], 0, SIZE_RGB_FRAME);

    if (vob->im_v_codec == TC_CODEC_RGB24) {
	if (verbose) tc_log_error(MOD_NAME, "only capable of YUV mode");
	return -1;
    }

    if(verbose) tc_log_info(MOD_NAME, "%s %s #%d", MOD_VERSION, MOD_CAP, ptr->filter_id);

    return(0);
  }

  //----------------------------------
  //
  // filter close
  //
  //----------------------------------

  if(ptr->tag & TC_FILTER_CLOSE) {
    if (tbuf[instance])
      free(tbuf[instance]);
    tbuf[instance] = NULL;

    return(0);
  }

  //----------------------------------
  //
  // filter frame routine
  //
  //----------------------------------

  // tag variable indicates, if we are called before
  // transcodes internal video/audo frame processing routines
  // or after and determines video/audio context

  if(ptr->tag & TC_PRE_M_PROCESS && ptr->tag & TC_VIDEO && !(ptr->attributes & TC_FRAME_IS_SKIPPED)) {

	if (vob->im_v_codec == TC_CODEC_YUV420P)
		smooth_yuv(ptr->video_buf, ptr->v_width, ptr->v_height, cdiff[instance],
		    ldiff[instance], range[instance], strength[instance], instance);

  }

  return(0);
}