Example #1
0
static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char *prop_name,
                                  AVDictionary **dictionary)
{
	IDProperty *prop;
	void *iter;
	IDProperty *curr;

	if (!rd->ffcodecdata.properties) {
		return;
	}
	
	prop = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, prop_name);
	if (!prop) {
		return;
	}

	iter = IDP_GetGroupIterator(prop);

	while ((curr = IDP_GroupIterNext(iter)) != NULL) {
		if (ffmpeg_proprty_valid(c, prop_name, curr))
			set_ffmpeg_property_option(c, curr, dictionary);
	}
}
Example #2
0
/**
 * \note group can be a pointer array or a group.
 * assume we already checked key is a string.
 *
 * \return success.
 */
bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group, PyObject *ob)
{
	IDProperty *prop = idp_from_PyObject(name_obj, ob);
	if (prop == NULL) {
		return false;
	}

	if (group->type == IDP_IDPARRAY) {
		IDP_AppendArray(group, prop);
		/* IDP_AppendArray does a shallow copy (memcpy), only free memory */
		MEM_freeN(prop);
	}
	else {
		IDProperty *prop_exist;

		/* avoid freeing when types match in case they are referenced by the UI, see: T37073
		 * obviously this isn't a complete solution, but helps for common cases. */
		prop_exist = IDP_GetPropertyFromGroup(group, prop->name);
		if ((prop_exist != NULL) &&
		    (prop_exist->type == prop->type) &&
		    (prop_exist->subtype == prop->subtype))
		{
			/* Preserve prev/next links!!! See T42593. */
			prop->prev = prop_exist->prev;
			prop->next = prop_exist->next;

			IDP_FreeProperty(prop_exist);
			*prop_exist = *prop;
			MEM_freeN(prop);
		}
		else {
			IDP_ReplaceInGroup_ex(group, prop, prop_exist);
		}
	}

	return true;
}
Example #3
0
int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
{
    if (prop->type  != IDP_GROUP) {
        PyErr_SetString(PyExc_TypeError, "unsubscriptable object");
        return -1;
    }

    if (val == NULL) { /* del idprop[key] */
        IDProperty *pkey = IDP_GetPropertyFromGroup(prop, _PyUnicode_AsString(key));
        if (pkey) {
            IDP_RemFromGroup(prop, pkey);
            IDP_FreeProperty(pkey);
            MEM_freeN(pkey);
            return 0;
        } else {
            PyErr_SetString(PyExc_KeyError, "property not found in group");
            return -1;
        }
    }
    else {
        const char *err;

        if (!PyUnicode_Check(key)) {
            PyErr_SetString(PyExc_TypeError, "only strings are allowed as subgroup keys");
            return -1;
        }

        err = BPy_IDProperty_Map_ValidateAndCreate(_PyUnicode_AsString(key), prop, val);
        if (err) {
            PyErr_SetString(PyExc_KeyError, err );
            return -1;
        }

        return 0;
    }
}
Example #4
0
static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char *prop_name,
                                  AVDictionary **dictionary)
{
	IDProperty *prop;
	void *iter;
	IDProperty *curr;

	/* TODO(sergey): This is actually rather stupid, because changing
	 * codec settings in render panel would also set expert options.
	 *
	 * But we need ti here in order to get rid of deprecated settings
	 * when opening old files in new blender.
	 *
	 * For as long we don't allow editing properties in the interface
	 * it's all good. bug if we allow editing them, we'll need to
	 * repace it with some smarter code which would port settings
	 * from deprecated to new one.
	 */
	ffmpeg_set_expert_options(rd);

	if (!rd->ffcodecdata.properties) {
		return;
	}
	
	prop = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, prop_name);
	if (!prop) {
		return;
	}

	iter = IDP_GetGroupIterator(prop);

	while ((curr = IDP_GroupIterNext(iter)) != NULL) {
		if (ffmpeg_proprty_valid(c, prop_name, curr))
			set_ffmpeg_property_option(c, curr, dictionary);
	}
}
Example #5
0
static IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, const AVOption *o, const AVOption *parent)
{
	AVCodecContext c;
	IDProperty *group;
	IDProperty *prop;
	IDPropertyTemplate val;
	int idp_type;
	char name[256];
	
	val.i = 0;

	avcodec_get_context_defaults3(&c, NULL);

	if (!rd->ffcodecdata.properties) {
		rd->ffcodecdata.properties = IDP_New(IDP_GROUP, &val, "ffmpeg"); 
	}

	group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type);
	
	if (!group) {
		group = IDP_New(IDP_GROUP, &val, type);
		IDP_AddToGroup(rd->ffcodecdata.properties, group);
	}

	if (parent) {
		BLI_snprintf(name, sizeof(name), "%s:%s", parent->name, o->name);
	}
	else {
		BLI_strncpy(name, o->name, sizeof(name));
	}

	PRINT("ffmpeg_property_add: %s %s\n", type, name);

	prop = IDP_GetPropertyFromGroup(group, name);
	if (prop) {
		return prop;
	}

	switch (o->type) {
		case AV_OPT_TYPE_INT:
		case AV_OPT_TYPE_INT64:
			val.i = FFMPEG_DEF_OPT_VAL_INT(o);
			idp_type = IDP_INT;
			break;
		case AV_OPT_TYPE_DOUBLE:
		case AV_OPT_TYPE_FLOAT:
			val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o);
			idp_type = IDP_FLOAT;
			break;
		case AV_OPT_TYPE_STRING:
			val.string.str = (char *)"                                                                               ";
			val.string.len = 80;
/*		val.str = (char *)"                                                                               ";*/
			idp_type = IDP_STRING;
			break;
		case AV_OPT_TYPE_CONST:
			val.i = 1;
			idp_type = IDP_INT;
			break;
		default:
			return NULL;
	}
	prop = IDP_New(idp_type, &val, name);
	IDP_AddToGroup(group, prop);
	return prop;
}
Example #6
0
IDProperty *ffmpeg_property_add(RenderData *rd, char * type, int opt_index, int parent_index)
{
	AVCodecContext c;
	const AVOption * o;
	const AVOption * parent;
	IDProperty * group;
	IDProperty * prop;
	IDPropertyTemplate val;
	int idp_type;
	char name[256];
	
	val.i = 0;

	avcodec_get_context_defaults(&c);

	o = c.av_class->option + opt_index;
	parent = c.av_class->option + parent_index;

	if (!rd->ffcodecdata.properties) {
		rd->ffcodecdata.properties 
			= IDP_New(IDP_GROUP, val, "ffmpeg"); 
	}

	group = IDP_GetPropertyFromGroup(
		rd->ffcodecdata.properties, (char*) type);
	
	if (!group) {
		group = IDP_New(IDP_GROUP, val, (char*) type); 
		IDP_AddToGroup(rd->ffcodecdata.properties, group);
	}

	if (parent_index) {
		sprintf(name, "%s:%s", parent->name, o->name);
	} else {
		strcpy(name, o->name);
	}

	fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
		type, parent_index, opt_index, name);

	prop = IDP_GetPropertyFromGroup(group, name);
	if (prop) {
		return prop;
	}

	switch (o->type) {
	case FF_OPT_TYPE_INT:
	case FF_OPT_TYPE_INT64:
		val.i = FFMPEG_DEF_OPT_VAL_INT(o);
		idp_type = IDP_INT;
		break;
	case FF_OPT_TYPE_DOUBLE:
	case FF_OPT_TYPE_FLOAT:
		val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o);
		idp_type = IDP_FLOAT;
		break;
	case FF_OPT_TYPE_STRING:
		val.str = "                                                                               ";
		idp_type = IDP_STRING;
		break;
	case FF_OPT_TYPE_CONST:
		val.i = 1;
		idp_type = IDP_INT;
		break;
	default:
		return NULL;
	}
	prop = IDP_New(idp_type, val, name);
	IDP_AddToGroup(group, prop);
	return prop;
}