# HG changeset patch # User lucabe # Date 1189757826 0 # Node ID e9c34ec665c6d903396ddeecae484c5ede6809fe # Parent 0cc87456f0ad019cd01b1766d845fdf4572a1bac Support for AAC streaming over RTP. Fragmentation is not implemented yet diff -r 0cc87456f0ad -r e9c34ec665c6 Makefile --- a/Makefile Thu Sep 13 12:46:30 2007 +0000 +++ b/Makefile Fri Sep 14 08:17:06 2007 +0000 @@ -122,7 +122,7 @@ OBJS-$(CONFIG_RM_MUXER) += rmenc.o OBJS-$(CONFIG_ROQ_DEMUXER) += idroq.o OBJS-$(CONFIG_ROQ_MUXER) += raw.o -OBJS-$(CONFIG_RTP_MUXER) += rtp.o rtp_h264.o rtp_mpv.o +OBJS-$(CONFIG_RTP_MUXER) += rtp.o rtp_h264.o rtp_mpv.o rtp_aac.o OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o diff -r 0cc87456f0ad -r e9c34ec665c6 rtp.c --- a/rtp.c Thu Sep 13 12:46:30 2007 +0000 +++ b/rtp.c Fri Sep 14 08:17:06 2007 +0000 @@ -28,6 +28,7 @@ #include "rtp_internal.h" #include "rtp_h264.h" #include "rtp_mpv.h" +#include "rtp_aac.h" //#define DEBUG @@ -762,6 +763,8 @@ s->max_payload_size = n * TS_PACKET_SIZE; s->buf_ptr = s->buf; break; + case CODEC_ID_AAC: + s->read_buf_index = 0; default: if (st->codec->codec_type == CODEC_TYPE_AUDIO) { av_set_pts_info(st, 32, 1, st->codec->sample_rate); @@ -993,6 +996,9 @@ case CODEC_ID_MPEG1VIDEO: ff_rtp_send_mpegvideo(s1, buf1, size); break; + case CODEC_ID_AAC: + ff_rtp_send_aac(s1, buf1, size); + break; case CODEC_ID_MPEG2TS: rtp_send_mpegts_raw(s1, buf1, size); break; diff -r 0cc87456f0ad -r e9c34ec665c6 rtp_aac.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtp_aac.c Fri Sep 14 08:17:06 2007 +0000 @@ -0,0 +1,72 @@ +/* + * copyright (c) 2007 Luca Abeni + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * 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. + * + * FFmpeg is distributed in the hope that it will be useful, + * 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 + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "rtp_aac.h" +#include "rtp_internal.h" + +#define MAX_FRAMES_PER_PACKET 5 +#define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET) + +void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, max_packet_size; + uint8_t *p; + + /* skip ADTS header, if present */ + if ((s1->streams[0]->codec->extradata_size) == 0) { + size -= 7; + buff += 7; + } + max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE; + + /* test if the packet must be sent */ + len = (s->buf_ptr - s->buf); + if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) { + int au_size = s->read_buf_index * 2; + + p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2; + 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); + + s->read_buf_index = 0; + } + if (s->read_buf_index == 0) { + s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE; + s->timestamp = s->cur_timestamp; + } + + if (size < max_packet_size) { + p = s->buf + s->read_buf_index++ * 2 + 2; + *p++ = size >> 5; + *p = (size & 0x1F) << 3; + memcpy(s->buf_ptr, buff, size); + s->buf_ptr += size; + } else { + av_log(s1, AV_LOG_ERROR, "Unsupported!\n"); + } +} diff -r 0cc87456f0ad -r e9c34ec665c6 rtp_aac.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rtp_aac.h Fri Sep 14 08:17:06 2007 +0000 @@ -0,0 +1,25 @@ +/* + * RTP definitions + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * 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. + * + * FFmpeg is distributed in the hope that it will be useful, + * 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 + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef RTP_AAC_H +#define RTP_AAC_H + +void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size); + +#endif /* RTP_AAC_H */