2 * RTP packetization for H.263 video
3 * Copyright (c) 2009 Luca Abeni
4 * Copyright (c) 2009 Martin Storsjo
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *av_restrict start,
27 const uint8_t *av_restrict end)
29 const uint8_t *p = end - 1;
30 start += 1; /* Make sure we never return the original start. */
31 for (; p > start; p -= 2) {
33 if (!p[ 1] && p[2]) return p;
34 else if (!p[-1] && p[1]) return p - 1;
41 * Packetize H.263 frames into RTP packets according to RFC 4629
43 void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
45 RTPMuxContext *s = s1->priv_data;
46 int len, max_packet_size;
49 max_packet_size = s->max_payload_size;
53 if (size >= 2 && (buf1[0] == 0) && (buf1[1] == 0)) {
62 len = FFMIN(max_packet_size - 2, size);
64 /* Look for a better place to split the frame into packets. */
66 const uint8_t *end = ff_h263_find_resync_marker_reverse(buf1,
74 /* 90 KHz time stamp */
75 s->timestamp = s->cur_timestamp;
76 ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));