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