コード例 #1
0
ファイル: VEditProducerScript.cpp プロジェクト: amongll/AVFX
void AsisScript::pre_judge() throw (Exception)
{
    ScriptProps::Property& service_prop = type_spec_props->get_property("service");
    if (!service_prop.Evaluable::finished())
        throw_error_v(ErrorScriptFmtError,"asis producer script service should be determinated");

    ScriptProps::Property& resource_prop = type_spec_props->get_property("resource");
    if (!resource_prop.Evaluable::finished())
        throw_error_v(ErrorScriptFmtError,"asis producer script resource should be determinated");

    json_t* svc_value = service_prop.compile();
    json_t* res_value = resource_prop.compile();
    JsonWrap svc_wrap(svc_value,1);
    JsonWrap res_wrap(res_value,1);

    if ( !svc_value || !json_is_string(svc_value) || !strlen(json_string_value(svc_value)))
        throw_error_v(ErrorScriptFmtError,"asis producer script service should be string value");
    if ( !res_value || !json_is_string(res_value) || !strlen(json_string_value(res_value)))
        throw_error_v(ErrorScriptFmtError,"asis producer script resource should be string value");

    mlt_profile prof = mlt_profile_clone(MltLoader::global_profile);
    mlt_producer tmp_prod = mlt_factory_producer(prof, json_string_value(svc_value), json_string_value(res_value));
    MltSvcWrap prod_wrap(mlt_producer_service(tmp_prod), 1);

    if (tmp_prod == NULL) {
        throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed", json_string_value(svc_value));
    }

    if ( mlt_props ) {
        ScriptProps::PropIter it = mlt_props->begin();
        for ( ; it!=mlt_props->end(); it++) {
            if ( it->second->Evaluable::finished() ) {
                json_t* prop_v = it->second->compile();
                JsonWrap prop_wrap(prop_v, 1);

                switch(prop_v->type) {
                case JSON_INTEGER:
                    mlt_properties_set_int64(mlt_producer_properties(tmp_prod),
                                             it->first.c_str(), json_integer_value(prop_v));
                    break;
                case JSON_REAL:
                    mlt_properties_set_double(mlt_producer_properties(tmp_prod),
                                              it->first.c_str(), json_real_value(prop_v));
                    break;
                case JSON_STRING:
                    mlt_properties_set(mlt_producer_properties(tmp_prod),
                                       it->first.c_str(), json_string_value(prop_v));
                    break;
                case JSON_TRUE:
                    mlt_properties_set_int(mlt_producer_properties(tmp_prod),
                                           it->first.c_str(), 1);
                    break;
                case JSON_FALSE:
                    mlt_properties_set_int(mlt_producer_properties(tmp_prod),
                                           it->first.c_str(), 0);
                    break;
                default:
                    throw_error_v(ErrorRuntimeLoadFailed, "producer %s load failed. %s prop invalid",
                                  json_string_value(svc_value), it->first.c_str());
                }
            }
        }
    }

    int in = mlt_producer_get_in(tmp_prod);
    int out = mlt_producer_get_out(tmp_prod);
    set_frame_range(in, out);

    if ( !mlt_props.get()) {
        mlt_props.reset(new ScriptProps(*this, NULL));
    }
    json_t* jv = json_integer(in);
    mlt_props->add_property("in", jv);
    json_decref(jv);

    jv = json_integer(out);
    mlt_props->add_property("out", jv);
    json_decref(jv);

    string uuid = Vm::uuid();
    type_spec_props->add_property("uuid", JsonWrap(json_string(uuid.c_str()),1).h);
    prod_wrap.obj = NULL;
    MltLoader::push_mlt_registry(mlt_producer_service(tmp_prod), uuid.c_str());
}
コード例 #2
0
ファイル: factory.c プロジェクト: elfring/mlt
static void add_parameters( mlt_properties params, void *object, int req_flags, const char *unit, const char *subclass )
{
	const AVOption *opt = NULL;

	// For each AVOption on the AVClass object
#if LIBAVUTIL_VERSION_INT >= ((51<<16)+(12<<8)+0)
	while ( ( opt = av_opt_next( object, opt ) ) )
#else
	while ( ( opt = av_next_option( object, opt ) ) )
#endif
	{
		// If matches flags and not a binary option (not supported by Mlt)
		if ( !( opt->flags & req_flags ) || ( opt->type == AV_OPT_TYPE_BINARY ) )
            continue;

		// Ignore constants (keyword values)
		if ( !unit && opt->type == AV_OPT_TYPE_CONST )
			continue;
		// When processing a groups of options (unit)...
		// ...ignore non-constants
		else if ( unit && opt->type != AV_OPT_TYPE_CONST )
			continue;
		// ...ignore constants not in this group
		else if ( unit && opt->type == AV_OPT_TYPE_CONST && strcmp( unit, opt->unit ) )
			continue;
		// ..add constants to the 'values' sequence
		else if ( unit && opt->type == AV_OPT_TYPE_CONST )
		{
			char key[20];
			snprintf( key, 20, "%d", mlt_properties_count( params ) );
			mlt_properties_set( params, key, opt->name );
			continue;
		}

		// Create a map for this option.
		mlt_properties p = mlt_properties_new();
		char key[20];
		snprintf( key, 20, "%d", mlt_properties_count( params ) );
		// Add the map to the 'parameters' sequence.
		mlt_properties_set_data( params, key, p, 0, (mlt_destructor) mlt_properties_close, NULL );

		// Add the parameter metadata for this AVOption.
		mlt_properties_set( p, "identifier", opt->name );
		if ( opt->help )
		{
			if ( subclass )
			{
				char *s = malloc( strlen( opt->help ) + strlen( subclass ) + 4 );
				strcpy( s, opt->help );
				strcat( s, " (" );
				strcat( s, subclass );
				strcat( s, ")" );
				mlt_properties_set( p, "description", s );
				free( s );
			}
			else
				mlt_properties_set( p, "description", opt->help );
		}

        switch ( opt->type )
		{
		case AV_OPT_TYPE_FLAGS:
			mlt_properties_set( p, "type", "string" );
			mlt_properties_set( p, "format", "flags" );
			break;
		case AV_OPT_TYPE_INT:
			if ( !opt->unit )
			{
				mlt_properties_set( p, "type", "integer" );
				if ( opt->min != INT_MIN )
					mlt_properties_set_int( p, "minimum", (int) opt->min );
				if ( opt->max != INT_MAX )
					mlt_properties_set_int( p, "maximum", (int) opt->max );
#if LIBAVUTIL_VERSION_MAJOR > 50
				mlt_properties_set_int( p, "default", (int) opt->default_val.dbl );
#endif
			}
			else
			{
				mlt_properties_set( p, "type", "string" );
				mlt_properties_set( p, "format", "integer or keyword" );
			}
			break;
		case AV_OPT_TYPE_INT64:
			mlt_properties_set( p, "type", "integer" );
			mlt_properties_set( p, "format", "64-bit" );
			if ( opt->min != INT64_MIN )
				mlt_properties_set_int64( p, "minimum", (int64_t) opt->min );
			if ( opt->max != INT64_MAX )
			mlt_properties_set_int64( p, "maximum", (int64_t) opt->max );
#if LIBAVUTIL_VERSION_MAJOR > 50
			mlt_properties_set_int64( p, "default", (int64_t) opt->default_val.dbl );
#endif
			break;
		case AV_OPT_TYPE_FLOAT:
			mlt_properties_set( p, "type", "float" );
			if ( opt->min != FLT_MIN && opt->min != -340282346638528859811704183484516925440.0 )
				mlt_properties_set_double( p, "minimum", opt->min );
			if ( opt->max != FLT_MAX )
				mlt_properties_set_double( p, "maximum", opt->max );
#if LIBAVUTIL_VERSION_MAJOR > 50
			mlt_properties_set_double( p, "default", opt->default_val.dbl );
#endif
			break;
		case AV_OPT_TYPE_DOUBLE:
			mlt_properties_set( p, "type", "float" );
			mlt_properties_set( p, "format", "double" );
			if ( opt->min != DBL_MIN )
				mlt_properties_set_double( p, "minimum", opt->min );
			if ( opt->max != DBL_MAX )
				mlt_properties_set_double( p, "maximum", opt->max );
#if LIBAVUTIL_VERSION_MAJOR > 50
			mlt_properties_set_double( p, "default", opt->default_val.dbl );
#endif
			break;
		case AV_OPT_TYPE_STRING:
			mlt_properties_set( p, "type", "string" );
#if LIBAVUTIL_VERSION_MAJOR > 50
			mlt_properties_set( p, "default", opt->default_val.str );
#endif
			break;
		case AV_OPT_TYPE_RATIONAL:
			mlt_properties_set( p, "type", "string" );
			mlt_properties_set( p, "format", "numerator:denominator" );
			break;
		case AV_OPT_TYPE_CONST:
		default:
			mlt_properties_set( p, "type", "integer" );
			mlt_properties_set( p, "format", "constant" );
			break;
        }
		// If the option belongs to a group (unit) and is not a constant (keyword value)
		if ( opt->unit && opt->type != AV_OPT_TYPE_CONST )
		{
			// Create a 'values' sequence.
			mlt_properties values = mlt_properties_new();

			// Recurse to add constants in this group to the 'values' sequence.
			add_parameters( values, object, req_flags, opt->unit, NULL );
			if ( mlt_properties_count( values ) )
				mlt_properties_set_data( p, "values", values, 0, (mlt_destructor) mlt_properties_close, NULL );
			else
				mlt_properties_close( values );
		}
	}
}
コード例 #3
0
ファイル: VEditProducerScript.cpp プロジェクト: amongll/AVFX
mlt_service SingleResourceLoader::get_asis_producer(JsonWrap js)
throw (Exception)
{
    json_t* defines = js.h;

    defines_tmp=js;

    json_t* je = json_object_get(defines, "resource");
    json_t* uuid_je = json_object_get(defines, "uuid");
    json_t* svc_je = json_object_get(defines, "service");

    assert( je && json_is_string(je) && strlen(json_string_value(je)));
    assert( svc_je && json_is_string(svc_je) && strlen(json_string_value(svc_je)));
    assert( uuid_je && json_is_string(uuid_je) && strlen(json_string_value(uuid_je)));

    mlt_producer obj = MLT_PRODUCER(MltLoader::pop_mlt_registry(json_string_value(uuid_je)));
    if (obj == NULL) {
        mlt_profile profile = mlt_profile_clone(global_profile);
        obj = mlt_factory_producer(profile, json_string_value(svc_je), json_string_value(je));
#ifdef DEBUG
        std::cout << mlt_producer_properties(obj);
#endif
    }

    if ( !obj ) {
        throw_error_v(ErrorRuntimeLoadFailed, "video producer load failed:%s", json_string_value(je));
    }

    mlt_properties props = mlt_producer_properties(obj);

    je = json_object_get(defines, "props");
    if (je && json_is_object(je) && json_object_size(je)) {

        json_t* inj = json_object_get(je,"in"), *outj = json_object_get(je,"out");
        assert(inj && outj && json_is_integer(inj) && json_is_integer(outj));

        mlt_producer_set_in_and_out(obj,json_integer_value(inj), json_integer_value(outj));

        void* it = json_object_iter(je);
        while(it) {
            const char* k = json_object_iter_key(it);
            json_t* prop_je = json_object_iter_value(it);
            it = json_object_iter_next(je, it);

            if ( json_is_object(prop_je) || json_is_array(prop_je))
                continue;

            if ( !strcmp(k,"in") || !strcmp(k,"out"))
                continue;

            switch(prop_je->type) {
            case JSON_INTEGER:
                mlt_properties_set_int64(props, k, json_integer_value(prop_je));
                break;
            case JSON_REAL:
                mlt_properties_set_double(props, k, json_real_value(prop_je));
                break;
            case JSON_STRING:
                mlt_properties_set(props, k, json_string_value(prop_je));
                break;
            case JSON_TRUE:
                mlt_properties_set_int(props,k, 1);
                break;
            case JSON_FALSE:
                mlt_properties_set_int(props,k, 0);
                break;
            default:
                break;
            }
        }
    }

    MltSvcWrap wrap(mlt_producer_service(obj), 1);
    producer_tmp  = obj;

    parse_filters();


    wrap.obj = NULL;
    return mlt_producer_service(obj);
}