LCOV - code coverage report
Current view: directory - content/media - nsAudioStream.h (source / functions) Found Hit Coverage
Test: app.info Lines: 3 0 0.0 %
Date: 2012-06-02 Functions: 1 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: MPL 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 Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2007
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *  Chris Double <chris.double@double.co.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                 : #if !defined(nsAudioStream_h_)
      39                 : #define nsAudioStream_h_
      40                 : 
      41                 : #include "nscore.h"
      42                 : #include "nsISupportsImpl.h"
      43                 : #include "nsIThread.h"
      44                 : #include "nsAutoPtr.h"
      45                 : 
      46                 : class nsAudioStream : public nsISupports
      47                 : {
      48                 : public:
      49                 : 
      50                 :   enum SampleFormat
      51                 :   {
      52                 :     FORMAT_U8,
      53                 :     FORMAT_S16_LE,
      54                 :     FORMAT_FLOAT32
      55                 :   };
      56                 : 
      57               0 :   nsAudioStream()
      58                 :     : mRate(0),
      59                 :       mChannels(0),
      60               0 :       mFormat(FORMAT_S16_LE)
      61               0 :   {}
      62                 : 
      63                 :   virtual ~nsAudioStream();
      64                 : 
      65                 :   // Initialize Audio Library. Some Audio backends require initializing the
      66                 :   // library before using it.
      67                 :   static void InitLibrary();
      68                 : 
      69                 :   // Shutdown Audio Library. Some Audio backends require shutting down the
      70                 :   // library after using it.
      71                 :   static void ShutdownLibrary();
      72                 : 
      73                 :   // Thread that is shared between audio streams.
      74                 :   // This may return null in the child process
      75                 :   nsIThread *GetThread();
      76                 : 
      77                 :   // AllocateStream will return either a local stream or a remoted stream
      78                 :   // depending on where you call it from.  If you call this from a child process,
      79                 :   // you may receive an implementation which forwards to a compositing process.
      80                 :   static nsAudioStream* AllocateStream();
      81                 : 
      82                 :   // Initialize the audio stream. aNumChannels is the number of audio
      83                 :   // channels (1 for mono, 2 for stereo, etc) and aRate is the sample rate
      84                 :   // (22050Hz, 44100Hz, etc).
      85                 :   // Unsafe to call with the decoder monitor held.
      86                 :   virtual nsresult Init(PRInt32 aNumChannels, PRInt32 aRate, SampleFormat aFormat) = 0;
      87                 : 
      88                 :   // Closes the stream. All future use of the stream is an error.
      89                 :   // Unsafe to call with the decoder monitor held.
      90                 :   virtual void Shutdown() = 0;
      91                 : 
      92                 :   // Write audio data to the audio hardware.  aBuf is an array of frames in
      93                 :   // the format specified by mFormat of length aCount.  If aFrames is larger
      94                 :   // than the result of Available(), the write will block until sufficient
      95                 :   // buffer space is available.
      96                 :   virtual nsresult Write(const void* aBuf, PRUint32 aFrames) = 0;
      97                 : 
      98                 :   // Return the number of audio frames that can be written without blocking.
      99                 :   virtual PRUint32 Available() = 0;
     100                 : 
     101                 :   // Set the current volume of the audio playback. This is a value from
     102                 :   // 0 (meaning muted) to 1 (meaning full volume).
     103                 :   virtual void SetVolume(double aVolume) = 0;
     104                 : 
     105                 :   // Block until buffered audio data has been consumed.
     106                 :   // Unsafe to call with the decoder monitor held.
     107                 :   virtual void Drain() = 0;
     108                 : 
     109                 :   // Pause audio playback
     110                 :   virtual void Pause() = 0;
     111                 : 
     112                 :   // Resume audio playback
     113                 :   virtual void Resume() = 0;
     114                 : 
     115                 :   // Return the position in microseconds of the audio frame being played by
     116                 :   // the audio hardware.
     117                 :   virtual PRInt64 GetPosition() = 0;
     118                 : 
     119                 :   // Return the position, measured in audio frames played since the stream
     120                 :   // was opened, of the audio hardware.
     121                 :   virtual PRInt64 GetPositionInFrames() = 0;
     122                 : 
     123                 :   // Returns true when the audio stream is paused.
     124                 :   virtual bool IsPaused() = 0;
     125                 : 
     126                 :   // Returns the minimum number of audio frames which must be written before
     127                 :   // you can be sure that something will be played.
     128                 :   // Unsafe to call with the decoder monitor held.
     129                 :   virtual PRInt32 GetMinWriteSize() = 0;
     130                 : 
     131                 :   int GetRate() { return mRate; }
     132                 :   int GetChannels() { return mChannels; }
     133                 :   SampleFormat GetFormat() { return mFormat; }
     134                 : 
     135                 : protected:
     136                 :   nsCOMPtr<nsIThread> mAudioPlaybackThread;
     137                 :   int mRate;
     138                 :   int mChannels;
     139                 :   SampleFormat mFormat;
     140                 : };
     141                 : 
     142                 : #endif

Generated by: LCOV version 1.7