📄 xdstorat.cpp
字号:
// When all chars of this packet contain all ones, it indicates the
// end of the current program. Sec. 9.5.1.1 DX9 states that we
// should return S_OK and TvRatDontKnow to indicate end of program.
if( newPID[0] == NBITS(6) && newPID[1] == NBITS(5) &&
newPID[2] == NBITS(5) )
{
DBP(( "XDStoRat::decodePID got all ones packet\n" ));
resetState();
return S_OK;
}
// _pid.size() == 0 Indicates that this object has been
// reset so any valid PID received is the new PID.
if( _pid.size() == 0 )
{
DBP(( "XDS pid= 0 new PID: min= %02d hr= %02d date=%02d mth=%02d\n",
newPID[0], newPID[1], newPID[2], newPID[3] ));
_pid = newPID;
return S_FALSE;
}
// Change in received PID means start of new program.
// DX9 states that we should return S_OK and
// TvRatDontKnow to indicate end of program.
if( newPID != _pid )
{
DBP(( "XDS new PID: min= %02d hr= %02d date=%02d mth=%02d\n",
newPID[0], newPID[1], newPID[2], newPID[3] ));
resetState();
_pid = newPID;
return S_OK;
}
}
// If the size is invalid or the PID has not changed return FALSE
return S_FALSE;
}
HRESULT
CXDSToRat::decodeProgName( std::string name )
{
if( name.size() >= INFO_MIN_PROG_NAME &&
name.size() <= INFO_MAX_PROG_NAME )
{
// _name.size() == 0 Indicates that this object has been reset so
// any valid Program Name received is the new Program Name.
if( _progName.size() == 0 )
{
DBP(( "XDS decodeName size = 0 new Name = %s\n", name.c_str() ));
_progName = name;
return S_FALSE;
}
// Change in received Program Name means start of new program.
// DX9 states that we should return S_OK and TvRatDontKnow
// to indicate end of program.
if( name != _progName )
{
DBP(( "XDS decodeName new Name = %s\n", name.c_str() ));
resetState();
_progName = name;
return S_OK;
}
}
// If the size is invalid or the Program Name has not changed return FALSE
return S_FALSE;
}
static const
LONG VALID_USTV_ATTRIBUTES[] =
{
0,
0,
US_TV_IsViolent,
0,
US_TV_IsViolent | US_TV_IsSexualSituation |
US_TV_IsAdultLanguage | US_TV_IsSexuallySuggestiveDialog,
US_TV_IsViolent | US_TV_IsSexualSituation |
US_TV_IsAdultLanguage | US_TV_IsSexuallySuggestiveDialog,
US_TV_IsViolent | US_TV_IsSexualSituation | US_TV_IsAdultLanguage,
0
};
HRESULT
CXDSToRat::decodeContAdv( BYTE char1,
BYTE char2,
bool arg2IsValid,
EnTvRat_System *p_system,
EnTvRat_GenericLevel *p_level,
LONG *p_attrib )
{
if( (char1 & BIT(3)) == 0 ) // MPA Rating system
{
EnTvRat_MPAA level;
// For MPA the rating is in the low order three bits of char 1
switch( char1 & NBITS(3) )
{
case 0: level = MPAA_NotApplicable; break;
case 1: level = MPAA_G; break;
case 2: level = MPAA_PG; break;
case 3: level = MPAA_PG13; break;
case 4: level = MPAA_R; break;
case 5: level = MPAA_NC17; break;
case 6: level = MPAA_X; break;
case 7: level = MPAA_NotRated; break;
}
// Return the decoded rating as per DX9 SDK.
DBP(( "XDS rating MPA lev = %x\n", level ));
*p_system = MPAA;
*p_level = (EnTvRat_GenericLevel)level;
*p_attrib = BfAttrNone; // Not used by MPA
return S_OK;
}
else if( !arg2IsValid ) // If not MPA, char2 must be valid.
{
return S_FALSE;
}
else if( (char1 & BIT(4)) == 0 ) // U.S. TV Rating system
{
EnTvRat_US_TV level;
// For U.S. TV the rating is in the low order three bits of char 2
switch( char2 & NBITS(3) )
{
case 0: level = US_TV_None; break;
case 1: level = US_TV_Y; break;
case 2: level = US_TV_Y7; break;
case 3: level = US_TV_G; break;
case 4: level = US_TV_PG; break;
case 5: level = US_TV_14; break;
case 6: level = US_TV_MA; break;
// For some reason, Media Center treats value 7 differently from 0.
// So even if a user checks the "block unrated showTV programs",
// the program is still being shown, whereas a VChip TV will block it.
// The workaround is to make this value to behave the same as 0.
case 7: level = US_TV_None; break;
}
// U.S. TV uses Content Attributes per EIA/CEA-608-B Sec. 9.5.1.5.1
LONG attrib = char1 & BIT(5) ? US_TV_IsSexuallySuggestiveDialog : 0;
attrib |= char2 & BIT(3) ? US_TV_IsAdultLanguage : 0;
attrib |= char2 & BIT(4) ? US_TV_IsSexualSituation : 0;
attrib |= char2 & BIT(5) ? US_TV_IsViolent : 0;
// Only certain combinations of ratings and attributes are allowed
attrib &= VALID_USTV_ATTRIBUTES[char2 & NBITS(3)];
// Return the decoded rating as per DX9 SDK.
DBP(( "XDS rating US_TV lev = %x atr = %x\n", level, attrib ));
*p_system = US_TV;
*p_level = (EnTvRat_GenericLevel)level;
*p_attrib = attrib;
return S_OK;
}
else if( (char1 & BIT(5)) == 0 && (char2 & BIT(3)) == 0 ) // Canadian Engli
{
EnTvRat_CAE_TV level;
// Canadian English rating is in the low order 3 bits of char 2
switch( char2 & NBITS(3) )
{
case 0: level = CAE_TV_Exempt; break;
case 1: level = CAE_TV_C; break;
case 2: level = CAE_TV_C8; break;
case 3: level = CAE_TV_G; break;
case 4: level = CAE_TV_PG; break;
case 5: level = CAE_TV_14; break;
case 6: level = CAE_TV_18; break;
case 7: return S_FALSE; // Rating == 7 is invalid Sec. 9.5.1.5.2
}
// Return the decoded rating as per DX9 SDK.
DBP(( "XDS CAE rate lev = %x\n", level ));
*p_system = Canadian_English;
*p_level = (EnTvRat_GenericLevel)level;
*p_attrib = BfAttrNone; // Not used by Canadian English
return S_OK;
}
else if( char1 & BIT(5) && (char2 & BIT(3)) == 0 ) // Canadian French
{
EnTvRat_CAF_TV level;
// Canadian French rating is in the low order 3 bits of char 2
switch( char2 & NBITS(3) )
{
case 0: level = CAF_TV_Exempt; break;
case 1: level = CAF_TV_G; break;
case 2: level = CAF_TV_8; break;
case 3: level = CAF_TV_13; break;
case 4: level = CAF_TV_16; break;
case 5: level = CAF_TV_18; break;
default: return S_FALSE; // Rating == 6 or 7 is invalid Sec. 9.5.1.5.3
}
// Return the decoded rating as per DX9 SDK.
DBP(( "XDS CAF rate lev = %x\n", level ));
*p_system = Canadian_French;
*p_level = (EnTvRat_GenericLevel)level;
*p_attrib = BfAttrNone; // Not used by Canadian French
return S_OK;
}
else // Reserved for non-U.S. & non-Canadian system
return S_FALSE;
}
void CXDSToRat::resetState()
{
// When we get an indication of the end of a program, or when a
// discontinuity occurs we need to reset our internal state.
_p_receivingPkt = NULL;
_xdsPackets.clear();
_pid.resize( 0 );
_progName.resize( 0 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -