FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/bitpacked_dec.c
Date: 2026-10-20 22:17:59
Exec Total Coverage
Lines: 0 58 0.0%
Functions: 0 4 0.0%
Branches: 0 32 0.0%

Line Branch Exec Source
1 /*
2 * Unpack bit-packed streams to formats supported by FFmpeg
3 * Copyright (c) 2017 Savoir-faire Linux, Inc
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 /* Development sponsored by CBC/Radio-Canada */
23
24 /**
25 * @file
26 * Bitpacked
27 */
28
29 #include "avcodec.h"
30 #include "bitpacked_dec.h"
31 #include "bitpacked_dec_init.h"
32 #include "codec_internal.h"
33 #include "libavutil/imgutils.h"
34 #include "thread.h"
35
36 /* For this format, it's a simple passthrough */
37 ✗ static int bitpacked_decode_uyvy422(AVCodecContext *avctx, AVFrame *frame,
38 const AVPacket *avpkt)
39 {
40 int ret;
41
42 /* there is no need to copy as the data already match
43 * a known pixel format */
44 ✗ frame->buf[0] = av_buffer_ref(avpkt->buf);
45 ✗ if (!frame->buf[0]) {
46 ✗ return AVERROR(ENOMEM);
47 }
48
49 ✗ ret = av_image_fill_arrays(frame->data, frame->linesize, avpkt->data,
50 avctx->pix_fmt, avctx->width, avctx->height, 1);
51 ✗ if (ret < 0) {
52 ✗ av_buffer_unref(&frame->buf[0]);
53 ✗ return ret;
54 }
55
56 ✗ return 0;
57 }
58
59 ✗ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
60 const AVPacket *avpkt)
61 {
62 ✗ struct BitpackedContext *bc = avctx->priv_data;
63 ✗ uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;
64 ✗ uint64_t packet_size = (uint64_t)avpkt->size * 8;
65 const uint8_t *src;
66 uint16_t *y, *u, *v;
67 ✗ const int bulk = avctx->width & ~7;
68 int ret, i;
69
70 ✗ ret = ff_thread_get_buffer(avctx, frame, 0);
71 ✗ if (ret < 0)
72 ✗ return ret;
73
74 ✗ if (frame_size > packet_size)
75 ✗ return AVERROR_INVALIDDATA;
76
77 ✗ if (avctx->width % 2)
78 ✗ return AVERROR_PATCHWELCOME;
79
80 ✗ src = avpkt->data;
81 ✗ for (i = 0; i < avctx->height; i++) {
82 ✗ y = (uint16_t*)(frame->data[0] + i * frame->linesize[0]);
83 ✗ u = (uint16_t*)(frame->data[1] + i * frame->linesize[1]);
84 ✗ v = (uint16_t*)(frame->data[2] + i * frame->linesize[2]);
85
86 ✗ if (bulk) {
87 ✗ bc->unpack_yuv422p10(src, y, u, v, bulk);
88 ✗ src += bulk * 5 / 2;
89 ✗ y += bulk;
90 ✗ u += bulk / 2;
91 ✗ v += bulk / 2;
92 }
93
94 ✗ bitpacked_unpack_yuv422p10_c(src, y, u, v, avctx->width - bulk);
95 ✗ src += (avctx->width - bulk) * 5 / 2;
96 }
97
98 ✗ return 0;
99 }
100
101 ✗ static av_cold int bitpacked_init_decoder(AVCodecContext *avctx)
102 {
103 ✗ struct BitpackedContext *bc = avctx->priv_data;
104
105 ✗ if (!avctx->codec_tag || !avctx->width || !avctx->height)
106 ✗ return AVERROR_INVALIDDATA;
107
108 ✗ ff_bitpackeddec_init(bc);
109
110 ✗ if (avctx->codec_tag == MKTAG('U', 'Y', 'V', 'Y')) {
111 ✗ if (avctx->bits_per_coded_sample == 16 &&
112 ✗ avctx->pix_fmt == AV_PIX_FMT_UYVY422)
113 ✗ bc->decode = bitpacked_decode_uyvy422;
114 ✗ else if (avctx->bits_per_coded_sample == 20 &&
115 ✗ avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
116 ✗ bc->decode = bitpacked_decode_yuv422p10;
117 else
118 ✗ return AVERROR_INVALIDDATA;
119 } else {
120 ✗ return AVERROR_INVALIDDATA;
121 }
122
123 ✗ return 0;
124 }
125
126 ✗ static int bitpacked_decode(AVCodecContext *avctx, AVFrame *frame,
127 int *got_frame, AVPacket *avpkt)
128 {
129 ✗ struct BitpackedContext *bc = avctx->priv_data;
130 ✗ int buf_size = avpkt->size;
131 int res;
132
133 ✗ res = bc->decode(avctx, frame, avpkt);
134 ✗ if (res)
135 ✗ return res;
136
137 ✗ *got_frame = 1;
138 ✗ return buf_size;
139
140 }
141
142 const FFCodec ff_bitpacked_decoder = {
143 .p.name = "bitpacked",
144 CODEC_LONG_NAME("Bitpacked"),
145 .p.type = AVMEDIA_TYPE_VIDEO,
146 .p.id = AV_CODEC_ID_BITPACKED,
147 .p.capabilities = AV_CODEC_CAP_FRAME_THREADS,
148 .priv_data_size = sizeof(struct BitpackedContext),
149 .init = bitpacked_init_decoder,
150 FF_CODEC_DECODE_CB(bitpacked_decode),
151 .codec_tags = (const uint32_t []){
152 MKTAG('U', 'Y', 'V', 'Y'),
153 FF_CODEC_TAGS_END,
154 },
155 };
156