[FFmpeg-cvslog] r18375 - in trunk: Changelog libavformat/Makefile libavformat/rtp_amr.c libavformat/rtpenc.c libavformat/rtpenc.h libavformat/sdp.c
lucabe
subversion
Wed Apr 8 09:16:14 CEST 2009
Author: lucabe
Date: Wed Apr 8 09:16:14 2009
New Revision: 18375
Log:
Add support for AMR audio in the RTP muxer
patch by Martin Storsj? (martin AT martin DOT st)
Added:
trunk/libavformat/rtp_amr.c
Modified:
trunk/Changelog
trunk/libavformat/Makefile
trunk/libavformat/rtpenc.c
trunk/libavformat/rtpenc.h
trunk/libavformat/sdp.c
Modified: trunk/Changelog
==============================================================================
--- trunk/Changelog Wed Apr 8 05:38:59 2009 (r18374)
+++ trunk/Changelog Wed Apr 8 09:16:14 2009 (r18375)
@@ -7,6 +7,7 @@ version <next>:
- Alpha channel scaler
- PCX encoder
- RTP packetization of H.263
+- RTP packetization of AMR
Modified: trunk/libavformat/Makefile
==============================================================================
--- trunk/libavformat/Makefile Wed Apr 8 05:38:59 2009 (r18374)
+++ trunk/libavformat/Makefile Wed Apr 8 09:16:14 2009 (r18375)
@@ -188,6 +188,7 @@ OBJS-$(CONFIG_ROQ_MUXER)
OBJS-$(CONFIG_RPL_DEMUXER) += rpl.o
OBJS-$(CONFIG_RTP_MUXER) += rtp.o \
rtp_aac.o \
+ rtp_amr.o \
rtp_asf.o \
rtp_h263.o \
rtp_mpv.o \
Added: trunk/libavformat/rtp_amr.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libavformat/rtp_amr.c Wed Apr 8 09:16:14 2009 (r18375)
@@ -0,0 +1,66 @@
+/*
+ * RTP packetization for AMR audio
+ * Copyright (c) 2007 Luca Abeni
+ * Copyright (c) 2009 Martin Storsjo
+ *
+ * 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 "rtpenc.h"
+
+/**
+ * Packetize AMR frames into RTP packets according to RFC 3267,
+ * in octet-aligned mode.
+ */
+void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
+{
+ RTPMuxContext *s = s1->priv_data;
+ int max_header_toc_size = 1 + s->max_frames_per_packet;
+ uint8_t *p;
+ int len;
+
+ /* Test if the packet must be sent. */
+ len = s->buf_ptr - s->buf;
+ if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
+ int header_size = s->num_frames + 1;
+ p = s->buf + max_header_toc_size - header_size;
+ if (p != s->buf)
+ memmove(p, s->buf, header_size);
+
+ ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
+
+ s->num_frames = 0;
+ }
+
+ if (!s->num_frames) {
+ s->buf[0] = 0xf0;
+ s->buf_ptr = s->buf + max_header_toc_size;
+ s->timestamp = s->cur_timestamp;
+ } else {
+ /* Mark the previous TOC entry as having more entries following. */
+ s->buf[1 + s->num_frames - 1] |= 0x80;
+ }
+
+ /* Copy the frame type and quality bits. */
+ s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
+ buff++;
+ size--;
+ memcpy(s->buf_ptr, buff, size);
+ s->buf_ptr += size;
+}
+
Modified: trunk/libavformat/rtpenc.c
==============================================================================
--- trunk/libavformat/rtpenc.c Wed Apr 8 05:38:59 2009 (r18374)
+++ trunk/libavformat/rtpenc.c Wed Apr 8 09:16:14 2009 (r18375)
@@ -60,6 +60,8 @@ static int is_supported(enum CodecID id)
case CODEC_ID_PCM_U16LE:
case CODEC_ID_PCM_U8:
case CODEC_ID_MPEG2TS:
+ case CODEC_ID_AMR_NB:
+ case CODEC_ID_AMR_WB:
return 1;
default:
return 0;
@@ -134,6 +136,23 @@ static int rtp_write_header(AVFormatCont
s->max_payload_size = n * TS_PACKET_SIZE;
s->buf_ptr = s->buf;
break;
+ case CODEC_ID_AMR_NB:
+ case CODEC_ID_AMR_WB:
+ if (!s->max_frames_per_packet)
+ s->max_frames_per_packet = 12;
+ if (st->codec->codec_id == CODEC_ID_AMR_NB)
+ n = 31;
+ else
+ n = 61;
+ /* max_header_toc_size + the largest AMR payload must fit */
+ if (1 + s->max_frames_per_packet + n > s->max_payload_size) {
+ av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
+ return -1;
+ }
+ if (st->codec->channels != 1) {
+ av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
+ return -1;
+ }
case CODEC_ID_AAC:
s->num_frames = 0;
default:
@@ -366,6 +385,10 @@ static int rtp_write_packet(AVFormatCont
case CODEC_ID_AAC:
ff_rtp_send_aac(s1, buf1, size);
break;
+ case CODEC_ID_AMR_NB:
+ case CODEC_ID_AMR_WB:
+ ff_rtp_send_amr(s1, buf1, size);
+ break;
case CODEC_ID_MPEG2TS:
rtp_send_mpegts_raw(s1, buf1, size);
break;
Modified: trunk/libavformat/rtpenc.h
==============================================================================
--- trunk/libavformat/rtpenc.h Wed Apr 8 05:38:59 2009 (r18374)
+++ trunk/libavformat/rtpenc.h Wed Apr 8 09:16:14 2009 (r18375)
@@ -59,6 +59,7 @@ void ff_rtp_send_data(AVFormatContext *s
void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size);
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size);
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size);
+void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size);
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size);
#endif /* AVFORMAT_RTPENC_H */
Modified: trunk/libavformat/sdp.c
==============================================================================
--- trunk/libavformat/sdp.c Wed Apr 8 05:38:59 2009 (r18374)
+++ trunk/libavformat/sdp.c Wed Apr 8 09:16:14 2009 (r18375)
@@ -228,6 +228,18 @@ static char *sdp_write_media_attributes(
payload_type,
c->sample_rate, c->channels);
break;
+ case CODEC_ID_AMR_NB:
+ av_strlcatf(buff, size, "a=rtpmap:%d AMR/%d/%d\r\n"
+ "a=fmtp:%d octet-align=1\r\n",
+ payload_type, c->sample_rate, c->channels,
+ payload_type);
+ break;
+ case CODEC_ID_AMR_WB:
+ av_strlcatf(buff, size, "a=rtpmap:%d AMR-WB/%d/%d\r\n"
+ "a=fmtp:%d octet-align=1\r\n",
+ payload_type, c->sample_rate, c->channels,
+ payload_type);
+ break;
default:
/* Nothing special to do here... */
break;
More information about the ffmpeg-cvslog
mailing list