LCOV - code coverage report
Current view: directory - content/media - VideoUtils.h (source / functions) Found Hit Coverage
Test: app.info Lines: 9 0 0.0 %
Date: 2012-06-02 Functions: 2 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: ML 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *  Chris Pearce <chris@pearce.org.nz>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef VideoUtils_h
      40                 : #define VideoUtils_h
      41                 : 
      42                 : #include "mozilla/ReentrantMonitor.h"
      43                 : 
      44                 : #include "nsRect.h"
      45                 : #include "nsIThreadManager.h"
      46                 : 
      47                 : #include "CheckedInt.h"
      48                 : 
      49                 : using mozilla::CheckedInt64;
      50                 : using mozilla::CheckedUint64;
      51                 : using mozilla::CheckedInt32;
      52                 : using mozilla::CheckedUint32;
      53                 : 
      54                 : // This file contains stuff we'd rather put elsewhere, but which is
      55                 : // dependent on other changes which we don't want to wait for. We plan to
      56                 : // remove this file in the near future.
      57                 : 
      58                 : 
      59                 : // This belongs in xpcom/monitor/Monitor.h, once we've made
      60                 : // mozilla::Monitor non-reentrant.
      61                 : namespace mozilla {
      62                 : 
      63                 : /**
      64                 :  * ReentrantMonitorAutoExit
      65                 :  * Exit the ReentrantMonitor when it enters scope, and enters it when it leaves 
      66                 :  * scope.
      67                 :  *
      68                 :  * MUCH PREFERRED to bare calls to ReentrantMonitor.Exit and Enter.
      69                 :  */ 
      70                 : class NS_STACK_CLASS ReentrantMonitorAutoExit
      71                 : {
      72                 : public:
      73                 :     /**
      74                 :      * Constructor
      75                 :      * The constructor releases the given lock.  The destructor
      76                 :      * acquires the lock. The lock must be held before constructing
      77                 :      * this object!
      78                 :      * 
      79                 :      * @param aReentrantMonitor A valid mozilla::ReentrantMonitor*. It
      80                 :      *                 must be already locked.
      81                 :      **/
      82               0 :     ReentrantMonitorAutoExit(ReentrantMonitor& aReentrantMonitor) :
      83               0 :         mReentrantMonitor(&aReentrantMonitor)
      84                 :     {
      85               0 :         NS_ASSERTION(mReentrantMonitor, "null monitor");
      86               0 :         mReentrantMonitor->AssertCurrentThreadIn();
      87               0 :         mReentrantMonitor->Exit();
      88               0 :     }
      89                 :     
      90               0 :     ~ReentrantMonitorAutoExit(void)
      91                 :     {
      92               0 :         mReentrantMonitor->Enter();
      93               0 :     }
      94                 :  
      95                 : private:
      96                 :     ReentrantMonitorAutoExit();
      97                 :     ReentrantMonitorAutoExit(const ReentrantMonitorAutoExit&);
      98                 :     ReentrantMonitorAutoExit& operator =(const ReentrantMonitorAutoExit&);
      99                 :     static void* operator new(size_t) CPP_THROW_NEW;
     100                 :     static void operator delete(void*);
     101                 : 
     102                 :     ReentrantMonitor* mReentrantMonitor;
     103                 : };
     104                 : 
     105                 : } // namespace mozilla
     106                 : 
     107                 : // Converts from number of audio frames (aFrames) to microseconds, given
     108                 : // the specified audio rate (aRate). Stores result in aOutUsecs. Returns true
     109                 : // if the operation succeeded, or false if there was an integer overflow
     110                 : // while calulating the conversion.
     111                 : CheckedInt64 FramesToUsecs(PRInt64 aFrames, PRUint32 aRate);
     112                 : 
     113                 : // Converts from microseconds (aUsecs) to number of audio frames, given the
     114                 : // specified audio rate (aRate). Stores the result in aOutFrames. Returns
     115                 : // true if the operation succeeded, or false if there was an integer
     116                 : // overflow while calulating the conversion.
     117                 : CheckedInt64 UsecsToFrames(PRInt64 aUsecs, PRUint32 aRate);
     118                 : 
     119                 : // Number of microseconds per second. 1e6.
     120                 : static const PRInt64 USECS_PER_S = 1000000;
     121                 : 
     122                 : // Number of microseconds per millisecond.
     123                 : static const PRInt64 USECS_PER_MS = 1000;
     124                 : 
     125                 : // The maximum height and width of the video. Used for
     126                 : // sanitizing the memory allocation of the RGB buffer.
     127                 : // The maximum resolution we anticipate encountering in the
     128                 : // wild is 2160p - 3840x2160 pixels.
     129                 : static const PRInt32 MAX_VIDEO_WIDTH = 4000;
     130                 : static const PRInt32 MAX_VIDEO_HEIGHT = 3000;
     131                 : 
     132                 : // Scales the display rect aDisplay by aspect ratio aAspectRatio.
     133                 : // Note that aDisplay must be validated by nsVideoInfo::ValidateVideoRegion()
     134                 : // before being used!
     135                 : void ScaleDisplayByAspectRatio(nsIntSize& aDisplay, float aAspectRatio);
     136                 : 
     137                 : // The amount of virtual memory reserved for thread stacks.
     138                 : #if defined(XP_WIN) || defined(XP_MACOSX) || defined(LINUX)
     139                 : #define MEDIA_THREAD_STACK_SIZE (128 * 1024)
     140                 : #else
     141                 : // All other platforms use their system defaults.
     142                 : #define MEDIA_THREAD_STACK_SIZE nsIThreadManager::DEFAULT_STACK_SIZE
     143                 : #endif
     144                 : 
     145                 : #endif

Generated by: LCOV version 1.7