00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavutil/avassert.h"
00023 #include "avformat.h"
00024 #include "rtpenc.h"
00025
00031 void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
00032 {
00033 RTPMuxContext *s = s1->priv_data;
00034 int max_pkt_size, xdt, frag;
00035 uint8_t *q;
00036
00037 max_pkt_size = s->max_payload_size;
00038
00039
00040 switch (*buff) {
00041 case 0x01:
00042 case 0x05:
00043 case 0x80:
00044 case 0x82:
00045 xdt = 1;
00046 break;
00047 case 0x03:
00048 case 0x81:
00049 xdt = 2;
00050 break;
00051 default:
00052 xdt = 0;
00053 break;
00054 }
00055
00056
00057
00058
00059 q = s->buf;
00060 *q++ = (RTP_XIPH_IDENT >> 16) & 0xff;
00061 *q++ = (RTP_XIPH_IDENT >> 8) & 0xff;
00062 *q++ = (RTP_XIPH_IDENT ) & 0xff;
00063
00064
00065
00066
00067
00068
00069 frag = size <= max_pkt_size ? 0 : 1;
00070
00071 if (!frag && !xdt) {
00072 uint8_t *end_ptr = s->buf + 6 + max_pkt_size;
00073 uint8_t *ptr = s->buf_ptr + 2 + size;
00074 int remaining = end_ptr - ptr;
00075
00076 av_assert1(s->num_frames <= s->max_frames_per_packet);
00077 if ((s->num_frames > 0 && remaining < 0) ||
00078 s->num_frames == s->max_frames_per_packet) {
00079
00080 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
00081 s->num_frames = 0;
00082 }
00083
00084
00085 if (0 == s->num_frames) s->timestamp = s->cur_timestamp;
00086 s->num_frames++;
00087
00088
00089
00090 *q++ = s->num_frames;
00091
00092 if (s->num_frames > 1) q = s->buf_ptr;
00093 *q++ = (size >> 8) & 0xff;
00094 *q++ = size & 0xff;
00095 memcpy(q, buff, size);
00096 q += size;
00097 s->buf_ptr = q;
00098
00099 return;
00100 } else if (s->num_frames) {
00101
00102
00103 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
00104 }
00105
00106 s->timestamp = s->cur_timestamp;
00107 s->num_frames = 0;
00108 s->buf_ptr = q;
00109 while (size > 0) {
00110 int len = (!frag || frag == 3) ? size : max_pkt_size;
00111 q = s->buf_ptr;
00112
00113
00114 *q++ = (frag << 6) | (xdt << 4);
00115 *q++ = (len >> 8) & 0xff;
00116 *q++ = len & 0xff;
00117
00118 memcpy(q, buff, len);
00119 q += len;
00120 buff += len;
00121 size -= len;
00122
00123 ff_rtp_send_data(s1, s->buf, q - s->buf, 0);
00124
00125 frag = size <= max_pkt_size ? 3 : 2;
00126 }
00127 }