draft-ietf-avt-jpeg-new-01.txt   rfc2435.txt 
Internet Engineering Task Force Audio-Video Transport Working Group
INTERNET-DRAFT L. Berc Network Working Group L. Berc
draft-ietf-avt-jpeg-new-01.txt Digital Equipment Corporation Request for Comments: 2435 Digital Equipment Corporation
W. Fenner Obsoletes: 2035 W. Fenner
Xerox PARC Category: Standards Track Xerox PARC
R. Frederick R. Frederick
Xerox PARC Xerox PARC
S. McCanne S. McCanne
Lawrence Berkeley Laboratory Lawrence Berkeley Laboratory
P. Stewart P. Stewart
Xerox PARC Xerox PARC
March 6, 1998 October 1998
Expires September 1998
RTP Payload Format for JPEG-compressed Video RTP Payload Format for JPEG-compressed Video
Status of this Memo Status of this Memo
This document is an Internet Draft. Internet Drafts are working This document specifies an Internet standards track protocol for the
documents of the Internet Engineering Task Force (IETF), its Areas, and Internet community, and requests discussion and suggestions for
its Working Groups. Note that other groups may also distribute working improvements. Please refer to the current edition of the "Internet
documents as Internet Drafts. Official Protocol Standards" (STD 1) for the standardization state
and status of this protocol. Distribution of this memo is unlimited.
Internet Drafts are draft documents valid for a maximum of six months.
Internet Drafts may be updated, replaced, or obsoleted by other
documents at any time. It is not appropriate to use Internet Drafts as
reference material or to cite them other than as a "working draft" or
"work in progress."
To learn the current status of any Internet-Draft, please check the Copyright Notice
"1id-abstracts.txt" listing contained in the Internet-Drafts Shadow
Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe),
munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or
ftp.isi.edu (US West Coast).
Distribution of this document is unlimited. Copyright (C) The Internet Society (1998). All Rights Reserved.
Abstract Abstract
This memo describes the RTP payload format for JPEG video streams. This memo describes the RTP payload format for JPEG video streams.
The packet format is optimized for real-time video streams where The packet format is optimized for real-time video streams where
codec parameters change rarely from frame to frame. codec parameters change rarely from frame to frame.
This document is a product of the Audio-Video Transport working group This document is a product of the Audio-Video Transport working group
within the Internet Engineering Task Force. Comments are solicited and within the Internet Engineering Task Force. Comments are solicited
should be addressed to the working group's mailing list at rem- and should be addressed to the working group's mailing list at rem-
conf@es.net and/or the author(s). conf@es.net and/or the author(s).
Changes from RFC 2035 Changes from RFC 2035
Most of this draft is identical to RFC 2035. The changes made to the Most of this memo is identical to RFC 2035. The changes made to the
protocol are summarized in Appendix D. protocol are summarized in Appendix D.
Key Words
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119 [9].
1. Introduction 1. Introduction
The Joint Photographic Experts Group (JPEG) standard [1,2,3] defines a The Joint Photographic Experts Group (JPEG) standard [1,2,3] defines
family of compression algorithms for continuous-tone, still images. a family of compression algorithms for continuous-tone, still images.
This still image compression standard can be applied to video by This still image compression standard can be applied to video by
compressing each frame of video as an independent still image and compressing each frame of video as an independent still image and
transmitting them in series. Video coded in this fashion is often transmitting them in series. Video coded in this fashion is often
called Motion-JPEG. called Motion-JPEG.
We first give an overview of JPEG and then describe the specific subset We first give an overview of JPEG and then describe the specific
of JPEG that is supported in RTP and the mechanism by which JPEG frames subset of JPEG that is supported in RTP and the mechanism by which
are carried as RTP payloads. JPEG frames are carried as RTP payloads.
The JPEG standard defines four modes of operation: the sequential DCT The JPEG standard defines four modes of operation: the sequential DCT
mode, the progressive DCT mode, the lossless mode, and the hierarchical mode, the progressive DCT mode, the lossless mode, and the
mode. Depending on the mode, the image is represented in one or more hierarchical mode. Depending on the mode, the image is represented
passes. Each pass (called a frame in the JPEG standard) is further in one or more passes. Each pass (called a frame in the JPEG
broken down into one or more scans. Within each scan, there are one to standard) is further broken down into one or more scans. Within each
four components, which represent the three components of a color signal scan, there are one to four components, which represent the three
(e.g., "red, green, and blue", or a luminance signal and two chrominance components of a color signal (e.g., "red, green, and blue", or a
signals). These components can be encoded as separate scans or luminance signal and two chrominance signals). These components can
interleaved into a single scan. be encoded as separate scans or interleaved into a single scan.
Each frame and scan is preceded with a header containing optional Each frame and scan is preceded with a header containing optional
definitions for compression parameters like quantization tables and definitions for compression parameters like quantization tables and
Huffman coding tables. The headers and optional parameters are Huffman coding tables. The headers and optional parameters are
identified with "markers" and comprise a marker segment; each scan identified with "markers" and comprise a marker segment; each scan
appears as an entropy-coded bit stream within two marker segments. appears as an entropy-coded bit stream within two marker segments.
Markers are aligned to byte boundaries and (in general) cannot appear in Markers are aligned to byte boundaries and (in general) cannot appear
the entropy-coded segment, allowing scan boundaries to be determined in the entropy-coded segment, allowing scan boundaries to be
without parsing the bit stream. determined without parsing the bit stream.
Compressed data is represented in one of three formats: the interchange Compressed data is represented in one of three formats: the
format, the abbreviated format, or the table-specification format. The interchange format, the abbreviated format, or the table-
interchange format contains definitions for all the tables used by the specification format. The interchange format contains definitions
entropy-coded segments, while the abbreviated format might omit some for all the tables used by the entropy-coded segments, while the
assuming they were defined out-of-band or by a "previous" image. abbreviated format might omit some assuming they were defined out-
of-band or by a "previous" image.
The JPEG standard does not define the meaning or format of the The JPEG standard does not define the meaning or format of the
components that comprise the image. Attributes like the color space and components that comprise the image. Attributes like the color space
pixel aspect ratio must be specified out-of-band with respect to the and pixel aspect ratio must be specified out-of-band with respect to
JPEG bit stream. The JPEG File Interchange Format (JFIF) [4] is a de- the JPEG bit stream. The JPEG File Interchange Format (JFIF) [4] is
facto standard that provides this extra information using an application a de-facto standard that provides this extra information using an
marker segment (APP0). Note that a JFIF file is simply a JPEG application marker segment (APP0). Note that a JFIF file is simply a
interchange format image along with the APP0 segment. In the case of JPEG interchange format image along with the APP0 segment. In the
video, additional parameters must be defined out-of-band (e.g., frame case of video, additional parameters must be defined out-of-band
rate, interlaced vs. non-interlaced, etc.). (e.g., frame rate, interlaced vs. non-interlaced, etc.).
While the JPEG standard provides a rich set of algorithms for flexible While the JPEG standard provides a rich set of algorithms for
compression, cost-effective hardware implementations of the full flexible compression, cost-effective hardware implementations of the
standard have not appeared. Instead, most hardware JPEG video codecs full standard have not appeared. Instead, most hardware JPEG video
implement only a subset of the sequential DCT mode of operation. codecs implement only a subset of the sequential DCT mode of
Typically, marker segments are interpreted in software (which "re- operation. Typically, marker segments are interpreted in software
programs" the hardware) and the hardware is presented with a single, (which "re-programs" the hardware) and the hardware is presented with
interleaved entropy-coded scan represented in the YUV color space. a single, interleaved entropy-coded scan represented in the YUV color
space.
The scan contains an ordered sequence of Minimum Coded Units, or MCUs, The scan contains an ordered sequence of Minimum Coded Units, or
which are the smallest group of image data coded in a JPEG bit stream. MCUs, which are the smallest group of image data coded in a JPEG bit
Each MCU defines the image data for a small rectangular block of the stream. Each MCU defines the image data for a small rectangular
output image. block of the output image.
Restart markers in the JPEG data denote a point where the decoder should Restart markers in the JPEG data denote a point where the decoder
reset its state. As defined by JPEG, restart markers are the only type should reset its state. As defined by JPEG, restart markers are the
of marker that may appear embedded in the entropy-coded segment, and only type of marker that may appear embedded in the entropy-coded
they may only appear on an MCU boundary. A "restart interval" is segment, and they may only appear on an MCU boundary. A "restart
defined to be a block of data containing a restart marker followed by interval" is defined to be a block of data containing a restart
some fixed number of MCUs. When these markers are used, each frame is marker followed by some fixed number of MCUs. An exception is made
composed of some fixed number of back-to-back restart intervals. for the first restart interval in each frame, which omits the initial
restart marker and just begins with the MCU data. When these markers
are used, each frame is composed of some fixed number of back-to-back
restart intervals.
2. JPEG Over RTP 2. JPEG Over RTP
To maximize interoperability among hardware-based codecs, we assume the To maximize interoperability among hardware-based codecs, we assume
sequential DCT operating mode [1,Annex F] and restrict the set of the sequential DCT operating mode [1,Annex F] and restrict the set of
predefined RTP/JPEG "type codes" (defined below) to single-scan, predefined RTP/JPEG "type codes" (defined below) to single-scan,
interleaved images. While this is more restrictive than even baseline interleaved images. While this is more restrictive than even
JPEG, many hardware implementation fall short of the baseline baseline JPEG, many hardware implementation fall short of the
specification (e.g., most hardware cannot decode non-interleaved scans). baseline specification (e.g., most hardware cannot decode non-
interleaved scans).
In practice, most of the table-specification data rarely changes from In practice, most of the table-specification data rarely changes from
frame to frame within a single video stream. Therefore RTP/JPEG data is frame to frame within a single video stream. Therefore RTP/JPEG data
represented in abbreviated format, with all of the tables omitted from is represented in abbreviated format, with all of the tables omitted
the bit stream where possible. Each frame begins immediately with the from the bit stream where possible. Each frame begins immediately
(single) entropy-coded scan. The information that would otherwise be in with the (single) entropy-coded scan. The information that would
both the frame and scan headers is represented entirely within the otherwise be in both the frame and scan headers is represented
RTP/JPEG header (defined below) that lies between the RTP header and the entirely within the RTP/JPEG header (defined below) that lies between
JPEG payload. the RTP header and the JPEG payload.
While parameters like Huffman tables and color space are likely to While parameters like Huffman tables and color space are likely to
remain fixed for the lifetime of the video stream, other parameters remain fixed for the lifetime of the video stream, other parameters
should be allowed to vary, notably the quantization tables and image should be allowed to vary, notably the quantization tables and image
size (e.g., to implement rate-adaptive transmission or allow a user to size (e.g., to implement rate-adaptive transmission or allow a user
adjust the "quality level" or resolution manually). Thus explicit to adjust the "quality level" or resolution manually). Thus explicit
fields in the RTP/JPEG header are allocated to represent this fields in the RTP/JPEG header are allocated to represent this
information. Since only a small set of quantization tables are information. Since only a small set of quantization tables are
typically used, we encode the entire set of quantization tables in a typically used, we encode the entire set of quantization tables in a
small integer field. Customized quantization tables are accommodated by small integer field. Customized quantization tables are accommodated
using a special range of values in this field, and then placing the by using a special range of values in this field, and then placing
table before the beginning of the JPEG payload. The image width and the table before the beginning of the JPEG payload. The image width
height are encoded explicitly. and height are encoded explicitly.
Because JPEG frames are typically larger than the underlying network's Because JPEG frames are typically larger than the underlying
maximum packet size, frames must often be fragmented into several network's maximum packet size, frames must often be fragmented into
packets. One approach is to allow the network layer below RTP (e.g., several packets. One approach is to allow the network layer below
IP) to perform the fragmentation. However, this precludes rate- RTP (e.g., IP) to perform the fragmentation. However, this precludes
controlling the resulting packet stream or partial delivery in the rate-controlling the resulting packet stream or partial delivery in
presence of loss. For example, IP will not deliver a fragmented the presence of loss, and frames may be larger than the maximum
datagram to the application if one or more fragments is lost, or IP network layer reassembly length (see [10] for more information). To
might fragment an 8000 byte frame into a burst of 8 back-to-back avoid these limitations, RTP/JPEG defines a simple fragmentation and
packets. Instead, RTP/JPEG defines a simple fragmentation and reassembly scheme at the RTP level.
reassembly scheme at the RTP level.
3. RTP/JPEG Packet Format 3. RTP/JPEG Packet Format
The RTP timestamp is in units of 90000Hz. The same timestamp must The RTP timestamp is in units of 90000Hz. The same timestamp MUST
appear in each fragment of a given frame. The RTP marker bit is set in appear in each fragment of a given frame. The RTP marker bit MUST be
the last packet of a frame. set in the last packet of a frame.
3.1. JPEG header 3.1. JPEG header
Each packet contains a special JPEG header which immediately follows the Each packet contains a special JPEG header which immediately follows
RTP header. The first 8 bytes of this header, called the "main JPEG the RTP header. The first 8 bytes of this header, called the "main
header", are as follows: JPEG header", are as follows:
0 1 2 3 0 1 2 3
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 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type-specific | Fragment Offset | | Type-specific | Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Q | Width | Height | | Type | Q | Width | Height |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
All fields in this header except for the Fragment Offset field MUST
remain the same in all packets that correspond to the same JPEG
frame.
A Restart Marker header and/or Quantization Table header may follow this A Restart Marker header and/or Quantization Table header may follow
header, depending on the values of the Type and Q fields. this header, depending on the values of the Type and Q fields.
3.1.1. Type-specific: 8 bits 3.1.1. Type-specific: 8 bits
Interpretation depends on the value of the type field. If no Interpretation depends on the value of the type field. If no
interpretation is specified, this field must be zeroed on transmission interpretation is specified, this field MUST be zeroed on
and ignored on reception. transmission and ignored on reception.
3.1.2. Fragment Offset: 24 bits 3.1.2. Fragment Offset: 24 bits
The Fragment Offset is the offset in bytes of the current packet in the The Fragment Offset is the offset in bytes of the current packet in
JPEG frame data. the JPEG frame data. This value is encoded in network byte order
(most significant byte first). The Fragment Offset plus the length of
the payload data in the packet MUST NOT exceed 2^24 bytes.
3.1.3. Type: 8 bits 3.1.3. Type: 8 bits
The type field specifies the information that would otherwise be present The type field specifies the information that would otherwise be
in a JPEG abbreviated table-specification as well as the additional present in a JPEG abbreviated table-specification as well as the
JFIF-style parameters not defined by JPEG. Types 0-63 are reserved as additional JFIF-style parameters not defined by JPEG. Types 0-63 are
fixed, well-known mappings to be defined by this document and future reserved as fixed, well-known mappings to be defined by this document
revisions of this document. Types 64-127 are the same as types 0-63, and future revisions of this document. Types 64-127 are the same as
except that restart markers are present in the JPEG data and a Restart types 0-63, except that restart markers are present in the JPEG data
Marker header appears immediately following the main JPEG header. Types and a Restart Marker header appears immediately following the main
128-255 are free to be dynamically defined by a session setup protocol JPEG header. Types 128-255 are free to be dynamically defined by a
(which is beyond the scope of this document). session setup protocol (which is beyond the scope of this document).
3.1.4. Q: 8 bits 3.1.4. Q: 8 bits
The Q field defines the quantization tables for this frame. Q values The Q field defines the quantization tables for this frame. Q values
0-127 indicate the quantization tables are computed using an algorithm 0-127 indicate the quantization tables are computed using an
determined by the Type field (see below). Q values 128-255 indicate algorithm determined by the Type field (see below). Q values 128-255
that a Quantization Table header appears after the main JPEG header (and indicate that a Quantization Table header appears after the main JPEG
the Restart Marker header, if present) in the first packet of the frame header (and the Restart Marker header, if present) in the first
(fragment offset 0). This header can be used to explicitly specify the packet of the frame (fragment offset 0). This header can be used to
quantization tables in-band. explicitly specify the quantization tables in-band.
3.1.5. Width: 8 bits 3.1.5. Width: 8 bits
This field encodes the width of the image in 8-pixel multiples (e.g., a This field encodes the width of the image in 8-pixel multiples (e.g.,
width of 40 denotes an image 320 pixels wide). The maximum width is a width of 40 denotes an image 320 pixels wide). The maximum width
2040 pixels. is 2040 pixels.
3.1.6. Height: 8 bits 3.1.6. Height: 8 bits
This field encodes the height of the image in 8-pixel multiples (e.g., a This field encodes the height of the image in 8-pixel multiples
height of 30 denotes an image 240 pixels tall). The maximum height is (e.g., a height of 30 denotes an image 240 pixels tall). When
2040 pixels. encoding interlaced video, this is the height of a video field, since
fields are individually JPEG encoded. The maximum height is 2040
pixels.
3.1.7. Restart Marker header 3.1.7. Restart Marker header
This header must be present immediately after the main JPEG header when This header MUST be present immediately after the main JPEG header
using types 64-127. It provides the additional information required to when using types 64-127. It provides the additional information
properly decode a data stream containing restart markers. required to properly decode a data stream containing restart markers.
0 1 2 3 0 1 2 3
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 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Restart Interval |F|L| Restart Count | | Restart Interval |F|L| Restart Count |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The Restart Interval field specifies the number of MCUs that appear The Restart Interval field specifies the number of MCUs that appear
between restart markers. It is identical to the 16 bit value that between restart markers. It is identical to the 16 bit value that
appears in the DRI marker segment in JFIF headers. This value must not would appear in the DRI marker segment of a JFIF header. This value
be zero. MUST NOT be zero.
If the restart intervals in a frame are not guaranteed to be aligned If the restart intervals in a frame are not guaranteed to be aligned
with packet boundaries, the F and L bits must be set to 1 and the with packet boundaries, the F (first) and L (last) bits MUST be set
Restart Count must be set to 0x3FFF. This indicates that a receiver to 1 and the Restart Count MUST be set to 0x3FFF. This indicates
must reassemble the entire frame before decoding it. that a receiver MUST reassemble the entire frame before decoding it.
To support partial frame decoding, the frame is broken into "chunks" To support partial frame decoding, the frame is broken into "chunks"
each containing an integral number of restart intervals. The Restart each containing an integral number of restart intervals. The Restart
Count field contains the position of the first restart interval in the Count field contains the position of the first restart interval in
current "chunk" so that receivers know which part of the frame this data the current "chunk" so that receivers know which part of the frame
corresponds to. Generally, a Restart Interval value should be chosen to this data corresponds to. A Restart Interval value SHOULD be chosen
allow a "chunk" to completely fit within a single packet. In this case, to allow a "chunk" to completely fit within a single packet. In this
both the F and L bits of the packet are set to 1. However, if a chunk case, both the F and L bits of the packet are set to 1. However, if
needs to be spread across multiple packets, the F bit will be set to 1 a chunk needs to be spread across multiple packets, the F bit will be
in the first packet of the chunk (and only that one) and the L bit will set to 1 in the first packet of the chunk (and only that one) and the
be set to 1 in the last packet of the chunk (and only that one). L bit will be set to 1 in the last packet of the chunk (and only that
one).
3.1.8. Quantization Table header 3.1.8. Quantization Table header
This header must be present after the main JPEG header (and after the This header MUST be present after the main JPEG header (and after the
Restart Marker header, if present) when using Q values 128-255. It Restart Marker header, if present) when using Q values 128-255. It
provides a way to specify the quantization tables associated with this Q provides a way to specify the quantization tables associated with
value in-band. this Q value in-band.
0 1 2 3 0 1 2 3
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 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| MBZ | Precision | Length | | MBZ | Precision | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Quantization Table Data | | Quantization Table Data |
| ... | | ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The Length field is set to the length in bytes of the quantization table The Length field is set to the length in bytes of the quantization
data to follow. The length field may be set to zero to indicate that no table data to follow. The Length field MAY be set to zero to
quantization table data is included in this frame. indicate that no quantization table data is included in this frame.
See section 4.2 for more information. If the Length field in a
received packet is larger than the remaining number of bytes, the
packet MUST be discarded.
When table data is included, the number of tables present depends on the When table data is included, the number of tables present depends on
JPEG type field. For example, type 0 uses two tables (one for the the JPEG type field. For example, type 0 uses two tables (one for
luminance component and one shared by the chrominance components). Each the luminance component and one shared by the chrominance
table is an array of 64 values given in zig-zag order, identical to the components). Each table is an array of 64 values given in zig-zag
format used in a JFIF DQT marker segment. order, identical to the format used in a JFIF DQT marker segment.
For each quantization table present, a bit in the Precision field For each quantization table present, a bit in the Precision field
specifies the size of the coefficients in that table. If the bit is specifies the size of the coefficients in that table. If the bit is
zero, the coefficients are 8 bits yielding a table length of 64 bytes. zero, the coefficients are 8 bits yielding a table length of 64
If the bit is one, the coefficients are 16 bits for a table length of bytes. If the bit is one, the coefficients are 16 bits for a table
128 bytes. For 16 bit tables, the coefficients are presented in network length of 128 bytes. For 16 bit tables, the coefficients are
byte order. The rightmost bit in the Precision field corresponds to the presented in network byte order. The rightmost bit in the Precision
first table and each additional table uses the next bit to the left. field (bit 15 in the diagram above) corresponds to the first table
Bits beyond those corresponding to the tables needed by the type in use and each additional table uses the next bit to the left. Bits beyond
must be ignored. those corresponding to the tables needed by the type in use MUST be
ignored.
For Q values from 128 to 254, the Q value to quantization table data For Q values from 128 to 254, the Q value to quantization table data
mapping must be static, i.e., the receivers are guaranteed that they mapping MUST be static, i.e., the receivers are guaranteed that they
only need to read the table data once in order to correctly decode only need to read the table data once in order to correctly decode
frames sent with that Q value. A Q value of 255 denotes that the frames sent with that Q value. A Q value of 255 denotes that the
quantization table mapping is dynamic and can change on every frame. quantization table mapping is dynamic and can change on every frame.
Decoders cannot depend on any previous version of the tables, and need Decoders MUST NOT depend on any previous version of the tables, and
to reload these tables on every frame. It is illegal to set Q = 255 and need to reload these tables on every frame. Packets MUST NOT contain
Length = 0. Q = 255 and Length = 0.
3.1.9. JPEG Payload 3.1.9. JPEG Payload
The data following the RTP/JPEG headers is an entropy-coded segment The data following the RTP/JPEG headers is an entropy-coded segment
consisting of a single scan. The scan header is not present and is consisting of a single scan. The scan header is not present and is
inferred from the RTP/JPEG header. The scan is terminated either inferred from the RTP/JPEG header. The scan is terminated either
implicitly (i.e., the point at which the image is fully parsed), or implicitly (i.e., the point at which the image is fully parsed), or
explicitly with an EOI marker. The scan may be padded to arbitrary explicitly with an EOI marker. The scan may be padded to arbitrary
length with undefined bytes. (Some existing hardware codecs generate length with undefined bytes. (Some existing hardware codecs generate
extra lines at the bottom of a video frame and removal of these lines extra lines at the bottom of a video frame and removal of these lines
would require a Huffman-decoding pass over the data.) would require a Huffman-decoding pass over the data.)
The type code determines whether restart markers are present. The The type code determines whether restart markers are present. If a
restart count in the Restart Marker header determines if the restart type supports restart markers, the packet MUST contain a non-zero
intervals will be aligned with RTP packets, allowing for partial Restart Interval value in a Restart Marker Header and restart markers
decoding of frames. Restart Markers markers appear explicitly on byte MUST appear on byte aligned boundaries beginning with an 0xFF between
aligned boundaries beginning with an 0xFF, between MCUs at the defined MCUs at that interval. Additional 0xFF bytes MAY appear between
restart interval. A "stuffed" 0x00 byte follows any 0xFF byte generated restart intervals. This can be used in the packetization process to
by the entropy coder [1, Sec. B.1.1.5]. align data to something like a word boundary for more efficient
copying. Restart markers MUST NOT appear anywhere else in the JPEG
payload. Types which do not support restart makers MUST NOT contain
restart markers anywhere in the JPEG payload. All packets MUST
contain a "stuffed" 0x00 byte following any true 0xFF byte generated
by the entropy coder [1, Sec. B.1.1.5].
4. Discussion 4. Discussion
4.1. The Type Field 4.1. The Type Field
The Type field defines the abbreviated table-specification and The Type field defines the abbreviated table-specification and
additional JFIF-style parameters not defined by JPEG, since they are not additional JFIF-style parameters not defined by JPEG, since they are
present in the body of the transmitted JPEG data. not present in the body of the transmitted JPEG data.
Three ranges of the type field are currently defined. Types 0-63 are Three ranges of the type field are currently defined. Types 0-63 are
reserved as fixed, well-known mappings to be defined by this document reserved as fixed, well-known mappings to be defined by this document
and future revisions of this document. Types 64-127 are the same as and future revisions of this document. Types 64-127 are the same as
types 0-63, except that restart markers are present in the JPEG data and types 0-63, except that restart markers are present in the JPEG data
a Restart Marker header appears immediately following the main JPEG and a Restart Marker header appears immediately following the main
header. Types 128-255 are free to be dynamically defined by a session JPEG header. Types 128-255 are free to be dynamically defined by a
setup protocol (which is beyond the scope of this document). session setup protocol (which is beyond the scope of this document).
Of the first group of fixed mappings, types 0 and 1 are currently Of the first group of fixed mappings, types 0 and 1 are currently
defined, along with the corresponding types 64 and 65 that indicate the defined, along with the corresponding types 64 and 65 that indicate
presence of restart markers. They correspond to an abbreviated table- the presence of restart markers. They correspond to an abbreviated
specification indicating the "Baseline DCT sequential" mode, 8-bit table-specification indicating the "Baseline DCT sequential" mode,
samples, square pixels, three components in the YUV color space, 8-bit samples, square pixels, three components in the YUV color
standard Huffman tables as defined in [1, Annex K.3], and a single space, standard Huffman tables as defined in [1, Annex K.3], and a
interleaved scan with a scan component selector indicating components 1, single interleaved scan with a scan component selector indicating
2, and 3 in that order. The Y, U, and V color planes correspond to components 1, 2, and 3 in that order. The Y, U, and V color planes
component numbers 1, 2, and 3, respectively. Component 1 (i.e., the correspond to component numbers 1, 2, and 3, respectively. Component
luminance plane) uses Huffman table number 0 and quantization table 1 (i.e., the luminance plane) uses Huffman table number 0 and
number 0 (defined below) and components 2 and 3 (i.e., the chrominance quantization table number 0 (defined below) and components 2 and 3
planes) use Huffman table number 1 and quantization table number 1 (i.e., the chrominance planes) use Huffman table number 1 and
(defined below). quantization table number 1 (defined below).
Type numbers 2-5 are reserved and should not be used. Applications Type numbers 2-5 are reserved and SHOULD NOT be used. Applications
based on previous versions of this document (RFC 2035) should be updated based on previous versions of this document (RFC 2035) should be
to indicate the presence of restart markers with type 64 or 65 and the updated to indicate the presence of restart markers with type 64 or
Restart Marker header. 65 and the Restart Marker header.
The two RTP/JPEG types currently defined are described below: The two RTP/JPEG types currently defined are described below:
horizontal vertical Quantization horizontal vertical Quantization
types component samp. fact. samp. fact. table number types component samp. fact. samp. fact. table number
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | 1 (Y) | 2 | 1 | 0 | | | 1 (Y) | 2 | 1 | 0 |
| 0, 64 | 2 (U) | 1 | 1 | 1 | | 0, 64 | 2 (U) | 1 | 1 | 1 |
| | 3 (V) | 1 | 1 | 1 | | | 3 (V) | 1 | 1 | 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | 1 (Y) | 2 | 2 | 0 | | | 1 (Y) | 2 | 2 | 0 |
| 1, 65 | 2 (U) | 1 | 1 | 1 | | 1, 65 | 2 (U) | 1 | 1 | 1 |
| | 3 (V) | 1 | 1 | 1 | | | 3 (V) | 1 | 1 | 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
These sampling factors indicate that the chrominance components of type These sampling factors indicate that the chrominance components of
0 video is downsampled horizontally by 2 (often called 4:2:2) while the type 0 video is downsampled horizontally by 2 (often called 4:2:2)
chrominance components of type 1 video are downsampled both horizontally while the chrominance components of type 1 video are downsampled both
and vertically by 2 (often called 4:2:0). horizontally and vertically by 2 (often called 4:2:0).
Types 0 and 1 can be used to carry both progressively scanned and Types 0 and 1 can be used to carry both progressively scanned and
interlaced image data. This is encoded using the Type-specific field in interlaced image data. This is encoded using the Type-specific field
the main JPEG header. The following values are defined: in the main JPEG header. The following values are defined:
0 : Image is progressively scanned. On a computer monitor, it can 0 : Image is progressively scanned. On a computer monitor, it can
be displayed as-is at the specified width and height. be displayed as-is at the specified width and height.
1 : Image is an odd field of an interlaced video signal. The 1 : Image is an odd field of an interlaced video signal. The
height specified in the main JPEG header is half of the height height specified in the main JPEG header is half of the height
of the entire displayed image. This field should be de- of the entire displayed image. This field should be de-
interlaced with the even field following it such that lines interlaced with the even field following it such that lines
from each of the images alternate. Corresponding lines from from each of the images alternate. Corresponding lines from
the even field should appear just above those same lines from the even field should appear just above those same lines from
the odd field. the odd field.
2 : Image is an even field of an interlaced video signal. 2 : Image is an even field of an interlaced video signal.
3 : Image is a single field from an interlaced video signal, but it 3 : Image is a single field from an interlaced video signal, but
should be displayed full frame as if it were received as both it should be displayed full frame as if it were received as
the odd & even fields of the frame. On a computer monitor, both the odd & even fields of the frame. On a computer
each line in the image should be displayed twice, doubling the monitor, each line in the image should be displayed twice,
height of the image. doubling the height of the image.
Appendix B contains C source code for transforming the RTP/JPEG header Appendix B contains C source code for transforming the RTP/JPEG
parameters into the JPEG frame and scan headers that are absent from the header parameters into the JPEG frame and scan headers that are
data payload. absent from the data payload.
4.2. The Q Field 4.2. The Q Field
For JPEG types 0 and 1 (and their corresponding types 64 and 65), Q For JPEG types 0 and 1 (and their corresponding types 64 and 65), Q
values between 1 and 99 inclusive are defined as follows. Other values values between 1 and 99 inclusive are defined as follows. Other
less than 128 are reserved. Additional types are encouraged to use this values less than 128 are reserved. Additional types are encouraged
definition if applicable. to use this definition if applicable.
Both type 0 and type 1 JPEG require two quantization tables. These Both type 0 and type 1 JPEG require two quantization tables. These
tables are calculated as follows. For 1 <= Q <= 99, the Independent tables are calculated as follows. For 1 <= Q <= 99, the Independent
JPEG Group's formula [5] is used to produce a scale factor S as: JPEG Group's formula [5] is used to produce a scale factor S as:
S = 5000 / Q for 1 <= Q <= 50 S = 5000 / Q for 1 <= Q <= 50
= 200 - 2 * Q for 51 <= Q <= 99 = 200 - 2 * Q for 51 <= Q <= 99
This value is then used to scale Tables K.1 and K.2 from [1] (saturating This value is then used to scale Tables K.1 and K.2 from [1]
each value to 8 bits) to give quantization table numbers 0 and 1, (saturating each value to 8 bits) to give quantization table numbers
respectively. C source code is provided in Appendix A to compute these 0 and 1, respectively. C source code is provided in Appendix A to
tables. compute these tables.
For Q values 128-255, dynamically defined quantization tables are used. For Q values 128-255, dynamically defined quantization tables are
These tables may be specified either in-band or out of band by something used. These tables may be specified either in-band or out of band by
like a session setup protocol, but the Quantization Table header must something like a session setup protocol, but the Quantization Table
always be present in the first packet of every frame. When the tables header MUST be present in the first packet of every frame. When the
are specified out of band, they may be omitted from the packet by tables are specified out of band, they may be omitted from the packet
setting the Length field in this header to 0. by setting the Length field in this header to 0.
When the quantization tables are sent in-band, they need not be sent When the quantization tables are sent in-band, they need not be sent
with every frame. Like the out of band case, frames which do not with every frame. Like the out of band case, frames which do not
contain tables will have a Quantization Table header with a Length field contain tables will have a Quantization Table header with a Length
of 0. While this does decrease the overhead of including the tables, field of 0. While this does decrease the overhead of including the
new receivers will be unable to properly decode frames from the time tables, new receivers will be unable to properly decode frames from
they start up until they receive the tables. the time they start up until they receive the tables.
4.3. Fragmentation and Reassembly 4.3. Fragmentation and Reassembly
Since JPEG frames can be large, they must often be fragmented. Frames Since JPEG frames can be large, they must often be fragmented.
should be fragmented into packets in a manner avoiding fragmentation at Frames SHOULD be fragmented into packets in a manner avoiding
a lower level. If support for partial frame decoding is desired, frames fragmentation at a lower level. If support for partial frame
should be fragmented such that each packet contains an integral number decoding is desired, frames SHOULD be fragmented such that each
of restart intervals (see below). packet contains an integral number of restart intervals (see below).
Each packet that makes up a single frame has the same timestamp. The Each packet that makes up a single frame MUST have the same
fragment offset field is set to the byte offset of this packet within timestamp, and the RTP marker bit MUST be set on the last packet in a
the original frame. The RTP marker bit is set on the last packet in a frame. The fragment offset field of each packet is set to the byte
frame. offset of its payload data within the original frame. Packets making
up a frame SHOULD be sent sequentially and the fragments they contain
MUST NOT overlap one another.
An entire frame can be identified as a sequence of packets beginning An entire frame can be identified as a sequence of packets beginning
with a packet having a zero fragment offset and ending with a packet with a packet having a zero fragment offset and ending with a packet
having the RTP marker bit set. Missing packets can be detected either having the RTP marker bit set. Missing packets can be detected
with RTP sequence numbers or with the fragment offset and lengths of either with RTP sequence numbers or with the fragment offset and
each packet. Reassembly could be carried out without the offset field lengths of each packet. Reassembly could be carried out without the
(i.e., using only the RTP marker bit and sequence numbers), but an offset field (i.e., using only the RTP marker bit and sequence
efficient single-copy implementation would not otherwise be possible in numbers), but an efficient single-copy implementation would not
the presence of misordered packets. Moreover, if the last packet of the otherwise be possible in the presence of misordered packets.
previous frame (containing the marker bit) were dropped, then a receiver Moreover, if the last packet of the previous frame (containing the
could not always detect that the current frame is entirely intact. marker bit) were dropped, then a receiver could not always detect
that the current frame is entirely intact.
4.4. Restart Markers 4.4. Restart Markers
Restart markers indicate a point in the JPEG stream at which the Huffman Restart markers indicate a point in the JPEG stream at which the
decoder and DC predictors are reset, allowing partial decoding starting Huffman decoder and DC predictors are reset, allowing partial
at that point. To fully take advantage of this, however, a decoder must decoding starting at that point. To fully take advantage of this,
know which MCUs of a frame a particular restart interval encodes. While however, a decoder must know which MCUs of a frame a particular
the original JPEG specification does provide a small sequence number restart interval encodes. While the original JPEG specification does
field in the restart markers for this purpose, it is not large enough to provide a small sequence number field in the restart markers for this
properly cope with the loss of an entire packet's worth of data at a purpose, it is not large enough to properly cope with the loss of an
typical network MTU size. The RTP/JPEG Restart Marker header contains entire packet's worth of data at a typical network MTU size. The
the additional information needed to accomplish this. RTP/JPEG Restart Marker header contains the additional information
needed to accomplish this.
Ideally, the size of restart intervals should be chosen to always allow The size of restart intervals SHOULD be chosen to always allow an
an integral number of restart intervals to fit within a single packet. integral number of restart intervals to fit within a single packet.
This will guarantee that packets can be decoded independently from one This will guarantee that packets can be decoded independently from
another. If a restart interval ends up being larger than a packet, the one another. If a restart interval ends up being larger than a
F and L bits in the Restart Marker header can be used to fragment it, packet, the F and L bits in the Restart Marker header can be used to
but the resulting set of packets must all be received by a decoder for fragment it, but the resulting set of packets must all be received by
that restart interval to be decoded properly. a decoder for that restart interval to be decoded properly.
Once a decoder has received either a single packet with both the F and L Once a decoder has received either a single packet with both the F
bits set on or a contiguous sequence of packets (based on the RTP and L bits set on or a contiguous sequence of packets (based on the
sequence number) which begin with an F bit and end with an L bit, it can RTP sequence number) which begin with an F bit and end with an L bit,
begin decoding. The position of the MCU at the beginning of the data it can begin decoding. The position of the MCU at the beginning of
can be determined by multiplying the Restart Count value by the Restart the data can be determined by multiplying the Restart Count value by
Interval value. A packet (or group of packets as identified by the F the Restart Interval value. A packet (or group of packets as
and L bits) may contain any number of consecutive restart intervals. identified by the F and L bits) may contain any number of consecutive
restart intervals.
To accommodate encoders which generate frames with restart markers in To accommodate encoders which generate frames with restart markers in
them but cannot fragment the data in this manner, the Restart Count them but cannot fragment the data in this manner, the Restart Count
field may be set to 0x3FFF with the F and L bits both set to 1. This field may be set to 0x3FFF with the F and L bits both set to 1. This
indicates to decoders that the entire frame must be reassembled before indicates to decoders that the entire frame must be reassembled
decoding it. before decoding it.
5. Security Considerations 5. Security Considerations
RTP packets using the payload format defined in this specification are RTP packets using the payload format defined in this specification
subject to the security considerations discussed in the RTP are subject to the security considerations discussed in the RTP
specification [6], and any appropriate RTP profile (for example [7]). specification [6], and any appropriate RTP profile (for example [7]).
This implies that confidentiality of the media streams is achieved by This implies that confidentiality of the media streams is achieved by
encryption. Because the data compression used with this payload format encryption. Because the data compression used with this payload
is applied end-to-end, encryption may be performed after compression so format is applied end-to-end, encryption may be performed after
there is no conflict between the two operations. compression so there is no conflict between the two operations.
A potential denial-of-service threat exists for data encodings using A potential denial-of-service threat exists for data encodings using
compression techniques that have non-uniform receiver-end computational compression techniques that have non-uniform receiver-end
load. The attacker can inject pathological datagrams into the stream computational load. The attacker can inject pathological datagrams
which are complex to decode and cause the receiver to be overloaded. into the stream which are complex to decode and cause the receiver to
However, this encoding does not exhibit any significant non-uniformity. be overloaded. However, this encoding does not exhibit any
significant non-uniformity.
As with any IP-based protocol, in some circumstances a receiver may be Another potential denial-of-service threat exists around the
overloaded simply by the receipt of too many packets, either desired or fragmentation mechanism presented here. Receivers should be prepared
undesired. Network-layer authentication may be used to discard packets to limit the total amount of data associated with assembling received
from undesired sources, but the processing cost of the authentication frames so as to avoid resource exhaustion.
itself may be too high. In a multicast environment, pruning of specific
sources may be implemented in future versions of IGMP [8] and in
multicast routing protocols to allow a receiver to select which sources
are allowed to reach it.
A security review of this payload format found no additional As with any IP-based protocol, in some circumstances a receiver may
considerations beyond those in the RTP specification. be overloaded simply by the receipt of too many packets, either
desired or undesired. Network-layer authentication may be used to
discard packets from undesired sources, but the processing cost of
the authentication itself may be too high. In a multicast
environment, pruning of specific sources will be implemented in a
future version of IGMP [8] and in multicast routing protocols to
allow a receiver to select which sources are allowed to reach it.
A security review of this payload format found no additional
considerations beyond those in the RTP specification.
6. Authors' Addresses 6. Authors' Addresses
Lance M. Berc Lance M. Berc
Systems Research Center Systems Research Center
Digital Equipment Corporation Digital Equipment Corporation
130 Lytton Ave 130 Lytton Ave
Palo Alto CA 94301 Palo Alto CA 94301
Phone: +1 650 853 2100 Phone: +1 650 853 2100
skipping to change at page 13, line 4 skipping to change at page 13, line 23
Phone: +1 650 853 2100 Phone: +1 650 853 2100
EMail: berc@pa.dec.com EMail: berc@pa.dec.com
William C. Fenner William C. Fenner
Xerox PARC Xerox PARC
3333 Coyote Hill Road 3333 Coyote Hill Road
Palo Alto, CA 94304 Palo Alto, CA 94304
Phone: +1 650 812 4816 Phone: +1 650 812 4816
EMail: fenner@parc.xerox.com EMail: fenner@parc.xerox.com
Ron Frederick Ron Frederick
Xerox PARC Xerox PARC
3333 Coyote Hill Road 3333 Coyote Hill Road
Palo Alto, CA 94304 Palo Alto, CA 94304
Phone: +1 650 812 4459 Phone: +1 650 812 4459
EMail: frederick@parc.xerox.com EMail: frederick@parc.xerox.com
Steven McCanne Steven McCanne
Lawrence Berkeley Laboratory University of California at Berkeley
M/S 46A-1123 Electrical Engineering and Computer Science
One Cyclotron Road 633 Soda Hall
Berkeley, CA 94720 Berkeley, CA 94720
Phone: +1 510 486 7520 Phone: +1 510 642 0865
EMail: mccanne@ee.lbl.gov EMail: mccanne@cs.berkeley.edu
Paul Stewart Paul Stewart
Xerox PARC Xerox PARC
3333 Coyote Hill Road 3333 Coyote Hill Road
Palo Alto, CA 94304 Palo Alto, CA 94304
Phone: +1 650 812 4821 Phone: +1 650 812 4821
EMail: stewart@parc.xerox.com EMail: stewart@parc.xerox.com
7. References 7. References
[1] ISO DIS 10918-1. Digital Compression and Coding of Continuous-tone [1] ISO DIS 10918-1. Digital Compression and Coding of Continuous-
Still Images (JPEG), CCITT Recommendation T.81. tone Still Images (JPEG), CCITT Recommendation T.81.
[2] William B. Pennebaker, Joan L. Mitchell, JPEG: Still Image Data [2] William B. Pennebaker, Joan L. Mitchell, JPEG: Still Image Data
Compression Standard, Van Nostrand Reinhold, 1993. Compression Standard, Van Nostrand Reinhold, 1993.
[3] Gregory K. Wallace, The JPEG Sill Picture Compression Standard, [3] Gregory K. Wallace, The JPEG Sill Picture Compression Standard,
Communications of the ACM, April 1991, Vol 34, No. 1, pp. 31-44. Communications of the ACM, April 1991, Vol 34, No. 1, pp. 31-44.
[4] The JPEG File Interchange Format. Maintained by C-Cube [4] The JPEG File Interchange Format. Maintained by C-Cube
Microsystems, Inc., and available in Microsystems, Inc., and available in
ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz. ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz.
[5] Tom Lane et. al., The Independent JPEG Group software JPEG codec. [5] Tom Lane et. al., The Independent JPEG Group software JPEG
Source code available in codec. Source code available in
ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6a.tar.gz. ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6a.tar.gz.
[6] H. Schulzrinne, S. Casner, R. Frederick, V. Jacobson, RTP: A [6] Schulzrinne, H., Casner, S., Frederick, R. and V. Jacobson,
Transport Protocol for Real-Time Applications, RFC1889, Audio-Video "RTP: A Transport Protocol for Real-Time Applications", RFC
Transport Working Group 1889, January 1996.
[7] H. Schulzrinne, RTP Profile for Audio and Video Conferences with [7] Schulzrinne, H., "RTP Profile for Audio and Video Conferences
Minimal Control, RFC1890, GMD Fokus with Minimal Control", RFC 1890, January 1996.
[8] W. Fenner, Internet Group Management Protocol Version 2, RFCxxxx [8] Fenner, W., "Internet Group Management Protocol Version 2", RFC
(currently draft-ietf-idmr-igmp-v2-08.txt, in rfc-editor queue), 2236, November 1997.
Xerox PARC
[9] Bradner, S., "Key words for use in RFCs to Indicate Requirement
Levels", BCP 14, RFC 2119, March 1997.
[10] Kent C., and J. Mogul, "Fragmentation Considered Harmful",
Proceedings of the ACM SIGCOMM '87 Workshop on Frontiers in
Computer Communications Technology, August 1987.
Appendix A Appendix A
The following code can be used to create a quantization table from a Q The following code can be used to create a quantization table from a
factor: Q factor:
/* /*
* Table K.1 from JPEG spec. * Table K.1 from JPEG spec.
*/ */
static const int jpeg_luma_quantizer[64] = { static const int jpeg_luma_quantizer[64] = {
16, 11, 10, 16, 24, 40, 51, 61, 16, 11, 10, 16, 24, 40, 51, 61,
12, 12, 14, 19, 26, 58, 60, 55, 12, 12, 14, 19, 26, 58, 60, 55,
14, 13, 16, 24, 40, 57, 69, 56, 14, 13, 16, 24, 40, 57, 69, 56,
14, 17, 22, 29, 51, 87, 80, 62, 14, 17, 22, 29, 51, 87, 80, 62,
18, 22, 37, 56, 68, 109, 103, 77, 18, 22, 37, 56, 68, 109, 103, 77,
skipping to change at page 15, line 39 skipping to change at page 15, line 39
18, 21, 26, 66, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99,
47, 66, 99, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99 99, 99, 99, 99, 99, 99, 99, 99
}; };
/* /*
* Call MakeTables with the Q factor and two int[64] return arrays * Call MakeTables with the Q factor and two u_char[64] return arrays
*/ */
void void
MakeTables(int q, u_char *lum_q, u_char *chr_q) MakeTables(int q, u_char *lqt, u_char *cqt)
{ {
int i; int i;
int factor = q; int factor = q;
if (q < 1) factor = 1; if (q < 1) factor = 1;
if (q > 99) factor = 99; if (q > 99) factor = 99;
if (q < 50) if (q < 50)
q = 5000 / factor; q = 5000 / factor;
else else
q = 200 - factor*2; q = 200 - factor*2;
for (i=0; i < 64; i++) { for (i=0; i < 64; i++) {
int lq = ( jpeg_luma_quantizer[i] * q + 50) / 100; int lq = (jpeg_luma_quantizer[i] * q + 50) / 100;
int cq = ( jpeg_chroma_quantizer[i] * q + 50) / 100; int cq = (jpeg_chroma_quantizer[i] * q + 50) / 100;
/* Limit the quantizers to 1 <= q <= 255 */ /* Limit the quantizers to 1 <= q <= 255 */
if ( lq < 1) lq = 1; if (lq < 1) lq = 1;
else if ( lq > 255) lq = 255; else if (lq > 255) lq = 255;
lum_q[i] = lq; lqt[i] = lq;
if ( cq < 1) cq = 1; if (cq < 1) cq = 1;
else if ( cq > 255) cq = 255; else if (cq > 255) cq = 255;
chr_q[i] = cq; cqt[i] = cq;
} }
} }
Appendix B Appendix B
The following routines can be used to create the JPEG marker segments The following routines can be used to create the JPEG marker segments
corresponding to the table-specification data that is absent from the corresponding to the table-specification data that is absent from the
RTP/JPEG body. RTP/JPEG body.
u_char lum_dc_codelens[] = { u_char lum_dc_codelens[] = {
0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
}; };
u_char lum_dc_symbols[] = { u_char lum_dc_symbols[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
}; };
u_char lum_ac_codelens[] = { u_char lum_ac_codelens[] = {
skipping to change at page 18, line 15 skipping to change at page 18, line 48
*p++ = 0xff; *p++ = 0xff;
*p++ = 0xdb; /* DQT */ *p++ = 0xdb; /* DQT */
*p++ = 0; /* length msb */ *p++ = 0; /* length msb */
*p++ = 67; /* length lsb */ *p++ = 67; /* length lsb */
*p++ = tableNo; *p++ = tableNo;
memcpy(p, qt, 64); memcpy(p, qt, 64);
return (p + 64); return (p + 64);
} }
u_char * u_char *
MakeHuffmanHeader(u_char *p, u_char *codelens, int ncodes, u_char *symbols, MakeHuffmanHeader(u_char *p, u_char *codelens, int ncodes,
int nsymbols, int tableNo, int tableClass) u_char *symbols, int nsymbols, int tableNo,
int tableClass)
{ {
*p++ = 0xff; *p++ = 0xff;
*p++ = 0xc4; /* DHT */ *p++ = 0xc4; /* DHT */
*p++ = 0; /* length msb */ *p++ = 0; /* length msb */
*p++ = 3 + ncodes + nsymbols; /* length lsb */ *p++ = 3 + ncodes + nsymbols; /* length lsb */
*p++ = tableClass << 4 | tableNo; *p++ = (tableClass << 4) | tableNo;
memcpy(p, codelens, ncodes); memcpy(p, codelens, ncodes);
p += ncodes; p += ncodes;
memcpy(p, symbols, nsymbols); memcpy(p, symbols, nsymbols);
p += nsymbols; p += nsymbols;
return (p); return (p);
} }
u_char * u_char *
MakeDRIHeader(u_char *p, u_short dri) { MakeDRIHeader(u_char *p, u_short dri) {
*p++ = 0xff; *p++ = 0xff;
skipping to change at page 19, line 4 skipping to change at page 19, line 37
* Arguments: * Arguments:
* type, width, height: as supplied in RTP/JPEG header * type, width, height: as supplied in RTP/JPEG header
* lqt, cqt: quantization tables as either derived from * lqt, cqt: quantization tables as either derived from
* the Q field using MakeTables() or as specified * the Q field using MakeTables() or as specified
* in section 4.2. * in section 4.2.
* dri: restart interval in MCUs, or 0 if no restarts. * dri: restart interval in MCUs, or 0 if no restarts.
* *
* p: pointer to return area * p: pointer to return area
* *
* Return value: * Return value:
* The length of the generated headers. * The length of the generated headers.
* *
* Generate a frame and scan headers that can be prepended to the * Generate a frame and scan headers that can be prepended to the
* RTP/JPEG data payload to produce a JPEG compressed image in * RTP/JPEG data payload to produce a JPEG compressed image in
* interchange format (except for possible trailing garbage and * interchange format (except for possible trailing garbage and
* absence of an EOI marker to terminate the scan). * absence of an EOI marker to terminate the scan).
*/ */
int MakeHeaders(u_char *p, int type, int w, int h, u_char *lqt, u_char *cqt, int MakeHeaders(u_char *p, int type, int w, int h, u_char *lqt,
u_short dri) u_char *cqt, u_short dri)
{ {
u_char *start = p; u_char *start = p;
u_char lqt[64];
u_char cqt[64];
/* convert from blocks to pixels */ /* convert from blocks to pixels */
w <<= 3; w <<= 3;
h <<= 3; h <<= 3;
*p++ = 0xff; *p++ = 0xff;
*p++ = 0xd8; /* SOI */ *p++ = 0xd8; /* SOI */
p = MakeQuantHeader(p, lqt, 0); p = MakeQuantHeader(p, lqt, 0);
p = MakeQuantHeader(p, cqt, 1); p = MakeQuantHeader(p, cqt, 1);
if (dri != 0) if (dri != 0)
p = MakeDRIHeader(p, dri); p = MakeDRIHeader(p, dri);
*p++ = 0xff; *p++ = 0xff;
skipping to change at page 20, line 40 skipping to change at page 22, line 4
*p++ = 1; /* comp 1 */ *p++ = 1; /* comp 1 */
*p++ = 0x11; /* huffman table 1 */ *p++ = 0x11; /* huffman table 1 */
*p++ = 2; /* comp 2 */ *p++ = 2; /* comp 2 */
*p++ = 0x11; /* huffman table 1 */ *p++ = 0x11; /* huffman table 1 */
*p++ = 0; /* first DCT coeff */ *p++ = 0; /* first DCT coeff */
*p++ = 63; /* last DCT coeff */ *p++ = 63; /* last DCT coeff */
*p++ = 0; /* sucessive approx. */ *p++ = 0; /* sucessive approx. */
return (p - start); return (p - start);
}; };
Appendix C Appendix C
The following routine is used to illustrate the RTP/JPEG packet The following routine is used to illustrate the RTP/JPEG packet
fragmentation and header creation. fragmentation and header creation.
For clarity and brevity, the structure definitions are only valid for For clarity and brevity, the structure definitions are only valid for
32-bit big- endian (most significant octet first) architectures. Bit 32-bit big-endian (most significant octet first) architectures. Bit
fields are assumed to be packed tightly in big-endian bit order, with no fields are assumed to be packed tightly in big-endian bit order, with
additional padding. Modifications would be required to construct a no additional padding. Modifications would be required to construct a
portable implementation. portable implementation.
/* /*
* RTP data header from RFC1889 * RTP data header from RFC1889
*/ */
typedef struct { typedef struct {
unsigned int version:2; /* protocol version */ unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */ unsigned int p:1; /* padding flag */
unsigned int x:1; /* header extension flag */ unsigned int x:1; /* header extension flag */
unsigned int cc:4; /* CSRC count */ unsigned int cc:4; /* CSRC count */
unsigned int m:1; /* marker bit */ unsigned int m:1; /* marker bit */
skipping to change at page 22, line 4 skipping to change at page 23, line 15
u_int8 mbz; u_int8 mbz;
u_int8 precision; u_int8 precision;
u_int16 length; u_int16 length;
}; };
#define RTP_JPEG_RESTART 0x40 #define RTP_JPEG_RESTART 0x40
/* Procedure SendFrame: /* Procedure SendFrame:
* *
* Arguments: * Arguments:
* start_seq: The sequence number for the first packet of the current
* start_seq: The sequence number for the first packet of the current frame. * frame.
* ts: RTP timestamp for the current frame * ts: RTP timestamp for the current frame
* ssrc: RTP SSRC value * ssrc: RTP SSRC value
* jpeg_data: Huffman encoded JPEG scan data * jpeg_data: Huffman encoded JPEG scan data
* len: Length of the JPEG scan data * len: Length of the JPEG scan data
* type: The value the RTP/JPEG type field should be set to * type: The value the RTP/JPEG type field should be set to
* typespec: The value the RTP/JPEG type-specific field should be set to * typespec: The value the RTP/JPEG type-specific field should be set
* to
* width: The width in pixels of the JPEG image * width: The width in pixels of the JPEG image
* height: The height in pixels of the JPEG image * height: The height in pixels of the JPEG image
* dri: The number of MCUs between restart markers (or 0 if ther are no * dri: The number of MCUs between restart markers (or 0 if there
* restart markers in the data * are no restart markers in the data
* q: The Q factor of the data, to be specified using the Independent * q: The Q factor of the data, to be specified using the Independent
* JPEG group's algorithm if 1 <= q <= 99, specified explicitly with * JPEG group's algorithm if 1 <= q <= 99, specified explicitly
* lqt and cqt if q >= 128, or undefined otherwise. * with lqt and cqt if q >= 128, or undefined otherwise.
* lqt: The quantization table for the luminance channel if q >= 128 * lqt: The quantization table for the luminance channel if q >= 128
* cqt: The quantization table for the chrominance channels if q >= 128 * cqt: The quantization table for the chrominance channels if
* q >= 128
* *
* Return value: * Return value:
* the sequence number to be sent for the first packet of the next frame. * the sequence number to be sent for the first packet of the next
* frame.
* *
* The following are assumed to be defined: * The following are assumed to be defined:
* *
* PACKET_SIZE - The size of the outgoing packet * PACKET_SIZE - The size of the outgoing packet
* send_packet(u_int8 *data, int len) - Sends the packet to the network * send_packet(u_int8 *data, int len) - Sends the packet to the network
*/ */
u_int16 SendFrame(u_int16 start_seq, u_int32 ts, u_int32 ssrc, u_int16 SendFrame(u_int16 start_seq, u_int32 ts, u_int32 ssrc,
u_int8 *jpeg_data, int len, u_int8 type, u_int8 typespec, u_int8 *jpeg_data, int len, u_int8 type,
int width, int height, int dri, u_int8 typespec, int width, int height, int dri,
u_int8 q, u_int8 *lqt, u_int8 *cqt) { u_int8 q, u_int8 *lqt, u_int8 *cqt) {
rtp_hdr_t rtphdr; rtp_hdr_t rtphdr;
struct jpeghdr jpghdr; struct jpeghdr jpghdr;
struct jpeghdr_rst rsthdr; struct jpeghdr_rst rsthdr;
struct jpeghdr_qtable qtblhdr; struct jpeghdr_qtable qtblhdr;
u_int8 packet_buf[PACKET_SIZE]; u_int8 packet_buf[PACKET_SIZE];
u_int8 *ptr; u_int8 *ptr;
int bytes_left = len; int bytes_left = len;
int seq = start_seq; int seq = start_seq;
int pkt_len, data_len; int pkt_len, data_len;
skipping to change at page 23, line 21 skipping to change at page 24, line 36
jpghdr.off = 0; jpghdr.off = 0;
jpghdr.type = type | ((dri != 0) ? RTP_JPEG_RESTART : 0); jpghdr.type = type | ((dri != 0) ? RTP_JPEG_RESTART : 0);
jpghdr.q = q; jpghdr.q = q;
jpghdr.width = width / 8; jpghdr.width = width / 8;
jpghdr.height = height / 8; jpghdr.height = height / 8;
/* Initialize DRI header /* Initialize DRI header
*/ */
if (dri != 0) { if (dri != 0) {
rsthdr.dri = dri; rsthdr.dri = dri;
rsthdr.f = 1; /* This code does not align RIs */ rsthdr.f = 1; /* This code does not align RIs */
rsthdr.l = 1; rsthdr.l = 1;
rsthdr.count = 0x3fff; rsthdr.count = 0x3fff;
} }
/* Initialize quantization table header /* Initialize quantization table header
*/ */
if (q >= 128) { if (q >= 128) {
qtblhdr.mbz = 0; qtblhdr.mbz = 0;
qtblhdr.precision = 0; /* This code uses 8 bit tables only */ qtblhdr.precision = 0; /* This code uses 8 bit tables only */
qtblhdr.length = 128; /* 2 64-byte tables */ qtblhdr.length = 128; /* 2 64-byte tables */
} }
while (bytes_left > 0) { while (bytes_left > 0) {
ptr = packet_buf + RTP_HDR_SZ; ptr = packet_buf + RTP_HDR_SZ;
memcpy(ptr, &jpghdr, sizeof(jpghdr)); memcpy(ptr, &jpghdr, sizeof(jpghdr));
ptr += sizeof(jpghdr); ptr += sizeof(jpghdr);
if (dri != 0) { if (dri != 0) {
memcpy(ptr, &rsthdr, sizeof(rsthdr)); memcpy(ptr, &rsthdr, sizeof(rsthdr));
ptr += sizeof(rsthdr); ptr += sizeof(rsthdr);
skipping to change at page 24, line 21 skipping to change at page 26, line 4
memcpy(ptr, jpeg_data + jpghdr.off, data_len); memcpy(ptr, jpeg_data + jpghdr.off, data_len);
send_packet(packet_buf, (ptr - packet_buf) + data_len); send_packet(packet_buf, (ptr - packet_buf) + data_len);
jpghdr.off += data_len; jpghdr.off += data_len;
bytes_left -= data_len; bytes_left -= data_len;
rtphdr.seq++; rtphdr.seq++;
} }
return rtphdr.seq; return rtphdr.seq;
} }
Appendix D Appendix D
This section outlines the changes between this document and its This section outlines the changes between this document and its
precdecessor, RFC 2035. The changes to the protocol were made with an precdecessor, RFC 2035. The changes to the protocol were made with
eye towards causing as few interoperability problems between an eye towards causing as few interoperability problems between
implementations based on the older text and newer implementations, and implementations based on the older text and newer implementations,
indeed, many of the obsolete conventions can still be unambiguously and indeed, many of the obsolete conventions can still be
decoded by a newer implementation. However, use of the older unambiguously decoded by a newer implementation. However, use of the
conventions in newer implementations is strongly discouraged. older conventions in newer implementations is strongly discouraged.
o Types 0 and 1 have been augmented to allow for the encoding of o Types 0 and 1 have been augmented to allow for the encoding of
interlaced video images, using 2 bits of the type-specific field. interlaced video images, using 2 bits of the type-specific
See section 4.1 for details. field. See section 4.1 for details.
o There has been discussion in the working group arguing for more o There has been discussion in the working group arguing for more
flexibility in specifying the JPEG quantization tables. This draft flexibility in specifying the JPEG quantization tables. This
allows table coefficients to be specified explicitly through the memo allows table coefficients to be specified explicitly
use of an optional Quantization Table header, discussed in sections through the use of an optional Quantization Table header,
3.1.8 and 4.2. discussed in sections 3.1.8 and 4.2.
o In RFC 2035, the encoding of restart marker information in the Type o In RFC 2035, the encoding of restart marker information in the
field made it difficult to add new types. Additionally, the type- Type field made it difficult to add new types. Additionally, the
specific field was used for the restart count, making it type- specific field was used for the restart count, making it
unavailable for other type-specific purposes. This draft moves the unavailable for other type-specific purposes. This memo moves
restart marker indication to a particular bit in the Type field, the restart marker indication to a particular bit in the Type
and adds an optional header to hold the additional information field, and adds an optional header to hold the additional
required, leaving the type-specific field free for its intended information required, leaving the type-specific field free for
purpose. The handling of partial frame decoding was also made more its intended purpose. The handling of partial frame decoding
robust against packet loss. See sections 3.1.7 and 4.4 for was also made more robust against packet loss. See sections
details. 3.1.7 and 4.4 for details.
Full Copyright Statement
Copyright (C) The Internet Society (1998). All Rights Reserved.
This document and translations of it may be copied and furnished to
others, and derivative works that comment on or otherwise explain it
or assist in its implementation may be prepared, copied, published
and distributed, in whole or in part, without restriction of any
kind, provided that the above copyright notice and this paragraph are
included on all such copies and derivative works. However, this
document itself may not be modified in any way, such as by removing
the copyright notice or references to the Internet Society or other
Internet organizations, except as needed for the purpose of
developing Internet standards in which case the procedures for
copyrights defined in the Internet Standards process must be
followed, or as required to translate it into languages other than
English.
The limited permissions granted above are perpetual and will not be
revoked by the Internet Society or its successors or assigns.
This document and the information contained herein is provided on an
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 End of changes. 118 change blocks. 
495 lines changed or deleted 528 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/