⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtp.h

📁 mgcp协议源代码。支持多种编码:g711
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * rtp.h * * RTP protocol handler * * Open H323 Library * * Copyright (c) 1998-2000 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Open H323 Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions of this code were written with the assisance of funding from * Vovida Networks, Inc. http://www.vovida.com. * * Contributor(s): ______________________________________. * * $Log: rtp.h,v $ * Revision 1.22  2000/05/23 12:57:28  robertj * Added ability to change IP Type Of Service code from applications. * * Revision 1.21  2000/05/18 11:53:34  robertj * Changes to support doc++ documentation generation. * * Revision 1.20  2000/05/04 11:49:21  robertj * Added Packets Too Late statistics, requiring major rearrangement of jitter buffer code. * * Revision 1.19  2000/05/02 04:32:25  robertj * Fixed copyright notice comment. * * Revision 1.18  2000/05/01 01:01:24  robertj * Added flag for what to do with out of orer packets (use if jitter, don't if not). * * Revision 1.17  2000/04/30 03:55:18  robertj * Improved the RTCP messages, epecially reports * * Revision 1.16  2000/04/10 17:39:21  robertj * Fixed debug output of RTP payload types to allow for unknown numbers. * * Revision 1.15  2000/04/05 03:17:31  robertj * Added more RTP statistics gathering and H.245 round trip delay calculation. * * Revision 1.14  2000/03/23 02:55:18  robertj * Added sending of SDES control packets. * * Revision 1.13  2000/03/20 20:54:04  robertj * Fixed problem with being able to reopen for reading an RTP_Session (Cisco compatibilty) * * Revision 1.12  2000/02/29 13:00:13  robertj * Added extra statistic display for RTP packets out of order. * * Revision 1.11  1999/12/30 09:14:31  robertj * Changed payload type functions to use enum. * * Revision 1.10  1999/12/23 23:02:35  robertj * File reorganision for separating RTP from H.323 and creation of LID for VPB support. * * Revision 1.9  1999/11/20 05:35:57  robertj * Fixed possibly I/O block in RTP read loops. * * Revision 1.8  1999/11/19 09:17:15  robertj * Fixed problems with aycnhronous shut down of logical channels. * * Revision 1.7  1999/11/14 11:41:18  robertj * Added access functions to RTP statistics. * * Revision 1.6  1999/09/08 04:05:48  robertj * Added support for video capabilities & codec, still needs the actual codec itself! * * Revision 1.5  1999/08/31 12:34:18  robertj * Added gatekeeper support. * * Revision 1.4  1999/07/13 09:53:24  robertj * Fixed some problems with jitter buffer and added more debugging. * * Revision 1.3  1999/07/09 06:09:49  robertj * Major implementation. An ENORMOUS amount of stuff added everywhere. * * Revision 1.2  1999/06/22 13:49:40  robertj * Added GSM support and further RTP protocol enhancements. * * Revision 1.1  1999/06/14 06:12:25  robertj * Changes for using RTP sessions correctly in H323 Logical Channel context * */#ifndef __RTP_H#define __RTP_H#include <ptlib/sockets.h>class RTP_JitterBuffer;///////////////////////////////////////////////////////////////////////////////// Real Time Protocol - IETF RFC1889 and RFC1890/**An RTP data frame encapsulation.  */class RTP_DataFrame : public PBYTEArray{  PCLASSINFO(RTP_DataFrame, PBYTEArray);  public:    RTP_DataFrame(PINDEX payloadSize = 2048);    enum {      ProtocolVersion = 2,      MinHeaderSize = 12    };    enum PayloadTypes {      PCMU,      FS1016,      G721,      GSM,      G7231,      DVI4_8k,      DVI4_16k,      LPC,      PCMA,      G722,      L16_Stereo,      L16_Mono,      G723,      CN,      MPA,      G728,      DVI4_11k,      DVI4_22k,      G729,      CelB = 25,      JPEG,      H261 = 31,      MPV,      MP2T,      H263,      LastKnownPayloadType,      DynamicBase = 96,      MaxPayloadType = 127    };    unsigned GetVersion() const { return (theArray[0]>>6)&3; }    BOOL GetExtension() const   { return (theArray[0]&0x10) != 0; }    void SetExtension(BOOL ext);    BOOL GetMarker() const { return (theArray[1]&0x80) != 0; }    void SetMarker(BOOL m);    PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }    void         SetPayloadType(PayloadTypes t);    WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }    void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }    DWORD GetTimestamp() const  { return *(PUInt32b *)&theArray[4]; }    void  SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }    DWORD GetSyncSource() const  { return *(PUInt32b *)&theArray[8]; }    void  SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }    PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }    DWORD  GetContribSource(PINDEX idx) const;    void   SetContribSource(PINDEX idx, DWORD src);    PINDEX GetHeaderSize()     const { return 12 + 4*GetContribSrcCount(); }    PINDEX GetPayloadSize() const { return payloadSize; }    BOOL   SetPayloadSize(PINDEX sz);    BYTE * GetPayloadPtr()     const { return (BYTE *)(theArray+GetHeaderSize()); }  protected:    PINDEX payloadSize;#if PTRACING    friend ostream & operator<<(ostream & o, PayloadTypes t);#endif};/**An RTP control frame encapsulation.  */class RTP_ControlFrame : public PBYTEArray{  PCLASSINFO(RTP_ControlFrame, PBYTEArray);  public:    RTP_ControlFrame(PINDEX payloadSize = 2048);    unsigned GetVersion() const { return (BYTE)theArray[0]>>6; }    unsigned GetCount() const { return (BYTE)theArray[0]&0x1f; }    void     SetCount(unsigned count);    enum PayloadTypes {      e_SenderReport = 200,      e_ReceiverReport,      e_SourceDescription,      e_Goodbye,      e_ApplDefined    };    unsigned GetPayloadType() const { return (BYTE)theArray[1]; }    void     SetPayloadType(unsigned t);    PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[2]); }    void   SetPayloadSize(PINDEX sz);    BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+4); }#pragma pack(1)    struct ReceiverReport {      PUInt32b ssrc;      /* data source being reported */      BYTE fraction;      /* fraction lost since last SR/RR */      BYTE lost[3];	  /* cumulative number of packets lost (signed!) */      PUInt32b last_seq;  /* extended last sequence number received */      PUInt32b jitter;    /* interarrival jitter */      PUInt32b lsr;       /* last SR packet from this source */      PUInt32b dlsr;      /* delay since last SR packet */      unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }      void SetLostPackets(unsigned lost);    };    struct SenderReport {      PUInt32b ssrc;      /* source this RTCP packet refers to */      PUInt32b ntp_sec;   /* NTP timestamp */      PUInt32b ntp_frac;      PUInt32b rtp_ts;    /* RTP timestamp */      PUInt32b psent;     /* packets sent */      PUInt32b osent;     /* octets sent */     };    enum DescriptionTypes {      e_END,      e_CNAME,      e_NAME,      e_EMAIL,      e_PHONE,      e_LOC,      e_TOOL,      e_NOTE,      e_PRIV,      NumDescriptionTypes    };    struct SourceDescription {      PUInt32b src;       /* first SSRC/CSRC */      struct Item {        BYTE type;        /* type of SDES item (enum DescriptionTypes) */        BYTE length;      /* length of SDES item (in octets) */        char data[1];     /* text, not zero-terminated */        const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }        Item * GetNextItem() { return (Item *)((char *)this + length + 2); }      } item[1];          /* list of SDES items */    };    SourceDescription & AddSourceDescription(      DWORD src   /// SSRC/CSRC identifier    );    SourceDescription::Item & AddSourceDescriptionItem(      SourceDescription & sdes, /// SDES record to add item to      unsigned type,            /// Description type      const PString & data      /// Data for description    );#pragma pack()};class RTP_Session;/**This class is the base for user data that may be attached to the RTP_session   allowing callbacks for statistics and progress monitoring to be passed to an   arbitrary object that an RTP consumer may require.  */class RTP_UserData : public PObject{  PCLASSINFO(RTP_UserData, PObject);  public:    /**Callback from the RTP session for transmit statistics monitoring.       This is called every RTP_Session::senderReportInterval packets on the       transmitter indicating that the statistics have been updated.       The default behaviour does nothing.      */    virtual void OnTxStatistics(      const RTP_Session & session   /// Session with statistics    ) const;    /**Callback from the RTP session for receive statistics monitoring.       This is called every RTP_Session::receiverReportInterval packets on the       receiver indicating that the statistics have been updated.       The default behaviour does nothing.      */    virtual void OnRxStatistics(      const RTP_Session & session   /// Session with statistics    ) const;};/**This class is for encpsulating the IETF Real Time Protocol interface. */class RTP_Session : public PObject{  PCLASSINFO(RTP_Session, PObject);  public:    enum {      DefaultAudioSessionID = 1,      DefaultVideoSessionID = 2    };  /**@name Construction */  //@{    /**Create a new RTP session.     */    RTP_Session(      unsigned id,                    /// Session ID for RTP channel      RTP_UserData * userData = NULL  /// Optional data for session.    );    /**Delete a session.       This deletes the userData field.     */    ~RTP_Session();  //@}  /**@name Operations */  //@{    /**Sets the size of the jitter buffer to be used by this RTP session.       A session default to not having any jitter buffer enabled for reading       and the ReadBufferedData() function simply calls ReadData(). Once a       jitter buffer has been created it cannot be removed, though its size       may be adjusted. The jitterDelay must thus always be greater than zero.      */    void SetJitterBufferSize(      unsigned jitterDelay    /// Total jitter buffer delay in milliseconds    );    /**Read a data frame from the RTP channel.       This function will conditionally read data from eth jitter buffer or       directly if there is no jitter buffer enabled. An application should       generally use this in preference to directly calling ReadData().      */    BOOL ReadBufferedData(      DWORD timestamp,        /// Timestamp to read from buffer.      RTP_DataFrame & frame   /// Frame read from the RTP session    );    /**Read a data frame from the RTP channel.       Any control frames received are dispatched to callbacks and are not       returned by this function. It will block until a data frame is       available or an error occurs.      */    virtual BOOL ReadData(      RTP_DataFrame & frame   /// Frame read from the RTP session    ) = 0;    /**Write a data frame from the RTP channel.      */    virtual BOOL WriteData(      RTP_DataFrame & frame   /// Frame to write to the RTP session    ) = 0;    /**Write a control frame from the RTP channel.      */    virtual BOOL WriteControl(      RTP_ControlFrame & frame    /// Frame to write to the RTP session    ) = 0;    /**Close down the RTP session.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -