FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/v210enc.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 49 61 80.3%
Branches: 11 24 45.8%

Line Branch Exec Source
1 /*
2 * V210 encoder
3 *
4 * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
5 * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "avcodec.h"
25 #include "bytestream.h"
26 #include "encode.h"
27 #include "internal.h"
28 #include "v210enc.h"
29
30 #define TYPE uint8_t
31 #define DEPTH 8
32 #define BYTES_PER_PIXEL 1
33 #define RENAME(a) a ## _ ## 8
34 #include "v210_template.c"
35 #undef RENAME
36 #undef DEPTH
37 #undef BYTES_PER_PIXEL
38 #undef TYPE
39
40 #define TYPE uint16_t
41 #define DEPTH 10
42 #define BYTES_PER_PIXEL 2
43 #define RENAME(a) a ## _ ## 10
44 #include "v210_template.c"
45 #undef RENAME
46 #undef DEPTH
47 #undef BYTES_PER_PIXEL
48 #undef TYPE
49
50 45023 static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
51 const uint8_t *v, uint8_t *dst,
52 ptrdiff_t width)
53 {
54 uint32_t val;
55 int i;
56
57 /* unroll this to match the assembly */
58
2/2
✓ Branch 0 taken 1258783 times.
✓ Branch 1 taken 45023 times.
1303806 for (i = 0; i < width - 11; i += 12) {
59 1258783 WRITE_PIXELS(u, y, v, 8);
60 1258783 WRITE_PIXELS(y, u, y, 8);
61 1258783 WRITE_PIXELS(v, y, u, 8);
62 1258783 WRITE_PIXELS(y, v, y, 8);
63 1258783 WRITE_PIXELS(u, y, v, 8);
64 1258783 WRITE_PIXELS(y, u, y, 8);
65 1258783 WRITE_PIXELS(v, y, u, 8);
66 1258783 WRITE_PIXELS(y, v, y, 8);
67 }
68 45023 }
69
70 45146 static void v210_planar_pack_10_c(const uint16_t *y, const uint16_t *u,
71 const uint16_t *v, uint8_t *dst,
72 ptrdiff_t width)
73 {
74 uint32_t val;
75 int i;
76
77
2/2
✓ Branch 0 taken 2524309 times.
✓ Branch 1 taken 45146 times.
2569455 for (i = 0; i < width - 5; i += 6) {
78 2524309 WRITE_PIXELS(u, y, v, 10);
79 2524309 WRITE_PIXELS(y, u, y, 10);
80 2524309 WRITE_PIXELS(v, y, u, 10);
81 2524309 WRITE_PIXELS(y, v, y, 10);
82 }
83 45146 }
84
85 21 av_cold void ff_v210enc_init(V210EncContext *s)
86 {
87 21 s->pack_line_8 = v210_planar_pack_8_c;
88 21 s->pack_line_10 = v210_planar_pack_10_c;
89 21 s->sample_factor_8 = 2;
90 21 s->sample_factor_10 = 1;
91
92 if (ARCH_X86)
93 21 ff_v210enc_init_x86(s);
94 21 }
95
96 8 static av_cold int encode_init(AVCodecContext *avctx)
97 {
98 8 V210EncContext *s = avctx->priv_data;
99
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (avctx->width & 1) {
101 av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
102 return AVERROR(EINVAL);
103 }
104
105 8 ff_v210enc_init(s);
106
107 8 avctx->bits_per_coded_sample = 20;
108 8 avctx->bit_rate = ff_guess_coded_bitrate(avctx) * 16 / 15;
109
110 8 return 0;
111 }
112
113 400 static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
114 const AVFrame *pic, int *got_packet)
115 {
116 400 int aligned_width = ((avctx->width + 47) / 48) * 48;
117 400 int stride = aligned_width * 8 / 3;
118 AVFrameSideData *side_data;
119 int ret;
120 uint8_t *dst;
121
122 400 ret = ff_get_encode_buffer(avctx, pkt, avctx->height * stride, 0);
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
400 if (ret < 0) {
124 av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
125 return ret;
126 }
127 400 dst = pkt->data;
128
129
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 200 times.
400 if (pic->format == AV_PIX_FMT_YUV422P10)
130 200 v210_enc_10(avctx, dst, pic);
131
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 else if(pic->format == AV_PIX_FMT_YUV422P)
132 200 v210_enc_8(avctx, dst, pic);
133
134 400 side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_A53_CC);
135
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
400 if (side_data && side_data->size) {
136 uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_A53_CC, side_data->size);
137 if (!buf)
138 return AVERROR(ENOMEM);
139 memcpy(buf, side_data->data, side_data->size);
140 }
141
142 400 side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_AFD);
143
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 400 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
400 if (side_data && side_data->size) {
144 uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_AFD, side_data->size);
145 if (!buf)
146 return AVERROR(ENOMEM);
147 memcpy(buf, side_data->data, side_data->size);
148 }
149
150 400 pkt->flags |= AV_PKT_FLAG_KEY;
151 400 *got_packet = 1;
152 400 return 0;
153 }
154
155 const AVCodec ff_v210_encoder = {
156 .name = "v210",
157 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
158 .type = AVMEDIA_TYPE_VIDEO,
159 .id = AV_CODEC_ID_V210,
160 .capabilities = AV_CODEC_CAP_DR1,
161 .priv_data_size = sizeof(V210EncContext),
162 .init = encode_init,
163 .encode2 = encode_frame,
164 .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P, AV_PIX_FMT_NONE },
165 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
166 };
167