FFmpeg
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/attributes.h"
25 #include "libavutil/intreadwrite.h"
26 
28  AVStream *st, AVPacket *pkt, uint32_t *timestamp,
29  const uint8_t *buf, int len, uint16_t seq, int flags)
30 {
31  uint8_t *ptr;
32  uint16_t header;
33  int startcode, vrc, picture_header;
34 
35  if (len < 2) {
36  av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
37  return AVERROR_INVALIDDATA;
38  }
39 
40  /* Decode the 16 bit H.263+ payload header, as described in section
41  * 5.1 of RFC 4629. The fields of this header are:
42  * - 5 reserved bits, should be ignored.
43  * - One bit (P, startcode), indicating a picture start, picture segment
44  * start or video sequence end. If set, two zero bytes should be
45  * prepended to the payload.
46  * - One bit (V, vrc), indicating the presence of an 8 bit Video
47  * Redundancy Coding field after this 16 bit header.
48  * - 6 bits (PLEN, picture_header), the length (in bytes) of an extra
49  * picture header, following the VRC field.
50  * - 3 bits (PEBIT), the number of bits to ignore of the last byte
51  * of the extra picture header. (Not used at the moment.)
52  */
53  header = AV_RB16(buf);
54  startcode = (header & 0x0400) >> 9;
55  vrc = header & 0x0200;
56  picture_header = (header & 0x01f8) >> 3;
57  buf += 2;
58  len -= 2;
59 
60  if (vrc) {
61  /* Skip VRC header if present, not used at the moment. */
62  buf += 1;
63  len -= 1;
64  }
65  if (picture_header) {
66  /* Skip extra picture header if present, not used at the moment. */
67  buf += picture_header;
68  len -= picture_header;
69  }
70 
71  if (len < 0) {
72  av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
73  return AVERROR_INVALIDDATA;
74  }
75 
76  if (av_new_packet(pkt, len + startcode)) {
77  av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
78  return AVERROR(ENOMEM);
79  }
80  pkt->stream_index = st->index;
81  ptr = pkt->data;
82 
83  if (startcode) {
84  *ptr++ = 0;
85  *ptr++ = 0;
86  }
87  memcpy(ptr, buf, len);
88 
89  return 0;
90 }
91 
93  .enc_name = "H263-1998",
94  .codec_type = AVMEDIA_TYPE_VIDEO,
95  .codec_id = AV_CODEC_ID_H263,
96  .need_parsing = AVSTREAM_PARSE_FULL,
97  .parse_packet = ff_h263_handle_packet,
98 };
99 
101  .enc_name = "H263-2000",
102  .codec_type = AVMEDIA_TYPE_VIDEO,
103  .codec_id = AV_CODEC_ID_H263,
104  .need_parsing = AVSTREAM_PARSE_FULL,
105  .parse_packet = ff_h263_handle_packet,
106 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
RTP/JPEG specific private data.
Definition: rdt.c:83
int index
stream index in AVFormatContext
Definition: avformat.h:882
static AVPacket pkt
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:87
Macro definitions for various function/variable attributes.
const RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler
Definition: rtpdec_h263.c:100
Format I/O context.
Definition: avformat.h:1358
uint8_t
uint8_t * data
Definition: avcodec.h:1477
static const uint8_t header[24]
Definition: sdr2.c:67
#define av_log(a,...)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:86
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int FUNC() picture_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawPictureHeader *current)
AVFormatContext * ctx
Definition: movenc.c:48
int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket *pkt, uint32_t *timestamp, const uint8_t *buf, int len, uint16_t seq, int flags)
Definition: rtpdec_h263.c:27
Stream structure.
Definition: avformat.h:881
void * buf
Definition: avisynth_c.h:766
const char * enc_name
Definition: rtpdec.h:116
#define flags(name, subs,...)
Definition: cbs_av1.c:561
full parsing and repack
Definition: avformat.h:800
Main libavformat public API header.
const RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler
Definition: rtpdec_h263.c:92
int len
int stream_index
Definition: avcodec.h:1479
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
This structure stores compressed data.
Definition: avcodec.h:1454