2007-09-14 08:17:06 +00:00
|
|
|
/*
|
|
|
|
* copyright (c) 2007 Luca Abeni
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* This file is part of Libav.
|
2007-09-14 08:17:06 +00:00
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-09-14 08:17:06 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2011-03-18 17:35:10 +00:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-09-14 08:17:06 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2011-03-18 17:35:10 +00:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-09-14 08:17:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2009-02-06 10:35:52 +00:00
|
|
|
#include "rtpenc.h"
|
2007-09-14 08:17:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
|
|
|
|
{
|
2009-02-06 10:35:52 +00:00
|
|
|
RTPMuxContext *s = s1->priv_data;
|
2007-09-14 08:17:06 +00:00
|
|
|
int len, max_packet_size;
|
|
|
|
uint8_t *p;
|
2009-04-09 21:48:45 +00:00
|
|
|
const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
|
|
|
|
const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
|
2007-09-14 08:17:06 +00:00
|
|
|
|
|
|
|
/* skip ADTS header, if present */
|
|
|
|
if ((s1->streams[0]->codec->extradata_size) == 0) {
|
|
|
|
size -= 7;
|
|
|
|
buff += 7;
|
|
|
|
}
|
2009-04-09 21:48:45 +00:00
|
|
|
max_packet_size = s->max_payload_size - max_au_headers_size;
|
2007-09-14 08:17:06 +00:00
|
|
|
|
|
|
|
/* test if the packet must be sent */
|
|
|
|
len = (s->buf_ptr - s->buf);
|
2009-04-09 21:48:45 +00:00
|
|
|
if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
|
2009-02-05 14:53:25 +00:00
|
|
|
int au_size = s->num_frames * 2;
|
2007-09-14 08:17:06 +00:00
|
|
|
|
2009-04-09 21:48:45 +00:00
|
|
|
p = s->buf + max_au_headers_size - au_size - 2;
|
2007-09-14 08:17:06 +00:00
|
|
|
if (p != s->buf) {
|
|
|
|
memmove(p + 2, s->buf + 2, au_size);
|
|
|
|
}
|
|
|
|
/* Write the AU header size */
|
|
|
|
p[0] = ((au_size * 8) & 0xFF) >> 8;
|
|
|
|
p[1] = (au_size * 8) & 0xFF;
|
|
|
|
|
|
|
|
ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
|
|
|
|
|
2009-02-05 14:53:25 +00:00
|
|
|
s->num_frames = 0;
|
2007-09-14 08:17:06 +00:00
|
|
|
}
|
2009-02-05 14:53:25 +00:00
|
|
|
if (s->num_frames == 0) {
|
2009-04-09 21:48:45 +00:00
|
|
|
s->buf_ptr = s->buf + max_au_headers_size;
|
2007-09-14 08:17:06 +00:00
|
|
|
s->timestamp = s->cur_timestamp;
|
|
|
|
}
|
|
|
|
|
2009-04-09 21:37:11 +00:00
|
|
|
if (size <= max_packet_size) {
|
2009-02-05 14:53:25 +00:00
|
|
|
p = s->buf + s->num_frames++ * 2 + 2;
|
2007-09-14 08:17:06 +00:00
|
|
|
*p++ = size >> 5;
|
|
|
|
*p = (size & 0x1F) << 3;
|
|
|
|
memcpy(s->buf_ptr, buff, size);
|
|
|
|
s->buf_ptr += size;
|
|
|
|
} else {
|
2009-05-29 13:46:46 +00:00
|
|
|
int au_size = size;
|
|
|
|
|
2007-09-14 09:00:31 +00:00
|
|
|
max_packet_size = s->max_payload_size - 4;
|
|
|
|
p = s->buf;
|
|
|
|
p[0] = 0;
|
|
|
|
p[1] = 16;
|
|
|
|
while (size > 0) {
|
|
|
|
len = FFMIN(size, max_packet_size);
|
2009-05-29 13:46:46 +00:00
|
|
|
p[2] = au_size >> 5;
|
|
|
|
p[3] = (au_size & 0x1F) << 3;
|
2007-09-14 09:00:31 +00:00
|
|
|
memcpy(p + 4, buff, len);
|
|
|
|
ff_rtp_send_data(s1, p, len + 4, len == size);
|
|
|
|
size -= len;
|
|
|
|
buff += len;
|
|
|
|
}
|
2007-09-14 08:17:06 +00:00
|
|
|
}
|
|
|
|
}
|