00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00028 #include "avformat.h"
00029 #include "avc.h"
00030 #include "rtpenc.h"
00031
00032 static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last)
00033 {
00034 RTPMuxContext *s = s1->priv_data;
00035
00036 av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last);
00037 if (size <= s->max_payload_size) {
00038 ff_rtp_send_data(s1, buf, size, last);
00039 } else {
00040 uint8_t type = buf[0] & 0x1F;
00041 uint8_t nri = buf[0] & 0x60;
00042
00043 av_log(s1, AV_LOG_DEBUG, "NAL size %d > %d\n", size, s->max_payload_size);
00044 s->buf[0] = 28;
00045 s->buf[0] |= nri;
00046 s->buf[1] = type;
00047 s->buf[1] |= 1 << 7;
00048 buf += 1;
00049 size -= 1;
00050 while (size + 2 > s->max_payload_size) {
00051 memcpy(&s->buf[2], buf, s->max_payload_size - 2);
00052 ff_rtp_send_data(s1, s->buf, s->max_payload_size, 0);
00053 buf += s->max_payload_size - 2;
00054 size -= s->max_payload_size - 2;
00055 s->buf[1] &= ~(1 << 7);
00056 }
00057 s->buf[1] |= 1 << 6;
00058 memcpy(&s->buf[2], buf, size);
00059 ff_rtp_send_data(s1, s->buf, size + 2, last);
00060 }
00061 }
00062
00063 void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
00064 {
00065 const uint8_t *r;
00066 RTPMuxContext *s = s1->priv_data;
00067
00068 s->timestamp = s->cur_timestamp;
00069 r = ff_avc_find_startcode(buf1, buf1 + size);
00070 while (r < buf1 + size) {
00071 const uint8_t *r1;
00072
00073 while(!*(r++));
00074 r1 = ff_avc_find_startcode(r, buf1 + size);
00075 nal_send(s1, r, r1 - r, (r1 == buf1 + size));
00076 r = r1;
00077 }
00078 }