packet.h
资源名称:h323.zip [点击查看]
上传用户:hnnddl
上传日期:2007-01-06
资源大小:3580k
文件大小:10k
源码类别:
IP电话/视频会议
开发平台:
WINDOWS
- /*
- * $Revision: 1.5 $
- * $Date: 1997/11/20 19:23:11 $
- */
- ////////////////////////////////////////////////////////////////
- // Copyright (c) 1996,97 Lucent Technologies //
- // All Rights Reserved //
- // //
- // THIS IS UNPUBLISHED //
- // PROPRIETARY SOURCE //
- // CODE OF Lucent Technologies //
- // AND elemedia //
- // //
- // The copyright notice above does not evidence any //
- // actual or intended publication of such source code//
- ////////////////////////////////////////////////////////////////
- //
- /////////////////////////////////////////////////////////////////
- // File : pkt.h //
- // //
- // This file declares RTPPacket and RTCPPacket classes //
- // //
- // //
- // History: //
- // 20_Jan_1997 Created //
- // 17_Feb_1997 //
- // 14_Feb_1997 Cosmetic changes to fn names and arg list. //
- // 01_May_1997 max_payload_length, max_datagram_length.. //
- // 08_Jul_1997 Merged Sun5 changes. //
- // 20_Aug_1997 Another Frame function in RTPPacket, for //
- // retransissions.. //
- // 04_Nov_1997 Updated the payload types for RTP //
- // 17_Nov_1997 Added 2 new variants of RTPPacket::Frame //
- // these methods allow the caller to supply //
- // the buffer, hence avoiding a copy operation. //
- // //
- /////////////////////////////////////////////////////////////////
- #if !defined(__PKT_H__)
- #define __PKT_H__
- #define MASK(BITS,SHIFT) (((1 << (BITS)) - 1) << (SHIFT))
- enum
- {
- RTP_VERSION_BITS = 2U,
- RTP_VERSION_SHIFT = 14U,
- RTP_VERSION_MASK = MASK(RTP_VERSION_BITS,RTP_VERSION_SHIFT),
- RTP_PADDING_BITS = 1U,
- RTP_PADDING_SHIFT = 13U,
- RTP_PADDING_MASK = MASK(RTP_PADDING_BITS,RTP_PADDING_SHIFT),
- RTP_EXTENSION_BITS = 1U,
- RTP_EXTENSION_SHIFT = 12U,
- RTP_EXTENSION_MASK = MASK(RTP_EXTENSION_BITS,RTP_EXTENSION_SHIFT),
- RTP_CC_BITS = 4U,
- RTP_CC_SHIFT = 8U,
- RTP_CC_MASK = MASK(RTP_CC_BITS,RTP_CC_SHIFT),
- RTP_MARKER_BITS = 1U,
- RTP_MARKER_SHIFT = 7U,
- RTP_MARKER_MASK = MASK(RTP_MARKER_BITS,RTP_MARKER_SHIFT),
- RTP_PT_BITS = 7U,
- RTP_PT_SHIFT = 0U,
- RTP_PT_MASK = MASK(RTP_PT_BITS,RTP_PT_SHIFT)
- };
- #define RTP_GET_VERSION(F) (((F) & RTP_VERSION_MASK) >> RTP_VERSION_SHIFT)
- #define RTP_GET_PADDING(F) (((F) & RTP_PADDING_MASK) >> RTP_PADDING_SHIFT)
- #define RTP_GET_CC(F) (((F) & RTP_CC_MASK) >> RTP_CC_SHIFT)
- #define RTP_GET_PT(F) (((F) & RTP_PT_MASK) >> RTP_PT_SHIFT)
- #define RTP_GET_EXTENSION(F) (((F) & RTP_EXTENSION_MASK) >>
- RTP_EXTENSION_SHIFT)
- #define RTP_GET_MARKER(F) (((F) & RTP_MARKER_MASK) >> RTP_MARKER_SHIFT)
- #define RTP_SET_VERSION(F,V)
- {
- (F) &= ~RTP_VERSION_MASK;
- (F) |= ((V) << RTP_VERSION_SHIFT)
- & RTP_VERSION_MASK;
- }
- #define RTP_SET_PADDING(F,P)
- {
- (F) &= ~RTP_PADDING_MASK;
- (F) |= ((P) << RTP_PADDING_SHIFT)
- & RTP_PADDING_MASK;
- }
- #define RTP_SET_EXTENSION(F,E)
- {
- (F) &= ~RTP_EXTENSION_MASK;
- (F) |= ((E) << RTP_EXTENSION_SHIFT)
- & RTP_EXTENSION_MASK;
- }
- #define RTP_SET_CC(F,COUNT)
- {
- (F) &= ~RTP_CC_MASK;
- (F) |= ((COUNT) << RTP_CC_SHIFT)
- & RTP_CC_MASK;
- }
- #define RTP_SET_MARKER(F,M)
- {
- (F) &= ~RTP_MARKER_MASK;
- (F) |= ((M) << RTP_MARKER_SHIFT)
- & RTP_MARKER_MASK;
- }
- #define RTP_SET_PT(F,PT)
- {
- (F) &= ~RTP_PT_MASK;
- (F) |= ((PT) << RTP_PT_SHIFT)
- & RTP_PT_MASK;
- }
- #define RTCP_GET_CUMULATIVE_LOSS(L)
- ((((unsigned long)L) & (unsigned long)0xFFFFFF00) >> 8)
- #define RTCP_GET_INCREMENTAL_LOSS(L) ((L) & 0xFF)
- enum
- {
- RTCP_VERSION_BITS = 2U,
- RTCP_VERSION_SHIFT = 14U,
- RTCP_VERSION_MASK = MASK(RTCP_VERSION_BITS,RTCP_VERSION_SHIFT),
- RTCP_PADDING_BITS = 1U,
- RTCP_PADDING_SHIFT = 13U,
- RTCP_PADDING_MASK = MASK(RTCP_PADDING_BITS,RTCP_PADDING_SHIFT),
- RTCP_CC_BITS = 5U,
- RTCP_CC_SHIFT = 8U,
- RTCP_CC_MASK = MASK(RTCP_CC_BITS,RTCP_CC_SHIFT),
- RTCP_PT_BITS = 8U,
- RTCP_PT_SHIFT = 0U,
- RTCP_PT_MASK = MASK(RTCP_PT_BITS,RTCP_PT_SHIFT)
- };
- #define RTCP_GET_VERSION(F)
- (((F) & RTCP_VERSION_MASK) >> RTCP_VERSION_SHIFT)
- #define RTCP_GET_PADDING(F)
- (((F) & RTCP_PADDING_MASK) >> RTCP_PADDING_SHIFT)
- #define RTCP_GET_COUNT(F)
- (((F) & RTCP_CC_MASK) >> RTCP_CC_SHIFT)
- #define RTCP_GET_PT(F)
- (((F) & RTCP_PT_MASK) >> RTCP_PT_SHIFT)
- #define RTCP_SET_VERSION(F,V)
- {
- (F) &= ~RTCP_VERSION_MASK;
- (F) |= ((V) << RTCP_VERSION_SHIFT)
- & RTCP_VERSION_MASK;
- }
- #define RTCP_SET_PADDING(F,P)
- {
- (F) &= ~RTCP_PADDING_MASK;
- (F) |= ((P) << RTCP_PADDING_SHIFT)
- & RTCP_PADDING_MASK;
- }
- #define RTCP_SET_COUNT(F,COUNT)
- {
- (F) &= ~RTCP_CC_MASK;
- (F) |= ((COUNT) << RTCP_CC_SHIFT)
- & RTCP_CC_MASK;
- }
- #define RTCP_SET_PT(F,PT)
- {
- (F) &= ~RTCP_PT_MASK;
- (F) |= ((PT) << RTCP_PT_SHIFT)
- & RTCP_PT_MASK;
- }
- #undef MASK
- class Logger;
- class DLLEXPORT RTCPPacket
- {
- public:
- friend class RTPSession;
- enum PayloadTypes
- {
- PT_SENDER_REPORT = 200,
- PT_RECEIVER_REPORT = 201,
- PT_SDES = 202,
- PT_BYE = 203,
- PT_APP = 204
- };
- enum SDESTypes
- {
- ST_CNAME = 1,
- ST_NAME = 2,
- ST_EMAIL = 3,
- ST_PHONE = 4,
- ST_LOC = 5,
- ST_TOOL = 6,
- ST_NOTE = 7,
- ST_PRIV = 8
- };
- RTCPPacket(RTPSession *session);
- ~RTCPPacket();
- void GetSenderInfo(RTCPSenderInfo *&sender_info);
- int GetReceptionReports(
- RTCPReceptionReport *&reception_report_list);
- // Get the raw bytes for an RTCP packet,
- // for sending out on the n/w.
- char *GetPacket();
- int GetPacketLength();
- unsigned int GetSSRC();
- ProtReturnCode Deframe(char *data, int length, unsigned int ntp_sec,
- unsigned int ntp_frac);
- ProtReturnCode Frame(unsigned int rtp_time, unsigned int ntp_sec,
- unsigned int ntp_frac, int extra_sdes,
- int bye, char *bye_reason, int length);
- protected:
- char *data;
- int length;
- // SSRC of the sender.
- unsigned int ssrc;
- // these are maintained in host byte order.
- RTCPSenderInfo *sender_info;
- RTCPReceptionReport *reception_reports;
- int rr_count;
- // The session to which this packet belongs
- RTPSession *session;
- private:
- Logger *_logger;
- };
- struct RTPHeader;
- //
- // The RTP packet class.
- //
- class DLLEXPORT RTPPacket
- {
- public:
- friend class RTPSession;
- // List of RTP payload types
- enum PayloadType
- {
- // Video encodings...
- // PT_RGB8 = 23, // 8-bit dithered RGB --> UNASSIGNED
- // PT_HDCC = 24, // SGI proprietary --> UNASSIGNED
- PT_CELLB = 25, // Sun CellB, 90000Hz
- PT_JPEG = 26, // JPEG, 90000Hz
- // PT_CUSEEME = 27,// Cornell CU-SeeMe --> UNASSIGNED
- PT_NV = 28, // Xerox PARC nv, 90000Hz
- // PT_PICW = 29, // BB&N PictureWindow --> UNASSIGNED
- // PT_CPV = 30, // Concept/Bolter/Viewpoint codec --> UNASSIGNED
- PT_H261 = 31, // ITU H.261, 90000Hz
- PT_MPEG = 32, // MPEG-I & MPEG-II, 90000Hz
- PT_MP2T = 33, // MPEG-II either audio or video, 90000Hz
- PT_H263 = 34, // ITU H.263, 90000Hz
- // Audio encodings...
- PT_PCMU = 0, // ITU G.711 Ulaw,8000Hz,1ch
- PT_CELP = 1, // 1016 audio,8000Hz,1ch
- PT_G726_32 = 2, // ITU G726, 8000Hz, 1ch (previously ITU G.721)
- PT_GSM = 3, // Group Speciale Mobile, GSM 6.10 audio,8000Hz,1ch
- PT_G723 = 4, // ITU G723.1,8000Hz,1ch
- PT_DVI4_8K = 5, // 8000Hz,1ch
- PT_DVI4_16K = 6,// 16000Hz,1ch
- PT_LPC = 7, // 8000Hz,1ch
- PT_PCMA = 8, // ITU G.711 Alaw,8000Hz,1ch
- PT_G722 = 9, // ITU G.722, 16000Hz,1ch
- PT_L16_2C = 10, // 44100Hz,2ch
- PT_L16_1C = 11, // 44100Hz,1ch
- PT_MPA = 14, // MPEG Audio,90000Hz
- PT_G728 = 15, // ITU G.728,8000Hz,1ch
- PT_DVI4_11 = 16,// DVI4 audio,11025Hz,1ch
- PT_DVI4_22 = 17,// DVI4 audio,22050Hz,1ch
- PT_G729 = 18, // ITU G.729,8000Hz,1ch
- PT_CN = 19 // Comfort Noise?,8000Hz,1ch
- };
- // session: pointer to the session class to which
- // this packet belongs.
- // payload_length: The maximum length of the payload
- // that is expected to be recd or sent in this session.
- RTPPacket(RTPSession *session, int max_payload_length = 0);
- ~RTPPacket();
- char *GetHeader();
- int GetHeaderLength();
- char* GetHeaderExt();
- int GetHeaderExtLength();
- int GetHeaderExtType();
- char *GetPayload();
- int GetPayloadLength();
- char *GetPacket();
- int GetPacketLength();
- // The following methods return information in
- // host byte order.
- unsigned short GetSequenceNumber();
- unsigned short GetFlags();
- ProtReturnCode SetFlags(unsigned short flags);
- unsigned int GetSSRC();
- unsigned int GetTimestamp();
- // Return the CSRC list.
- unsigned int *GetCSRCList();
- // Called to un-frame an incoming RTP packet.
- ProtReturnCode Deframe(char *data, int length,
- unsigned int arrival_time);
- // Called for framing an RTP packet, to be sent out. Sequence
- // numbers are generated internally.
- ProtReturnCode Frame(unsigned int rtp_time,
- int marker, int payload_length);
- // Buffer is user supplied, and note that the RTP header is
- // copied at the beginning of the buffer.
- // Caveat: the buffer has to be aligned to a longword boundary
- // in architectures that do not support misaligned accesses.
- ProtReturnCode Frame(char *buffer, int buffer_length,
- unsigned int rtp_time, int marker, int payload_length);
- // Called for framing an RTP packet to be sent out. Sequence
- // number can be supplied. This is used whenever a retransmission
- // of a lost packet is deemed necessary.
- ProtReturnCode Frame(unsigned short sequence_no, unsigned int rtp_time,
- int marker, int payload_length);
- // buffer is user supplied and note that the RTP header is
- // copied at the beginning of the buffer.
- // Caveat: the buffer has to be aligned to a longword boundary
- // in architectures that do not support misaligned accesses.
- ProtReturnCode Frame(char *buffer, int buffer_length,
- unsigned short sequence_no, unsigned int rtp_time,
- int marker, int payload_length);
- // Methods return the maximum payload/packet lengths.
- int GetMaxPayloadLength();
- int GetMaxPacketLength();
- protected:
- RTPHeader *header;
- unsigned int * csrc_list;
- char *header_extension;
- int header_extension_length;
- int header_extension_type;
- char *payload;
- int max_payload_length;
- int cur_payload_length;
- unsigned short rtp_flags;
- // saved datagram.
- char *datagram;
- int max_datagram_length;
- int cur_datagram_length;
- RTPSession* session;
- private:
- Logger *_logger;
- };
- #endif