annotate ffmpeg/libavformat/rtpenc_h263.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RTP packetization for H.263 video
yading@11 3 * Copyright (c) 2009 Luca Abeni
yading@11 4 * Copyright (c) 2009 Martin Storsjo
yading@11 5 *
yading@11 6 * This file is part of FFmpeg.
yading@11 7 *
yading@11 8 * FFmpeg is free software; you can redistribute it and/or
yading@11 9 * modify it under the terms of the GNU Lesser General Public
yading@11 10 * License as published by the Free Software Foundation; either
yading@11 11 * version 2.1 of the License, or (at your option) any later version.
yading@11 12 *
yading@11 13 * FFmpeg is distributed in the hope that it will be useful,
yading@11 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 16 * Lesser General Public License for more details.
yading@11 17 *
yading@11 18 * You should have received a copy of the GNU Lesser General Public
yading@11 19 * License along with FFmpeg; if not, write to the Free Software
yading@11 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 21 */
yading@11 22
yading@11 23 #include "avformat.h"
yading@11 24 #include "rtpenc.h"
yading@11 25
yading@11 26 const uint8_t *ff_h263_find_resync_marker_reverse(const uint8_t *av_restrict start,
yading@11 27 const uint8_t *av_restrict end)
yading@11 28 {
yading@11 29 const uint8_t *p = end - 1;
yading@11 30 start += 1; /* Make sure we never return the original start. */
yading@11 31 for (; p > start; p -= 2) {
yading@11 32 if (!*p) {
yading@11 33 if (!p[ 1] && p[2]) return p;
yading@11 34 else if (!p[-1] && p[1]) return p - 1;
yading@11 35 }
yading@11 36 }
yading@11 37 return end;
yading@11 38 }
yading@11 39
yading@11 40 /**
yading@11 41 * Packetize H.263 frames into RTP packets according to RFC 4629
yading@11 42 */
yading@11 43 void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
yading@11 44 {
yading@11 45 RTPMuxContext *s = s1->priv_data;
yading@11 46 int len, max_packet_size;
yading@11 47 uint8_t *q;
yading@11 48
yading@11 49 max_packet_size = s->max_payload_size;
yading@11 50
yading@11 51 while (size > 0) {
yading@11 52 q = s->buf;
yading@11 53 if (size >= 2 && (buf1[0] == 0) && (buf1[1] == 0)) {
yading@11 54 *q++ = 0x04;
yading@11 55 buf1 += 2;
yading@11 56 size -= 2;
yading@11 57 } else {
yading@11 58 *q++ = 0;
yading@11 59 }
yading@11 60 *q++ = 0;
yading@11 61
yading@11 62 len = FFMIN(max_packet_size - 2, size);
yading@11 63
yading@11 64 /* Look for a better place to split the frame into packets. */
yading@11 65 if (len < size) {
yading@11 66 const uint8_t *end = ff_h263_find_resync_marker_reverse(buf1,
yading@11 67 buf1 + len);
yading@11 68 len = end - buf1;
yading@11 69 }
yading@11 70
yading@11 71 memcpy(q, buf1, len);
yading@11 72 q += len;
yading@11 73
yading@11 74 /* 90 KHz time stamp */
yading@11 75 s->timestamp = s->cur_timestamp;
yading@11 76 ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
yading@11 77
yading@11 78 buf1 += len;
yading@11 79 size -= len;
yading@11 80 }
yading@11 81 }