FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dv.c
Date: 2021-09-22 05:58:22
Exec Total Coverage
Lines: 68 79 86.1%
Branches: 38 45 84.4%

Line Branch Exec Source
1 /*
2 * DV decoder
3 * Copyright (c) 2002 Fabrice Bellard
4 * Copyright (c) 2004 Roman Shaposhnik
5 *
6 * DV encoder
7 * Copyright (c) 2003 Roman Shaposhnik
8 *
9 * 50 Mbps (DVCPRO50) support
10 * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com>
11 *
12 * 100 Mbps (DVCPRO HD) support
13 * Initial code by Daniel Maas <dmaas@maasdigital.com> (funded by BBC R&D)
14 * Final code by Roman Shaposhnik
15 *
16 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
17 * of DV technical info.
18 *
19 * This file is part of FFmpeg.
20 *
21 * FFmpeg is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2.1 of the License, or (at your option) any later version.
25 *
26 * FFmpeg is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with FFmpeg; if not, write to the Free Software
33 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 */
35
36 /**
37 * @file
38 * DV codec.
39 */
40
41 #include "libavutil/internal.h"
42 #include "libavutil/pixdesc.h"
43
44 #include "avcodec.h"
45 #include "dv.h"
46 #include "dvdata.h"
47 #include "internal.h"
48 #include "put_bits.h"
49 #include "simple_idct.h"
50
51 43038 static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan,
52 int seq, int slot, uint16_t *tbl)
53 {
54 static const uint8_t off[] = { 2, 6, 8, 0, 4 };
55 static const uint8_t shuf1[] = { 36, 18, 54, 0, 72 };
56 static const uint8_t shuf2[] = { 24, 12, 36, 0, 48 };
57 static const uint8_t shuf3[] = { 18, 9, 27, 0, 36 };
58
59 static const uint8_t l_start[] = { 0, 4, 9, 13, 18, 22, 27, 31, 36, 40 };
60 static const uint8_t l_start_shuffled[] = { 9, 4, 13, 0, 18 };
61
62 static const uint8_t serpent1[] = {
63 0, 1, 2, 2, 1, 0,
64 0, 1, 2, 2, 1, 0,
65 0, 1, 2, 2, 1, 0,
66 0, 1, 2, 2, 1, 0,
67 0, 1, 2
68 };
69 static const uint8_t serpent2[] = {
70 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
71 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0,
72 0, 1, 2, 3, 4, 5
73 };
74
75 static const uint8_t remap[][2] = {
76 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, /* dummy */
77 { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 10, 0 },
78 { 10, 1 }, { 10, 2 }, { 10, 3 }, { 20, 0 }, { 20, 1 },
79 { 20, 2 }, { 20, 3 }, { 30, 0 }, { 30, 1 }, { 30, 2 },
80 { 30, 3 }, { 40, 0 }, { 40, 1 }, { 40, 2 }, { 40, 3 },
81 { 50, 0 }, { 50, 1 }, { 50, 2 }, { 50, 3 }, { 60, 0 },
82 { 60, 1 }, { 60, 2 }, { 60, 3 }, { 70, 0 }, { 70, 1 },
83 { 70, 2 }, { 70, 3 }, { 0, 64 }, { 0, 65 }, { 0, 66 },
84 { 10, 64 }, { 10, 65 }, { 10, 66 }, { 20, 64 }, { 20, 65 },
85 { 20, 66 }, { 30, 64 }, { 30, 65 }, { 30, 66 }, { 40, 64 },
86 { 40, 65 }, { 40, 66 }, { 50, 64 }, { 50, 65 }, { 50, 66 },
87 { 60, 64 }, { 60, 65 }, { 60, 66 }, { 70, 64 }, { 70, 65 },
88 { 70, 66 }, { 0, 67 }, { 20, 67 }, { 40, 67 }, { 60, 67 }
89 };
90
91 int i, k, m;
92 int x, y, blk;
93
94
2/2
✓ Branch 0 taken 215190 times.
✓ Branch 1 taken 43038 times.
258228 for (m = 0; m < 5; m++) {
95
3/5
✓ Branch 0 taken 72900 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32400 times.
✓ Branch 3 taken 109890 times.
✗ Branch 4 not taken.
215190 switch (d->width) {
96 72900 case 1440:
97 72900 blk = (chan * 11 + seq) * 27 + slot;
98
99
4/4
✓ Branch 0 taken 19440 times.
✓ Branch 1 taken 53460 times.
✓ Branch 2 taken 1620 times.
✓ Branch 3 taken 17820 times.
72900 if (chan == 0 && seq == 11) {
100 1620 x = m * 27 + slot;
101
2/2
✓ Branch 0 taken 1080 times.
✓ Branch 1 taken 540 times.
1620 if (x < 90) {
102 1080 y = 0;
103 } else {
104 540 x = (x - 90) * 2;
105 540 y = 67;
106 }
107 } else {
108 71280 i = (4 * chan + blk + off[m]) % 11;
109 71280 k = (blk / 11) % 27;
110
111 71280 x = shuf1[m] + (chan & 1) * 9 + k % 9;
112 71280 y = (i * 3 + k / 9) * 2 + (chan >> 1) + 1;
113 }
114 72900 tbl[m] = (x << 1) | (y << 9);
115 72900 break;
116 case 1280:
117 blk = (chan * 10 + seq) * 27 + slot;
118
119 i = (4 * chan + (seq / 5) + 2 * blk + off[m]) % 10;
120 k = (blk / 5) % 27;
121
122 x = shuf1[m] + (chan & 1) * 9 + k % 9;
123 y = (i * 3 + k / 9) * 2 + (chan >> 1) + 4;
124
125 if (x >= 80) {
126 x = remap[y][0] + ((x - 80) << (y > 59));
127 y = remap[y][1];
128 }
129 tbl[m] = (x << 1) | (y << 9);
130 break;
131 32400 case 960:
132 32400 blk = (chan * 10 + seq) * 27 + slot;
133
134 32400 i = (4 * chan + (seq / 5) + 2 * blk + off[m]) % 10;
135 32400 k = (blk / 5) % 27 + (i & 1) * 3;
136
137 32400 x = shuf2[m] + k % 6 + 6 * (chan & 1);
138 32400 y = l_start[i] + k / 6 + 45 * (chan >> 1);
139 32400 tbl[m] = (x << 1) | (y << 9);
140 32400 break;
141 109890 case 720:
142
3/4
✓ Branch 0 taken 45360 times.
✓ Branch 1 taken 38880 times.
✓ Branch 2 taken 25650 times.
✗ Branch 3 not taken.
109890 switch (d->pix_fmt) {
143 45360 case AV_PIX_FMT_YUV422P:
144 45360 x = shuf3[m] + slot / 3;
145 45360 y = serpent1[slot] +
146 45360 ((((seq + off[m]) % d->difseg_size) << 1) + chan) * 3;
147 45360 tbl[m] = (x << 1) | (y << 8);
148 45360 break;
149 38880 case AV_PIX_FMT_YUV420P:
150 38880 x = shuf3[m] + slot / 3;
151 38880 y = serpent1[slot] +
152 38880 ((seq + off[m]) % d->difseg_size) * 3;
153 38880 tbl[m] = (x << 1) | (y << 9);
154 38880 break;
155 25650 case AV_PIX_FMT_YUV411P:
156 25650 i = (seq + off[m]) % d->difseg_size;
157
4/4
✓ Branch 0 taken 20520 times.
✓ Branch 1 taken 5130 times.
✓ Branch 2 taken 5130 times.
✓ Branch 3 taken 15390 times.
25650 k = slot + ((m == 1 || m == 2) ? 3 : 0);
158
159 25650 x = l_start_shuffled[m] + k / 6;
160 25650 y = serpent2[k] + i * 6;
161
2/2
✓ Branch 0 taken 570 times.
✓ Branch 1 taken 25080 times.
25650 if (x > 21)
162 570 y = y * 2 - i * 6;
163 25650 tbl[m] = (x << 2) | (y << 8);
164 25650 break;
165 }
166 default:
167 109890 break;
168 }
169 }
170 43038 }
171
172 79 int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
173 {
174 int j, i, c, s, p;
175
176 79 p = i = 0;
177
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 79 times.
220 for (c = 0; c < d->n_difchan; c++) {
178
2/2
✓ Branch 0 taken 1678 times.
✓ Branch 1 taken 141 times.
1819 for (s = 0; s < d->difseg_size; s++) {
179 1678 p += 6;
180
2/2
✓ Branch 0 taken 45306 times.
✓ Branch 1 taken 1678 times.
46984 for (j = 0; j < 27; j++) {
181 45306 p += !(j % 3);
182
7/8
✓ Branch 0 taken 15552 times.
✓ Branch 1 taken 29754 times.
✓ Branch 2 taken 15552 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11664 times.
✓ Branch 5 taken 3888 times.
✓ Branch 6 taken 10692 times.
✓ Branch 7 taken 972 times.
45306 if (!(DV_PROFILE_IS_1080i50(d) && c != 0 && s == 11) &&
183
5/6
✓ Branch 0 taken 7776 times.
✓ Branch 1 taken 36558 times.
✓ Branch 2 taken 7776 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6480 times.
✓ Branch 5 taken 1296 times.
44334 !(DV_PROFILE_IS_720p50(d) && s > 9)) {
184 43038 dv_calc_mb_coordinates(d, c, s, j, &ctx->work_chunks[i].mb_coordinates[0]);
185 43038 ctx->work_chunks[i++].buf_offset = p;
186 }
187 45306 p += 5;
188 }
189 }
190 }
191
192 79 return 0;
193 }
194
195 81 av_cold int ff_dvvideo_init(AVCodecContext *avctx)
196 {
197 81 DVVideoContext *s = avctx->priv_data;
198
199 81 s->avctx = avctx;
200 81 avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
201
202 81 return 0;
203 }
204