FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rtpdec_h263.c
Go to the documentation of this file.
1 /*
2  * RTP H.263 Depacketizer, RFC 4629
3  * Copyright (c) 2010 Martin Storsjo
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "avformat.h"
23 #include "rtpdec_formats.h"
24 #include "libavutil/intreadwrite.h"
25 
27  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
28  const uint8_t *buf, int len, uint16_t seq, int flags)
29 {
30  uint8_t *ptr;
31  uint16_t header;
32  int startcode, vrc, picture_header;
33 
34  if (len < 2) {
35  av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
36  return AVERROR_INVALIDDATA;
37  }
38 
39  /* Decode the 16 bit H.263+ payload header, as described in section
40  * 5.1 of RFC 4629. The fields of this header are:
41  * - 5 reserved bits, should be ignored.
42  * - One bit (P, startcode), indicating a picture start, picture segment
43  * start or video sequence end. If set, two zero bytes should be
44  * prepended to the payload.
45  * - One bit (V, vrc), indicating the presence of an 8 bit Video
46  * Redundancy Coding field after this 16 bit header.
47  * - 6 bits (PLEN, picture_header), the length (in bytes) of an extra
48  * picture header, following the VRC field.
49  * - 3 bits (PEBIT), the number of bits to ignore of the last byte
50  * of the extra picture header. (Not used at the moment.)
51  */
52  header = AV_RB16(buf);
53  startcode = (header & 0x0400) >> 9;
54  vrc = header & 0x0200;
55  picture_header = (header & 0x01f8) >> 3;
56  buf += 2;
57  len -= 2;
58 
59  if (vrc) {
60  /* Skip VRC header if present, not used at the moment. */
61  buf += 1;
62  len -= 1;
63  }
64  if (picture_header) {
65  /* Skip extra picture header if present, not used at the moment. */
66  buf += picture_header;
67  len -= picture_header;
68  }
69 
70  if (len < 0) {
71  av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
72  return AVERROR_INVALIDDATA;
73  }
74 
75  if (av_new_packet(pkt, len + startcode)) {
76  av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
77  return AVERROR(ENOMEM);
78  }
79  pkt->stream_index = st->index;
80  ptr = pkt->data;
81 
82  if (startcode) {
83  *ptr++ = 0;
84  *ptr++ = 0;
85  }
86  memcpy(ptr, buf, len);
87 
88  return 0;
89 }
90 
92  .enc_name = "H263-1998",
93  .codec_type = AVMEDIA_TYPE_VIDEO,
94  .codec_id = AV_CODEC_ID_H263,
95  .parse_packet = ff_h263_handle_packet,
96 };
97 
99  .enc_name = "H263-2000",
100  .codec_type = AVMEDIA_TYPE_VIDEO,
101  .codec_id = AV_CODEC_ID_H263,
102  .parse_packet = ff_h263_handle_packet,
103 };