root/vic/branches/mpeg4/rtp/rtp.h @ 3974

Revision 3974, 7.7 KB (checked in by piers, 7 years ago)

RTP Payload format for H.264 (RFC 3984)

Most of this work below has been done by Socrates. Tidy up and bug fixes by Piers.

General comments:

1. Implemented the H.264 RTP framing according to RFC 3984. The implementation covers the "Single NAL Unit" (Single NALU packet type) and "Non-Interleaved" modes (STAP-A, FU-A packet types). The interleaved mode (STAP-B, MTAP16, MTAP24, FU-B) has not been implemented at this stage. [I don't know of another tool, closed source or open, that has implemented this mode to date to be able to test with (the current QuickTime? Player 7.1.3 does not implement it either, as far as I know).]

2. The decoder has been tested with the MPEG4IP's mp4live server 1.5.0.1. An example SDP file is provided to set up VIC to decode mp4live streams. Please edit the file default_mpeg4ip.sdp with your details, or better generate your own SDP files using mp4live, and place the edited SDP file in your home directory. The filename should be "default.sdp"

3. The H264 depayloader implementation is currently based libavformat (part of ffpmeg). The plan to is re-write the H264 depayloader under BSD license in the near future.

4. The H.264 VIC encoder will not aggregate NAL units at the moment (STAP-A). The decoder will properly decode such packets.

5. VIC sends SPS/PPS NAL units in-band at the start of H.264 transmission. One has to check whether this can be done periodically. This way we may avoid SDP and sprep-parameter-set.

6. The SDP may be configured for the decoder which uses either a default embedded SDP or from "$HOME/default.sdp"

7. The SDP file is only used to convey SPS/PPS sprop-parameter-sets. IP addresses, ports, etc. are read from VIC command-line as normal.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*-
2 * Copyright (c) 1993-1994 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and the Network Research Group at
17 *      Lawrence Berkeley Laboratory.
18 * 4. Neither the name of the University nor of the Laboratory may be used
19 *    to endorse or promote products derived from this software without
20 *    specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef vic_rtp_h
36#define vic_rtp_h
37
38#ifndef WIN32
39#include <sys/param.h>
40#endif
41#include "sys-time.h"
42
43#define RTP_PT_RAW              126     /* XXX */
44#define RTP_PT_BVC              22      /* Berkeley video codec */
45
46/* RTP standard content encodings for video */
47#define RTP_PT_LDCT             20      /* Layered DCT */
48#define RTP_PT_PVH              21      /* Steve McCanne's  */
49#define RTP_PT_RGB8             23      /* 8-bit dithered RGB */
50#define RTP_PT_HDCC             24      /* SGI proprietary */
51#define RTP_PT_CELLB            25      /* Sun CellB */
52#define RTP_PT_JPEG             26      /* JPEG */
53#define RTP_PT_CUSEEME          27      /* Cornell CU-SeeMe */
54#define RTP_PT_NV               28      /* Xerox PARC nv */
55#define RTP_PT_PICW             29      /* BB&N PictureWindow */
56#define RTP_PT_CPV              30      /* Concept/Bolter/Viewpoint codec */
57#define RTP_PT_H261             31      /* ITU H.261 */
58#define RTP_PT_MPEG             32      /* MPEG-I & MPEG-II */
59#define RTP_PT_MP2T             33      /* MPEG-II either audio or video */
60#define RTP_PT_H263P    42      /* ITU H.263 */
61#define RTP_PT_H263             34      /* ITU H.263 */
62#define RTP_PT_DV               123     /* DV */
63#define RTP_PT_MPEG4            45
64#define RTP_PT_H264             96
65
66/* backward compat hack for decoding RTPv1 ivs streams */
67#define RTP_PT_H261_COMPAT 127
68
69/* non-standard arbitrary sized h261 */
70#define RTP_PT_H261AS           77
71
72/* RTP standard content encodings for audio */
73#define RTP_PT_PCMU             0
74#define RTP_PT_CELP             1
75#define RTP_PT_GSM              3
76#define RTP_PT_DVI              5
77#define RTP_PT_LPC              7
78
79
80/* Offset from UNIX's epoch to the NTP epoch in seconds (NTP's JAN_1970) */
81#define RTP_EPOCH_OFFSET        2208988800UL
82#define RTP_VERSION 2
83
84#define RTP_M   0x0080  /* Marker: significant event <e.g. frame boundary> */
85#define RTP_P   0x2000  /* Padding is present */
86#define RTP_X   0x1000  /* Extension Header is present */
87
88/* Basic RTP header */
89struct rtphdr {
90        u_int16_t rh_flags;     /* T:2 P:1 X:1 CC:4 M:1 PT:7 */
91        u_int16_t rh_seqno;     /* sequence number */
92        u_int32_t rh_ts;        /* media-specific time stamp */
93        u_int32_t rh_ssrc;      /* synchronization src id */
94        /* data sources follow per cc */
95};
96
97struct rtcphdr {
98        u_int16_t rh_flags;     /* T:2 P:1 CNT:5 PT:8 */
99        u_int16_t rh_len;       /* length of message (in bytes) */
100        u_int32_t rh_ssrc;      /* synchronization src id */
101};
102
103typedef struct {
104        u_int32_t upper;        /* more significant 32 bits */
105        u_int32_t lower;        /* less significant 32 bits */
106} ntp64;
107
108/*
109 * Sender report.
110 */
111struct rtcp_sr {
112        ntp64 sr_ntp;           /* 64-bit ntp timestamp */
113        u_int32_t sr_ts;        /* reference media timestamp */
114        u_int32_t sr_np;        /* no. packets sent */
115        u_int32_t sr_nb;        /* no. bytes sent */
116};
117
118/*
119 * Receiver report.
120 * Time stamps are middle 32-bits of ntp timestamp.
121 */
122struct rtcp_rr {
123        u_int32_t rr_srcid;     /* sender being reported */
124        u_int32_t rr_loss;      /* loss stats (8:fraction, 24:cumulative)*/
125        u_int32_t rr_ehsr;      /* ext. highest seqno received */
126        u_int32_t rr_dv;        /* jitter (delay variance) */
127        u_int32_t rr_lsr;       /* orig. ts from last rr from this src  */
128        u_int32_t rr_dlsr;      /* time from recpt of last rr to xmit time */
129};
130
131#define RTCP_PT_SR      200     /* sender report */
132#define RTCP_PT_RR      201     /* receiver report */
133#define RTCP_PT_SDES    202     /* source description */
134#define         RTCP_SDES_CNAME 1       /* official name (mandatory) */
135#define         RTCP_SDES_NAME  2       /* personal name (optional) */
136#define         RTCP_SDES_EMAIL 3       /* e-mail addr (optional) */
137#define         RTCP_SDES_PHONE 4       /* telephone # (optional) */
138#define         RTCP_SDES_LOC   5       /* geographical location */
139#define         RTCP_SDES_TOOL  6       /* name/(vers) of app */
140#define         RTCP_SDES_NOTE  7       /* transient messages */
141#define         RTCP_SDES_PRIV  8       /* private SDES extensions */
142#define RTCP_PT_BYE     203     /* end of participation */
143#define RTCP_PT_APP     204     /* application specific functions */
144
145#define         RTCP_SDES_MIN   1
146#define         RTCP_SDES_MAX   7
147
148/*
149 * Parameters controling the RTCP report rate timer.
150 */
151#define RTCP_SESSION_BW_FRACTION (0.05)
152#define RTCP_MIN_RPT_TIME (5.)
153#define RTCP_SENDER_BW_FRACTION (0.25)
154#define RTCP_RECEIVER_BW_FRACTION (1. - RTCP_SENDER_BW_FRACTION)
155#define RTCP_SIZE_GAIN (1./8.)
156
157/*
158 * Largest (user-level) packet size generated by our rtp applications.
159 * Individual video formats may use smaller mtu's.
160 */
161#define RTP_MTU 1024
162
163//now defined in pktbuf.h
164//#define MAXHDR 24
165
166/*
167 * Motion JPEG encapsulation.
168 *
169 * 0                   1                   2                   3
170 * 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
171 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
172 * |      MBZ      |                frag offset                    |
173 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
174 * |      Type     |       Q       |     Width     |     Height    |
175 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
176 *
177 * Type = Index into a table of predefined JPEG parameters
178 * Width = Width of input in 8-pixel blocks
179 * Height = Height of input in 8-pixel blocks
180 * Q = Quality factor (0-100 = std, >100 = custom)
181 * Frag offset = The byte offset into the frame for the data in
182 * this packet
183 */
184struct jpeghdr {
185        u_int32_t off;          /* fragment offset */
186        u_int8_t type;          /* id of jpeg decoder params */
187        u_int8_t q;             /* quantization factor (or table id) */
188        u_int8_t width;         /* 1/8 frame width */
189        u_int8_t height;        /* 1/8 frame height */
190};
191
192/*
193 * NV encapsulation.
194 */
195struct nvhdr {
196        u_int16_t width;
197        u_int16_t height;
198        /* nv data */
199};
200
201/*
202 * CellB encapsulation.
203 */
204struct cellbhdr {
205        u_int16_t x;
206        u_int16_t y;
207        u_int16_t width;
208        u_int16_t height;
209        /* cells */
210};
211
212/*
213 * H.261 encapsulation.
214 * See Internet draft.
215 *
216 *  0                   1                   2                   3
217 *  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
218 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219 * |SBIT |EBIT |I|V| GOBN  |  MBAP   |  QUANT  |  HMVD   |  VMVD   |
220 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221 */
222#ifdef notdef
223struct h261hdr {
224        u_int16_t       flags;
225        u_int16_t off;
226};
227#endif
228
229struct bvchdr {
230        u_int8_t version;
231        u_int8_t pad;
232        u_int8_t width;
233        u_int8_t height;
234        u_int32_t quant;
235        u_int8_t sbit;
236        u_int8_t ebit;
237        u_int16_t blkno;
238};
239
240#endif
Note: See TracBrowser for help on using the browser.