Exemplo n.º 1
0
static int test_autoloop_from_ratio(int dom, TCPair pair)
{
    int ret = 0, code;
    TCPair mypair;

    ret = tc_code_from_ratio(dom, &code, pair.a, pair.b);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "from_ratio: failed conversion_from for "
                             "ratio=%i/%i (dom=%i)", pair.a, pair.b, dom);
        return 2;
    }

    ret = tc_code_to_ratio(dom, code, &mypair.a, &mypair.b);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "from_ratio: failed conversion_to for "
                             "ratio=%i/%i (dom=%i)", pair.a, pair.b, dom);
        return 1;
    }

    if (pair.a == mypair.a && pair.b == mypair.b) {
        tc_log_msg(PACKAGE, "from_ratio: test for ratio=%i/%i (dom=%i)"
                             " -> OK", pair.a, pair.b, dom);
    } else {
        tc_log_warn(PACKAGE, "from_ratio: test for ratio=%i/%i (dom=%i)"
                             " -> FAILED (%i/%i)", pair.a, pair.b, dom,
                             mypair.a, mypair.b);
        ret = -1;
    }
    return ret;
}
Exemplo n.º 2
0
static int test_autoloop_to_ratio(int dom, int code)
{
    int ret = 0, mycode;
    TCPair pair;

    ret = tc_code_to_ratio(dom, code, &pair.a, &pair.b);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "to_ratio: failed conversion_to for "
                             "code=%i (dom=%i)", code, dom);
        return 1;
    }

    ret = tc_code_from_ratio(dom, &mycode, pair.a, pair.b);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "to_ratio: failed conversion_from for "
                             "code=%i (dom=%i)", code, dom);
        return 2;
    }

    if (code == mycode) {
        tc_log_msg(PACKAGE, "to_ratio: test for code=%i (dom=%i) -> OK",
                             code, dom);
    } else {
        tc_log_warn(PACKAGE, "to_ratio: test for code=%i (dom=%i) -> FAILED"
                             " (%i)", code, dom, mycode);
        ret = -1;
    }
    return ret;
}
Exemplo n.º 3
0
static int modrequest_load(TCFactory factory,
                           ModRequest *modr, const char *str)
{
    size_t pieces = 0;

    if (factory == NULL || modr == NULL || str == NULL) {
        tc_log_warn(EXE, "wrong parameters for modrequest_load");
        return TC_ERROR;
    }

    modr->rawdata = tc_strsplit(str, ':', &pieces);
    if (modr->rawdata == NULL || pieces != 2) {
        tc_log_warn(EXE, "malformed module string: %s", str);
        return TC_ERROR;
    }
    modr->type = modr->rawdata[0];
    modr->name = modr->rawdata[1];

    modr->module = tc_new_module(factory, modr->type, modr->name, TC_NONE);
    if (modr->module == NULL) {
        tc_log_warn(EXE, "failed creation of module: %s", str);
        return TC_ERROR;
    }
    return TC_OK;
}
Exemplo n.º 4
0
static int test_autoloop_to_fps(int frc)
{
    int ret = 0, myfrc;
    double fps;

    ret = tc_frc_code_to_value(frc, &fps);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "to_fps: failed conversion_to for frc=%i",
                             frc);
        return 1;
    }

    ret = tc_frc_code_from_value(&myfrc, fps);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "to_fps: failed conversion_from for frc=%i",
                             frc);
        return 2;
    }

    if (frc == myfrc) {
        tc_log_msg(PACKAGE, "to_fps: test for frc=%i -> OK", frc);
    } else {
        tc_log_warn(PACKAGE, "to_fps: test for frc=%i -> FAILED (%i)",
                             frc, myfrc);
        ret = -1;
    }
    return ret;
}
Exemplo n.º 5
0
static int test_autoloop_from_fps(double fps)
{
    int ret = 0, frc;
    double myfps;

    ret = tc_frc_code_from_value(&frc, fps);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "from_fps: failed conversion_from for fps=%f",
                             fps);
        return 1;
    }

    ret = tc_frc_code_to_value(frc, &myfps);
    if (ret == TC_NULL_MATCH) {
        tc_log_warn(PACKAGE, "from_fps: failed conversion_to for fps=%f",
                             fps);
        return 2;
    }

    if (myfps - DELTA < fps && fps < myfps + DELTA) {
        tc_log_msg(PACKAGE, "from_fps: test for fps=%f -> OK",
                             fps);
    } else {
        tc_log_warn(PACKAGE, "from_fps: test for fps=%f -> FAILED (%f)",
                             fps, myfps);
        ret = -1;
    }
    return ret;
}
Exemplo n.º 6
0
int probe_source(const char *vid_file, const char *aud_file, int range,
                 int flags, vob_t *vob)
{
    ProbeInfo vinfo, ainfo;  // video and audio info structures

    /* Probe the video file, if present */
    if (vid_file) {
        if (!do_probe(vid_file, vob->nav_seek_file, vob->dvd_title, range,
                      (flags & TC_PROBE_NO_BUILTIN),
                      (verbose >= TC_DEBUG) ? verbose : 0, &vinfo)
        ) {
            if (verbose & TC_DEBUG) {
                tc_log_warn(PACKAGE, "(%s) failed to probe video source",
                            __FILE__);
            }
            return 0;
        }
    } else {
        vob->has_video = 0;
    }

    /* Probe the audio file, if present */
    if (aud_file) {
        if (!do_probe(aud_file, vob->nav_seek_file, vob->dvd_title, range,
                      (flags & TC_PROBE_NO_BUILTIN),
                      (verbose >= TC_DEBUG) ? verbose : 0, &ainfo)
        ) {
            if (verbose & TC_DEBUG) {
                tc_log_warn(PACKAGE, "(%s) failed to probe audio source",
                            __FILE__);
            }
            return 0;
        }
    }  /* else it might be contained in the video file */

    /* Set global parameters based on probed data */
    probe_to_vob(vid_file ? &vinfo : NULL, aud_file ? &ainfo : NULL,
                 flags, vob);
    if (verbose & TC_DEBUG) {
        tc_log_info(PACKAGE, "(%s) V format=0x%lx, A format=0x%lx,"
                    " V codec=0x%lx, A codec=0x%lx", __FILE__,
                    vob->v_format_flag, vob->a_format_flag,
                    vob->v_codec_flag, vob->a_codec_flag);
        tc_log_info(PACKAGE, "(%s) V format=%s, A format=%s, V codec=%s,"
                    " A codec=%s", __FILE__,
                    tc_format_to_comment(vob->v_format_flag),
                    tc_format_to_comment(vob->a_format_flag),
                    tc_codec_to_comment(vob->v_codec_flag),
                    tc_codec_to_comment(vob->a_codec_flag));
    }

    /* All done, return success */
    return 1;
}
Exemplo n.º 7
0
static int divx5_init(const char *path) {
  const char *error;
  int *quiet_encore;

  tc_snprintf(module, sizeof(module), "%s/%s", path, MODULE);


  // try transcode's module directory

  handle = dlopen(module, RTLD_NOW);

  if (!handle) {

    //try the default:

    handle = dlopen(MODULE, RTLD_GLOBAL| RTLD_LAZY);

    if (!handle) {
      tc_log_warn(MOD_NAME, "%s", dlerror());
      return(-1);
    } else {
      if(verbose_flag & TC_DEBUG)
        tc_log_info(MOD_NAME, "Loading external codec module %s", MODULE);
    }

  } else {
    if(verbose_flag & TC_DEBUG)
      tc_log_info(MOD_NAME, "Loading external codec module %s", module);
  }

  divx5_encore = dlsym(handle, "encore");

  if ((error = dlerror()) != NULL)  {
    tc_log_warn(MOD_NAME, "%s", error);
    return(-1);
  }

  quiet_encore=dlsym(handle, "quiet_encore");

  if ((error = dlerror()) != NULL)  {
    tc_log_warn(MOD_NAME, "%s", error);
    return(-1);
  }

  *quiet_encore=1;

  // debug
  if(verbose_flag & TC_STATS) *quiet_encore=0;

  return(0);
}
Exemplo n.º 8
0
static int parse_stream_header(FILE* stream, int width){
	char	cursor = 0;
	int		aart_width = 0;

	/* Purge the first line of the header */
	while (cursor!='\n')
		cursor = fgetc(stream);

	/* Purge additionnal commentary lines */
	while (cursor == '#')
		while ((cursor = fgetc(stream)) != '\n');
	cursor = fgetc(stream);

	/* Purge dimensions line */
	while (cursor!=' '){
		/* We have to check the width in case of re-size */
		aart_width = 10*aart_width + ((int) cursor - 48);
		cursor = fgetc(stream);
	}
	if ((aart_width != width) && (verbose & TC_DEBUG))
		tc_log_warn(MOD_NAME, "Picture has been re-sized by `aart`.");

	/* Purge the rest of the line */
	while (cursor!='\n')
		cursor = fgetc(stream);

	cursor = fgetc(stream);

	/* Purge dynamic line */
	while (cursor!='\n')
		cursor = fgetc(stream);

	return aart_width;
}
Exemplo n.º 9
0
static int tc_y4m_multiplex(TCModuleInstance *self,
                            vframe_list_t *vframe, aframe_list_t *aframe)
{
    ssize_t w_vid = 0;

    Y4MPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "multiplex");

    pd = self->userdata;
    if (vframe != NULL && vframe->video_len > 0) {
        uint8_t *planes[3] = { NULL, NULL, NULL };
        int ret = 0;

        y4m_init_frame_info(&pd->frameinfo);
        YUV_INIT_PLANES(planes, vframe->video_buf, IMG_YUV420P,
                        pd->width, pd->height);
        
        ret = y4m_write_frame(pd->fd_vid, &(pd->streaminfo),
                                 &pd->frameinfo, planes);
        if (ret != Y4M_OK) {
            tc_log_warn(MOD_NAME, "error while writing video frame: %s",
                                  y4m_strerr(ret));
            return TC_ERROR;
        }
        w_vid = vframe->video_len;
    }

    if (aframe != NULL && aframe->audio_len > 0) {
        return TC_OK;
    }

    return (int)w_vid;
}
Exemplo n.º 10
0
static int tc_v4l2_video_get_frame(V4L2Source *vs, uint8_t *data, size_t size)
{
    int ret;
    int buffers_filled = tc_v4l2_video_count_buffers(vs);

    if (buffers_filled == -1) {
        tc_log_warn(MOD_NAME, "unable to get the capture buffers count," 
                              " assuming OK");
        buffers_filled = 0;
    }

    if (buffers_filled > (vs->buffers_count * 3 / 4)) {
        tc_log_error(MOD_NAME, "running out of capture buffers (%d left from %d total), "
                               "stopping capture",
                               vs->buffers_count - buffers_filled,
                               vs->buffers_count);

        ret = tc_v4l2_capture_stop(vs);
    } else {
        ret = tc_v4l2_video_grab_frame(vs, data, size);
        vs->video_sequence++;
    }

    return ret;
}
Exemplo n.º 11
0
static int tc_x11_configure(TCModuleInstance *self,
                            const char *options, vob_t *vob)
{
    TCX11PrivateData *priv = NULL;
    int ret = 0, skew_lim = SKEW_LIM_DEFAULT;

    TC_MODULE_SELF_CHECK(self, "configure");

    priv = self->userdata;

    if (options != NULL) {
        optstr_get(options, "skew_limit", "%i", &skew_lim);
        if (skew_lim < SKEW_LIM_MIN || skew_lim > SKEW_LIM_MAX) {
            tc_log_warn(MOD_NAME, "skew limit value out of range,"
                                  " reset to defaults [%i]",
                        SKEW_LIM_DEFAULT);
        }
    }

    priv->skew = 0;
    priv->reftime = 0;
    priv->expired = 0;
    priv->frame_delay = (uint64_t)(1000000.0 / vob->fps); /* microseconds */
    priv->skew_limit = priv->frame_delay / frame_delay_divs[skew_lim];

    if (verbose >= TC_DEBUG) {
        tc_log_info(MOD_NAME, "frame delay: %lu ms",
                              (unsigned long)priv->frame_delay);
        tc_log_info(MOD_NAME, "skew limit:  %li ms",
                              (long)priv->skew_limit);
    }


    ret = tc_timer_init_soft(&priv->timer, 0);
    if (ret != 0) {
        tc_log_error(MOD_NAME, "configure: can't initialize timer");
        return TC_ERROR;
    }

    /* nothing to do here, yet */
    ret = tc_x11source_is_display_name(vob->video_in_file);
    if (ret == TC_FALSE) {
        tc_log_error(MOD_NAME, "configure: given source doesn't look like"
                               " a DISPLAY specifier");
        return TC_ERROR;
    }

    ret = tc_x11source_open(&priv->src, vob->video_in_file,
                            TC_X11_MODE_BEST, vob->im_v_codec);
    if (ret != 0) {
        tc_log_error(MOD_NAME, "configure: failed to open X11 connection"
                               " to '%s'", vob->video_in_file);
        return TC_ERROR;
    }

    return TC_OK;
}
Exemplo n.º 12
0
/* FIXME: explain why don't use funcpointers in here */
static void tc_x11source_acquire_cursor_plain(TCX11Source *handle,
                                              uint8_t *data, int maxdata)
{
    static int warn = 0;

    if (!warn) {
        tc_log_warn(__FILE__, "cursor grabbing not supported!");
        warn = 1;
    }
}
Exemplo n.º 13
0
int bktr_grab(size_t size, char *dest)
{
    /* wait for a "buffer full" signal, but longer than 1 second */

    alarm(1);
    sigsuspend(&sa_mask);
    alarm(0);

    if (bktr_frame_waiting) {
        bktr_frame_waiting = 0;
        if (dest) {
            if (verbose_flag & TC_DEBUG) {
                tc_log_info(MOD_NAME, "copying %lu bytes, buffer size is %lu",
                            (unsigned long)size,
                            (unsigned long)bktr_buffer_size);
            }
            switch (bktr_convert) {
            case BKTR2RGB:
                copy_buf_rgb(dest, size);
                break;
            case BKTR2YUV422:
                copy_buf_yuv422(dest, size);
                break;
            case BKTR2YUV:
                copy_buf_yuv(dest, size);
                break;
            default:
                tc_log_warn(MOD_NAME,
                            "unrecognized video conversion request");
                return(1);
                break;
            }
        } else {
            tc_log_warn(MOD_NAME,
                        "no destination buffer to copy frames to");
            return(1);
        }
    } else {  /* bktr_frame_waiting */
        tc_log_warn(MOD_NAME, "sigalrm");
    }

    return(0);
}
Exemplo n.º 14
0
static int fields_configure(TCModuleInstance *self,
            			    const char *options,
                            TCJob *vob,
                            TCModuleExtraData *xdata[])
{
    FieldsPrivateData *pd = NULL;

    TC_MODULE_SELF_CHECK(self, "configure");

    pd = self->userdata;

    // Some of the data in buffer may get used for half of the first frame (when
    // shifting) so make sure it's blank to start with.
    pd->buffer = tc_zalloc(SIZE_RGB_FRAME);
    if (!pd->buffer) {
        tc_log_error(MOD_NAME, "Unable to allocate memory.  Aborting.");
        return TC_ERROR;
    }

    if (options != NULL) {
        if (optstr_lookup(options, "flip"))
            pd->field_ops |= FIELD_OP_FLIP;
        if (optstr_lookup(options, "shift"))
            pd->field_ops |= FIELD_OP_SHIFT;
        if (optstr_lookup(options, "flip_first"))
            pd->field_ops |= FIELD_OP_REVERSE;
    }

    // FIELD_OP_REVERSE (aka flip_first) only makes sense if we're doing
    // both operations.  If we're not, unset it.
    if (pd->field_ops != FIELD_OP_FLIPSHIFT)
        pd->field_ops &= ~FIELD_OP_REVERSE;

    if (verbose) {
        if (pd->field_ops & FIELD_OP_SHIFT)
            tc_log_info(MOD_NAME, "Adjusting frame positions (shift)");
        if (pd->field_ops & FIELD_OP_FLIP)
            tc_log_info(MOD_NAME, "Transposing input fields  (flip)");
        if (pd->field_ops & FIELD_OP_REVERSE)
            tc_log_info(MOD_NAME, "Flipping will occur before shifting (flip_first)");
    }

    if (!pd->field_ops) {
        tc_log_warn(MOD_NAME, "No operations specified to perform.");
        return TC_ERROR;
    }

    if (vob->im_v_codec == TC_CODEC_RGB24);
        pd->rgb_mode = TC_TRUE;

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

    return TC_OK;
}
Exemplo n.º 15
0
static int doublefps_configure(TCModuleInstance *self,
                               const char *options, vob_t *vob)
{
    DfpsPrivateData *pd;
    int new_topfirst = -1;

    TC_MODULE_SELF_CHECK(self, "configure");

    pd = self->userdata;

    if (options) {
        if (optstr_get(options, "shiftEven", "%d", &pd->topfirst) == 1) {
            tc_log_warn(MOD_NAME, "The \"shiftEven\" option name is obsolete;"
                        " please use \"topfirst\" instead.");
        }
        optstr_get(options, "topfirst", "%d", &new_topfirst);
        optstr_get(options, "fullheight", "%d", &pd->fullheight);
    }
    if (new_topfirst == -1) {
        if (pd->topfirst == -1)
            pd->topfirst = (vob->im_v_height == 480 ? 0 : 1);
    } else {
        pd->topfirst = new_topfirst;
    }

    if (!pd->fullheight) {
        if (vob->encode_fields == TC_ENCODE_FIELDS_TOP_FIRST
         || vob->encode_fields == TC_ENCODE_FIELDS_BOTTOM_FIRST
        ) {
            pd->topfirst = (vob->encode_fields == TC_ENCODE_FIELDS_TOP_FIRST);
            if (vob->export_attributes & TC_EXPORT_ATTRIBUTE_FIELDS) {
                tc_log_warn(MOD_NAME, "Use \"-J doublefps=topfirst=%d\","
                            " not \"--encode_fields %c\"", pd->topfirst,
                            pd->topfirst ? 't' : 'b');
            }
        }
        vob->encode_fields = TC_ENCODE_FIELDS_PROGRESSIVE;
        vob->export_attributes |= TC_EXPORT_ATTRIBUTE_FIELDS;
    }

    return TC_OK;
}
Exemplo n.º 16
0
static void enable_levels_filter(void)
{
    int handle = 0, id = tc_filter_find("levels");
    if (id == 0) {
        tc_log_info(MOD_NAME, "input is mjpeg, reducing range from YUVJ420P to YUV420P");
        handle = tc_filter_add("levels", "output=16-240:pre=1");
        if (!handle) {
            tc_log_warn(MOD_NAME, "cannot load levels filter");
        }
    }
}
Exemplo n.º 17
0
static void copy_buf_yuv422(char *dest, size_t size)
{
    uint8_t *planes;

    if (bktr_buffer_size != size) {
        tc_log_warn(MOD_NAME,
                    "buffer sizes do not match (input %lu != output %lu)",
                    (unsigned long)bktr_buffer_size, (unsigned long)size);
    }
    tcv_convert(bktr_tcvhandle, bktr_buffer, dest, size/2, 1,
                IMG_UYVY, IMG_YUV422P);
}
Exemplo n.º 18
0
static int yw_decode_audio(YWPrivateData *pd, transfer_t *param)
{
    ssize_t r = wav_read_data(pd->wav, param->buffer, param->size);

    if (r <= 0 || (int)r < param->size) {
        if (verbose & TC_DEBUG) {
            tc_log_warn(MOD_NAME, "WAV audio read failed");
        }
        return(TC_IMPORT_ERROR);
    }
    return(TC_IMPORT_OK);
}
Exemplo n.º 19
0
static int modrequest_fill(TCFactory factory, ModRequest *mods,
                           size_t maxmods, size_t *modnum, glob_t *globbuf)
{
    char modstr[TC_BUF_MIN];
    int i = 0, count = 0, lim = 0;

    if (!factory || !mods || !globbuf) {
        return TC_ERROR;
    }
    if (maxmods < globbuf->gl_pathc) {
        tc_log_warn(EXE, "found %u candidate modules, but "
                              "only %u allowed (dropping remaining)",
                    (unsigned)globbuf->gl_pathc, (unsigned)maxmods);
    }
    lim = TC_MIN(maxmods, globbuf->gl_pathc);

    for (i = 0; i < lim; i++) {
        int ret;

        ret = parse_path(globbuf->gl_pathv[i], modstr, TC_BUF_MIN);
        if (ret != 0) {
            tc_log_warn(EXE, "error while parsing '%s', skipping",
                                  globbuf->gl_pathv[i]);
            continue;
        }
        ret = modrequest_load(factory, &mods[i], modstr);
        if (ret != 0) {
            tc_log_warn(EXE, "error while loading '%s', skipping",
                                  modstr);
            continue;
        }
        count++;
    }

    if (modnum != NULL) {
        *modnum += count;
    }

    return TC_OK;
}
Exemplo n.º 20
0
static void tc_x11source_acquire_cursor_fixes(TCX11Source *handle,
                                              uint8_t *data, int maxdata)
{
    XFixesCursorImage *cursor = XFixesGetCursorImage(handle->dpy);

    if (cursor == NULL) {
        /* this MUST be noisy! */
        tc_log_warn(__FILE__, "failed to get cursor image");
    } else {
        /* FIXME: this has to be rewritten and need significant
         * internal refactoring :( */
    }
}
Exemplo n.º 21
0
/**
 * probe_stream_data:  Probe a single source file and store the stream
 * informations in data structure.
 *
 * Parameters:
 *       file: File name to probe.
 *      range: Amount of input file to probe, in MB.
 *       info: Structure to be filled in with probed data.
 * Return value:
 *     Nonzero on success, zero on error.
 * Preconditions:
 *     info != NULL, range > 0
 */
int probe_stream_data(const char *file, int range, ProbeInfo *info)
{
    if (!info || range <= 0) {
        tc_log_error(PACKAGE, "wrong probing parameters");
        return 0;
    }

    if (!file) {
        tc_log_warn(PACKAGE, "missing source to probe");
        memset(info, 0, sizeof(ProbeInfo));
    } else {
        if (!do_probe(file, NULL, 0, range, 0,
                      (verbose >= TC_DEBUG) ? verbose : 0, info)
        ) {
            if (verbose & TC_DEBUG) {
                tc_log_warn(PACKAGE, "(%s) failed to probe stream '%s'",
                            __FILE__, file);
            }
            return 0;
        }
    }
    return 1;
}
Exemplo n.º 22
0
static int modrequest_unload(TCFactory factory, ModRequest *modr)
{
    if (factory == NULL || modr == NULL) {
        tc_log_warn(EXE, "wrong parameters for modrequest_load");
        return TC_ERROR;
    }

    tc_del_module(factory, modr->module);
    tc_strfreev(modr->rawdata);

    /* re-blank fields */
    modrequest_init(modr);

    return TC_OK;
}
Exemplo n.º 23
0
static int sendall(int sock, const void *buf, size_t count)
{
    int total_sent = 0;

    if (sock < 0 || !buf || count < 0) {
        tc_log_warn(__FILE__, "sendall(): invalid parameters!");
        errno = EINVAL;
        return -1;
    }
    while (count > 0) {
        int retval = send(sock, buf, count, 0);
        if (retval <= 0) {
            tc_log_warn(__FILE__, "sendall(): socket write failed (%s)",
                        retval<0 ? strerror(errno) : "Connection closed");
            if (total_sent == 0)
                return -1;  /* Nothing sent yet, abort with error return */
            break;
        }
        total_sent += retval;
        buf = (int8_t *)buf + retval;
        count -= retval;
    }
    return total_sent;
}
Exemplo n.º 24
0
static void copy_buf_rgb(char *dest, size_t size)
{
    int i;

    /* 24 bit RGB packed into 32 bits (NULL, R, G, B) */

    if ((bktr_buffer_size * 3 / 4) != size)
        tc_log_warn(MOD_NAME,
                    "buffer sizes do not match (input %lu != output %lu)",
                    (unsigned long)bktr_buffer_size * 3 / 4, (unsigned long)size);

    /* bktr_buffer_size was set to width * height * 4 (32 bits) */
    /* so width * height = bktr_buffer_size / 4                 */
    tcv_convert(bktr_buffer, dest, bktr_buffer_size/4, 1,
                IMG_ARGB32, IMG_RGB24);
}
Exemplo n.º 25
0
static int yw_decode_video(YWPrivateData *pd, transfer_t *param)
{
    int errnum = 0;
    YUV_INIT_PLANES(pd->planes, param->buffer, pd->dstfmt,
                    pd->width, pd->height);

    errnum = y4m_read_frame(pd->fd_vid, &pd->streaminfo,
                            &pd->frameinfo, pd->planes);
    if (errnum != Y4M_OK) {
        if (verbose & TC_DEBUG) {
            tc_log_warn(MOD_NAME, "YUV4MPEG2 video read failed: %s",
                        y4m_strerr(errnum));
        }
        return(TC_IMPORT_ERROR);
    }
    return(TC_IMPORT_OK);
}
Exemplo n.º 26
0
static void copy_buf_yuv(char *dest, size_t size)
{
    int y_size = bktr_buffer_size * 4 / 6;
    int u_size = bktr_buffer_size * 1 / 6;
    int y_offset = 0;
    int u1_offset = y_size + 0;
    int u2_offset = y_size + u_size;

    if (bktr_buffer_size != size)
        tc_log_warn(MOD_NAME,
                    "buffer sizes do not match (input %lu != output %lu)",
                    (unsigned long)bktr_buffer_size, (unsigned long)size);

    ac_memcpy(dest + y_offset,  bktr_buffer + y_offset,  y_size);
    ac_memcpy(dest + u1_offset, bktr_buffer + u1_offset, u_size);
    ac_memcpy(dest + u2_offset, bktr_buffer + u2_offset, u_size);
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
0
static int tc_v4l2_video_setup_stream_parameters(V4L2Source *vs, int fps)
{
    struct v4l2_streamparm streamparm;
    int err = 0;

    memset(&streamparm, 0, sizeof(streamparm));
    streamparm.type                                  = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    streamparm.parm.capture.capturemode              = 0;
    streamparm.parm.capture.timeperframe.numerator   = 1e7;
    streamparm.parm.capture.timeperframe.denominator = fps;

    err = v4l2_ioctl(vs->video_fd, VIDIOC_S_PARM, &streamparm);
    if (err < 0) {
        tc_log_warn(MOD_NAME, "driver does not support setting parameters"
                              " (ioctl(VIDIOC_S_PARM) returns \"%s\")",
                    errno <= sys_nerr ? sys_errlist[errno] : "unknown");
    }
    return TC_OK;
}
Exemplo n.º 29
0
static int tc_import_video_close(TCImportData *imdata)
{
    int ret;
    transfer_t import_para;

    memset(&import_para, 0, sizeof(transfer_t));

    import_para.flag = TC_VIDEO;
    import_para.fd   = imdata->fd;

    ret = tcv_import(TC_IMPORT_CLOSE, &import_para, NULL);
    if (ret == TC_IMPORT_ERROR) {
        tc_log_warn(PACKAGE, "video import module error: CLOSE failed");
        return TC_ERROR;
    }
    imdata->fd = NULL;

    return TC_OK;
}
Exemplo n.º 30
0
int tc_mangle_cmdline(int *argc, char ***argv,
                      const char *opt, const char **optval)
{
    int i = 0, skew = (optval == NULL) ?1 :2, err = -1;

    if (argc == NULL || argv == NULL || opt == NULL) {
        return err;
    }

    err = 1;
    /* first we looking for our option (and it's value) */
    for (i = 1; i < *argc; i++) {
        if ((*argv)[i] && strcmp((*argv)[i], opt) == 0) {
            if (optval == NULL) {
                err = 0; /* we're set */
            } else {
                /* don't peek after the end... */
                if (i + 1 >= *argc || (*argv)[i + 1][0] == '-') {
                    tc_log_warn(__FILE__, "wrong usage for option '%s'", opt);
                    err = 1; /* no option and/or value found */
                } else {
                    *optval = (*argv)[i + 1];
                    err = 0;
                }
            }
            break;
        }
    }

    /*
     * if we've found our option, now we must shift back all
     * the other options after the ours and we must also update argc.
     */
    if (!err) {
        for (; i < (*argc - skew); i++) {
            (*argv)[i] = (*argv)[i + skew];
        }
        (*argc) -= skew;
    }

    return err;
}