annotate ffmpeg/libavformat/rtpenc_amr.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RTP packetization for AMR audio
yading@11 3 * Copyright (c) 2007 Luca Abeni
yading@11 4 * Copyright (c) 2009 Martin Storsjo
yading@11 5 *
yading@11 6 * This file is part of FFmpeg.
yading@11 7 *
yading@11 8 * FFmpeg is free software; you can redistribute it and/or
yading@11 9 * modify it under the terms of the GNU Lesser General Public
yading@11 10 * License as published by the Free Software Foundation; either
yading@11 11 * version 2.1 of the License, or (at your option) any later version.
yading@11 12 *
yading@11 13 * FFmpeg is distributed in the hope that it will be useful,
yading@11 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 16 * Lesser General Public License for more details.
yading@11 17 *
yading@11 18 * You should have received a copy of the GNU Lesser General Public
yading@11 19 * License along with FFmpeg; if not, write to the Free Software
yading@11 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 21 */
yading@11 22
yading@11 23 #include "avformat.h"
yading@11 24 #include "rtpenc.h"
yading@11 25
yading@11 26 /**
yading@11 27 * Packetize AMR frames into RTP packets according to RFC 3267,
yading@11 28 * in octet-aligned mode.
yading@11 29 */
yading@11 30 void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
yading@11 31 {
yading@11 32 RTPMuxContext *s = s1->priv_data;
yading@11 33 int max_header_toc_size = 1 + s->max_frames_per_packet;
yading@11 34 uint8_t *p;
yading@11 35 int len;
yading@11 36
yading@11 37 /* Test if the packet must be sent. */
yading@11 38 len = s->buf_ptr - s->buf;
yading@11 39 if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
yading@11 40 int header_size = s->num_frames + 1;
yading@11 41 p = s->buf + max_header_toc_size - header_size;
yading@11 42 if (p != s->buf)
yading@11 43 memmove(p, s->buf, header_size);
yading@11 44
yading@11 45 ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
yading@11 46
yading@11 47 s->num_frames = 0;
yading@11 48 }
yading@11 49
yading@11 50 if (!s->num_frames) {
yading@11 51 s->buf[0] = 0xf0;
yading@11 52 s->buf_ptr = s->buf + max_header_toc_size;
yading@11 53 s->timestamp = s->cur_timestamp;
yading@11 54 } else {
yading@11 55 /* Mark the previous TOC entry as having more entries following. */
yading@11 56 s->buf[1 + s->num_frames - 1] |= 0x80;
yading@11 57 }
yading@11 58
yading@11 59 /* Copy the frame type and quality bits. */
yading@11 60 s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
yading@11 61 buff++;
yading@11 62 size--;
yading@11 63 memcpy(s->buf_ptr, buff, size);
yading@11 64 s->buf_ptr += size;
yading@11 65 }