FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/rawutils.c
Date: 2022-12-05 03:11:11
Exec Total Coverage
Lines: 31 43 72.1%
Functions: 2 2 100.0%
Branches: 16 28 57.1%

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 600 int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecParameters *par, int expected_stride)
28 {
29 int ret;
30 600 AVPacket *pkt = *ppkt;
31
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 200 times.
600 int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
32 600 int min_stride = (par->width * bpc + 7) >> 3;
33 600 int with_pal_size = min_stride * par->height + 1024;
34
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
600 int contains_pal = bpc == 8 && pkt->size == with_pal_size;
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 int size = contains_pal ? min_stride * par->height : pkt->size;
36 600 int stride = size / par->height;
37 600 int padding = expected_stride - FFMIN(expected_stride, stride);
38 int y;
39 AVPacket *new_pkt;
40
41
2/2
✓ Branch 0 taken 500 times.
✓ Branch 1 taken 100 times.
600 if (pkt->size == expected_stride * par->height)
42 500 return 0;
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (size != stride * par->height)
44 return 0;
45
46 100 new_pkt = av_packet_alloc();
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (!new_pkt)
48 return AVERROR(ENOMEM);
49
50 100 ret = av_new_packet(new_pkt, expected_stride * par->height);
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (ret < 0)
52 goto fail;
53
54 100 ret = av_packet_copy_props(new_pkt, pkt);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (ret < 0)
56 goto fail;
57
58
2/2
✓ Branch 0 taken 3400 times.
✓ Branch 1 taken 100 times.
3500 for (y = 0; y<par->height; y++) {
59 3400 memcpy(new_pkt->data + y*expected_stride, pkt->data + y*stride, FFMIN(expected_stride, stride));
60 3400 memset(new_pkt->data + y*expected_stride + expected_stride - padding, 0, padding);
61 }
62
63 100 *ppkt = new_pkt;
64 100 return 1 + contains_pal;
65 fail:
66 av_packet_free(&new_pkt);
67
68 return ret;
69 }
70
71 117 int ff_get_packet_palette(AVFormatContext *s, AVPacket *pkt, int ret, uint32_t *palette)
72 {
73 uint8_t *side_data;
74 size_t size;
75
76 117 side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_PALETTE, &size);
77
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 113 times.
117 if (side_data) {
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (size != AVPALETTE_SIZE) {
79 av_log(s, AV_LOG_ERROR, "Invalid palette side data\n");
80 return AVERROR_INVALIDDATA;
81 }
82 4 memcpy(palette, side_data, AVPALETTE_SIZE);
83 4 return 1;
84 }
85
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
113 if (ret == CONTAINS_PAL) {
87 for (int i = 0; i < AVPALETTE_COUNT; i++)
88 palette[i] = AV_RL32(pkt->data + pkt->size - AVPALETTE_SIZE + i*4);
89 return 1;
90 }
91
92 113 return 0;
93 }
94