Пример #1
0
struct ast_format *ast_format_set(struct ast_format *format, enum ast_format_id id, int set_attributes, ... )
{
	/* initialize the structure before setting it. */
	ast_format_clear(format);

	format->id = id;

	if (set_attributes) {
		va_list ap;
		va_start(ap, set_attributes);
		format_set_helper(format, ap);
		va_end(ap);
	}

	return format;
}
Пример #2
0
static struct interface_ao2_wrapper *find_interface(const struct ast_format *format)
{
	struct interface_ao2_wrapper *wrapper;
	struct interface_ao2_wrapper tmp_wrapper = {
		.id = format->id,
	};

	ast_rwlock_rdlock(&ilock);
	wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK));
	ast_rwlock_unlock(&ilock);

	return wrapper;
}

static int has_interface(const struct ast_format *format)
{
	struct interface_ao2_wrapper *wrapper;

	wrapper = find_interface(format);
	if (!wrapper) {
		return 0;
	}
	ao2_ref(wrapper, -1);
	return 1;
}

/*! \internal
 * \brief set format attributes using an interface
 */
static int format_set_helper(struct ast_format *format, va_list ap)
{
	struct interface_ao2_wrapper *wrapper;

	if (!(wrapper = find_interface(format))) {
		ast_log(LOG_WARNING, "Could not find format interface to set.\n");
		return -1;
	}

	ast_rwlock_rdlock(&wrapper->wraplock);
	if (!wrapper->interface || !wrapper->interface->format_attr_set) {
		ast_rwlock_unlock(&wrapper->wraplock);
		ao2_ref(wrapper, -1);
		return -1;
	}

	wrapper->interface->format_attr_set(&format->fattr, ap);

	ast_rwlock_unlock(&wrapper->wraplock);
	ao2_ref(wrapper, -1);

	return 0;
}

struct ast_format *ast_format_append(struct ast_format *format, ... )
{
	va_list ap;
	va_start(ap, format);
	format_set_helper(format, ap);
	va_end(ap);

	return format;
}
Пример #3
0
static struct interface_ao2_wrapper *find_interface(const struct ast_format *format)
{
	struct interface_ao2_wrapper tmp_wrapper = {
		.id = format->id,
	};

	return ao2_find(interfaces, &tmp_wrapper, OBJ_POINTER);
}

static int has_interface(const struct ast_format *format)
{
	struct interface_ao2_wrapper *wrapper;

	wrapper = find_interface(format);
	if (!wrapper) {
		return 0;
	}
	ao2_ref(wrapper, -1);
	return 1;
}

int ast_format_sdp_parse(struct ast_format *format, const char *attributes)
{
	struct interface_ao2_wrapper *wrapper;
	int res;

	if (!(wrapper = find_interface(format))) {
		return 0;
	}

	ao2_rdlock(wrapper);
	if (!(wrapper->interface || !wrapper->interface->format_attr_sdp_parse)) {
		ao2_unlock(wrapper);
		ao2_ref(wrapper, -1);
		return 0;
	}

	res = wrapper->interface->format_attr_sdp_parse(&format->fattr, attributes);

	ao2_unlock(wrapper);
	ao2_ref(wrapper, -1);

	return res;
}

void ast_format_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str)
{
	struct interface_ao2_wrapper *wrapper;

	if (!(wrapper = find_interface(format))) {
		return;
	}

	ao2_rdlock(wrapper);
	if (!(wrapper->interface || !wrapper->interface->format_attr_sdp_generate)) {
		ao2_unlock(wrapper);
		ao2_ref(wrapper, -1);
		return;
	}

	wrapper->interface->format_attr_sdp_generate(&format->fattr, payload, str);

	ao2_unlock(wrapper);
	ao2_ref(wrapper, -1);
}

/*! \internal
 * \brief set format attributes using an interface
 */
static int format_set_helper(struct ast_format *format, va_list ap)
{
	struct interface_ao2_wrapper *wrapper;

	if (!(wrapper = find_interface(format))) {
		ast_log(LOG_WARNING, "Could not find format interface to set.\n");
		return -1;
	}

	ao2_rdlock(wrapper);
	if (!wrapper->interface || !wrapper->interface->format_attr_set) {
		ao2_unlock(wrapper);
		ao2_ref(wrapper, -1);
		return -1;
	}

	wrapper->interface->format_attr_set(&format->fattr, ap);

	ao2_unlock(wrapper);
	ao2_ref(wrapper, -1);

	return 0;
}

struct ast_format *ast_format_append(struct ast_format *format, ... )
{
	va_list ap;
	va_start(ap, format);
	format_set_helper(format, ap);
	va_end(ap);

	return format;
}