📄 smlprstime.cpp
字号:
} time_t thisTime = mktime(&ourtime); double diff = 0.0; if (m_bRelativeToUTC) {//XXXJHUG need a crossplatform way to get the timezone offset.#ifdef _WIN32 diff = difftime(thisTime + _timezone, tRefTime + m_UTCOffsetMin);#else diff = difftime(thisTime, tRefTime + m_UTCOffsetMin);#endif } else { diff = difftime(thisTime, tRefTime); } double dDiffMS = diff * 1000.0; double dMaxDiff = (double) 0x7FFFFFFF; double dMinDiff = -dMaxDiff; // Clip at the min and max if (dDiffMS > dMaxDiff) { dDiffMS = dMaxDiff - 10; } else if (dDiffMS < dMinDiff) { dDiffMS = dMinDiff +10; } // Now convert to INT32 m_lOffset = (INT32) dDiffMS; m_lOriginalOffset = m_lOffset; } return ret;}HX_RESULTSmilTimeValue::parseOffset(const char* pCh){ HX_RESULT pnretval = HXR_OK; // eat whitespace while (*pCh && isspace(*pCh)) { ++pCh; } if (*pCh == '-') { // /Eat any whitespace following the '-' do { ++pCh; } while (*pCh && isspace(*pCh)); UINT32 clockTime = 0; pnretval = parseClockValue(pCh, clockTime); m_lOffset = -(INT32)clockTime; } else if (*pCh == '+') { // /Eat any whitespace following the '+' do { ++pCh; } while (*pCh && isspace(*pCh)); UINT32 clockTime = 0; pnretval = parseClockValue(pCh, clockTime); m_lOffset = (INT32)clockTime; } else { UINT32 clockTime = 0; pnretval = parseClockValue(pCh, clockTime); m_lOffset = (INT32)clockTime; } m_lOriginalOffset = m_lOffset; return pnretval;}HX_RESULTSmilTimeValue::parseClockValue(const char* pValue, UINT32& ulTimeValue){ if (!pValue || strlen(pValue) < 1) { return HXR_FAILED; } // try npt char* pPtr = (char *)strstr(pValue, "npt="); if(pPtr) { pPtr += 4; // point to beginning of clock value NPTime clockTime(pPtr); ulTimeValue = (UINT32)clockTime; return HXR_OK; } // try smpte pPtr = (char *)strstr(pValue, "smpte="); if(pPtr) { pPtr += 6; // point to beginning of clock value SMPTETimeCode clockTime(pPtr); ulTimeValue = (UINT32)clockTime; return HXR_OK; } pPtr = (char *)strstr(pValue, "smpte-30-drop="); if(pPtr) { pPtr += 14; // point to beginning of clock value SMPTETimeCode clockTime(pPtr); ulTimeValue = (UINT32)clockTime; return HXR_OK; } pPtr = (char *)strstr(pValue, "smpte-25="); if(pPtr) { pPtr += 9; // point to beginning of clock value SMPTETimeCode clockTime; clockTime.m_framesPerSec = SMPTETimeCode::FPS_25; clockTime.fromString(pPtr); ulTimeValue = (UINT32)clockTime; return HXR_OK; } else { BOOL bAllow_h_min_s_ms_units = TRUE; BOOL bSucceeded = FALSE; // /First, get rid of trailing spaces: UINT32 ulStrlen = (UINT32)strlen(pValue); char* pEnd = (char*)(&pValue[ulStrlen-1]); while (isspace(*pEnd) && pEnd>pValue) { pEnd--; } pEnd[1] = '\0'; // /This first tries just hh:mm:ss with no prefix/suffix // and then tries suffixes: {"h" | "min" | "s" | "ms"} with // the default (no ":" inside and no prefix or suffix) being // in seconds per the SMIL 1.0 spec ([SMIL 1.0 compliance] // Fixes PR 22673): NPTime clockTime(pValue, bAllow_h_min_s_ms_units, bSucceeded); if (bSucceeded) { ulTimeValue = (UINT32)clockTime; return HXR_OK; } } return HXR_FAIL;}HX_RESULTSmilTimeValue::parseEvent(const char* pBase, const char* pEvent, const char* pOffset){ HX_RESULT rslt = HXR_OK; m_type = SmilTimeEvent; UINT32 ulLen = 0; if (pBase) { ulLen = strlen(pBase); m_idRef = pBase; } if( !pEvent || !strlen(pEvent)) { // /XXXEH- not sure why we'd ever get this state so put assert here // to check it out: HX_ASSERT(pEvent && strlen(pEvent)); m_pEventName = NULL; rslt = HXR_UNEXPECTED; // /XXXEH- at least I *think* it's unexpected. } else { // /Handle "foo.\xyz" as meaning the "xyz" event that may have the // same name as a sync-arc, e.g., "foo.begin". Treat them as // events that get resolved when the m_idRef element (renderer) // fires off a an event with the matching name: if ('\\' == *pEvent && strlen(pEvent)>=2) { // /Add -1 for removing the '\', +1 for the terminating '\0': m_pEventName = new char[strlen(pEvent)-1 + 1]; if (m_pEventName) { strcpy(m_pEventName, &pEvent[1]); /* Flawfinder: ignore */ } else { rslt = HXR_OUTOFMEMORY; } } else { m_pEventName = new char[strlen(pEvent)+1]; if (m_pEventName) { strcpy(m_pEventName, pEvent); /* Flawfinder: ignore */ } else { rslt = HXR_OUTOFMEMORY; } } } if (SUCCEEDED(rslt) && pOffset && *pOffset) { parseOffset(pOffset); } return rslt;}HX_RESULTSmilTimeValue::parseSyncBase(const char* pBase, const char* pCommand, const char* pOffset){ m_type = SmilTimeSyncBase; UINT32 ulLen = strlen(pBase); if (pBase && pCommand) { m_idRef = pBase; } else { HX_ASSERT(FALSE); return HXR_FAIL; } BOOL bTimeValueOK = FALSE; BOOL bRepeatValueParsed = FALSE; if (strncmp(pCommand, "begin", 5) == 0) { m_position = SMILEventSourceBegin; bTimeValueOK = TRUE; } else if (strncmp(pCommand, "end", 3) == 0) { m_position = SMILEventSourceEnd; bTimeValueOK = TRUE; }#if defined(XXXEH_REPEAT_VALUE_TIMING_SHOULD_BE_EVENT_BASED)#else else if (strncmp(pCommand, "repeat(", 7) == 0) { bRepeatValueParsed = TRUE; INT32 strlenCommand = strlen(pCommand); if (strlenCommand >= 9 && ')' == pCommand[strlenCommand-1]) { m_position = SMILEventSourceBegin; char* pTmp = (char*)&pCommand[7]; // /Make sure that every character inside the () is a number: while (*pTmp && ')' != *pTmp && '0'<=*pTmp && '9'>=*pTmp) { pTmp++; } if (pTmp == (char*)&pCommand[strlenCommand-1]) { INT32 lNum = (INT32)atoi(&pCommand[7]); // /0 or negative repeat iterations are not allowed, even // though repeat(0) *could* have been interpreted as the // first play of foo (prior to it repeating), but wasn't: if (lNum > 0) { *pTmp = '\0'; m_idRef += "_repeat_copy_"; m_idRef += &pCommand[7]; *pTmp = ')'; // /restore it. m_uRepeatIteration = (UINT16)lNum; bTimeValueOK = TRUE; } } } }#endif if (!bTimeValueOK) { if (!bRepeatValueParsed) { HX_ASSERT(FALSE); } CSmilSMILSyntaxErrorHandler errHandler(m_pContext); errHandler.ReportError(SMILErrorBadTimeValue, pCommand, m_ulStartLine); return HXR_FAIL; } if (pOffset) { parseOffset(pOffset); } return HXR_OK;}HX_RESULT SmilTimeValue::parseMarker(const char* pBase, const char* pMarker, const char* pOffset){ HX_RESULT retVal = HXR_FAIL; if (pBase && pMarker) { // Set the type m_type = SmilTimeMediaMarker; // Set the base m_idRef = pBase; // Set the offset (if we have one) if (pOffset) { parseOffset(pOffset); } // Move past the "marker.(", which we already // checked for before we were called pMarker += 7; // Allocate space for our string HX_VECTOR_DELETE(m_pszMarkerName); m_pszMarkerName = new char [strlen(pMarker) + 1]; if (m_pszMarkerName) { // Look for the end of the marker name char* pEnd = (char *)strchr(pMarker, ')'); if (pEnd) { // Copy the full marker name - might or // might not contain an external file reference strncpy(m_pszMarkerName, pMarker, pEnd - pMarker); /* Flawfinder: ignore */ m_pszMarkerName[pEnd - pMarker] = '\0'; // Now parse to see if there is an external file reference CHXString cMarker; CHXString cExtFileName; BOOL bIsExternalMarker = m_bIsExternalMarker; retVal = CSmilParser::parseMarkerURI(m_pszMarkerName, cMarker, bIsExternalMarker, cExtFileName); m_bIsExternalMarker = bIsExternalMarker; if (SUCCEEDED(retVal) && m_bIsExternalMarker) { // Set the flag in the element that this // element references an external media marker file m_pElement->m_bUsesExternalMediaMarkerFile = TRUE; // We just need to copy the marker string and // the external file name string into our members HX_VECTOR_DELETE(m_pszExternalMarkerFileName); m_pszExternalMarkerFileName = new char [cExtFileName.GetLength() + 1]; if (m_pszExternalMarkerFileName) { strcpy(m_pszExternalMarkerFileName, (const char*) cExtFileName); /* Flawfinder: ignore */ HX_VECTOR_DELETE(m_pszExternalMarkerName); m_pszExternalMarkerName = new char [cMarker.GetLength() + 1]; if (m_pszExternalMarkerName) { strcpy(m_pszExternalMarkerName, (const char*) cMarker); /* Flawfinder: ignore */ } else { retVal = HXR_OUTOFMEMORY; } } else { retVal = HXR_OUTOFMEMORY; } } } } } if (FAILED(retVal)) { HX_ASSERT(FALSE); CSmilSMILSyntaxErrorHandler errHandler(m_pContext); errHandler.ReportError(SMILErrorBadTimeValue, pMarker, m_ulStartLine); } return retVal;}#if defined(ENABLE_SYNC_TO_PREV)HX_RESULTSmilTimeValue::parseSyncToPrev(REF(const char*) pCh){ HX_RESULT ret = HXR_OK; // move past "prev." pCh += 5; m_type = SmilTimeSyncToPrev; if (strncmp(pCh, "begin", 5) == 0) { m_position = SMILEventSourceBegin; pCh += 5; } else if (strncmp(pCh, "end", 3) == 0) { m_position = SMILEventSourceEnd; pCh += 3; } else { HX_ASSERT(FALSE); CSmilSMILSyntaxErrorHandler errHandler(m_pContext); errHandler.ReportError(SMILErrorBadTimeValue, pCh, m_ulStartLine); return HXR_FAIL; } // eat white space while (*pCh && isspace(*pCh)) { ++pCh; } if (*pCh == '+' || *pCh == '-') { ret = parseOffset(pCh); } return ret;}#endifHX_RESULTSmilTimeValue::parseWallClockValue(REF(const char*) pCh){ HX_RESULT ret = HXR_OK; m_type = SmilTimeWallclock; m_bTimeIsResolved = TRUE; // move past "wallclock(" pCh += 10; // eat whitespace. while (*pCh && isspace(*pCh)) { ++pCh; } // find the end ')' const char* begin = pCh; const char* end = NULL; const char* pT = NULL; const char* pTimeZone = NULL; const char* pTimePos = NULL; const char* pDatePos = NULL; INT32 year = -1; INT32 month = -1; INT32 day = -1; INT32 hour = 0; INT32 min = 0; INT32 sec = 0; INT32 ms = 0; char buf[10]; /* Flawfinder: ignore */ // store offset in min. INT32 UTCOffset = 0; while (*pCh) { if (*pCh == ')') { end = pCh; } else if (*pCh == 'T') { pT = pCh; } else if (isspace(*pCh) || *pCh == '+' || *pCh == '-' || *pCh == 'Z') { // this will find the last +, - or Z... which is what we want. pTimeZone = pCh; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -