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

libavformat/rtpenc_h264.c

Go to the documentation of this file.
00001 /*
00002  * RTP packetization for H.264 (RFC3984)
00003  * Copyright (c) 2008 Luca Abeni
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00028 #include "avformat.h"
00029 #include "avc.h"
00030 #include "rtpenc.h"
00031 
00032 static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last)
00033 {
00034     RTPMuxContext *s = s1->priv_data;
00035 
00036     av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last);
00037     if (size <= s->max_payload_size) {
00038         ff_rtp_send_data(s1, buf, size, last);
00039     } else {
00040         uint8_t type = buf[0] & 0x1F;
00041         uint8_t nri = buf[0] & 0x60;
00042 
00043         av_log(s1, AV_LOG_DEBUG, "NAL size %d > %d\n", size, s->max_payload_size);
00044         s->buf[0] = 28;        /* FU Indicator; Type = 28 ---> FU-A */
00045         s->buf[0] |= nri;
00046         s->buf[1] = type;
00047         s->buf[1] |= 1 << 7;
00048         buf += 1;
00049         size -= 1;
00050         while (size + 2 > s->max_payload_size) {
00051             memcpy(&s->buf[2], buf, s->max_payload_size - 2);
00052             ff_rtp_send_data(s1, s->buf, s->max_payload_size, 0);
00053             buf += s->max_payload_size - 2;
00054             size -= s->max_payload_size - 2;
00055             s->buf[1] &= ~(1 << 7);
00056         }
00057         s->buf[1] |= 1 << 6;
00058         memcpy(&s->buf[2], buf, size);
00059         ff_rtp_send_data(s1, s->buf, size + 2, last);
00060     }
00061 }
00062 
00063 void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
00064 {
00065     const uint8_t *r;
00066     RTPMuxContext *s = s1->priv_data;
00067 
00068     s->timestamp = s->cur_timestamp;
00069     r = ff_avc_find_startcode(buf1, buf1 + size);
00070     while (r < buf1 + size) {
00071         const uint8_t *r1;
00072 
00073         while(!*(r++));
00074         r1 = ff_avc_find_startcode(r, buf1 + size);
00075         nal_send(s1, r, r1 - r, (r1 == buf1 + size));
00076         r = r1;
00077     }
00078 }

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