⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invtelec.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					obviousPatternFlag = TRUE;
					goto INTERLEAVE_EVEN;
				}
				else 
					goto DO_NOTHING;
			}
		}

		// Do we have a pretty clear pattern? Only trust this test 
		// if we have succeeded with the strongest test a couple of times
		for (i = 0; i < 5; i++)
		{
			if (groupValidFlagEven[i] == FALSE)
				continue;
			if (groupValidFlagOdd[i] == FALSE)
				continue;
			if (groupValidFlagEven[(i+2)%5] == FALSE)
				continue;
			if (groupValidFlagOdd[(i+2)%5] == FALSE)
				continue;

			if ((state->ulPulldownActiveTimerIntl > 10) &&
				(inGroupMeanEven[i]      + inThresh[patternStart]*inGroupStdEven[i]      < outMinEven[i]     ) &&
				(inGroupMeanOdd[(i+2)%5] + inThresh[patternStart]*inGroupStdOdd[(i+2)%5] < outMinOdd[(i+2)%5]) &&
				(inGroupMeanEven[i]      + inGroupStdEven[i]      < inGroupMeanOdd[i]       ) &&
				(inGroupMeanOdd[(i+2)%5] + inGroupStdOdd[(i+2)%5] < inGroupMeanEven[(i+2)%5]))
			{
#ifdef CODEC_DEBUG_32PULLDOWN
				fprintf(fp_log,"pretty clear pattern, i is %d, pulldown timer is %d, patternStart is %d\n",i,state->ulPulldownActiveTimerIntl,patternStart);
#endif
				// Set the removal pattern phase
				state->frameRemovalPattern=i;

				// If this is the right frame remove it!
				if(i == (PULLDOWN_HIST_LEN - 1) % 5)
				{
					// Set a counter that goes up if we have a consistent pattern 80+% of the time, down otherwise
					if ((timestamp - state->lastRemovedTimestamp > 145) &&
						(timestamp - state->lastRemovedTimestamp < 175))
					{
						if (state->ulPulldownActiveTimerIntl < 95)
							state->ulPulldownActiveTimerIntl += 5;
						else
						{
							state->ulPulldownActiveTimerIntl = 100;
							state->bInterlacedTelecineSeen = TRUE;
						}

						if (state->ulPulldownActiveTimerProg > 5)
							state->ulPulldownActiveTimerProg -= 5;
						else
							state->ulPulldownActiveTimerProg = 0;
					}
					else if (timestamp - state->lastRemovedTimestamp < 300)
					{
						if (state->ulPulldownActiveTimerIntl > 5)
							state->ulPulldownActiveTimerIntl -= 5;
						else
							state->ulPulldownActiveTimerIntl = 0;
					}
					state->lastRemovedTimestamp = timestamp;

					goto REMOVE_FRAME;
				}
				else if (i == ((PULLDOWN_HIST_LEN - 2) % 5))
				{
					obviousPatternFlag = TRUE;
					goto INTERLEAVE_ODD;
				}
				else 
					goto DO_NOTHING;
			}

			if ((state->ulPulldownActiveTimerIntl > 10) &&
				(inGroupMeanOdd[i]        + inThresh[patternStart]*inGroupStdOdd[i]        < outMinOdd[i]       ) &&
				(inGroupMeanEven[(i+2)%5] + inThresh[patternStart]*inGroupStdEven[(i+2)%5] < outMinEven[(i+2)%5]) &&
				(inGroupMeanOdd[i]        + inGroupStdOdd[i]        < inGroupMeanEven[i]     ) &&
				(inGroupMeanEven[(i+2)%5] + inGroupStdEven[(i+2)%5] < inGroupMeanOdd[(i+2)%5]))
			{
#ifdef CODEC_DEBUG_32PULLDOWN
				fprintf(fp_log,"pretty clear pattern, i is %d, pulldown timer is %d, patternStart is %d\n",i,state->ulPulldownActiveTimerIntl,patternStart);
#endif
				// Set the removal pattern phase
				state->frameRemovalPattern=i;

				// If this is the right frame remove it!
				if(i == (PULLDOWN_HIST_LEN - 1) % 5)
				{
					// Set a counter that goes up if we have a consistent pattern 80+% of the time, down otherwise
					if ((timestamp - state->lastRemovedTimestamp > 145) && 
						(timestamp - state->lastRemovedTimestamp < 175))
					{
						if (state->ulPulldownActiveTimerIntl < 95)
							state->ulPulldownActiveTimerIntl += 5;
						else
						{
							state->ulPulldownActiveTimerIntl = 100;
							state->bInterlacedTelecineSeen = TRUE;
						}

						if (state->ulPulldownActiveTimerProg > 5)
							state->ulPulldownActiveTimerProg -= 5;
						else
							state->ulPulldownActiveTimerProg = 0;
					}
					else if (timestamp - state->lastRemovedTimestamp < 300)
					{
						if (state->ulPulldownActiveTimerIntl > 5)
							state->ulPulldownActiveTimerIntl -= 5;
						else
							state->ulPulldownActiveTimerIntl = 0;
					}
					state->lastRemovedTimestamp = timestamp;

					goto REMOVE_FRAME;
				}
				else if (i == ((PULLDOWN_HIST_LEN - 2) % 5))
				{
					obviousPatternFlag = TRUE;
					goto INTERLEAVE_EVEN;
				}
				else 
					goto DO_NOTHING;
			}
		}
	}

	// Rule that maintains the pattern
	// No pattern, but things are VERY quiet, and we have been seeing a 3:2 pattern 
	if ((state->frameRemovalPattern == ((PULLDOWN_HIST_LEN-1)%5)) &&
		(state->ulPulldownActiveTimerIntl > 50) &&
		(inMaxEven [(PULLDOWN_HIST_LEN-1)%5] < 13) && 
		(inMaxOdd  [(PULLDOWN_HIST_LEN-1)%5] < 13) && 
		(outMaxOdd [(PULLDOWN_HIST_LEN-1)%5] < 13) &&
		(outMaxEven[(PULLDOWN_HIST_LEN-1)%5] < 13) && 
		(groupValidFlagEven[(PULLDOWN_HIST_LEN-1)%5] == TRUE) &&
		(groupValidFlagOdd[(PULLDOWN_HIST_LEN-1)%5] == TRUE))
	{
#ifdef CODEC_DEBUG_32PULLDOWN
		fprintf(fp_log,"maintain pattern 1 - things are very quiet, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerIntl,patternStart);
#endif
		state->lastRemovedTimestamp = timestamp;
		state->checkNextFrameForInterlace = TRUE;

		goto REMOVE_FRAME;
	}

	// Rule that maintains the pattern
	// If we have been seeing consistent pulldown, 
	// and the last frame looks a bit interlaced, but it is in the right place.
	// This is a weak test.
	if ((state->frameRemovalPattern == ((PULLDOWN_HIST_LEN-1)%5)) &&
		(state->ulPulldownActiveTimerIntl > 50) &&
		(!state->checkNextFrameForInterlace) &&
		(state->pulldownSadHistEven[(PULLDOWN_HIST_LEN-1)] < (.6*state->pulldownSadHistOdd[(PULLDOWN_HIST_LEN-1)]) ||
		 state->pulldownSadHistOdd[(PULLDOWN_HIST_LEN-1)] < (.6*state->pulldownSadHistEven[(PULLDOWN_HIST_LEN-1)])))
	{
#ifdef CODEC_DEBUG_32PULLDOWN
		fprintf(fp_log,"maintain pattern 2, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerIntl,patternStart);
#endif
		state->lastRemovedTimestamp = timestamp;
		state->checkNextFrameForInterlace = TRUE;
		goto REMOVE_FRAME;
	}

	// If we have been seeing consistent pulldown, and the last frame looks very interlaced.
	// This is a weak test
	if ((state->ulPulldownActiveTimerIntl > 50) &&
		(!state->checkNextFrameForInterlace) &&
		(
		 (state->pulldownSadHistEven[(PULLDOWN_HIST_LEN-1)] < (state->pulldownSadHistOdd[(PULLDOWN_HIST_LEN-1)]*.3)) &&
		 (state->pulldownSadHistOdd[(PULLDOWN_HIST_LEN-1)] > 9)
		) || (
		 (state->pulldownSadHistOdd[(PULLDOWN_HIST_LEN-1)] < (state->pulldownSadHistEven[(PULLDOWN_HIST_LEN-1)]*.3)) &&
		 (state->pulldownSadHistEven[(PULLDOWN_HIST_LEN-1)] > 9)
		)
	   )
	{
#ifdef CODEC_DEBUG_32PULLDOWN
		fprintf(fp_log,"things look interlaced, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerIntl,patternStart);
#endif
		state->lastRemovedTimestamp = timestamp;
		state->checkNextFrameForInterlace = TRUE;
		goto REMOVE_FRAME;
	}

	if(state->checkNextFrameForInterlace)
	{
#ifdef CODEC_DEBUG_32PULLDOWN
		fprintf(fp_log,"checking frame for interlace\n",i,state->ulPulldownActiveTimerIntl,patternStart);
#endif
		state->checkNextFrameForInterlace = FALSE;
		if(state->interleaveEvenFlag)
			goto INTERLEAVE_EVEN;
		if(state->interleaveOddFlag)
			goto INTERLEAVE_ODD;
	}

	// Otherwise no pulldown!
#ifdef CODEC_DEBUG_32PULLDOWN
	fprintf(fp_log,"no pattern, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerIntl,patternStart);
#endif
	if ((inMaxEven[(PULLDOWN_HIST_LEN-1)%5] > 30) || 
		(outMaxEven[(PULLDOWN_HIST_LEN-1)%5] > 30))
	{
		if (state->ulPulldownActiveTimerIntl > 0)
			state->ulPulldownActiveTimerIntl--;
	}

	// should we attempt progressive patterns?
	if ((lines > 242) || 
		(state->ulPulldownActiveTimerIntl > 90 && state->ulPulldownActiveTimerProg < 10))
	{
		goto NO_PATTERN;
	}

PROGRESSIVE_TESTS:

	// Now test to see if there is an entire repeated frame
	for (patternStart = histLength; patternStart < PULLDOWN_HIST_LEN; patternStart += 5)
	{
		for (i = 0; i < 5; i++)
		{
			inGroupMean[i]  = 0;
			outGroupMean[i] = 0;
			inGroupStd[i]   = 0;
			outGroupStd[i]  = 0;
			inGroupCount    = 0;
			outGroupCount   = 0;
			outMin[i] = 255*255;
			outMax[i] = 0;
			inMax[i]  = 0;

			for (j = patternStart + i; j < PULLDOWN_HIST_LEN; j++)
			{
				if (state->pulldownSadHistAll[j] == MISSING_SAD ||
					state->pulldownSadHistAll[j] == UN_INIT_SAD)
					continue;

				if (((j - i) % 5) == 0)
				{
					inGroupMean[i] += state->pulldownSadHistAll[j];
					inGroupStd[i] += state->pulldownSadHistAll[j] * state->pulldownSadHistAll[j];
					if (inMax[i] < state->pulldownSadHistAll[j])
						inMax[i] = state->pulldownSadHistAll[j];
					inGroupCount++;
				}
				else
				{
					outGroupMean[i] += state->pulldownSadHistAll[j];
					outGroupStd[i] += state->pulldownSadHistAll[j] * state->pulldownSadHistAll[j];
					if (outMin[i] > state->pulldownSadHistAll[j])
						outMin[i] = state->pulldownSadHistAll[j];
					if (outMax[i] < state->pulldownSadHistAll[j])
						outMax[i] = state->pulldownSadHistAll[j];
					outGroupCount++;
				}
			}
			if ((inGroupCount > 1) && (outGroupCount > 3))
			{
				groupValidFlag[i] = TRUE;

				inGroupMean[i] = inGroupMean[i]/inGroupCount;
				if ((inGroupStd[i]/inGroupCount)-(inGroupMean[i]*inGroupMean[i]) > 0.0f)
					inGroupStd[i] = (float)sqrt((inGroupStd[i]/inGroupCount)-(inGroupMean[i]*inGroupMean[i]));
				else
					inGroupStd[i] = 0.0f;

				outGroupMean[i] = outGroupMean[i]/outGroupCount;
				if ((outGroupStd[i]/outGroupCount)-(outGroupMean[i]*outGroupMean[i]) > 0.0f)
					outGroupStd[i] = (float)sqrt((outGroupStd[i]/outGroupCount)-(outGroupMean[i]*outGroupMean[i]));
				else
					outGroupStd[i] = 0.0f;
			}
			else
			{
				groupValidFlag[i] = FALSE;
				inGroupMean[i] = 0;
				outGroupMean[i] = 0;
				inGroupStd[i] = 1;
				outGroupStd[i] = 1;
			}
		}

		// Do we have a clear pattern? Always trust this test.
		for (i = 0;i < 5; i++)
		{
			if ((inGroupMean[i]+inThresh[patternStart]*inGroupStd[i] < outGroupMean[i] - outThresh[patternStart]*outGroupStd[i]) &&
				(groupValidFlag[i] == TRUE))
			{
#ifdef CODEC_DEBUG_32PULLDOWN
				fprintf(fp_log,"clear pattern, i is %d, pulldown timer is %d, patternStart is %d\n",i,state->ulPulldownActiveTimerProg,patternStart);
#endif
				// If this is the right frame remove it!
				state->frameRemovalPattern=i;
				if(i==(PULLDOWN_HIST_LEN-1)%5)
				{
					// Set a counter that goes up if we have a consistent pattern 80+% of the time, down otherwise
					if ((timestamp - state->lastRemovedTimestamp > 145) &&
						(timestamp - state->lastRemovedTimestamp < 175))
					{
						if (state->ulPulldownActiveTimerProg < 95)
							state->ulPulldownActiveTimerProg += 5;
						else
						{
							state->ulPulldownActiveTimerProg = 100;
							state->bProgressiveTelecineSeen = TRUE;
						}

						if (state->ulPulldownActiveTimerIntl > 5)
							state->ulPulldownActiveTimerIntl -= 5;
						else
							state->ulPulldownActiveTimerIntl = 0;
					}
					else if (timestamp - state->lastRemovedTimestamp < 300)
					{
						if (state->ulPulldownActiveTimerProg > 5)
							state->ulPulldownActiveTimerProg -= 5;
						else
							state->ulPulldownActiveTimerProg = 0;
					}
					state->lastRemovedTimestamp = timestamp;
					goto REMOVE_FRAME;
				}
				else 
					goto DO_NOTHING;
			}
		}

		// Do we have a pretty clear pattern? Only trust this test if we have succeeded with the strongest test a couple of times
		for(i = 0; i < 5; i++)
		{
			if ((inGroupMean[i]+inThresh[patternStart]*inGroupStd[i] < outMin[i]) &&
				(state->ulPulldownActiveTimerProg > 10) &&
				(groupValidFlag[i] == TRUE))
			{
#ifdef CODEC_DEBUG_32PULLDOWN
				fprintf(fp_log,"pretty clear pattern, i is %d, pulldown timer is %d, patternStart is %d\n",i,state->ulPulldownActiveTimerProg,patternStart);
#endif
				// If this is the right frame remove it!
				state->frameRemovalPattern = i;
				if (i == (PULLDOWN_HIST_LEN-1)%5)
				{
					// Set a counter that goes up if we have a consistent pattern 80+% of the time, down otherwise
					if ((timestamp - state->lastRemovedTimestamp > 145) && 
						(timestamp - state->lastRemovedTimestamp < 175))
					{
						if (state->ulPulldownActiveTimerProg < 95)
							state->ulPulldownActiveTimerProg += 5;
						else
						{
							state->ulPulldownActiveTimerProg = 100;
							state->bProgressiveTelecineSeen = TRUE;
						}

						if (state->ulPulldownActiveTimerIntl > 5)
							state->ulPulldownActiveTimerIntl -= 5;
						else
							state->ulPulldownActiveTimerIntl = 0;
					}
					else if (timestamp - state->lastRemovedTimestamp < 300)
					{
						if (state->ulPulldownActiveTimerProg > 5)
							state->ulPulldownActiveTimerProg -= 5;
						else
							state->ulPulldownActiveTimerProg = 0;
					}
					state->lastRemovedTimestamp = timestamp;
					goto REMOVE_FRAME;
				}
				else 
					goto DO_NOTHING;
			}
		}

		// No pattern, but things are VERY quiet, and we have been seeing a 3:2 pattern 
		if ((inMax[(PULLDOWN_HIST_LEN-1)%5] < 9) && (state->ulPulldownActiveTimerProg > 50) &&
			(outMax[(PULLDOWN_HIST_LEN-1)%5] < 9) && (groupValidFlag[(PULLDOWN_HIST_LEN-1)%5] == TRUE) &&
			(state->frameRemovalPattern==((PULLDOWN_HIST_LEN-1)%5))
		   )
		{
#ifdef CODEC_DEBUG_32PULLDOWN
			fprintf(fp_log,"things are quiet, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerProg,patternStart);
#endif
			state->lastRemovedTimestamp = timestamp;
			goto REMOVE_FRAME;
		}
	}

	// If we have been seeing consistent pulldown, and the last two frames have been quiet frames.
	// This is our weakest test
	if (((state->pulldownSadHistAll[(PULLDOWN_HIST_LEN-1)] < 9) ||
		(state->pulldownSadHistAll[(PULLDOWN_HIST_LEN-1)] < state->pulldownSadHistAll[(PULLDOWN_HIST_LEN-2)])) &&
		(state->ulPulldownActiveTimerProg > 50) &&
		(groupValidFlag[(PULLDOWN_HIST_LEN-1)%5] == TRUE)&&(state->frameRemovalPattern==((PULLDOWN_HIST_LEN-1)%5))
	   )
	{
#ifdef CODEC_DEBUG_32PULLDOWN
		fprintf(fp_log,"things are quiet, pulldown timer is %d, patternStart is %d\n",state->ulPulldownActiveTimerProg,patternStart);
#endif
		state->lastRemovedTimestamp = timestamp;
		goto REMOVE_FRAME;
	}


	// If we have been seeing consistent pulldown, and the last frame looks very interlaced.
	// This is a weak test
	if ((state->pulldownSadHistAll[(PULLDOWN_HIST_LEN-1)] < state->pulldownSadHistAll[(PULLDOWN_HIST_LEN-2)] * 0.5) &&
		(state->ulPulldownActiveTimerProg > 50) &&
		(groupValidFlag[(PULLDOWN_HIST_LEN-1)%5] == TRUE))
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -