FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/rtpenc_rfc4175.c
Date: 2026-10-30 17:37:53
Exec Total Coverage
Lines: 0 83 0.0%
Functions: 0 1 0.0%
Branches: 0 30 0.0%

Line Branch Exec Source
1 /*
2 * RTP Packetization of RAW video (RFC4175)
3 * Copyright (c) 2021 Limin Wang
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 #include "avformat.h"
22 #include "rtpenc.h"
23
24 ✗ void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced, int field)
25 {
26 ✗ RTPMuxContext *s = s1->priv_data;
27 ✗ int width = s1->streams[0]->codecpar->width;
28 ✗ int height = s1->streams[0]->codecpar->height;
29 int xinc, yinc, pgroup;
30 ✗ int i = field;
31 ✗ int offset = 0;
32
33 ✗ s->timestamp = s->cur_timestamp;
34 ✗ switch (s1->streams[0]->codecpar->format) {
35 ✗ case AV_PIX_FMT_UYVY422:
36 ✗ xinc = 2;
37 ✗ yinc = 1 << interlaced;
38 ✗ pgroup = 4;
39 ✗ break;
40 ✗ case AV_PIX_FMT_YUV422P10:
41 ✗ xinc = 2;
42 ✗ yinc = 1 << interlaced;
43 ✗ pgroup = 5;
44 ✗ break;
45 ✗ case AV_PIX_FMT_YUV420P:
46 ✗ xinc = 4;
47 ✗ yinc = 1 << interlaced;
48 ✗ pgroup = 6;
49 ✗ break;
50 ✗ case AV_PIX_FMT_RGB24:
51 ✗ xinc = 1;
52 ✗ yinc = 1 << interlaced;
53 ✗ pgroup = 3;
54 ✗ break;
55 ✗ case AV_PIX_FMT_BGR24:
56 ✗ xinc = 1;
57 ✗ yinc = 1 << interlaced;
58 ✗ pgroup = 3;
59 ✗ break;
60 ✗ default:
61 ✗ return;
62 }
63
64 ✗ if (s->max_payload_size < 2 + 6 + pgroup) {
65 ✗ av_log(s1, AV_LOG_ERROR, "Max payload size %d too low\n", s->max_payload_size);
66 ✗ return;
67 }
68
69 ✗ while (i < height) {
70 ✗ int left = s->max_payload_size;
71 ✗ uint8_t *dest = s->buf;
72 uint8_t *headers;
73 ✗ const int head_size = 6;
74 int next_line;
75 int length, cont, pixels;
76
77 /* Extended Sequence Number */
78 ✗ *dest++ = 0;
79 ✗ *dest++ = 0;
80 ✗ left -= 2;
81
82 ✗ headers = dest;
83 do {
84 int l_line;
85
86 ✗ pixels = width - offset;
87 ✗ length = (pixels * pgroup) / xinc;
88
89 ✗ left -= head_size;
90 ✗ if (left >= length && length <= 0xFFFF) {
91 ✗ next_line = 1;
92 } else {
93 ✗ pixels = (FFMIN(left, 0xFFFF) / pgroup) * xinc;
94 ✗ length = (pixels * pgroup) / xinc;
95 ✗ next_line = 0;
96 }
97 ✗ left -= length;
98
99 /* Length */
100 ✗ *dest++ = (length >> 8) & 0xff;
101 ✗ *dest++ = length & 0xff;
102
103 /* Line No */
104 ✗ l_line = i >> interlaced;
105 ✗ *dest++ = ((l_line >> 8) & 0x7f) | ((field << 7) & 0x80);
106 ✗ *dest++ = l_line & 0xff;
107 ✗ if (next_line) i += yinc;
108
109 ✗ cont = (left > (head_size + pgroup) && i < height) ? 0x80 : 0x00;
110 /* Offset and Continuation marker */
111 ✗ *dest++ = ((offset >> 8) & 0x7f) | cont;
112 ✗ *dest++ = offset & 0xff;
113
114 ✗ if (next_line)
115 ✗ offset = 0;
116 else
117 ✗ offset += pixels;
118 ✗ } while (cont);
119
120 do {
121 int l_field;
122 int l_line;
123 int l_off;
124 int64_t copy_offset;
125
126 ✗ length = (headers[0] << 8) | headers[1];
127 ✗ l_field = (headers[2] & 0x80) >> 7;
128 ✗ l_line = ((headers[2] & 0x7f) << 8) | headers[3];
129 ✗ l_off = ((headers[4] & 0x7f) << 8) | headers[5];
130 ✗ cont = headers[4] & 0x80;
131 ✗ headers += head_size;
132
133 ✗ if (interlaced)
134 ✗ l_line = 2 * l_line + l_field;
135 ✗ copy_offset = (l_line * (int64_t)width + l_off) * pgroup / xinc;
136 ✗ if (copy_offset + length > size)
137 ✗ return;
138 ✗ memcpy (dest, buf + copy_offset, length);
139 ✗ dest += length;
140 ✗ } while (cont);
141
142 ✗ ff_rtp_send_data (s1, s->buf, s->max_payload_size - left, i >= height);
143 }
144 }
145