annotate rtpdec_h263.c @ 6062:92871def02f1 libavformat

Make sure that when the parser is feeded with frame==packet that the packets are passed through and wont be marked as static which would require them to be copied by av_dup_packet().
author michael
date Thu, 27 May 2010 17:11:37 +0000
parents 08cd1179a20d
children 491eea5c52d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5601
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
1 /*
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
2 * RTP H.263 Depacketizer, RFC 4629
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
3 * Copyright (c) 2010 Martin Storsjo
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
4 *
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
5 * This file is part of FFmpeg.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
6 *
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
11 *
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
15 * Lesser General Public License for more details.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
16 *
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
20 */
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
21
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
22 #include "avformat.h"
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
23 #include "rtpdec_h263.h"
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
24 #include "libavutil/intreadwrite.h"
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
25
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
26 static int h263_handle_packet(AVFormatContext *ctx,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
27 PayloadContext *data,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
28 AVStream *st,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
29 AVPacket * pkt,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
30 uint32_t * timestamp,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
31 const uint8_t * buf,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
32 int len, int flags)
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
33 {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
34 uint8_t *ptr;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
35 uint16_t header;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
36 int startcode, vrc, picture_header;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
37
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
38 if (len < 2) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
39 av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
40 return AVERROR_INVALIDDATA;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
41 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
42
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
43 /* Decode the 16 bit H.263+ payload header, as described in section
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
44 * 5.1 of RFC 4629. The fields of this header are:
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
45 * - 5 reserved bits, should be ignored.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
46 * - One bit (P, startcode), indicating a picture start, picture segment
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
47 * start or video sequence end. If set, two zero bytes should be
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
48 * prepended to the payload.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
49 * - One bit (V, vrc), indicating the presence of an 8 bit Video
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
50 * Redundancy Coding field after this 16 bit header.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
51 * - 6 bits (PLEN, picture_header), the length (in bytes) of an extra
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
52 * picture header, following the VRC field.
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
53 * - 3 bits (PEBIT), the number of bits to ignore of the last byte
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
54 * of the extra picture header. (Not used at the moment.)
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
55 */
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
56 header = AV_RB16(buf);
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
57 startcode = (header & 0x0400) >> 9;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
58 vrc = header & 0x0200;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
59 picture_header = (header & 0x01f8) >> 3;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
60 buf += 2;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
61 len -= 2;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
62
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
63 if (vrc) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
64 /* Skip VRC header if present, not used at the moment. */
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
65 buf += 1;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
66 len -= 1;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
67 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
68 if (picture_header) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
69 /* Skip extra picture header if present, not used at the moment. */
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
70 buf += picture_header;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
71 len -= picture_header;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
72 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
73
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
74 if (len < 0) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
75 av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
76 return AVERROR_INVALIDDATA;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
77 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
78
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
79 if (av_new_packet(pkt, len + startcode)) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
80 av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
5930
08cd1179a20d Replace all remaining occurrences of AVERROR_NOMEM with
stefano
parents: 5910
diff changeset
81 return AVERROR(ENOMEM);
5601
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
82 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
83 pkt->stream_index = st->index;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
84 ptr = pkt->data;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
85
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
86 if (startcode) {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
87 *ptr++ = 0;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
88 *ptr++ = 0;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
89 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
90 memcpy(ptr, buf, len);
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
91
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
92 return 0;
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
93 }
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
94
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
95 RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
96 .enc_name = "H263-1998",
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5601
diff changeset
97 .codec_type = AVMEDIA_TYPE_VIDEO,
5601
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
98 .codec_id = CODEC_ID_H263,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
99 .parse_packet = h263_handle_packet,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
100 };
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
101
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
102 RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = {
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
103 .enc_name = "H263-2000",
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5601
diff changeset
104 .codec_type = AVMEDIA_TYPE_VIDEO,
5601
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
105 .codec_id = CODEC_ID_H263,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
106 .parse_packet = h263_handle_packet,
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
107 };
96d885709963 Add RTP/H.263 depacketizer by Martin Storsj <$firstname () $firstname st>.
rbultje
parents:
diff changeset
108