Coverage Report

Created: 2026-07-25 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/rtpdec_h263.c
Line
Count
Source
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
27
int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
28
                          AVStream *st, AVPacket *pkt, uint32_t *timestamp,
29
                          const uint8_t *buf, int len, uint16_t seq, int flags)
30
0
{
31
0
    uint8_t *ptr;
32
0
    uint16_t header;
33
0
    int startcode, vrc, picture_header, ret;
34
35
0
    if (len < 2) {
36
0
        av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
37
0
        return AVERROR_INVALIDDATA;
38
0
    }
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
0
    header = AV_RB16(buf);
54
0
    startcode      = (header & 0x0400) >> 9;
55
0
    vrc            =  header & 0x0200;
56
0
    picture_header = (header & 0x01f8) >> 3;
57
0
    buf += 2;
58
0
    len -= 2;
59
60
0
    if (vrc) {
61
        /* Skip VRC header if present, not used at the moment. */
62
0
        buf += 1;
63
0
        len -= 1;
64
0
    }
65
0
    if (picture_header) {
66
        /* Skip extra picture header if present, not used at the moment. */
67
0
        buf += picture_header;
68
0
        len -= picture_header;
69
0
    }
70
71
0
    if (len < 0) {
72
0
        av_log(ctx, AV_LOG_ERROR, "Too short H.263 RTP packet\n");
73
0
        return AVERROR_INVALIDDATA;
74
0
    }
75
76
0
    if ((ret = av_new_packet(pkt, len + startcode)) < 0) {
77
0
        av_log(ctx, AV_LOG_ERROR, "Out of memory\n");
78
0
        return ret;
79
0
    }
80
0
    pkt->stream_index = st->index;
81
0
    ptr = pkt->data;
82
83
0
    if (startcode) {
84
0
        *ptr++ = 0;
85
0
        *ptr++ = 0;
86
0
    }
87
0
    memcpy(ptr, buf, len);
88
89
0
    return 0;
90
0
}
91
92
const RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler = {
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
100
const RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler = {
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
};