00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022 #include "rtpenc.h"
00023
00024
00025 void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
00026 {
00027 RTPMuxContext *s = s1->priv_data;
00028 int len, max_packet_size;
00029 uint8_t *p;
00030 const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
00031 const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
00032
00033
00034 if ((s1->streams[0]->codec->extradata_size) == 0) {
00035 size -= 7;
00036 buff += 7;
00037 }
00038 max_packet_size = s->max_payload_size - max_au_headers_size;
00039
00040
00041 len = (s->buf_ptr - s->buf);
00042 if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
00043 int au_size = s->num_frames * 2;
00044
00045 p = s->buf + max_au_headers_size - au_size - 2;
00046 if (p != s->buf) {
00047 memmove(p + 2, s->buf + 2, au_size);
00048 }
00049
00050 p[0] = ((au_size * 8) & 0xFF) >> 8;
00051 p[1] = (au_size * 8) & 0xFF;
00052
00053 ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
00054
00055 s->num_frames = 0;
00056 }
00057 if (s->num_frames == 0) {
00058 s->buf_ptr = s->buf + max_au_headers_size;
00059 s->timestamp = s->cur_timestamp;
00060 }
00061
00062 if (size <= max_packet_size) {
00063 p = s->buf + s->num_frames++ * 2 + 2;
00064 *p++ = size >> 5;
00065 *p = (size & 0x1F) << 3;
00066 memcpy(s->buf_ptr, buff, size);
00067 s->buf_ptr += size;
00068 } else {
00069 int au_size = size;
00070
00071 max_packet_size = s->max_payload_size - 4;
00072 p = s->buf;
00073 p[0] = 0;
00074 p[1] = 16;
00075 while (size > 0) {
00076 len = FFMIN(size, max_packet_size);
00077 p[2] = au_size >> 5;
00078 p[3] = (au_size & 0x1F) << 3;
00079 memcpy(p + 4, buff, len);
00080 ff_rtp_send_data(s1, p, len + 4, len == size);
00081 size -= len;
00082 buff += len;
00083 }
00084 }
00085 }