Skip to content

Commit b1d8555

Browse files
committed
added dummy I420->UYVY decompress
As there is no line decoder for I420, because it is a planar format, added regular decompress to be able to display simple uncompressed I420 as in the this command: `uv -t testcard:c=I420 -d gl`
1 parent 756d9ee commit b1d8555

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,7 @@ if test "$build_default" != no; then
33483348
src/video_capture/import.o
33493349
src/video_capture/switcher.o
33503350
src/video_capture/ug_input.o
3351+
src/video_decompress/i420.o
33513352
src/video_display/aggregate.o
33523353
src/video_display/dump.o
33533354
src/video_display/multiplier.o

src/video_decompress/i420.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* @file video_decompress/i420.c
3+
* @author Martin Pulec <pulec@cesnet.cz>
4+
*
5+
* implementation of I420->UYVY "decompression", because for the planar
6+
* format there is no line decoder and when the display iw unable to display
7+
* I420 directly, it is not possible to present it.
8+
*
9+
* As this is implementation is quite short, it can also hold as a decompress
10+
* module template.
11+
*/
12+
/*
13+
* Copyright (c) 2024 CESNET z.s.p.o.
14+
* All rights reserved.
15+
*
16+
* Redistribution and use in source and binary forms, with or without
17+
* modification, is permitted provided that the following conditions
18+
* are met:
19+
*
20+
* 1. Redistributions of source code must retain the above copyright
21+
* notice, this list of conditions and the following disclaimer.
22+
*
23+
* 2. Redistributions in binary form must reproduce the above copyright
24+
* notice, this list of conditions and the following disclaimer in the
25+
* documentation and/or other materials provided with the distribution.
26+
*
27+
* 3. Neither the name of CESNET nor the names of its contributors may be
28+
* used to endorse or promote products derived from this software without
29+
* specific prior written permission.
30+
*
31+
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
32+
* "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
33+
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
34+
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
35+
* EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
36+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
38+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
41+
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
42+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43+
*/
44+
45+
#include <assert.h>
46+
#include <stdbool.h>
47+
#include <stdlib.h>
48+
49+
#include "lib_common.h"
50+
#include "types.h"
51+
#include "video_codec.h"
52+
#include "video_decompress.h"
53+
54+
struct i420_decompress_state {
55+
struct video_desc desc;
56+
};
57+
58+
static void *
59+
i420_decompress_init(void)
60+
{
61+
return malloc(sizeof(struct i420_decompress_state));
62+
}
63+
64+
static int
65+
i420_decompress_reconfigure(void *state, struct video_desc desc, int rshift,
66+
int gshift, int bshift, int pitch,
67+
codec_t out_codec)
68+
{
69+
(void) rshift, (void) gshift, (void) bshift;
70+
assert(out_codec == UYVY);
71+
assert(pitch == (int) desc.width * 2); // implement other ir needed
72+
struct i420_decompress_state *s = state;
73+
s->desc = desc;
74+
return true;
75+
}
76+
77+
static decompress_status
78+
i420_decompress(void *state, unsigned char *dst, unsigned char *buffer,
79+
unsigned int src_len, int frame_seq,
80+
struct video_frame_callbacks *callbacks,
81+
struct pixfmt_desc *internal_prop)
82+
{
83+
(void) src_len, (void) frame_seq, (void) callbacks,
84+
(void) internal_prop;
85+
struct i420_decompress_state *s = state;
86+
i420_8_to_uyvy((int) s->desc.width, (int) s->desc.height, buffer, dst);
87+
return DECODER_GOT_FRAME;
88+
}
89+
90+
static int
91+
i420_decompress_get_property(void *state, int property, void *val, size_t *len)
92+
{
93+
(void) state;
94+
95+
if (property == DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME) {
96+
assert(*len >= sizeof(int));
97+
*(int *) val = true;
98+
*len = sizeof(int);
99+
return true;
100+
}
101+
return false;
102+
}
103+
104+
static void
105+
i420_decompress_done(void *state)
106+
{
107+
free(state);
108+
}
109+
110+
static int
111+
i420_decompress_get_priority(codec_t compression, struct pixfmt_desc internal,
112+
codec_t ugc)
113+
{
114+
(void) internal;
115+
enum {
116+
PRIO_NA = -1,
117+
PRIO_NORMAL = 500,
118+
};
119+
// probing (ugc==VC_NONE) is skipped (optional, not necessary)
120+
return compression == I420 && ugc == UYVY ? PRIO_NORMAL : PRIO_NA;
121+
}
122+
123+
static const struct video_decompress_info i420_info = {
124+
i420_decompress_init, i420_decompress_reconfigure,
125+
i420_decompress, i420_decompress_get_property,
126+
i420_decompress_done, i420_decompress_get_priority,
127+
};
128+
129+
REGISTER_MODULE(i420, &i420_info, LIBRARY_CLASS_VIDEO_DECOMPRESS,
130+
VIDEO_DECOMPRESS_ABI_VERSION);

0 commit comments

Comments
 (0)