DurationStatistic.hxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:5k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. #if !defined(DURATION_STATISTIC_DOT_HXX)
  2. #define DURATION_STATISTIC_DOT_HXX
  3. /* ====================================================================
  4.  * The Vovida Software License, Version 1.0 
  5.  * 
  6.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  7.  * 
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in
  17.  *    the documentation and/or other materials provided with the
  18.  *    distribution.
  19.  * 
  20.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  21.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  22.  *    not be used to endorse or promote products derived from this
  23.  *    software without prior written permission. For written
  24.  *    permission, please contact vocal@vovida.org.
  25.  *
  26.  * 4. Products derived from this software may not be called "VOCAL", nor
  27.  *    may "VOCAL" appear in their name, without prior written
  28.  *    permission of Vovida Networks, Inc.
  29.  * 
  30.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  31.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  33.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  34.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  35.  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  36.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  37.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  41.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  42.  * DAMAGE.
  43.  * 
  44.  * ====================================================================
  45.  * 
  46.  * This software consists of voluntary contributions made by Vovida
  47.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  48.  * Inc.  For more information on Vovida Networks, Inc., please see
  49.  * <http://www.vovida.org/>.
  50.  *
  51.  */
  52. static const char* const DurationStatistic_hxx_Version = 
  53.     "$Id: DurationStatistic.hxx,v 1.2 2001/01/26 23:32:07 icahoon Exp $";
  54. #include "Statistic.hxx"
  55. #include "Duration.hxx"
  56. /** Infrastructure common to VOCAL.<br><br>
  57.  */
  58. namespace Vocal 
  59. {
  60. /** Infrastructure in VOCAL to measuring, recording and reporting
  61.  *  statistics.<br><br>
  62.  */
  63. namespace Statistics
  64. {
  65. /** One or more duration statistics.<br><br>
  66.  */
  67. class DurationStatistic : public Vocal::Statistics::Statistic
  68. {
  69.     public:
  70. /** Create the statistic given the associated database,
  71.  *  the label and the optional window width. The window width
  72.  *  default to 0 indicating no window, thus it remembers all
  73.  *  combined durations. 
  74.  */
  75. DurationStatistic(StatisticsDb  &   db, 
  76.             const Data  &   name, 
  77.   u_int32_t      window = 0);
  78. /** Copy constructor.
  79.  */
  80. DurationStatistic(const DurationStatistic &);
  81. /** Assignment operator.
  82.  */
  83. const DurationStatistic & operator=(const DurationStatistic &);
  84. /** Virtual destructor.
  85.  */
  86. virtual ~DurationStatistic();
  87.     
  88. /** This will combine the two statistics, chaining them together.
  89.  *  If a window set and this addition exceeds the window size, the 
  90.  *  oldest list element will be removed from the list.
  91.       */
  92. virtual void combine(const Statistic &);
  93.      /** Create a copy of this statistic.
  94.       */
  95. virtual Statistic *  copy() const;
  96. /** Start measuring the duration. If this is a combined statistic,
  97.  *  it will be cleared first.
  98.  */
  99. void start();
  100. /** Stop measuring the duration.
  101.  */
  102. void stop();
  103. /** Return the next statistic or 0 if this is the last statistic.
  104.  */
  105. DurationStatistic *  next() const;
  106.      /** Return the number of statistics.
  107.  */
  108.      u_int32_t   size() const;
  109. /** Return the window size or 0 if there is no window.
  110.  */
  111. u_int32_t   window() const;
  112. /** Returns the combined length of all durations.
  113.  */
  114. int64_t length() const;
  115. /** The length divided by the size.
  116.  */
  117. double average() const;
  118. /** Write the statistic to an ostream.
  119.  */
  120.         virtual ostream &   writeTo(ostream &) const;
  121.  
  122.     private:
  123.     
  124.      /*  Copy constructor used by append. Copies only the first element
  125.  *  from a combination statistic, creating an individual statistic.
  126.  */
  127. DurationStatistic(const Statistic &, const Duration  &, u_int32_t);
  128. /* Append a list to the end.
  129.  */
  130. void append(const DurationStatistic &);
  131. /* Pop from the front as needed.
  132.  */
  133. void pop();
  134. /* Clears list.
  135.  */
  136. void clear();
  137.     
  138.      Duration             m_duration;
  139.      DurationStatistic    *   m_next;
  140.      DurationStatistic    *   m_last;
  141.      u_int32_t             m_window;
  142. u_int32_t             m_size;
  143. int64_t               m_length;
  144. };
  145. inline void
  146. DurationStatistic::start()
  147. {
  148.     clear();
  149.     m_duration.start();
  150. }
  151. inline void
  152. DurationStatistic::stop()
  153. {
  154.     m_duration.stop();
  155.     m_length = m_duration.length();
  156. }
  157. } // namespace Statistics
  158. } // namespace Vocal 
  159. #endif // !defined(DURATION_STATISTIC_DOT_HXX)