📄 smlprstime.cpp
字号:
}
if (FAILED(ret))
{
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
// check for a 'T'
if (pT)
{
//YYYY-MM-DDT
if (*(begin+4) == '-' && *(begin+7) == '-' && pT == (begin+10))
{
pDatePos = begin;
if (pTimeZone < begin+10)
{
pTimeZone = NULL;
}
}
else
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
if (*(pT+3) == ':')
{
pTimePos = pT+1;
}
else
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
}
// else just the date or time.
//YYYY-MM-DDT
else if (*(begin+4) == '-' && *(begin+7) == '-' && pT == (begin+10))
{
// just date
// there is a date.
pDatePos = begin;
if (pTimeZone < begin+10)
{
pTimeZone = NULL;
}
}
else if (*(begin+2) == ':')
{
pTimePos = begin;
}
else
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
// there is a date.
if (pDatePos)
{
//YYYY-MM-DDT
const char* pos = pDatePos;
strncpy(buf, pos, 4); /* Flawfinder: ignore */
buf[4] = '\0';
pos += 5;
year = HX_SAFEINT(strtol(buf, 0, 10));
if (year < 0 || year > 9999)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pDatePos,
m_ulStartLine);
goto cleanup;
}
strncpy(buf, pos, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pos += 3;
month = HX_SAFEINT(strtol(buf, 0, 10));
// /month can't be 0 or less or greater than 12 (i.e., it's
// 1-based):
if (month < 1 || month > 12)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pDatePos,
m_ulStartLine);
goto cleanup;
}
strncpy(buf, pos, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pos += 3;
day = HX_SAFEINT(strtol(buf, 0, 10));
if (day < 0 || day > 31)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pDatePos,
m_ulStartLine);
goto cleanup;
}
}
if (pTimePos)
{
//HH:MM...
const char* pos = pTimePos;
strncpy(buf, pos, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pos += 3;
hour = HX_SAFEINT(strtol(buf, 0, 10));
if (hour < 0 || hour > 24)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pTimePos,
m_ulStartLine);
goto cleanup;
}
// just time
strncpy(buf, pos, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pos += 3;
min = HX_SAFEINT(strtol(buf, 0, 10));
if (min < 0 || min > 59)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pTimePos,
m_ulStartLine);
goto cleanup;
}
if (*(pos-1) == ':')
{
strncpy(buf, pos, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pos +=3;
sec = HX_SAFEINT(strtol(buf, 0, 10));
if (sec < 0 || sec > 59)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pTimePos,
m_ulStartLine);
goto cleanup;
}
if (*(pos-1) == '.')
{
// find end.
UINT32 len = 0;
if (pTimeZone)
{
len = pTimeZone - pos;
}
else
{
len = end - pos;
}
strncpy(buf, pos, len); /* Flawfinder: ignore */
buf[len] = '\0';
pos += len;
if (*buf)
{
if (isdigit(*buf))
{
ms = (*buf - '0') * 100;
if (isdigit(*(buf+1)))
{
ms += (*buf - '0') * 10;
if (isdigit(*(buf+2)))
{
ms += (*buf - '0');
}
}
}
else
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, pTimePos,
m_ulStartLine);
goto cleanup;
}
}
}
}
}
if (pTimeZone)
{
BOOL bSyntaxOK = FALSE;
const char* begin = pTimeZone;
if (*pTimeZone == 'Z')
{
m_bRelativeToUTC = TRUE;
UTCOffset = 0;
bSyntaxOK = TRUE;
}
else if ((*pTimeZone == '+' || *pTimeZone == '-') && *(pTimeZone+3) == ':')
{
m_bRelativeToUTC = TRUE;
int sign = 1;
if (*pTimeZone == '-')
{
++pTimeZone;
sign = -1;
}
else if (*pTimeZone == '+')
{
++pTimeZone;
}
strncpy(buf, pTimeZone, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pTimeZone += 3;
INT32 hour = HX_SAFEINT(strtol(buf, 0, 10));
if (hour < 0 || hour > 12)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
UTCOffset = hour * 60;
strncpy(buf, pTimeZone, 2); /* Flawfinder: ignore */
buf[2] = '\0';
pTimeZone += 3;
INT32 min = HX_SAFEINT(strtol(buf, 0, 10));
if (min < 0 || min > 59)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
UTCOffset += min;
UTCOffset *= sign;
bSyntaxOK = TRUE;
}
else if (isspace(*pTimeZone))
{
bSyntaxOK = TRUE;
do
{
*pTimeZone++;
if (!(*pTimeZone) || ')' == *pTimeZone)
{
break;
}
if (!isspace(*pTimeZone))
{
bSyntaxOK = FALSE;
break;
}
} while (*pTimeZone);
}
if (!bSyntaxOK)
{
ret = HXR_FAIL;
CSmilSMILSyntaxErrorHandler errHandler(m_pContext);
errHandler.ReportError(SMILErrorBadWallClockValue, begin,
m_ulStartLine);
goto cleanup;
}
}
// else use the -1 value.
m_UTCOffsetMin = (INT16)UTCOffset;
m_ms = (UINT16)ms;
m_sec = (UINT8)sec;
m_min = (UINT8)min;
m_hour = (UINT8)hour;
m_day = (INT8)day;
m_month = (INT8)month;
m_year = (INT16)year;
cleanup:
if (SUCCEEDED(ret))
{
m_bTimeIsResolved = TRUE;
}
return ret;
}
void SmilTimeValue::setIsTimeResolved(BOOL bIsResolved)
{
m_bTimeIsResolved = bIsResolved;
}
HX_RESULT
SmilTimeValue::setPauseTime(LONG32 lTimeOfPause)
{
HX_RESULT pnr = HXR_OK;
if (!isResumeEvent())
{
pnr = HXR_UNEXPECTED;
}
else
{
m_lTimeOfPause = lTimeOfPause;
}
return pnr;
}
BOOL
SmilTimeValue::isSameTimeValue(SmilTimeValue* pOtherTimeVal)
{
BOOL bIsSame = FALSE;
// /Using this fixes freeze-up in use of strcmp(NULL,...) [PR 65817]
// found while fixing Interop Timing #18.37 which has begin="0s;7s" :
BOOL bHasSameEventNameOrBothHaveNoEventName =
(NULL == m_pEventName && NULL == pOtherTimeVal->m_pEventName);
if (!bHasSameEventNameOrBothHaveNoEventName)
{
if (NULL != m_pEventName && NULL != pOtherTimeVal->m_pEventName)
{
bHasSameEventNameOrBothHaveNoEventName =
!strcmp(m_pEventName, pOtherTimeVal->m_pEventName);
}
}
// /Now compare type, timing, event name, ...etc:
if (pOtherTimeVal == this)
{
bIsSame = TRUE;
}
else if (pOtherTimeVal &&
m_pElement == pOtherTimeVal->m_pElement &&
m_type == pOtherTimeVal->m_type &&
m_position == pOtherTimeVal->m_position &&
m_uRepeatIteration == pOtherTimeVal->m_uRepeatIteration &&
m_pszMarkerName == pOtherTimeVal->m_pszMarkerName &&
bHasSameEventNameOrBothHaveNoEventName &&
m_lOffset == pOtherTimeVal->m_lOffset &&
m_bTimeIsResolved == pOtherTimeVal->m_bTimeIsResolved)
{
// /Note: if time isn't resolved, we don't care if times are same:
if (m_bTimeIsResolved &&
m_lResolvedToTime == pOtherTimeVal->m_lResolvedToTime)
{
bIsSame = TRUE;
}
else
{
switch (m_type)
{
case SmilTimeOffset:
case SmilTimeClockValue:
case SmilTimeWallclock:
case SmilTimeNone:
{
bIsSame = TRUE;
}
break;
case SmilTimeSyncBase:
#if defined(ENABLE_SYNC_TO_PREV)
case SmilTimeSyncToPrev:
#endif
case SmilTimeMediaMarker:
case SmilTimeEvent:
{
HX_ASSERT(m_idRef.GetLength());
HX_ASSERT(pOtherTimeVal->m_idRef.GetLength());
bIsSame = !strcmp(m_idRef, pOtherTimeVal->m_idRef);
}
break;
}
}
}
return bIsSame;
}
BOOL
SmilTimeValue::deferUntil(LONG32 lNewStartTime)
{
BOOL bSucceeded = FALSE;
if (m_bTimeIsResolved && m_lResolvedToTime < lNewStartTime)
{
// /XXXEH- TODO: determine if it's necessary to have a separate
// variable that keeps track of the deferred amount, and that is
// reset to 0 if and when this time is used to begin the element.
// This might be needed if this SmilTimeValue gets reused due to
// a repeat, seek, or ???
switch (m_type)
{
case SmilTimeWallclock:
case SmilTimeClockValue:
case SmilTimeOffset:
{
// /Fixes PR 55936. Add the amount deferred by to the
// offset instead of just setting offset to newStartTime:
m_lOffset += (lNewStartTime - m_lResolvedToTime);
bSucceeded = TRUE;
}
break;
case SmilTimeSyncBase:
#if defined(ENABLE_SYNC_TO_PREV)
case SmilTimeSyncToPrev:
#endif
case SmilTimeMediaMarker:
case SmilTimeEvent:
{
m_lResolvedToTime = lNewStartTime;
bSucceeded = TRUE;
}
break;
default:
HX_ASSERT(0);
break;
}
}
return (bSucceeded);
}
void SmilTimeValue::setMarkerTime(UINT32 ulTime)
{
// Only do this if either we aren't resolved
if (!m_bTimeIsResolved && m_type == SmilTimeMediaMarker)
{
// Save our marker time
m_ulMarkerTime = ulTime;
// This time is an offset from the beginning
// of the media. We need to add this offset to
// any previously existing offset
m_lOffset += (INT32) ulTime;
// Convert ourselves to a syncbase and
// set the flag which will tell us that
// we used to be a media marker.
m_type = SmilTimeSyncBase;
m_bUsedToBeMediaMarker = TRUE;
// By definition we are an offset from the beginning
// of the media
m_position = SMILEventSourceBegin;
// Set the flag saying we are resolved
m_bTimeIsResolved = TRUE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -