00001 //media_timer.cpp,v 1.5 2006/03/14 06:14:24 jtc Exp 00002 /* 00003 * Copyright (c) 1995 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Computer Systems 00017 * Engineering Group at Lawrence Berkeley Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 */ 00034 00035 /* 00036 static const char rcsid[] = 00037 "@(#) /project/cvs-repository/ACE_wrappers-repository/TAO/orbsvcs/orbsvcs/AV/media_timer.cpp,v 1.5 2006/03/14 06:14:24 jtc Exp"; 00038 */ 00039 00040 #include "orbsvcs/AV/media_timer.h" 00041 #include "ace/Time_Value.h" 00042 #include "ace/OS_NS_sys_time.h" 00043 #include "ace/OS_NS_stdlib.h" 00044 00045 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00046 00047 MediaTimer* MediaTimer::instance_; 00048 00049 MediaTimer::MediaTimer() 00050 { 00051 instance_ = this; 00052 offset_ = ACE_OS::rand (); 00053 } 00054 00055 MediaTimer::~MediaTimer() 00056 { 00057 instance_ = 0; 00058 } 00059 00060 /* 00061 * Default media timestamp -- convert unix system clock 00062 * into a 90Khz timestamp. Grabbers override this virtual 00063 * method if they can provide their own time base. 00064 * 00065 * XXX 00066 * We save the corresponding unix time stamp to handle the 00067 * unix_ts() call the transmitter will make to get the correspondence 00068 * between the media timestamp & unix time. 00069 */ 00070 ACE_UINT32 MediaTimer::media_ts() 00071 { 00072 //timeval tv; 00073 ACE_Time_Value tv = ACE_OS::gettimeofday(); 00074 ACE_UINT32 u = tv.usec (); 00075 u = (u << 3) + u; /* x 9 */ 00076 /* sec * 90Khz + (usec * 90Khz) / 1e6 */ 00077 u = tv.sec () * 90000 + (u / 100); 00078 return (u + offset_); 00079 } 00080 00081 /* 00082 * compute media time corresponding to the current unix time. 00083 * in this generic routine, this is the same as media_ts() but, 00084 * if a grabber has hardware or kernel timestamping, this routine 00085 * must compute the correspondence between the hardware timestamp 00086 * and the unix clock and appropriately offset the timestamp to 00087 * correspond to the current clock. (This information if vital 00088 * for cross-media synchronization.) 00089 */ 00090 ACE_UINT32 MediaTimer::ref_ts() 00091 { 00092 return (media_ts()); 00093 } 00094 00095 TAO_END_VERSIONED_NAMESPACE_DECL