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

libavformat/rtp_aac.c

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2007 Luca Abeni
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00021 #include "avformat.h"
00022 #include "rtpenc.h"
00023 
00024 #define MAX_FRAMES_PER_PACKET (s->max_frames_per_packet ? s->max_frames_per_packet : 5)
00025 #define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET)
00026 
00027 void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
00028 {
00029     RTPMuxContext *s = s1->priv_data;
00030     int len, max_packet_size;
00031     uint8_t *p;
00032 
00033     /* skip ADTS header, if present */
00034     if ((s1->streams[0]->codec->extradata_size) == 0) {
00035         size -= 7;
00036         buff += 7;
00037     }
00038     max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE;
00039 
00040     /* test if the packet must be sent */
00041     len = (s->buf_ptr - s->buf);
00042     if ((s->num_frames == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) {
00043         int au_size = s->num_frames * 2;
00044 
00045         p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2;
00046         if (p != s->buf) {
00047             memmove(p + 2, s->buf + 2, au_size);
00048         }
00049         /* Write the AU header size */
00050         p[0] = ((au_size * 8) & 0xFF) >> 8;
00051         p[1] = (au_size * 8) & 0xFF;
00052 
00053         ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
00054 
00055         s->num_frames = 0;
00056     }
00057     if (s->num_frames == 0) {
00058         s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE;
00059         s->timestamp = s->cur_timestamp;
00060     }
00061 
00062     if (size < max_packet_size) {
00063         p = s->buf + s->num_frames++ * 2 + 2;
00064         *p++ = size >> 5;
00065         *p = (size & 0x1F) << 3;
00066         memcpy(s->buf_ptr, buff, size);
00067         s->buf_ptr += size;
00068     } else {
00069         if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) {
00070             av_log(s1, AV_LOG_ERROR, "Strange...\n");
00071             av_abort();
00072         }
00073         max_packet_size = s->max_payload_size - 4;
00074         p = s->buf;
00075         p[0] = 0;
00076         p[1] = 16;
00077         while (size > 0) {
00078             len = FFMIN(size, max_packet_size);
00079             p[2] = len >> 5;
00080             p[3] = (size & 0x1F) << 3;
00081             memcpy(p + 4, buff, len);
00082             ff_rtp_send_data(s1, p, len + 4, len == size);
00083             size -= len;
00084             buff += len;
00085         }
00086     }
00087 }

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1