[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-server-cvs
Subject:    [Server-cvs] common/util/pub tscalc.h,NONE,1.1.2.1
From:       jgordon () helixcommunity ! org
Date:       2008-10-23 18:51:52
Message-ID: 200810231858.m9NIwS1w031140 () mailer ! progressive-comp ! com
[Download RAW message or body]

Update of /cvsroot/server/common/util/pub
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv29684/pub

Added Files:
      Tag: SERVER_12_0
	tscalc.h 
Log Message:
Synopsis
========
Fixes PR 227668
Fixes numerous issues that are screwing up sync on switches of
live RTP streams

Branches: SERVER_12_0
Reviewer: jzeng


Description
===========
Many areas were having issues with timestamp rollover on
calculation and comparisons. These are fixed to handle rollover.

There were issues with comparisons/calculations using the delivery
timestamp in RTP live where it needs to use the RTP timestamp.

There can be rollover issues with using the TimestampConverter for
certain things, like comparisons between two different RTP streams.
Also this loses precision with conversion to ms. These are changed
to use precise conversion to Timeval, etc.

Timeval did not work correctly with negative values.

NTPTime has no conversion to usable units more precise than ms.
ToTimeval added. Note: There is some weirdness with the pre-existing
FromTimeval that is a little awkward here and needs thought for HEAD.

The comparisons that skip out of order late packets after a switch
on live for RM were causing many RTP live packets to be incorrectly
skipped due to different timestamps etc. This check is now skipped
for RTP live streams and the ingress seq number checked. Only the
first 10 packets after a switch are checked now, to avoid inappropriate
skipping after we get halfway through the seq-no space!


RTP live streams were being synced to the time of the earliest SR
report. It instead needs to be sync'ed to the first packet of the
audio stream, with the SRs times used to determine offsets between
the two streams, etc. This is a major issue for RTP live because the
encoder's RTCP time line tends to be a few seconds off from the RTP
streams. So take NTP diffs between the SRs (signed) PLUS diff between
sync packet RTP time and sync stream SR RTP time (rolled over and
converted - signed), need to be added to the stream's SR RTP time
(converted) then converted back.

We have to make sure that the earliest packet we send is the last audio
packet before the next video key frame. Also, we need to make sure that
earliest packet is sent first, regardless what order our GetPackets came
in, etc.

TODO:
Much of this is hacked in and needs to be moved for 12.1+. A large
portion of the stuff this adds to RTP live FCS needs to be moved to
qtbcplin RTP live general (and much of that will also be needed for
LRA); and a lot of this stuff that is in RTP live FCS should be in more
general FCS.


Files Affected
==============
common/util/pub/ntptime.h
common/util/pub/timeval.h
server/include/sink.h
server/common/util/pub/tscalc.h[new]
server/engine/inputsource/Umakefil
server/engine/inputsource/base_shim.cpp
server/engine/inputsource/live_source_wrapper.cpp
server/engine/inputsource/pub/base_shim.h
server/engine/inputsource/pub/live_source_wrapper.h


Testing Performed
=================
Integration Tests:
* Verified RTP live plays and maintains reasonable A/V sync with
Microcore player after 20 switches
* Verified on-demand 3gp switching still works as expected
* Verified on-demand RM switching
* Verified RM live switching

Leak Tests:
* PENDING: --lct with switch request

Platforms Tested: linux-rhel4-i686
Build verified: linux-rhel4-i686, sunos-5.10-sparc-server, win32-i386-vc7



--- NEW FILE: tscalc.h ---
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: tscalc.h,v 1.1.2.1 2008/10/23 18:51:50 jgordon Exp $ 
 *
 * Portions Copyright (c) 1995-2007 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.
 *
 * 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 "timeval.h"

/* 
 * DiffTimeStamp
 * Given 2 32-bit unsigned timestamps with unknown order
 * Returns 32-bit signed PTS1 - PTS2, accounting for rollover
 * So return > 0 => ulPTS1 is later, return  < 0 => ulPTS2 is later, 
 * return == 0 => timestamps are identical 
 * e.g. DiffTimeStamp(0x100, 0xFD) == 2; DiffTimeStamp(98, 100) == -2
 * DiffTimeStamp(1, 0xFFFFFFFF) == 2; DiffTimeStamp(0xFFFFFFFF, 1) == -2
 */
inline INT32
DiffTimeStamp(UINT32 ulPTS1, UINT32 ulPTS2)
{
    // Exploit rollover and unsigned->signed cast for efficient
    // computation
    return (INT32)(ulPTS1 - ulPTS2);
}

/*
 * ConvertToTimestamp
 * Given a Timeval and RTP timestamp frequency
 * Returns the time as a 32-bit RTP timestamp
 */
inline UINT32
ConvertToTimestamp(Timeval& tv, INT32 lFrequency)
{
    INT64 llTmp = (INT64)tv.tv_sec * lFrequency;
    llTmp += ((INT64)lFrequency * tv.tv_usec + 500000) / 1000000;

    // and exploit the typecast to handle rollover/negative rollover 
    return (UINT32)llTmp;
}

/*
 * DiffRTPSeqNo
 * Given 2 16-bit unsigned RTP sequence numbers with unknown order
 * Returns 16-bit signed SN1 - SN22, accounting for rollover
 *
 * Do not use for RDT sequence numbers! The rollover interval is
 * is different.
 */
inline INT16
DiffRTPSeqNo(UINT16 unSN1, UINT16 unSN2)
{
    // Exploit rollover and unsigned->signed cast for efficient
    // computation
    // UINT16 rollover cast to signed INT16 will account for RTP
    // sequence number rollover.
    return (INT16)(unSN1 - unSN2);
}


_______________________________________________
Server-cvs mailing list
Server-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/server-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic