RTP.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /*-
00004  * Copyright (c) 1993-1994 The Regents of the University of California.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. All advertising materials mentioning features or use of this software
00016  *    must display the following acknowledgement:
00017  *      This product includes software developed by the University of
00018  *      California, Berkeley and the Network Research Group at
00019  *      Lawrence Berkeley Laboratory.
00020  * 4. Neither the name of the University nor of the Laboratory may be used
00021  *    to endorse or promote products derived from this software without
00022  *    specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00025  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00027  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00030  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00031  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00033  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGE.
00035  */
00036 
00037 
00038 //=============================================================================
00039 /**
00040  *  @file   RTP.h
00041  *
00042  *  $Id: RTP.h 71526 2006-03-14 06:14:35Z jtc $
00043  *
00044  *  @author Nagarajan Surendran <naga@cs.wustl.edu>
00045  */
00046 //=============================================================================
00047 
00048 
00049 #ifndef TAO_AV_RTP_H
00050 #define TAO_AV_RTP_H
00051 #include /**/ "ace/pre.h"
00052 
00053 #include "orbsvcs/AV/AV_export.h"
00054 #include "orbsvcs/AV/Protocol_Factory.h"
00055 
00056 #include "ace/Service_Config.h"
00057 
00058 
00059 #define RTP_PT_BVC              22      /* Berkeley video codec */
00060 
00061 /* RTP standard content encodings for video */
00062 #define RTP_PT_RGB8             23      /* 8-bit dithered RGB */
00063 #define RTP_PT_HDCC             24      /* SGI proprietary */
00064 #define RTP_PT_CELLB            25      /* Sun CellB */
00065 #define RTP_PT_JPEG             26      /* JPEG */
00066 #define RTP_PT_CUSEEME          27      /* Cornell CU-SeeMe */
00067 #define RTP_PT_NV               28      /* Xerox PARC nv */
00068 #define RTP_PT_PICW             29      /* BB&N PictureWindow */
00069 #define RTP_PT_CPV              30      /* Concept/Bolter/Viewpoint codec */
00070 #define RTP_PT_H261             31      /* ITU H.261 */
00071 #define RTP_PT_MPEG             32      /* MPEG-I & MPEG-II */
00072 #define RTP_PT_MP2T             33      /* MPEG-II either audio or video */
00073 
00074 /* backward compat hack for decoding RTPv1 ivs streams */
00075 #define RTP_PT_H261_COMPAT 127
00076 
00077 /* RTP standard content encodings for audio */
00078 #define RTP_PT_PCMU             0       /* 8k */
00079 #define RTP_PT_CELP             1       /* 8k */
00080 #define RTP_PT_G721             2       /* 8k */
00081 #define RTP_PT_GSM              3       /* 8k */
00082 #define RTP_PT_DVI              5       /* 8k */
00083 #define RTP_PT_LPC              7       /* 8k */
00084 #define RTP_PT_PCMA             8       /* 8k */
00085 #define RTP_PT_G722             9       /* 8k */
00086 #define RTP_PT_L16_STEREO       10      /* 44.1k */
00087 #define RTP_PT_L16_MONO         11      /* 44.1k */
00088 
00089 /* TODO: keep??
00090    non-standard encodings for audio
00091    */
00092 #define RTP_PT_L16_OTHER        23      /* */
00093 
00094 /* Offset from UNIX's epoch to the NTP epoch in seconds (NTP's JAN_1970) */
00095 #define RTP_EPOCH_OFFSET        2208988800UL
00096 #define RTP_VERSION 2
00097 
00098 #define RTP_M   0x0080  /* Marker: significant event <e.g. frame boundary> */
00099 #define RTP_P   0x2000  /* Padding is present */
00100 #define RTP_X   0x1000  /* Extension Header is present */
00101 
00102 
00103 #define RTCP_PT_SR      200     /* sender report */
00104 #define RTCP_PT_RR      201     /* receiver report */
00105 #define RTCP_PT_SDES    202     /* source description */
00106 #define RTCP_SDES_END   0       /* indicates the end of the sdes message */
00107 #define RTCP_SDES_CNAME 1       /* official name (mandatory) */
00108 #define RTCP_SDES_NAME  2       /* personal name (optional) */
00109 #define RTCP_SDES_EMAIL 3       /* e-mail addr (optional) */
00110 #define RTCP_SDES_PHONE 4       /* telephone # (optional) */
00111 #define RTCP_SDES_LOC   5       /* geographical location */
00112 #define RTCP_SDES_TOOL  6       /* name/(vers) of app */
00113 #define RTCP_SDES_NOTE  7       /* transient messages */
00114 #define RTCP_SDES_PRIV  8       /* private SDES extensions */
00115 #define RTCP_PT_BYE     203     /* end of participation */
00116 #define RTCP_PT_APP     204     /* application specific functions */
00117 
00118 #define RTCP_SDES_MIN   1
00119 
00120 #define RTP_SEQ_MOD (1<<16)
00121 
00122 
00123 /*
00124  * Parameters controling the RTCP report rate timer.
00125  */
00126 #define RTCP_SESSION_BW_FRACTION (0.05)
00127 #define RTCP_MIN_RPT_TIME (5.)
00128 #define RTCP_SENDER_BW_FRACTION (0.25)
00129 #define RTCP_RECEIVER_BW_FRACTION (1. - RTCP_SENDER_BW_FRACTION)
00130 #define RTCP_SIZE_GAIN (1./8.)
00131 
00132 /*
00133  * Largest (user-level) packet size generated by our rtp applications.
00134  * Individual video formats may use smaller mtu's.
00135  */
00136 #define RTP_MTU 2*ACE_MAX_DGRAM_SIZE
00137 
00138 #define MAXHDR 24
00139 
00140 #include "orbsvcs/AV/Policy.h"
00141 #include "orbsvcs/AV/FlowSpec_Entry.h"
00142 #include "orbsvcs/AV/MCast.h"
00143 
00144 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00145 
00146 //------------------------------------------------------------
00147 // TAO_AV_RTP
00148 //------------------------------------------------------------
00149 
00150 /**
00151  * @class TAO_AV_RTP
00152  * @brief Encapsulate the Real Time Protocol (RTP) header format.
00153  */
00154 class TAO_AV_Export TAO_AV_RTP
00155 {
00156 public:
00157   /* Basic RTP header */
00158   struct rtphdr
00159   {
00160     ACE_UINT16 rh_flags;        /* T:2 P:1 X:1 CC:4 M:1 PT:7 */
00161     ACE_UINT16 rh_seqno;        /* sequence number */
00162     ACE_UINT32 rh_ts;   /* media-specific time stamp */
00163     ACE_UINT32 rh_ssrc; /* synchronization src id */
00164     /* data sources follow per cc */
00165   };
00166 
00167   /*
00168  * Motion JPEG encapsulation.
00169  *
00170  * 0                   1                   2                   3
00171  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
00172  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00173  * |      MBZ      |                frag offset                    |
00174  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00175  * |      Type     |       Q       |     Width     |     Height    |
00176  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00177  *
00178  * Type = Index into a table of predefined JPEG parameters
00179  * Width = Width of input in 8-pixel blocks
00180  * Height = Height of input in 8-pixel blocks
00181  * Q = Quality factor (0-100 = std, >100 = custom)
00182  * Frag offset = The byte offset into the frame for the data in
00183  * this packet
00184  */
00185   struct jpeghdr
00186   {
00187     ACE_UINT32 off;             /* fragment offset */
00188     unsigned char type;         /* id of jpeg decoder params */
00189     unsigned char q;            /* quantization factor (or table id) */
00190     unsigned char width;                /* 1/8 frame width */
00191     unsigned char height;       /* 1/8 frame height */
00192   };
00193 
00194   /*
00195  * NV encapsulation.
00196  */
00197   struct nvhdr
00198   {
00199     ACE_UINT16 width;
00200     ACE_UINT16 height;
00201     /* nv data */
00202   };
00203 
00204   /*
00205  * CellB encapsulation.
00206  */
00207   struct cellbhdr
00208   {
00209     ACE_UINT16 x;
00210     ACE_UINT16 y;
00211     ACE_UINT16 width;
00212     ACE_UINT16 height;
00213     /* cells */
00214   };
00215 
00216   /*
00217  * H.261 encapsulation.
00218  * See Internet draft.
00219  *
00220  *  0                   1                   2                   3
00221  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
00222  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00223  * |SBIT |EBIT |I|V| GOBN  |  MBAP   |  QUANT  |  HMVD   |  VMVD   |
00224  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00225  */
00226 #ifdef notdef
00227   struct h261hdr
00228   {
00229     ACE_UINT16  flags;
00230     ACE_UINT16 off;
00231   };
00232 #endif
00233 
00234   struct bvchdr
00235   {
00236     unsigned char version;
00237     unsigned char pad;
00238     unsigned char width;
00239     unsigned char height;
00240     ACE_UINT32 quant;
00241     unsigned char sbit;
00242     unsigned char ebit;
00243     ACE_UINT16 blkno;
00244   };
00245 
00246 };
00247 
00248 /**
00249  * @class RTP_Packet
00250  * @brief This class encapsulates all the necessary information to break down
00251  * or build up an RTP data packet as well as operations to access all data
00252  * items in the packet.
00253  */
00254 class RTP_Packet
00255 {
00256 public:
00257   /// Constructor for incoming RTP packets.
00258   RTP_Packet(char* buffer,
00259              int length);
00260 
00261   /// Constructor for outgoing RTP packets
00262   RTP_Packet(unsigned char padding,
00263              unsigned char marker,
00264              unsigned char payloadType,
00265              ACE_UINT32 sequenceNumber,
00266              ACE_UINT32 timeStamp,
00267              ACE_UINT32 syncSource,
00268              unsigned char contribSourcCount,
00269              ACE_UINT32 contribSourceList[],
00270              char *data,
00271              ACE_UINT16 dataSize);
00272 
00273   /// Destructor
00274   ~RTP_Packet(void);
00275 
00276   /// Returns the size of the RTP packet in bytes.
00277   ACE_UINT16 packet_size(void);
00278 
00279   /// Returns the size of the payload in bytes.
00280   ACE_UINT16 payload_size(void);
00281 
00282   /// Populates the passed in frame_info.
00283   void get_frame_info (TAO_AV_frame_info *frame_info);
00284 
00285   /// Returns 1 if packet is valid and 0 if not.
00286   int is_valid (void);
00287 
00288   /// Returns the RTP version of the packet.
00289   unsigned int ver (void);
00290 
00291   /// Returns 1 if the padding bit is set, 0 if not.
00292   unsigned int pad (void);
00293 
00294   /// Returns 1 if the header extension bit is set, 0 if not.
00295   unsigned int ext (void);
00296 
00297   /// Returns the number of bytes in the header extension or 0 if no extension.
00298   unsigned int ext_bytes (void);
00299 
00300   /// Returns the contributing source count.
00301   /// This should only be non-zero for mixers.
00302   unsigned int cc  (void);
00303 
00304   /// Returns 1 if the marker bit is set, 0 if not.
00305   unsigned int mrk (void);
00306 
00307   /// Returns the payload type of the packet.
00308   unsigned int pt  (void);
00309 
00310   /// Returns the sequence number of the packet.
00311   ACE_UINT16   sn  (void);
00312 
00313   /// Returns the timestamp of the packet.
00314   ACE_UINT32   ts  (void);
00315 
00316   /// Returns the synchronization source id of the packet.
00317   ACE_UINT32  ssrc (void);
00318 
00319   /// Returns a pointer to the local contributing source list and its length.
00320   /// This should be empty except for mixers.
00321   /// RTP_Packet retains ownership.
00322   void get_csrc_list (ACE_UINT32 **csrc_list, ACE_UINT16 &length);
00323 
00324   /// Returns a pointer to the locally stored payload and its size in bytes.
00325   /// The payload is returned in host byte order.
00326   /// RTP_Packet retains ownership.
00327   void get_payload (char **payload, ACE_UINT16 &size);
00328 
00329   /// Returns a pointer to the locally stored rtp packet and its size in bytes.
00330   /// RTP_Packet retains ownership.
00331   void get_packet_data (char **packet, ACE_UINT16 &size);
00332 
00333 private:
00334   /// Local buffer to hold the RTP packet.
00335   char packet_[RTP_MTU];
00336 
00337   /// Local buffer to hold the contributing source list with the values stored
00338   /// in host byte order.
00339   ACE_UINT32 host_byte_order_csrc_list_[15];
00340 
00341   /// Local buffer to hold the payload with the values stored in host byte order.
00342   char host_byte_order_payload_[RTP_MTU];
00343 
00344   /// The number of bytes in the header extension - 0 if no extension.
00345   unsigned int extension_bytes_;
00346 
00347   /// The size of the overall data packet.
00348   ACE_UINT16 packet_size_;
00349 
00350   /// The size of the payload portion of the packet.
00351   ACE_UINT16 payload_size_;
00352 };
00353 
00354 /**
00355  * @class TAO_AV_RTP_Object
00356  * @brief TAO_AV_Protocol_object for the RTP protocol
00357  */
00358 class TAO_AV_Export TAO_AV_RTP_Object : public TAO_AV_Protocol_Object
00359 {
00360 public:
00361   TAO_AV_RTP_Object (TAO_AV_Callback *callback,
00362                      TAO_AV_Transport *transport);
00363 
00364   virtual ~TAO_AV_RTP_Object (void);
00365 
00366   virtual int start (void);
00367   virtual int stop (void);
00368   virtual int handle_input (void);
00369   virtual int send_frame (ACE_Message_Block *frame,
00370                           TAO_AV_frame_info *frame_info = 0);
00371 
00372   virtual int send_frame (const iovec *iov,
00373                           int iovcnt,
00374                           TAO_AV_frame_info *frame_info = 0);
00375 
00376   virtual int send_frame (const char*buf,
00377                           size_t len);
00378 
00379   virtual int destroy (void);
00380   virtual int set_policies (const TAO_AV_PolicyList &policy_list);
00381   virtual void control_object (TAO_AV_Protocol_Object *object);
00382 
00383 protected:
00384   ACE_UINT16 sequence_num_;
00385   ACE_UINT32 timestamp_offset_;
00386   int format_;
00387   ACE_UINT32 ssrc_;
00388   TAO_AV_Protocol_Object *control_object_;
00389 
00390   /// Pre-allocated memory to receive the data...
00391   ACE_Message_Block frame_;
00392 
00393   int connection_gone_;
00394 };
00395 
00396 
00397 
00398 /**
00399  * @class TAO_AV_RTP_Flow_Factory
00400  * @brief
00401  */
00402 class TAO_AV_Export TAO_AV_RTP_Flow_Factory : public TAO_AV_Flow_Protocol_Factory
00403 {
00404 public:
00405   /// Initialization hook.
00406   TAO_AV_RTP_Flow_Factory (void);
00407   virtual ~TAO_AV_RTP_Flow_Factory (void);
00408   virtual int init (int argc, char *argv[]);
00409   virtual int match_protocol (const char *flow_string);
00410   virtual TAO_AV_Protocol_Object* make_protocol_object (TAO_FlowSpec_Entry *entry,
00411                                                         TAO_Base_StreamEndPoint *endpoint,
00412                                                         TAO_AV_Flow_Handler *handler,
00413                                                         TAO_AV_Transport *transport);
00414   virtual const char*control_flow_factory (void);
00415 };
00416 
00417 TAO_END_VERSIONED_NAMESPACE_DECL
00418 
00419 ACE_STATIC_SVC_DECLARE (TAO_AV_RTP_Flow_Factory)
00420 ACE_FACTORY_DECLARE (TAO_AV, TAO_AV_RTP_Flow_Factory)
00421 
00422 #include /**/ "ace/post.h"
00423 #endif /* TAO_AV_RTP_H */

Generated on Tue Feb 2 17:47:49 2010 for TAO_AV by  doxygen 1.4.7