Libav 0.7.1
|
00001 /* 00002 * copyright (c) 2007 Luca Abeni 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 /* skip ADTS header, if present */ 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 /* test if the packet must be sent */ 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 /* Write the AU header size */ 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 }