FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/rawutils.c
Date: 2026-08-20 03:03:04
Exec Total Coverage
Lines: 34 47 72.3%
Functions: 2 2 100.0%
Branches: 21 38 55.3%

Line Branch Exec Source
1 /*
2 * Raw video utils
3 * Copyright (c) 2016 Michael Niedermayer
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 "libavutil/intreadwrite.h"
23 #include "libavcodec/packet.h"
24 #include "avformat.h"
25 #include "rawutils.h"
26
27 625 int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride)
28 {
29 int ret;
30 625 AVPacket *pkt = *ppkt;
31
2/2
✓ Branch 0 taken 425 times.
✓ Branch 1 taken 200 times.
625 int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
32 625 int64_t min_stride = (par->width * bpc + 7) >> 3;
33 int with_pal_size, contains_pal, size, stride, padding, y;
34 AVPacket *new_pkt;
35
36
3/6
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 625 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 625 times.
✗ Branch 5 not taken.
625 if (par->height <= 0 || min_stride <= 0 || expected_stride <= 0 ||
37
1/2
✓ Branch 0 taken 625 times.
✗ Branch 1 not taken.
625 min_stride > (INT_MAX - 1024) / par->height ||
38
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 625 times.
625 expected_stride > (INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) / par->height)
39 return AVERROR(EINVAL);
40
41 625 with_pal_size = min_stride * par->height + 1024;
42
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 625 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
625 contains_pal = bpc == 8 && pkt->size == with_pal_size;
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 625 times.
625 size = contains_pal ? min_stride * par->height : pkt->size;
44 625 stride = size / par->height;
45 625 padding = expected_stride - FFMIN(expected_stride, stride);
46
47
2/2
✓ Branch 0 taken 525 times.
✓ Branch 1 taken 100 times.
625 if (pkt->size == expected_stride * par->height)
48 525 return 0;
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (size != stride * par->height)
50 return 0;
51
52 100 new_pkt = av_packet_alloc();
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (!new_pkt)
54 return AVERROR(ENOMEM);
55
56 100 ret = av_new_packet(new_pkt, expected_stride * par->height);
57
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (ret < 0)
58 goto fail;
59
60 100 ret = av_packet_copy_props(new_pkt, pkt);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (ret < 0)
62 goto fail;
63
64
2/2
✓ Branch 0 taken 3400 times.
✓ Branch 1 taken 100 times.
3500 for (y = 0; y<par->height; y++) {
65 3400 memcpy(new_pkt->data + y*expected_stride, pkt->data + y*stride, FFMIN(expected_stride, stride));
66 3400 memset(new_pkt->data + y*expected_stride + expected_stride - padding, 0, padding);
67 }
68
69 100 *ppkt = new_pkt;
70 100 return 1 + contains_pal;
71 fail:
72 av_packet_free(&new_pkt);
73
74 return ret;
75 }
76
77 321 int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
78 {
79 uint8_t *side_data;
80 size_t size;
81
82 321 side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PALETTE, &size);
83
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 113 times.
321 if (side_data) {
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
208 if (size != AVPALETTE_SIZE) {
85 av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
86 return AVERROR_INVALIDDATA;
87 }
88 208 memcpy(palette, side_data, AVPALETTE_SIZE);
89 208 return 1;
90 }
91
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
113 if (ret == CONTAINS_PAL) {
93 for (int i = 0; i < AVPALETTE_COUNT; i++)
94 palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4);
95 return 1;
96 }
97
98 113 return 0;
99 }
100