1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #include "time_comparison_utils.h" 20 #include "media_clock_converter.h" 21 22 23 OSCL_EXPORT_REF bool PVTimeComparisonUtils::IsEarlier(uint32 aTimeA, uint32 aTimeB, uint32& delta) 24 { 25 delta = aTimeB - aTimeA; 26 if (delta < WRAP_THRESHOLD) 27 return true; 28 delta = 0 - delta; 29 return false; 30 } 31 32 OSCL_EXPORT_REF PVTimeComparisonUtils::MediaTimeStatus PVTimeComparisonUtils::CheckTimeWindow(PVMFTimestamp aTimeStamp, uint32 aClock, 33 uint32 aEarlyMargin, uint32 aLateMargin, uint32 &aDelta) 34 { 35 bool flag = IsEarlier(aClock, aTimeStamp, aDelta); 36 37 if (0 == aDelta) 38 { 39 return MEDIA_ONTIME_WITHIN_WINDOW; 40 } 41 42 if (flag) 43 { 44 if (aDelta < aEarlyMargin) 45 return MEDIA_EARLY_WITHIN_WINDOW; 46 else 47 return MEDIA_EARLY_OUTSIDE_WINDOW; 48 } 49 else if (aDelta < aLateMargin) 50 { 51 return MEDIA_LATE_WITHIN_WINDOW; 52 } 53 54 return MEDIA_LATE_OUTSIDE_WINDOW; 55 } 56