切莫是什么意思| 什么是水痘| 担心是什么意思| 女人耳鸣是什么前兆| 什么情况下才做冠脉cta| 八岁属什么生肖| 孙耀威为什么被封杀| 什么祛斑产品效果好| 心脏杂音是什么意思| aoa是什么意思| 2007年是什么命| 吃醋是什么意思| 电焊打眼睛用什么眼药水| 两榜进士是什么意思| 小沈阳属什么生肖| 胃炎吃什么药好使| 10点是什么时辰| 一饿就胃疼是什么原因| 下午1点是什么时辰| 火箭是干什么用的| 青葱岁月是什么意思| 为什么会晨勃| 10月19日什么星座| 继发不孕什么意思| 用你的手解我的锁是什么歌| 摩卡是什么意思| 黄皮什么时候成熟| 喝酒会得什么病| 一票制什么意思| 碳水化合物指的是什么| 学考成绩什么时候公布| 隔离的作用是什么| 什么水果减肥最有效| 支原体感染吃什么食物好| 楚楚动人是什么意思| 贴脸是什么意思| 10月21号是什么星座| 黄豆炒什么好吃| 挂名什么意思| 铁扇公主是什么妖精| 西瓜又什么又什么填空| 抗战纪念日为什么是9月3日| 孕妇咳嗽可以吃什么药| 什么是码率| dpoy什么意思| 大腿粗是什么原因导致的| clara是什么意思| 扳机指是什么原因造成的| 77年属什么| 首级是什么意思| 内膜薄吃什么增长最快| 欣什么若什么| 短裙配什么鞋子好看| 乳腺结节三级是什么意思| 舌头中间裂纹是什么病| 宠物邮寄用什么快递| 淋巴结稍大是什么意思| 啦啦是什么意思| 西瓜吃多了有什么坏处| 鸟对什么| 双向情感障碍吃什么药| 月经来了腰疼是什么原因| 梦见老公出轨预示什么| 肚子痛吃什么药好| 6541是什么药| 挂是什么意思| 什么不止| 酗酒是什么意思| 最大的动物是什么| 为什么突然流鼻血| 鼹鼠吃什么| 拉肚子吃什么最好| 三里屯有什么好玩的地方| 吃什么降低甘油三酯| 肾气不足是什么原因| 息影是什么意思| 三个火读什么| 育婴员是做什么的| 胃痉挛是什么| 美国为什么打朝鲜| 尿道口感染吃什么药| 亥时属什么生肖| 喝黑枸杞有什么好处| 带状疱疹吃什么药| 皮蛋和什么不能一起吃| 欲情故纵什么意思| 角化异常性疾病是什么| 非分之想什么意思| 魑魅魍魉什么意思| 出离心是什么意思| 下午四点多是什么时辰| 虾皮是什么虾| 考幼师证需要什么条件| 三个龙是什么字| 肥猪拱门是什么生肖| 10月25是什么星座| 60岁生日送什么礼物| 噤若寒蝉是什么意思| 567是什么意思| 绞丝旁一个奇念什么| 晕车为什么读第四声| 魏大勋什么星座| 服役是什么意思| 补钾吃什么药| 怀孕前检查什么项目内容| 磨牙吃什么药能治好| 伏天从什么时候开始| 乙醇是什么| 摸摸唱是什么意思| bonnie是什么意思| 三毛为什么自杀| 抑郁症什么症状表现| 兰花什么时候开| 下焦湿热阴囊潮湿吃什么药| 归脾丸的功效与作用治什么病| 石榴花是什么颜色| 自相矛盾什么意思| 膝盖疼痛挂什么科| 基础代谢是什么意思| 看头部挂什么科| gp什么意思| 去医院要带什么| 松花蛋是什么蛋做的| 屁股出血什么原因| 什么是胆固醇| 味美思是什么酒| 过敏性鼻炎吃什么食物好| 吃阿莫西林过敏有什么症状| 1月18日什么星座| 粘鞋子用什么胶水最好| 养猫有什么好处| 肝气虚吃什么中成药| 神经性耳鸣有什么症状| 荔枝不能和什么一起吃| 为什么不能打死飞蛾| instagram是什么软件| 太平洋中间是什么| 阿拉伯人是什么种人| 山茶花是什么颜色| hoka是什么牌子| 夹页念什么| 右手掌心有痣代表什么| 素女是什么意思| 什么是胃溃疡| 丙二醇是什么东西| 酸野是什么| 牛油果吃了有什么好处| 苯磺酸氨氯地平片什么时候吃| 冠状动脉粥样硬化性心脏病吃什么药| 舌苔厚腻发白是什么原因| 什么洗面奶最好用排行第一| 红色尿液是什么原因| 很能睡觉是什么原因| 什么叫稽留流产| 安逸什么意思| 本子是什么意思| 心影增大是什么意思| 打2个喷嚏代表什么| 后面的牙齿叫什么| 痛风打什么针| 儿童过敏性鼻炎吃什么药| 属猪的守护神是什么菩萨| 京ag6是什么意思| 冷冻跟冷藏有什么区别| 农历六月十三是什么星座| 车水马龙是什么生肖| 唇红齿白是什么生肖| 回笼觉是什么意思| 什么多么什么造句| 新蒜什么时候上市| 拉风是什么意思| 什么叫甘油三酯| 8月28日什么星座| 弥漫性肝病是什么意思| 腰底部疼痛跟什么病有关| 薤是什么菜图片| 举的部首是什么| 为什么可乐能溶解鱼刺| 肝功能八项检查什么| 褥疮用什么药| 县副局长是什么级别| 缺铁吃什么补得最快| 三颗星是什么军衔| 大便粘马桶吃什么药| 产检建档需要什么资料| 女生做彩超是检查什么| 胎动在肚脐周围是什么胎位| 7月25日是什么星座| 翡翠和玉有什么不同| 什么白酒好喝| 梦见着火了是什么意思| 8月11是什么星座| 五谷有什么| 鸟为什么会飞| 阿莫西林主要治疗什么| 穆赫兰道到底讲的什么| amo是什么意思| 多吃洋葱有什么好处| 魑魅魍魉是什么意思| 脉冲是什么意思| 为什么同房后小腹疼痛| 肾有结晶是什么意思| 手脚热吃什么药效果好| 穿拖鞋脚臭是什么原因| 牙齿疼吃什么药| 肠易激综合征吃什么药| 眼睛上火用什么眼药水| 什么伐桂| 藿香正气水能治什么病| 屁股后面骨头疼是什么原因| 肠胀气是什么原因引起的怎么解决| 舌苔发紫是什么原因| 外痔用什么药可以消除| 肠胃消化不好吃什么药| 门庭若什么| 吃什么东西越吃越饿| 什么是diy| 一个口一个且念什么字| 减肥早餐适合吃什么| 石斛花有什么功效| 在水一方什么意思| 关节疼是什么原因| 觉悟是什么意思| 什么不什么当| 毛躁是什么意思| 鼻咽炎有什么症状| 出去旅游需要带什么| 什么是上火| 芸豆是什么| 木瓜不能和什么一起吃| 胃烧心吃什么药| 头晕挂什么科比较好| 为什么感冒会流鼻涕| 请问紫苏叶有什么功效| robam是什么牌子| 股票xd开头是什么意思| 盘古是一个什么样的人| 沙悟净是什么生肖| 头疼检查什么项目| 百香果配什么好喝| 防晒霜什么牌子好| 乙肝两对半245阳性是什么意思| 为什么要小心吉普赛人| 小人痣代表什么意思| 野鸭子吃什么| 补肝血吃什么药| 沙虫是什么| 喝水多尿少是什么原因| 十指纤纤尽夸巧是什么生肖| 舌头干燥吃什么药| 抚触是什么意思| 哪吒是一个什么样的人| 核磁共振和ct有什么区别| 甲胎蛋白偏高是什么原因| 午马是什么意思| 肝实质弥漫性回声改变什么意思| 不长毛的猫叫什么名字| 泻盐是什么东西| 阑尾炎有什么症状表现| 什么充电宝可以带上飞机| 教师编制是什么意思| 巴基斯坦是什么语言| 黑豚肉是什么肉| 胰腺在人体什么位置| 百度

petct是什么


Directory: ../../../ffmpeg/
File: src/libavcodec/utvideoenc.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 248 289 85.8%
Functions: 11 11 100.0%
Branches: 104 131 79.4%

Line Branch Exec Source
1 /*
2 * Ut Video encoder
3 * Copyright (c) 2012 Jan Ekstr?m
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 /**
23 * @file
24 * Ut Video encoder
25 */
26
27 #include "libavutil/avassert.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/opt.h"
32
33 #include "avcodec.h"
34 #include "codec_internal.h"
35 #include "encode.h"
36 #include "bswapdsp.h"
37 #include "bytestream.h"
38 #include "lossless_videoencdsp.h"
39 #include "put_bits.h"
40 #include "utvideo.h"
41 #include "huffman.h"
42
43 typedef struct UtvideoContext {
44 const AVClass *class;
45 BswapDSPContext bdsp;
46 LLVidEncDSPContext llvidencdsp;
47
48 uint32_t frame_info_size, flags;
49 int planes;
50 int slices;
51 int compression;
52 int frame_pred;
53
54 ptrdiff_t slice_stride;
55 uint8_t *slice_bits, *slice_buffer[4];
56 int slice_bits_size;
57 } UtvideoContext;
58
59 typedef struct HuffEntry {
60 uint16_t sym;
61 uint8_t len;
62 uint32_t code;
63 } HuffEntry;
64
65 /* Compare huffman tree nodes */
66 3203178 static int ut_huff_cmp_len(const void *a, const void *b)
67 {
68 3203178 const HuffEntry *aa = a, *bb = b;
69 3203178 return (aa->len - bb->len)*256 + aa->sym - bb->sym;
70 }
71
72 /* Compare huffentry symbols */
73 3158830 static int huff_cmp_sym(const void *a, const void *b)
74 {
75 3158830 const HuffEntry *aa = a, *bb = b;
76 3158830 return aa->sym - bb->sym;
77 }
78
79 136 static av_cold int utvideo_encode_close(AVCodecContext *avctx)
80 {
81 136 UtvideoContext *c = avctx->priv_data;
82 int i;
83
84 136 av_freep(&c->slice_bits);
85
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 136 times.
680 for (i = 0; i < 4; i++)
86 544 av_freep(&c->slice_buffer[i]);
87
88 136 return 0;
89 }
90
91 136 static av_cold int utvideo_encode_init(AVCodecContext *avctx)
92 {
93 136 UtvideoContext *c = avctx->priv_data;
94 int i, subsampled_height;
95 uint32_t original_format;
96
97 136 c->frame_info_size = 4;
98 136 c->slice_stride = FFALIGN(avctx->width, 32);
99
100
5/6
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 27 times.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
136 switch (avctx->pix_fmt) {
101 27 case AV_PIX_FMT_GBRP:
102 27 c->planes = 3;
103 27 avctx->codec_tag = MKTAG('U', 'L', 'R', 'G');
104 27 original_format = UTVIDEO_RGB;
105 27 break;
106 27 case AV_PIX_FMT_GBRAP:
107 27 c->planes = 4;
108 27 avctx->codec_tag = MKTAG('U', 'L', 'R', 'A');
109 27 original_format = UTVIDEO_RGBA;
110 27 avctx->bits_per_coded_sample = 32;
111 27 break;
112 28 case AV_PIX_FMT_YUV420P:
113
2/4
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
28 if (avctx->width & 1 || avctx->height & 1) {
114 av_log(avctx, AV_LOG_ERROR,
115 "4:2:0 video requires even width and height.\n");
116 return AVERROR_INVALIDDATA;
117 }
118 28 c->planes = 3;
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (avctx->colorspace == AVCOL_SPC_BT709)
120 avctx->codec_tag = MKTAG('U', 'L', 'H', '0');
121 else
122 28 avctx->codec_tag = MKTAG('U', 'L', 'Y', '0');
123 28 original_format = UTVIDEO_420;
124 28 break;
125 27 case AV_PIX_FMT_YUV422P:
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (avctx->width & 1) {
127 av_log(avctx, AV_LOG_ERROR,
128 "4:2:2 video requires even width.\n");
129 return AVERROR_INVALIDDATA;
130 }
131 27 c->planes = 3;
132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (avctx->colorspace == AVCOL_SPC_BT709)
133 avctx->codec_tag = MKTAG('U', 'L', 'H', '2');
134 else
135 27 avctx->codec_tag = MKTAG('U', 'L', 'Y', '2');
136 27 original_format = UTVIDEO_422;
137 27 break;
138 27 case AV_PIX_FMT_YUV444P:
139 27 c->planes = 3;
140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (avctx->colorspace == AVCOL_SPC_BT709)
141 avctx->codec_tag = MKTAG('U', 'L', 'H', '4');
142 else
143 27 avctx->codec_tag = MKTAG('U', 'L', 'Y', '4');
144 27 original_format = UTVIDEO_444;
145 27 break;
146 default:
147 av_unreachable("Already checked via CODEC_PIXFMTS");
148 }
149
150 136 ff_bswapdsp_init(&c->bdsp);
151 136 ff_llvidencdsp_init(&c->llvidencdsp);
152
153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
136 if (c->frame_pred == PRED_GRADIENT) {
154 av_log(avctx, AV_LOG_ERROR, "Gradient prediction is not supported.\n");
155 return AVERROR_PATCHWELCOME;
156 }
157
158 /*
159 * Check the asked slice count for obviously invalid
160 * values (> 256 or negative).
161 */
162
2/4
✓ Branch 0 taken 136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 136 times.
136 if (avctx->slices > 256 || avctx->slices < 0) {
163 av_log(avctx, AV_LOG_ERROR,
164 "Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
165 avctx->slices);
166 return AVERROR(EINVAL);
167 }
168
169 /* Check that the slice count is not larger than the subsampled height */
170 136 subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
136 if (avctx->slices > subsampled_height) {
172 av_log(avctx, AV_LOG_ERROR,
173 "Slice count %d is larger than the subsampling-applied height %d.\n",
174 avctx->slices, subsampled_height);
175 return AVERROR(EINVAL);
176 }
177
178 /* extradata size is 4 * 32 bits */
179 136 avctx->extradata_size = 16;
180
181 136 avctx->extradata = av_mallocz(avctx->extradata_size +
182 AV_INPUT_BUFFER_PADDING_SIZE);
183
184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
136 if (!avctx->extradata) {
185 av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata.\n");
186 return AVERROR(ENOMEM);
187 }
188
189
2/2
✓ Branch 0 taken 435 times.
✓ Branch 1 taken 136 times.
571 for (i = 0; i < c->planes; i++) {
190 435 c->slice_buffer[i] = av_malloc(c->slice_stride * (avctx->height + 2) +
191 AV_INPUT_BUFFER_PADDING_SIZE);
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 435 times.
435 if (!c->slice_buffer[i]) {
193 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 1.\n");
194 return AVERROR(ENOMEM);
195 }
196 }
197
198 /*
199 * Set the version of the encoder.
200 * Last byte is "implementation ID", which is
201 * obtained from the creator of the format.
202 * Libavcodec has been assigned with the ID 0xF0.
203 */
204 136 AV_WB32(avctx->extradata, MKTAG(1, 0, 0, 0xF0));
205
206 /*
207 * Set the "original format"
208 * Not used for anything during decoding.
209 */
210 136 AV_WL32(avctx->extradata + 4, original_format);
211
212 /* Write 4 as the 'frame info size' */
213 136 AV_WL32(avctx->extradata + 8, c->frame_info_size);
214
215 /*
216 * Set how many slices are going to be used.
217 * By default uses multiple slices depending on the subsampled height.
218 * This enables multithreading in the official decoder.
219 */
220
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 135 times.
136 if (!avctx->slices) {
221 1 c->slices = subsampled_height / 120;
222
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!c->slices)
224 c->slices = 1;
225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 else if (c->slices > 256)
226 c->slices = 256;
227 } else {
228 135 c->slices = avctx->slices;
229 }
230
231 /* Set compression mode */
232 136 c->compression = COMP_HUFF;
233
234 /*
235 * Set the encoding flags:
236 * - Slice count minus 1
237 * - Interlaced encoding mode flag, set to zero for now.
238 * - Compression mode (none/huff)
239 * And write the flags.
240 */
241 136 c->flags = (c->slices - 1U) << 24;
242 136 c->flags |= 0 << 11; // bit field to signal interlaced encoding mode
243 136 c->flags |= c->compression;
244
245 136 AV_WL32(avctx->extradata + 12, c->flags);
246
247 136 return 0;
248 }
249
250 300 static void mangle_rgb_planes(uint8_t *dst[4], ptrdiff_t dst_stride,
251 uint8_t *const src[4], int planes, const int stride[4],
252 int width, int height)
253 {
254 int i, j;
255 300 int k = 2 * dst_stride;
256 300 const uint8_t *sg = src[0];
257 300 const uint8_t *sb = src[1];
258 300 const uint8_t *sr = src[2];
259 300 const uint8_t *sa = src[3];
260 unsigned int g;
261
262
2/2
✓ Branch 0 taken 86400 times.
✓ Branch 1 taken 300 times.
86700 for (j = 0; j < height; j++) {
263
2/2
✓ Branch 0 taken 43200 times.
✓ Branch 1 taken 43200 times.
86400 if (planes == 3) {
264
2/2
✓ Branch 0 taken 15206400 times.
✓ Branch 1 taken 43200 times.
15249600 for (i = 0; i < width; i++) {
265 15206400 g = sg[i];
266 15206400 dst[0][k] = g;
267 15206400 g += 0x80;
268 15206400 dst[1][k] = sb[i] - g;
269 15206400 dst[2][k] = sr[i] - g;
270 15206400 k++;
271 }
272 } else {
273
2/2
✓ Branch 0 taken 15206400 times.
✓ Branch 1 taken 43200 times.
15249600 for (i = 0; i < width; i++) {
274 15206400 g = sg[i];
275 15206400 dst[0][k] = g;
276 15206400 g += 0x80;
277 15206400 dst[1][k] = sb[i] - g;
278 15206400 dst[2][k] = sr[i] - g;
279 15206400 dst[3][k] = sa[i];
280 15206400 k++;
281 }
282 43200 sa += stride[3];
283 }
284 86400 k += dst_stride - width;
285 86400 sg += stride[0];
286 86400 sb += stride[1];
287 86400 sr += stride[2];
288 }
289 300 }
290
291 #undef A
292 #undef B
293
294 /* Write data to a plane with median prediction */
295 800 static void median_predict(UtvideoContext *c, const uint8_t *src, uint8_t *dst,
296 ptrdiff_t stride, int width, int height)
297 {
298 int i, j;
299 int A, B;
300 uint8_t prev;
301
302 /* First line uses left neighbour prediction */
303 800 prev = 0x80; /* Set the initial value */
304
2/2
✓ Branch 0 taken 246400 times.
✓ Branch 1 taken 800 times.
247200 for (i = 0; i < width; i++) {
305 246400 *dst++ = src[i] - prev;
306 246400 prev = src[i];
307 }
308
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 800 times.
800 if (height == 1)
310 return;
311
312 800 src += stride;
313
314 /*
315 * Second line uses top prediction for the first sample,
316 * and median for the rest.
317 */
318 800 A = B = 0;
319
320 /* Rest of the coded part uses median prediction */
321
2/2
✓ Branch 0 taken 215200 times.
✓ Branch 1 taken 800 times.
216000 for (j = 1; j < height; j++) {
322 215200 c->llvidencdsp.sub_median_pred(dst, src - stride, src, width, &A, &B);
323 215200 dst += width;
324 215200 src += stride;
325 }
326 }
327
328 /* Count the usage of values in a plane */
329 2403 static void count_usage(uint8_t *src, int width,
330 int height, uint64_t *counts)
331 {
332 int i, j;
333
334
2/2
✓ Branch 0 taken 649280 times.
✓ Branch 1 taken 2403 times.
651683 for (j = 0; j < height; j++) {
335
2/2
✓ Branch 0 taken 205632000 times.
✓ Branch 1 taken 649280 times.
206281280 for (i = 0; i < width; i++) {
336 205632000 counts[src[i]]++;
337 }
338 649280 src += width;
339 }
340 2403 }
341
342 /* Calculate the actual huffman codes from the code lengths */
343 2353 static void calculate_codes(HuffEntry *he)
344 {
345 int last, i;
346 uint32_t code;
347
348 2353 qsort(he, 256, sizeof(*he), ut_huff_cmp_len);
349
350 2353 last = 255;
351
3/4
✓ Branch 0 taken 84131 times.
✓ Branch 1 taken 2353 times.
✓ Branch 2 taken 84131 times.
✗ Branch 3 not taken.
86484 while (he[last].len == 255 && last)
352 84131 last--;
353
354 2353 code = 0;
355
2/2
✓ Branch 0 taken 518237 times.
✓ Branch 1 taken 2353 times.
520590 for (i = last; i >= 0; i--) {
356 518237 he[i].code = code >> (32 - he[i].len);
357 518237 code += 0x80000000u >> (he[i].len - 1);
358 }
359
360 2353 qsort(he, 256, sizeof(*he), huff_cmp_sym);
361 2353 }
362
363 /* Write huffman bit codes to a memory block */
364 2356 static int write_huff_codes(uint8_t *src, uint8_t *dst, int dst_size,
365 int width, int height, HuffEntry *he)
366 {
367 PutBitContext pb;
368 int i, j;
369 int count;
370
371 2356 init_put_bits(&pb, dst, dst_size);
372
373 /* Write the codes */
374
2/2
✓ Branch 0 taken 634880 times.
✓ Branch 1 taken 2356 times.
637236 for (j = 0; j < height; j++) {
375
2/2
✓ Branch 0 taken 200563200 times.
✓ Branch 1 taken 634880 times.
201198080 for (i = 0; i < width; i++)
376 200563200 put_bits(&pb, he[src[i]].len, he[src[i]].code);
377
378 634880 src += width;
379 }
380
381 /* Pad output to a 32-bit boundary */
382 2356 count = put_bits_count(&pb) & 0x1F;
383
384
2/2
✓ Branch 0 taken 2176 times.
✓ Branch 1 taken 180 times.
2356 if (count)
385 2176 put_bits(&pb, 32 - count, 0);
386
387 /* Flush the rest with zeroes */
388 2356 flush_put_bits(&pb);
389
390 /* Return the amount of bytes written */
391 2356 return put_bytes_output(&pb);
392 }
393
394 2403 static int encode_plane(AVCodecContext *avctx, const uint8_t *src,
395 uint8_t *dst, ptrdiff_t stride, int plane_no,
396 int width, int height, PutByteContext *pb)
397 {
398 2403 UtvideoContext *c = avctx->priv_data;
399 uint8_t lengths[256];
400 2403 uint64_t counts[256] = { 0 };
401
402 HuffEntry he[256];
403
404 2403 uint32_t offset = 0, slice_len = 0;
405
4/4
✓ Branch 0 taken 751 times.
✓ Branch 1 taken 1652 times.
✓ Branch 2 taken 151 times.
✓ Branch 3 taken 600 times.
2403 const int cmask = ~(!plane_no && avctx->pix_fmt == AV_PIX_FMT_YUV420P);
406 2403 int i, sstart, send = 0;
407 int symbol;
408 int ret;
409
410 /* Do prediction / make planes */
411
3/4
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 803 times.
✓ Branch 2 taken 800 times.
✗ Branch 3 not taken.
2403 switch (c->frame_pred) {
412 800 case PRED_NONE:
413
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 800 times.
1600 for (i = 0; i < c->slices; i++) {
414 800 sstart = send;
415 800 send = height * (i + 1) / c->slices & cmask;
416 800 av_image_copy_plane(dst + sstart * width, width,
417 800 src + sstart * stride, stride,
418 width, send - sstart);
419 }
420 800 break;
421 803 case PRED_LEFT:
422
2/2
✓ Branch 0 taken 806 times.
✓ Branch 1 taken 803 times.
1609 for (i = 0; i < c->slices; i++) {
423 806 sstart = send;
424 806 send = height * (i + 1) / c->slices & cmask;
425 806 c->llvidencdsp.sub_left_predict(dst + sstart * width, src + sstart * stride, stride, width, send - sstart);
426 }
427 803 break;
428 800 case PRED_MEDIAN:
429
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 800 times.
1600 for (i = 0; i < c->slices; i++) {
430 800 sstart = send;
431 800 send = height * (i + 1) / c->slices & cmask;
432 800 median_predict(c, src + sstart * stride, dst + sstart * width,
433 stride, width, send - sstart);
434 }
435 800 break;
436 default:
437 av_log(avctx, AV_LOG_ERROR, "Unknown prediction mode: %d\n",
438 c->frame_pred);
439 return AVERROR_OPTION_NOT_FOUND;
440 }
441
442 /* Count the usage of values */
443 2403 count_usage(dst, width, height, counts);
444
445 /* Check for a special case where only one symbol was used */
446
1/2
✓ Branch 0 taken 16843 times.
✗ Branch 1 not taken.
16843 for (symbol = 0; symbol < 256; symbol++) {
447 /* If non-zero count is found, see if it matches width * height */
448
2/2
✓ Branch 0 taken 2403 times.
✓ Branch 1 taken 14440 times.
16843 if (counts[symbol]) {
449 /* Special case if only one symbol was used */
450
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2353 times.
2403 if (counts[symbol] == width * (int64_t)height) {
451 /*
452 * Write a zero for the single symbol
453 * used in the plane, else 0xFF.
454 */
455
2/2
✓ Branch 0 taken 12800 times.
✓ Branch 1 taken 50 times.
12850 for (i = 0; i < 256; i++) {
456
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12750 times.
12800 if (i == symbol)
457 50 bytestream2_put_byte(pb, 0);
458 else
459 12750 bytestream2_put_byte(pb, 0xFF);
460 }
461
462 /* Write zeroes for lengths */
463
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 50 times.
100 for (i = 0; i < c->slices; i++)
464 50 bytestream2_put_le32(pb, 0);
465
466 /* And that's all for that plane folks */
467 50 return 0;
468 }
469 2353 break;
470 }
471 }
472
473 /* Calculate huffman lengths */
474
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2353 times.
2353 if ((ret = ff_huff_gen_len_table(lengths, counts, 256, 1)) < 0)
475 return ret;
476
477 /*
478 * Write the plane's header into the output packet:
479 * - huffman code lengths (256 bytes)
480 * - slice end offsets (gotten from the slice lengths)
481 */
482
2/2
✓ Branch 0 taken 602368 times.
✓ Branch 1 taken 2353 times.
604721 for (i = 0; i < 256; i++) {
483 602368 bytestream2_put_byte(pb, lengths[i]);
484
485 602368 he[i].len = lengths[i];
486 602368 he[i].sym = i;
487 }
488
489 /* Calculate the huffman codes themselves */
490 2353 calculate_codes(he);
491
492 2353 send = 0;
493
2/2
✓ Branch 0 taken 2356 times.
✓ Branch 1 taken 2353 times.
4709 for (i = 0; i < c->slices; i++) {
494 2356 sstart = send;
495 2356 send = height * (i + 1) / c->slices & cmask;
496
497 /*
498 * Write the huffman codes to a buffer,
499 * get the offset in bytes.
500 */
501 4712 offset += write_huff_codes(dst + sstart * width, c->slice_bits,
502 2356 width * height + 4, width,
503 send - sstart, he);
504
505 2356 slice_len = offset - slice_len;
506
507 /* Byteswap the written huffman codes */
508 2356 c->bdsp.bswap_buf((uint32_t *) c->slice_bits,
509 2356 (uint32_t *) c->slice_bits,
510 2356 slice_len >> 2);
511
512 /* Write the offset to the stream */
513 2356 bytestream2_put_le32(pb, offset);
514
515 /* Seek to the data part of the packet */
516 2356 bytestream2_seek_p(pb, 4 * (c->slices - i - 1) +
517 2356 offset - slice_len, SEEK_CUR);
518
519 /* Write the slices' data into the output packet */
520 2356 bytestream2_put_buffer(pb, c->slice_bits, slice_len);
521
522 /* Seek back to the slice offsets */
523 2356 bytestream2_seek_p(pb, -4 * (c->slices - i - 1) - offset,
524 SEEK_CUR);
525
526 2356 slice_len = offset;
527 }
528
529 /* And at the end seek to the end of written slice(s) */
530 2353 bytestream2_seek_p(pb, offset, SEEK_CUR);
531
532 2353 return 0;
533 }
534
535 751 static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
536 const AVFrame *pic, int *got_packet)
537 {
538 751 UtvideoContext *c = avctx->priv_data;
539 PutByteContext pb;
540
541 uint32_t frame_info;
542
543 uint8_t *dst;
544
545 751 int width = avctx->width, height = avctx->height;
546 751 int i, ret = 0;
547
548 /* Allocate a new packet if needed, and set it to the pointer dst */
549 751 ret = ff_alloc_packet(avctx, pkt, (256 + 4 * c->slices + width * height)
550 751 * c->planes + 4);
551
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 751 times.
751 if (ret < 0)
553 return ret;
554
555 751 dst = pkt->data;
556
557 751 bytestream2_init_writer(&pb, dst, pkt->size);
558
559 751 av_fast_padded_malloc(&c->slice_bits, &c->slice_bits_size, width * height + 4);
560
561
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 751 times.
751 if (!c->slice_bits) {
562 av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer 2.\n");
563 return AVERROR(ENOMEM);
564 }
565
566 /* In case of RGB, mangle the planes to Ut Video's format */
567
4/4
✓ Branch 0 taken 601 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 451 times.
751 if (avctx->pix_fmt == AV_PIX_FMT_GBRAP || avctx->pix_fmt == AV_PIX_FMT_GBRP)
568 300 mangle_rgb_planes(c->slice_buffer, c->slice_stride, pic->data,
569 300 c->planes, pic->linesize, width, height);
570
571 /* Deal with the planes */
572
4/5
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 150 times.
✓ Branch 2 taken 150 times.
✓ Branch 3 taken 151 times.
✗ Branch 4 not taken.
751 switch (avctx->pix_fmt) {
573 300 case AV_PIX_FMT_GBRP:
574 case AV_PIX_FMT_GBRAP:
575
2/2
✓ Branch 0 taken 1050 times.
✓ Branch 1 taken 300 times.
1350 for (i = 0; i < c->planes; i++) {
576 1050 ret = encode_plane(avctx, c->slice_buffer[i] + 2 * c->slice_stride,
577 c->slice_buffer[i], c->slice_stride, i,
578 width, height, &pb);
579
580
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1050 times.
1050 if (ret) {
581 av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
582 return ret;
583 }
584 }
585 300 break;
586 150 case AV_PIX_FMT_YUV444P:
587
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 150 times.
600 for (i = 0; i < c->planes; i++) {
588 450 ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
589 450 pic->linesize[i], i, width, height, &pb);
590
591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret) {
592 av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
593 return ret;
594 }
595 }
596 150 break;
597 150 case AV_PIX_FMT_YUV422P:
598
2/2
✓ Branch 0 taken 450 times.
✓ Branch 1 taken 150 times.
600 for (i = 0; i < c->planes; i++) {
599 450 ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
600 450 pic->linesize[i], i, width >> !!i, height, &pb);
601
602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
450 if (ret) {
603 av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
604 return ret;
605 }
606 }
607 150 break;
608 151 case AV_PIX_FMT_YUV420P:
609
2/2
✓ Branch 0 taken 453 times.
✓ Branch 1 taken 151 times.
604 for (i = 0; i < c->planes; i++) {
610 453 ret = encode_plane(avctx, pic->data[i], c->slice_buffer[0],
611 453 pic->linesize[i], i, width >> !!i, height >> !!i,
612 &pb);
613
614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 453 times.
453 if (ret) {
615 av_log(avctx, AV_LOG_ERROR, "Error encoding plane %d.\n", i);
616 return ret;
617 }
618 }
619 151 break;
620 default:
621 av_log(avctx, AV_LOG_ERROR, "Unknown pixel format: %d\n",
622 avctx->pix_fmt);
623 return AVERROR_INVALIDDATA;
624 }
625
626 /*
627 * Write frame information (LE 32-bit unsigned)
628 * into the output packet.
629 * Contains the prediction method.
630 */
631 751 frame_info = c->frame_pred << 8;
632 751 bytestream2_put_le32(&pb, frame_info);
633
634 751 pkt->size = bytestream2_tell_p(&pb);
635
636 /* Packet should be done */
637 751 *got_packet = 1;
638
639 751 return 0;
640 }
641
642 #define OFFSET(x) offsetof(UtvideoContext, x)
643 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
644 static const AVOption options[] = {
645 { "pred", "Prediction method", OFFSET(frame_pred), AV_OPT_TYPE_INT, { .i64 = PRED_LEFT }, PRED_NONE, PRED_MEDIAN, VE, .unit = "pred" },
646 { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_NONE }, INT_MIN, INT_MAX, VE, .unit = "pred" },
647 { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_LEFT }, INT_MIN, INT_MAX, VE, .unit = "pred" },
648 { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRED_MEDIAN }, INT_MIN, INT_MAX, VE, .unit = "pred" },
649
650 { NULL},
651 };
652
653 static const AVClass utvideo_class = {
654 .class_name = "utvideo",
655 .item_name = av_default_item_name,
656 .option = options,
657 .version = LIBAVUTIL_VERSION_INT,
658 };
659
660 const FFCodec ff_utvideo_encoder = {
661 .p.name = "utvideo",
662 CODEC_LONG_NAME("Ut Video"),
663 .p.type = AVMEDIA_TYPE_VIDEO,
664 .p.id = AV_CODEC_ID_UTVIDEO,
665 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
666 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
667 .priv_data_size = sizeof(UtvideoContext),
668 .p.priv_class = &utvideo_class,
669 .init = utvideo_encode_init,
670 FF_CODEC_ENCODE_CB(utvideo_encode_frame),
671 .close = utvideo_encode_close,
672 CODEC_PIXFMTS(AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
673 AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV444P),
674 .color_ranges = AVCOL_RANGE_MPEG,
675 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
676 };
677

左眼皮跳是什么预兆 榨菜的原料菜叫什么 肠炎可以吃什么食物 三丧日是什么意思 糖尿病筛查做什么检查
送男生什么生日礼物 茉莉花茶属于什么茶类 胃炎吃什么最好 汗味重是什么原因 肛瘘不治疗有什么后果
舌苔厚发黄是什么原因 长江后浪推前浪是什么意思 益气是什么意思 手掌发紫是什么原因 衿字五行属什么
枸杞子和什么泡水喝补肾壮阳 势利眼是什么意思 冬虫夏草生长在什么地方 刘邦字什么 29周岁属什么生肖
超声检查是什么hcv9jop2ns8r.cn 燕窝有什么功效和作用hcv9jop6ns2r.cn 前列腺在人体什么位置hcv8jop3ns2r.cn 刻舟求剑的意思是什么hcv7jop5ns5r.cn 明年是什么年啊hcv8jop7ns0r.cn
什么空调省电hcv9jop4ns3r.cn 0代表什么意思xianpinbao.com 蜱虫长什么样子图片hcv8jop9ns5r.cn 深闺是什么意思hcv9jop1ns8r.cn 12月23日什么星座hcv8jop4ns8r.cn
南五行属什么hcv7jop9ns1r.cn 十月十一日是什么星座hcv8jop2ns8r.cn 比干是什么神hcv8jop4ns4r.cn 乱点鸳鸯谱什么意思bjhyzcsm.com 风度是什么意思hcv8jop4ns7r.cn
水过鸭背是什么意思cj623037.com 醋有什么功效和作用hcv9jop6ns3r.cn 深褐色是什么颜色hcv8jop4ns4r.cn 95年属什么生肖aiwuzhiyu.com 异常的异是什么意思wmyky.com
百度