rfc2435.txt
来自「RFC 的详细文档!」· 文本 代码 · 共 1,516 行 · 第 1/4 页
TXT
1,516 行
*p++ = 0; /* first DCT coeff */
*p++ = 63; /* last DCT coeff */
*p++ = 0; /* sucessive approx. */
return (p - start);
};
Berc, et. al. Standards Track [Page 21]
RFC 2435 RTP Payload Format for JPEG October 1998
Appendix C
The following routine is used to illustrate the RTP/JPEG packet
fragmentation and header creation.
For clarity and brevity, the structure definitions are only valid for
32-bit big-endian (most significant octet first) architectures. Bit
fields are assumed to be packed tightly in big-endian bit order, with
no additional padding. Modifications would be required to construct a
portable implementation.
/*
* RTP data header from RFC1889
*/
typedef struct {
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
unsigned int x:1; /* header extension flag */
unsigned int cc:4; /* CSRC count */
unsigned int m:1; /* marker bit */
unsigned int pt:7; /* payload type */
u_int16 seq; /* sequence number */
u_int32 ts; /* timestamp */
u_int32 ssrc; /* synchronization source */
u_int32 csrc[1]; /* optional CSRC list */
} rtp_hdr_t;
#define RTP_HDR_SZ 12
/* The following definition is from RFC1890 */
#define RTP_PT_JPEG 26
struct jpeghdr {
unsigned int tspec:8; /* type-specific field */
unsigned int off:24; /* fragment byte offset */
u_int8 type; /* id of jpeg decoder params */
u_int8 q; /* quantization factor (or table id) */
u_int8 width; /* frame width in 8 pixel blocks */
u_int8 height; /* frame height in 8 pixel blocks */
};
struct jpeghdr_rst {
u_int16 dri;
unsigned int f:1;
unsigned int l:1;
unsigned int count:14;
};
Berc, et. al. Standards Track [Page 22]
RFC 2435 RTP Payload Format for JPEG October 1998
struct jpeghdr_qtable {
u_int8 mbz;
u_int8 precision;
u_int16 length;
};
#define RTP_JPEG_RESTART 0x40
/* Procedure SendFrame:
*
* Arguments:
* start_seq: The sequence number for the first packet of the current
* frame.
* ts: RTP timestamp for the current frame
* ssrc: RTP SSRC value
* jpeg_data: Huffman encoded JPEG scan data
* len: Length of the JPEG scan data
* 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
* width: The width 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 there
* are no restart markers in the data
* q: The Q factor of the data, to be specified using the Independent
* JPEG group's algorithm if 1 <= q <= 99, specified explicitly
* with lqt and cqt if q >= 128, or undefined otherwise.
* lqt: The quantization table for the luminance channel if q >= 128
* cqt: The quantization table for the chrominance channels if
* q >= 128
*
* Return value:
* the sequence number to be sent for the first packet of the next
* frame.
*
* The following are assumed to be defined:
*
* PACKET_SIZE - The size of the outgoing packet
* 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_int8 *jpeg_data, int len, u_int8 type,
u_int8 typespec, int width, int height, int dri,
u_int8 q, u_int8 *lqt, u_int8 *cqt) {
rtp_hdr_t rtphdr;
struct jpeghdr jpghdr;
struct jpeghdr_rst rsthdr;
Berc, et. al. Standards Track [Page 23]
RFC 2435 RTP Payload Format for JPEG October 1998
struct jpeghdr_qtable qtblhdr;
u_int8 packet_buf[PACKET_SIZE];
u_int8 *ptr;
int bytes_left = len;
int seq = start_seq;
int pkt_len, data_len;
/* Initialize RTP header
*/
rtphdr.version = 2;
rtphdr.p = 0;
rtphdr.x = 0;
rtphdr.cc = 0;
rtphdr.m = 0;
rtphdr.pt = RTP_PT_JPEG;
rtphdr.seq = start_seq;
rtphdr.ts = ts;
rtphdr.ssrc = ssrc;
/* Initialize JPEG header
*/
jpghdr.tspec = typespec;
jpghdr.off = 0;
jpghdr.type = type | ((dri != 0) ? RTP_JPEG_RESTART : 0);
jpghdr.q = q;
jpghdr.width = width / 8;
jpghdr.height = height / 8;
/* Initialize DRI header
*/
if (dri != 0) {
rsthdr.dri = dri;
rsthdr.f = 1; /* This code does not align RIs */
rsthdr.l = 1;
rsthdr.count = 0x3fff;
}
/* Initialize quantization table header
*/
if (q >= 128) {
qtblhdr.mbz = 0;
qtblhdr.precision = 0; /* This code uses 8 bit tables only */
qtblhdr.length = 128; /* 2 64-byte tables */
}
while (bytes_left > 0) {
ptr = packet_buf + RTP_HDR_SZ;
memcpy(ptr, &jpghdr, sizeof(jpghdr));
Berc, et. al. Standards Track [Page 24]
RFC 2435 RTP Payload Format for JPEG October 1998
ptr += sizeof(jpghdr);
if (dri != 0) {
memcpy(ptr, &rsthdr, sizeof(rsthdr));
ptr += sizeof(rsthdr);
}
if (q >= 128 && jpghdr.off == 0) {
memcpy(ptr, &qtblhdr, sizeof(qtblhdr));
ptr += sizeof(qtblhdr);
memcpy(ptr, lqt, 64);
ptr += 64;
memcpy(ptr, cqt, 64);
ptr += 64;
}
data_len = PACKET_SIZE - (ptr - packet_buf);
if (data_len >= bytes_left) {
data_len = bytes_left;
rtphdr.m = 1;
}
memcpy(packet_buf, &rtphdr, RTP_HDR_SZ);
memcpy(ptr, jpeg_data + jpghdr.off, data_len);
send_packet(packet_buf, (ptr - packet_buf) + data_len);
jpghdr.off += data_len;
bytes_left -= data_len;
rtphdr.seq++;
}
return rtphdr.seq;
}
Berc, et. al. Standards Track [Page 25]
RFC 2435 RTP Payload Format for JPEG October 1998
Appendix D
This section outlines the changes between this document and its
precdecessor, RFC 2035. The changes to the protocol were made with
an eye towards causing as few interoperability problems between
implementations based on the older text and newer implementations,
and indeed, many of the obsolete conventions can still be
unambiguously decoded by a newer implementation. However, use of the
older conventions in newer implementations is strongly discouraged.
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. See section 4.1 for details.
o There has been discussion in the working group arguing for more
flexibility in specifying the JPEG quantization tables. This
memo allows table coefficients to be specified explicitly
through the use of an optional Quantization Table header,
discussed in sections 3.1.8 and 4.2.
o In RFC 2035, the encoding of restart marker information in the
Type field made it difficult to add new types. Additionally, the
type- specific field was used for the restart count, making it
unavailable for other type-specific purposes. This memo moves
the restart marker indication to a particular bit in the Type
field, and adds an optional header to hold the additional
information required, leaving the type-specific field free for
its intended purpose. The handling of partial frame decoding
was also made more robust against packet loss. See sections
3.1.7 and 4.4 for details.
Berc, et. al. Standards Track [Page 26]
RFC 2435 RTP Payload Format for JPEG October 1998
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.
Berc, et. al. Standards Track [Page 27]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?