Libav 0.7.1
|
00001 /* 00002 * RTP packetization for H.263 video 00003 * Copyright (c) 2009 Luca Abeni 00004 * Copyright (c) 2009 Martin Storsjo 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav 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 * Libav 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 Libav; 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 00026 static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start, 00027 const uint8_t *restrict end) 00028 { 00029 const uint8_t *p = end - 1; 00030 start += 1; /* Make sure we never return the original start. */ 00031 for (; p > start; p -= 2) { 00032 if (!*p) { 00033 if (!p[ 1] && p[2]) return p; 00034 else if (!p[-1] && p[1]) return p - 1; 00035 } 00036 } 00037 return end; 00038 } 00039 00043 void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size) 00044 { 00045 RTPMuxContext *s = s1->priv_data; 00046 int len, max_packet_size; 00047 uint8_t *q; 00048 00049 max_packet_size = s->max_payload_size; 00050 00051 while (size > 0) { 00052 q = s->buf; 00053 if (size >= 2 && (buf1[0] == 0) && (buf1[1] == 0)) { 00054 *q++ = 0x04; 00055 buf1 += 2; 00056 size -= 2; 00057 } else { 00058 *q++ = 0; 00059 } 00060 *q++ = 0; 00061 00062 len = FFMIN(max_packet_size - 2, size); 00063 00064 /* Look for a better place to split the frame into packets. */ 00065 if (len < size) { 00066 const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len); 00067 len = end - buf1; 00068 } 00069 00070 memcpy(q, buf1, len); 00071 q += len; 00072 00073 /* 90 KHz time stamp */ 00074 s->timestamp = s->cur_timestamp; 00075 ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size)); 00076 00077 buf1 += len; 00078 size -= len; 00079 } 00080 }