invtelec.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,656 行 · 第 1/4 页
CPP
1,656 行
/* ***** BEGIN LICENSE BLOCK *****
* Source last modified: $Id: invtelec.cpp,v 1.7.32.1 2004/07/09 01:55:14 hubbe Exp $
*
* Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file,
* are subject to the current version of the RealNetworks Public
* Source License (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the current version of the RealNetworks Community
* Source License (the "RCSL") available at
* http://www.helixcommunity.org/content/rcsl, in which case the RCSL
* will apply. You may also obtain the license terms directly from
* RealNetworks. You may not use this file except in compliance with
* the RPSL or, if you have a valid RCSL with RealNetworks applicable
* to this file, the RCSL. Please see the applicable RPSL or RCSL for
* the rights, obligations and limitations governing use of the
* contents of the file.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU General Public License Version 2 or later (the
* "GPL") in which case the provisions of the GPL are applicable
* instead of those above. If you wish to allow use of your version of
* this file only under the terms of the GPL, and not to allow others
* to use your version of this file under the terms of either the RPSL
* or RCSL, indicate your decision by deleting the provisions above
* and replace them with the notice and other provisions required by
* the GPL. If you do not delete the provisions above, a recipient may
* use your version of this file under the terms of any one of the
* RPSL, the RCSL or the GPL.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the
* portions it created.
*
* This file, and the files included with this file, is distributed
* and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
* ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
////////////////////////////////////////////////////////
// include files
////////////////////////////////////////////////////////
#include "invtelec.h"
#include "hxtick.h"
#include "mmx_util.h"
#include "hlxclib/stdlib.h"
#include "hlxclib/string.h"
#include "hlxclib/math.h"
////////////////////////////////////////////////////////
// internal prototypes
////////////////////////////////////////////////////////
static T_INVTELE_RESULT
InvTelecineDetect(
UCHAR *data, UCHAR *prevData,
double frameRate,
ULONG32 timestamp,
ULONG32 pels, ULONG32 lines,
BOOL bDeInterlaced,
T_INVTELE_STATE *state);
//#define CODEC_DEBUG_32PULLDOWN
#ifdef CODEC_DEBUG_32PULLDOWN
#include <stdio.h>
static FILE *fp_log = NULL;
#endif
const T_INVTELE_FLOAT inThresh[PULLDOWN_HIST_LEN+1] = {3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4};
const T_INVTELE_FLOAT outThresh[PULLDOWN_HIST_LEN+1] = {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2};
#ifdef ALLOW_MMX_INVTELE
void
SumSqaredFrameDiff_MMX(
unsigned char *frame,
unsigned char *prev_frame,
int pels,
int lines,
int pitch,
float *ssd_odd,
float *ssd_even);
void
RestitchCheck_MMX(
unsigned char *frame,
unsigned char *prev_frame,
int pels,
int lines,
int pitch,
float *ssd_new,
float *ssd_old);
#endif
////////////////////////////////////////////////////////
//
// InitInvTelecine
//
// Allocates and initializes memory for state information
//
// Parameters:
// state: Pointer to the allocated state pointer
//
////////////////////////////////////////////////////////
INT32
InitInvTelecine(T_INVTELE_STATE **state)
{
T_INVTELE_STATE *new_state = 0;
if (*state != 0)
return 1;
new_state = (T_INVTELE_STATE *)malloc(sizeof(T_INVTELE_STATE));
if (new_state == 0)
{
return 1;
}
new_state->impl_id = INVTELE_IMPL_ID_C;
new_state->firstFrame = TRUE;
new_state->ulPulldownActiveTimerIntl = 0;
new_state->ulPulldownActiveTimerProg = 0;
new_state->lastRemovedTimestamp = 0;
new_state->frameCountMod = 4;
new_state->frameRemovalPattern = 4;
new_state->NTSCTrackingFrameCounter = 500;
new_state->interleaveEvenFlag = FALSE;
new_state->interleaveOddFlag = FALSE;
new_state->checkNextFrameForInterlace = FALSE;
new_state->checkNextFrameForProgressive = FALSE;
new_state->bProgressiveTelecineSeen = FALSE;
new_state->bInterlacedTelecineSeen = FALSE;
new_state->pulldownTimeBuffer = 0;
for (int i = 0; i < PULLDOWN_HIST_LEN; i++)
{
new_state->pulldownSadHistEven[i] = UN_INIT_SAD;
new_state->pulldownSadHistOdd[i] = UN_INIT_SAD;
new_state->pulldownSadHistAll[i] = UN_INIT_SAD;
new_state->pulldownTimeHist[i] = 0;
}
#ifdef ALLOW_MMX_INVTELE
// Check for MMx availability
if (checkMmxAvailablity() & CPU_HAS_MMX)
new_state->impl_id = INVTELE_IMPL_ID_MMX;
#endif
*state = new_state;
return 0;
}
////////////////////////////////////////////////////////
//
// FreeInvTelecine
//
// Frees memory for state information
//
// Parameters:
// state: Pointer to the allocated state pointer
//
////////////////////////////////////////////////////////
void
FreeInvTelecine(T_INVTELE_STATE **state)
{
if (*state != 0)
free(*state);
*state = 0;
}
////////////////////////////////////////////////////////
//
// IsContentProgressiveTelecine
//
// Returns TRUE if the telecine detector has seen
// interlaced telecine content
//
// Parameters:
// state: State pointer
//
////////////////////////////////////////////////////////
BOOL
IsContentProgressiveTelecine(T_INVTELE_STATE *state)
{
if (state != 0)
return (state->bProgressiveTelecineSeen)?(TRUE):(FALSE);
return FALSE;
}
////////////////////////////////////////////////////////
//
// IsContentInterlacedTelecine
//
// Returns TRUE if the telecine detector has seen
// progressive telecine content
//
// Parameters:
// state: State pointer
//
////////////////////////////////////////////////////////
BOOL
IsContentInterlacedTelecine(T_INVTELE_STATE *state)
{
if (state != 0)
return (state->bInterlacedTelecineSeen)?(TRUE):(FALSE);
return FALSE;
}
////////////////////////////////////////////////////////
//
// GetTelecinePattern
//
// Returns the frame modulo for the removal pattern
//
// Parameters:
// state: State pointer
//
////////////////////////////////////////////////////////
UCHAR
GetTelecinePattern(T_INVTELE_STATE *state)
{
INT32 pattern;
if (state != 0)
pattern = (state->frameRemovalPattern - state->frameCountMod) % 5;
else
pattern = 0;
if (pattern < 0)
pattern +=5;
return (UCHAR)pattern;
}
////////////////////////////////////////////////////////
//
// SetTelecinePattern
//
// Sets the frame modulo for the removal pattern
//
// Parameters:
// state: State pointer
//
////////////////////////////////////////////////////////
void
SetTelecinePattern(T_INVTELE_STATE *state, UCHAR telecine_pattern)
{
if (state != 0)
state->frameRemovalPattern = ((telecine_pattern + state->frameCountMod) % 5);
}
////////////////////////////////////////////////////////
//
// DoInvTelecine
//
// Performs inverse Telecine
//
// Parameters:
// data: Pointer to the current planar frame.
// prevData: Pointer to the previous source frame.
// frameRate: The input frame rate.
// timestamp: The timestamp of the current frame.
// This value will be adjusted to account
// for the change to 24 fps
// pels, lines: Frame dimensions.
// bDeInterlaced: Should be set to TRUE if frame is known
// to be progressive.
// state: State pointer
//
////////////////////////////////////////////////////////
T_INVTELE_RESULT
DoInvTelecine(
UCHAR *data,
UCHAR *prevData,
double frameRate,
ULONG32 ×tamp,
ULONG32 pels, ULONG32 lines,
BOOL bDeInterlaced,
T_INVTELE_STATE *state)
{
T_INVTELE_RESULT ret;
if (frameRate < 25.5)
return (INVTELE_RESULT_LOW_FRAMERATE);
#ifdef CODEC_DEBUG_32PULLDOWN
if(fp_log == NULL)
fp_log = fopen("c:\\pulldown.log","w");
#endif
ret = InvTelecineDetect(data, prevData, frameRate, timestamp, pels, lines, bDeInterlaced, state);
// hack -- don't drop more than 1 out of every 5 progressive frames
if ((state->pulldownTimeBuffer > 1) &&
(bDeInterlaced || lines < 242) &&
(ret == INVTELE_RESULT_DROP_FRAME))
{
ret = INVTELE_RESULT_FRAME_OK;
}
if (ret == INVTELE_RESULT_DROP_FRAME)
{
state->pulldownTimeBuffer = 33;
}
else
{
// adjust timestamp
// -- allowed offsets will be -33, -25, -17, -9, -1, 0
timestamp -= state->pulldownTimeBuffer;
if (state->pulldownTimeBuffer > 8)
{
state->pulldownTimeBuffer -= 8;
}
else
{
state->pulldownTimeBuffer = 0;
}
}
return (ret);
}
////////////////////////////////////////////////////////
//
// InvTelecineDetect
//
// Performs detection of the inverse telecine pattern
//
// Parameters:
// data: Pointer to the current planar frame.
// prevData: Pointer to the previous source frame.
// frameRate: The input frame rate.
// timestamp: The timestamp of the current frame.
// pels, lines: Frame dimensions.
// bDeInterlaced: Should be set to TRUE if frame is known
// to be progressive.
// state: State pointer
//
////////////////////////////////////////////////////////
T_INVTELE_RESULT
InvTelecineDetect
(
UCHAR *data,
UCHAR *prevData,
double frameRate,
ULONG32 timestamp,
ULONG32 pels, ULONG32 lines,
BOOL bDeInterlaced,
T_INVTELE_STATE *state
)
{
unsigned int i, j, k, ll;
ULONG32 patternStart, histLength;
LONG32 *pNew, *pOld;
float temp;
float sumEven = 0.0f, sumOdd = 0.0f;
float sumOld = 0.0f, sumNew = 0.0f;
float sumAll = 0.0f;
float inGroupMeanEven[5],outGroupMeanEven[5];
float inGroupStdEven[5],outGroupStdEven[5];
ULONG32 inGroupCountEven,outGroupCountEven;
float outMinEven[5],outMaxEven[5];
float inMaxEven[5],inMinEven[5];
BOOL groupValidFlagEven[5];
float inGroupMeanOdd[5],outGroupMeanOdd[5];
float inGroupStdOdd[5],outGroupStdOdd[5];
ULONG32 inGroupCountOdd,outGroupCountOdd;
float outMinOdd[5],outMaxOdd[5];
float inMaxOdd[5],inMinOdd[5];
BOOL groupValidFlagOdd[5];
float inGroupMean[5], outGroupMean[5];
float inGroupStd[5], outGroupStd[5];
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?