All pastes #218346 Raw Edit

Someone

public text v1 · immutable
#218346 ·published 2006-10-24 03:36 UTC
rendered paste body
/* remove all formats from 'dest' that not either present in 'src'
   or translatable from 'src'; assumes only a single audio format
   and optionally a single video format will be present in 'src'
*/
unsigned int ast_translate_available_formats(unsigned int dest, unsigned int src)
{
	unsigned int res = dest;
	unsigned int x;
	unsigned int src_audio = powerof(src & AST_FORMAT_AUDIO_MASK);
	unsigned int src_video = powerof(src & AST_FORMAT_VIDEO_MASK);

	for (x = 1; x < AST_FORMAT_MAX_AUDIO; x <<= 1) {
		/* if this is not a desired format, nothing to do */
		if (!dest & x)
			continue;

		/* if the source is supplying this format, then
		   we can leave it in the result */
		if (src & x)
			continue;

		/* if we don't have a translation path from the src
		   to this format, remove it from the result */
		if (!tr_matrix[src_audio][powerof(x)].step)
			dest &= ~x;
	}

	/* roll over into video formats */
	for (; x < AST_FORMAT_MAX_VIDEO; x <<= 1) {
		/* if this is not a desired format, nothing to do */
		if (!dest & x)
			continue;

		/* if the source is supplying this format, then
		   we can leave it in the result */
		if (src & x)
			continue;

		/* if we don't have a translation path from the src
		   to this format, remove it from the result */
		if (!tr_matrix[src_video][powerof(x)].step)
			dest &= ~x;
	}

	return res;
}