Exemplo n.º 1
0
/**
 * \brief merges an XVC_CapTypeOptions struct into the current preferences
 *
 * @param tmp_capture_options the XVC_CapTypeOptions to assimilate
 * @return a pointer to the XVC_CapTypeOptions within the current preferences,
 *      i.e. the global XVC_AppData struct representing the currently
 *      active capture mode
 */
static XVC_CapTypeOptions *
merge_cli_options (XVC_CapTypeOptions * tmp_capture_options)
{
#define DEBUGFUNCTION "merge_cli_options()"
    int current_mode_by_filename = -1, current_mode_by_target = -1;
    XVC_CapTypeOptions *target;

    // evaluate tmp_capture_options and set real ones accordingly

    // determine capture mode
    // either explicitly set in cli options or default_mode in options
    // (prefs/xdefaults), the latter does not need special action because
    // it will have been set by now or fall back to the
    // default set in init_app_data.

    // app->current_mode is either -1 (not explicitly specified), 0
    // (single_frame), or 1 (multi_frame) ...
    // setting current_mode_by_* accordingly

    // by filename
    if (tmp_capture_options->file == NULL)
        current_mode_by_filename = -1;
    else {
        current_mode_by_filename =
            xvc_codec_get_target_from_filename (tmp_capture_options->file);
#ifdef USE_FFMPEG
        if (current_mode_by_filename >= CAP_MF)
            current_mode_by_filename = 1;
        else
#endif     // USE_FFMPEG
        if (current_mode_by_filename > 0)
            current_mode_by_filename = 0;
        // if we can't determine capture type by filename treat as not
        // set for all practical purposes and leave error handling to
        // error handling
        else
            current_mode_by_filename = -1;
    }

    // by target
    if (tmp_capture_options->target < 0)
        current_mode_by_target = -1;
    else {
#ifdef USE_FFMPEG
        if (tmp_capture_options->target >= CAP_MF)
            current_mode_by_target = 1;
        else
#endif     // USE_FFMPEG
        if (tmp_capture_options->target > 0)
            current_mode_by_target = 0;
        // if we have an invalide target treat as not
        // set for all practical purposes and leave error handling to
        // error handling
        else
            current_mode_by_target = -1;
    }

    if (app->current_mode >= 0) {
        if (app->current_mode == 0)
            target = &(app->single_frame);
        else
            target = &(app->multi_frame);
    } else {
        app->current_mode = app->default_mode;
        // in case default_mode is not set correctly (will trigger error
        // later)
        if (app->current_mode < 0 || app->current_mode > 1)
            app->current_mode = 0;
        // preferences defaults are overridden by filename
        if (current_mode_by_filename >= 0)
            app->current_mode = current_mode_by_filename;
        // filename is overridden by format
        if (current_mode_by_target >= 0)
            app->current_mode = current_mode_by_target;

        if (app->current_mode == 0)
            target = &(app->single_frame);
        else
            target = &(app->multi_frame);
    }

    // merge cli options with app
    xvc_appdata_merge_captypeoptions (tmp_capture_options, app);

    return target;
#undef DEBUGFUNCTION
}
Exemplo n.º 2
0
/**
 * \brief set the Job's contents from the current preferences
 *
 * @param app the preferences struct to set the Job from
 */
void
xvc_job_set_from_app_data (XVC_AppData * app)
{
    XVC_CapTypeOptions *cto;
    char file[PATH_MAX + 1];

    // make sure we do have a job
    if (!job) {
        job_new ();
    }
    // switch sf or mf
    if (app->current_mode != 0)
        cto = &(app->multi_frame);
    else
        cto = &(app->single_frame);

    // various manual settings
    // need to have the flags set to smth. before other functions try to
    // do: flags |= or smth.
    job->flags = app->flags;
    if (app->current_mode == 0 || xvc_is_filename_mutable (cto->file))
        job->flags &= ~(FLG_AUTO_CONTINUE);

    job->time_per_frame = (int) (1000 /
                                 ((float) cto->fps.num / (float) cto->fps.den));

    job->state = VC_STOP;              // FIXME: better move this outta here?
    job->pic_no = cto->start_no;
    job->movie_no = 0;                 // FIXME: make this configurable
    if (cto->audioWanted != 0)
        job->flags |= FLG_REC_SOUND;
    else
        job->flags &= ~FLG_REC_SOUND;
    job_set_sound_dev (app->snddev, cto->sndrate, cto->sndsize,
                       cto->sndchannels);

    job->target = cto->target;
    if (job->target <= 0) {
        if (job->target == 0) {
            // we should be able to safely assume cto->filename is longer
            // smaller than 0 for the next bit because with target == 0
            // it would have been set to a default value otherwise
            job->target = xvc_codec_get_target_from_filename (cto->file);
            // we assume job->target can never be == 0 now, because a
            // sanity checking function should have checked before if
            // we have a valid specification  for a target either
            // through target itself or the filename extension
            if (job->target <= 0) {
                fprintf (stderr, "Unrecoverable error while initializing job from app_data.\n");
                fprintf (stderr, "targetCodec is still 0. This should never happen.\n");
                fprintf (stderr, "Please contact the xvidcap project team.\n");
                exit (1);
            }
        }
    }

    job->targetCodec = cto->targetCodec;
    if (job->targetCodec <= 0) {
        if (job->targetCodec == 0)
            job->targetCodec = xvc_formats[job->target].def_vid_codec;
        if (job->targetCodec < 0) {
            fprintf (stderr, "Unrecoverable error while initializing job from app_data.\n");
            fprintf (stderr, "targetCodec is still < 0. This should never happen.\n");
            fprintf (stderr, "Please contact the xvidcap project team.\n");
            exit (1);
        }
    }
    job->au_targetCodec = cto->au_targetCodec;
    if (job->au_targetCodec <= 0) {
        if (job->au_targetCodec == 0)
            job->au_targetCodec = xvc_formats[job->target].def_au_codec;
        // if 0 the format has no default audio codec. This should only be
        // the case if the format does not support audio or recording
        // without audio is encouraged
        if (job->au_targetCodec < 0) {
            fprintf (stderr, "Unrecoverable error while initializing job from app_data.\n");
            fprintf (stderr, "au_targetCodec is still < 0. This should never happen.\n");
            fprintf (stderr, "Please contact the xvidcap project team.\n");
            exit (1);
        }
    }

    // set temporary filename if set to "ask-user"
    if (strlen (cto->file) < 1) {
        char *home = NULL;
        int pid;

        home = getenv ("HOME");
        pid = (int) getpid ();

        snprintf (file, (PATH_MAX + 1), "%s/.xvidcap-tmp.%i.%s", home, pid,
                  xvc_formats[job->target].extensions[0]);
    } else {
        snprintf (file, (PATH_MAX + 1), "%s", cto->file);
    }

    /** \todo double I need a strdup here? */
    job->file = strdup (file);

    job_set_capture ();

    // the order of the following actions is key!
    // the default is to use the colormap of the root window
    xvc_job_set_save_function (job->target);
    xvc_job_set_colors ();
}