• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavformat/rtpenc_amr.c

Go to the documentation of this file.
00001 /*
00002  * RTP packetization for AMR audio
00003  * Copyright (c) 2007 Luca Abeni
00004  * Copyright (c) 2009 Martin Storsjo
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "avformat.h"
00024 #include "rtpenc.h"
00025 
00030 void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
00031 {
00032     RTPMuxContext *s          = s1->priv_data;
00033     int max_header_toc_size   = 1 + s->max_frames_per_packet;
00034     uint8_t *p;
00035     int len;
00036 
00037     /* Test if the packet must be sent. */
00038     len = s->buf_ptr - s->buf;
00039     if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
00040         int header_size = s->num_frames + 1;
00041         p = s->buf + max_header_toc_size - header_size;
00042         if (p != s->buf)
00043             memmove(p, s->buf, header_size);
00044 
00045         ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
00046 
00047         s->num_frames = 0;
00048     }
00049 
00050     if (!s->num_frames) {
00051         s->buf[0]    = 0xf0;
00052         s->buf_ptr   = s->buf + max_header_toc_size;
00053         s->timestamp = s->cur_timestamp;
00054     } else {
00055         /* Mark the previous TOC entry as having more entries following. */
00056         s->buf[1 + s->num_frames - 1] |= 0x80;
00057     }
00058 
00059     /* Copy the frame type and quality bits. */
00060     s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
00061     buff++;
00062     size--;
00063     memcpy(s->buf_ptr, buff, size);
00064     s->buf_ptr += size;
00065 }
00066 

Generated on Fri Sep 16 2011 17:17:50 for FFmpeg by  doxygen 1.7.1