annotate rtp_h263.c @ 5163:01514407ab35 libavformat

Use all 32 bits of the timestamp when calculating flv duration. At the moment, duration is mainly set from the metadata packet. If that is not available, the fallback is checking the low 24 bits of the last packet. This is not enough for files over 4,6 hours in length, so read all 32 bits instead. patch by Martin Storsj, martin martin st
author diego
date Mon, 07 Sep 2009 10:49:51 +0000
parents 845b21056111
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4814
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
1 /*
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
2 * RTP packetization for H.263 video
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
3 * Copyright (c) 2009 Luca Abeni
4815
845b21056111 Fix the copyright year
lucabe
parents: 4814
diff changeset
4 * Copyright (c) 2009 Martin Storsjo
4814
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
5 *
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
6 * This file is part of FFmpeg.
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
7 *
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
12 *
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
16 * Lesser General Public License for more details.
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
17 *
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
21 */
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
22
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
23 #include "avformat.h"
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
24 #include "rtpenc.h"
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
25
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
26 static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start,
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
27 const uint8_t *restrict end)
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
28 {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
29 const uint8_t *p = end - 1;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
30 start += 1; /* Make sure we never return the original start. */
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
31 for (; p > start; p -= 2) {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
32 if (!*p) {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
33 if (!p[ 1] && p[2]) return p;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
34 else if (!p[-1] && p[1]) return p - 1;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
35 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
36 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
37 return end;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
38 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
39
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
40 /**
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
41 * Packetize H.263 frames into RTP packets according to RFC 4629
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
42 */
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
43 void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
44 {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
45 RTPMuxContext *s = s1->priv_data;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
46 int len, max_packet_size;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
47 uint8_t *q;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
48
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
49 max_packet_size = s->max_payload_size;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
50
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
51 while (size > 0) {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
52 q = s->buf;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
53 if ((buf1[0] == 0) && (buf1[1] == 0)) {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
54 *q++ = 0x04;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
55 buf1 += 2;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
56 size -= 2;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
57 } else {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
58 *q++ = 0;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
59 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
60 *q++ = 0;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
61
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
62 len = FFMIN(max_packet_size - 2, size);
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
63
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
64 /* Look for a better place to split the frame into packets. */
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
65 if (len < size) {
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
66 const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len);
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
67 len = end - buf1;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
68 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
69
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
70 memcpy(q, buf1, len);
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
71 q += len;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
72
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
73 /* 90 KHz time stamp */
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
74 s->timestamp = s->cur_timestamp;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
75 ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
76
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
77 buf1 += len;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
78 size -= len;
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
79 }
730b214077ca Add support for H.263 video in the RTP muxer
lucabe
parents:
diff changeset
80 }