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

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. #ifndef RtspFile_HXX
  2. #define RtspFile_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 281421,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 RtspFile_hxx_version =
  53.     "$Id: RtspFile.hxx,v 1.14 2001/05/15 20:26:08 bko Exp $";
  54. #include "cpLog.h"
  55. #include "Data.hxx"
  56. #include "Rtp.hxx"
  57. #include "RtspSdp.hxx"
  58. #include "RtspConfiguration.hxx"
  59. /** Rtsp file modes.
  60.  */
  61. enum RtspFileMode
  62. {
  63.     RTSP_FILE_MODE_PLAY,
  64.     RTSP_FILE_MODE_REC,
  65.     RTSP_FILE_MODE_UNKNOWN
  66. };
  67. /** Base class for all the file types ( *.au, *.wav, *.raw, *.rtp ).
  68.     Handles reading and writing to audio file and audio header.
  69.  */
  70. class RtspFile
  71. {
  72.     public:
  73.         /** constructor
  74.             @param shortFilename rtsp based filename of audio file
  75.          */
  76.         RtspFile( const string& shortFilename )
  77.             { myShortFilename = shortFilename; }
  78.         /** deconstructor */
  79.         virtual ~RtspFile() {};
  80.         /** Save sdp block into audio header.
  81.             Child class either uses <code>ftIndex</code> or
  82.             <code>rtspSdp</code> to determine correct header to write.  
  83.             Overwrite any existing header information.
  84.             @param ftIndex new codec parameters indexed base on RtpFileTypes 
  85.             @param rtspSdp sdp block to write into sdp file (if configured)
  86.          */
  87.         virtual bool saveHeader( const int ftIndex, RtspSdp& rtspSdp ) = 0;
  88.         /** Load audio header codec information.
  89.             @param ftIndex return param of new codec index
  90.             @param lenghtInMs return param of file length in milliseconds.
  91.             @return false on failure (ie can't open audio header or fail to
  92.                 read audio header)
  93.          */
  94.         virtual bool loadHeader( int* ftIndex, int* lengthInMs ) = 0;
  95.         /** Opens audio file for reading or writing.
  96.             @param bReadWrite <code>true</code> for write;
  97.                               <code>false</code> for reading
  98.             @param ftIndex codec index of audio file.
  99.                            Value obtainable from loadHeader().
  100.             @return false on failure (ie can't find audio file)
  101.          */
  102.         virtual bool open( bool bReadWrite, int ftIndex ) = 0;
  103.         /** Close audio file and updates audio header.
  104.             @return false on failure. (ie file not open)
  105.          */
  106.         virtual bool close() = 0;
  107.         /** Read from audio file.
  108.             @param data return param preallocationed memory location for 
  109.                         new data
  110.             @param max size of preallocationed memory location in bytes
  111.             @param pSeqNum rtp sequence number of new data
  112.             @param pTs rtp time stamp of new data
  113.             @return bytes of new data read
  114.          */
  115.         virtual int read( void* data, int max,
  116.                           unsigned short* pSeqNum, unsigned int* pTS ) = 0;        
  117.         /** Write to audio file.
  118.             @param data new data to write 
  119.             @param max size of new data in bytes
  120.             @param uSeqNum rtp sequence number of new data
  121.             @param uTs rtp time stamp of new data
  122.             @return bytes of new data written
  123.          */
  124.         virtual int write( void* data, int max,
  125.                            unsigned short uSeqNum = 0,
  126.                            unsigned int uTS = 0 ) = 0;
  127.         /** Seek read/write pointer into file.
  128.             @param seekToMs new read/write pointer location
  129.             @param whence relative seek
  130.                           [<code>SEEK_SET</code>|<code>SEEK_CUR</code>]
  131.             @return actual read/write pointer location in milliseconds
  132.          */
  133.         virtual long seek( const long seekToMs, const int whence ) = 0;
  134.         /** File extension string.
  135.             @return file extension (ie "*.au")
  136.          */
  137.         virtual string fileExtensionString() const = 0;
  138.         /** Filename string.  Used for rtsp messages.
  139.             @return file name with rtsp file path and extension.
  140.                     (ie "/samples/foo.au")
  141.          */
  142.         Data filename() const
  143.             {
  144.                 Data result = myShortFilename;
  145.                 result += fileExtensionString();
  146.                 return result;
  147.             }
  148.         /** Local filename string.  Used for local file access.
  149.             @return filename with local file path and extension.
  150.                     (ie "/usr/local/sounds/foo.au")
  151.          */
  152.         Data localFilename() const
  153.             {
  154.                 Data result = RtspConfiguration::instance().audioDirectory;
  155.                 if( result.length() )
  156.                 {
  157.                     result += "/";
  158.                 }
  159.                 result += filename();
  160.                 return result;
  161.             }
  162.         /** Filename sting only.  Used for printing or debug messages.
  163.             @return filename without extension
  164.                     (ie "foo")
  165.          */
  166.         const string& shortFilename()
  167.             { return myShortFilename; }
  168.     public:
  169.         /** Writes rtspSdp to *.sdp file.
  170.             @param rtspSdp sdp block
  171.             @return false on failure
  172.          */
  173.         bool writeSdpFile( RtspSdp& rtspSdp );
  174.         /** Reads rtspSdp from *.sdp file.
  175.             @param rtspSdp return param of sdp block
  176.             @return false on failure
  177.          */
  178.         bool readSdpFile( RtspSdp& rtspSdp );
  179.         /** Append data to *.sdp file.  Data should end with "n".
  180.             @param data new line to be writen to file
  181.             @param len length of new data
  182.             @return false on failure
  183.          */
  184.         bool appendSdpFile( const char* data, const int len );
  185.         /** Delete line from *.sdp file.  (TODO function not completed!)
  186.             @param data beginning of which line to delete (null terminated)
  187.             @return false on failure (ie can't match line)
  188.          */
  189.         bool deleteLineSdpFile( const char* data );
  190.     protected:
  191.         /** filename only (stripped of codec string and file extension) */
  192.         string myShortFilename;
  193.         /** play/rec/unknown file modes */
  194.         RtspFileMode myFileMode;
  195.         /** codec parameters of audio file (index based on RtpFileTypes) */
  196.         int myFtIndex;
  197.         /** Updates sdp file with new audio length.
  198.             Called while closing audio file. */
  199.         void updateSdpFileRange();
  200.     private:
  201.         /** suppress copy constructor */
  202.         RtspFile( const RtspFile& rhs );
  203.         /** suppress assignment operator */
  204.         RtspFile& operator=( const RtspFile& rhs );
  205. };
  206. /* Local Variables: */
  207. /* c-file-style: "stroustrup" */
  208. /* indent-tabs-mode: nil */
  209. /* c-file-offsets: ((access-label . -) (inclass . ++)) */
  210. /* c-basic-offset: 4 */
  211. /* End: */
  212. #endif