48#include <libgpujpeg/gpujpeg_decoder.h>
49#include <libgpujpeg/gpujpeg_version.h>
57#define MOD_NAME "[GPUJPEG dec.] "
59#if GPUJPEG_VERSION_INT >= GPUJPEG_MK_VERSION_INT(0, 25, 0)
60#define NEW_PARAM_IMG_NO_COMP_COUNT
78 s->
decoder = gpujpeg_decoder_create(NULL);
85 struct gpujpeg_parameters
param;
86 gpujpeg_set_default_parameters(&
param);
87 param.color_space_internal = GPUJPEG_YCBCR_BT709;
89 struct gpujpeg_image_parameters param_image;
90 gpujpeg_image_set_default_parameters(¶m_image);
93 param_image.color_space = GPUJPEG_YCBCR_BT709;
96 int rc = gpujpeg_decoder_init(s->
decoder, &
param, ¶m_image);
101 gpujpeg_decoder_set_output_format(s->
decoder, GPUJPEG_YCBCR_BT709,
102 GPUJPEG_420_U8_P0P1P2);
105 gpujpeg_decoder_set_output_format(s->
decoder, GPUJPEG_RGB,
108 GPUJPEG_4444_U8_P0123 : GPUJPEG_444_U8_P012);
110 GPUJPEG_444_U8_P012A : GPUJPEG_444_U8_P012);
114 gpujpeg_decoder_set_output_format(s->
decoder, GPUJPEG_RGB,
115 GPUJPEG_444_U8_P012);
118 gpujpeg_decoder_set_output_format(s->
decoder, GPUJPEG_YCBCR_BT709,
119 GPUJPEG_422_U8_P1020);
124 assert(
"Invalid codec!" && 0);
132 if (gpujpeg_version() >> 8 != GPUJPEG_VERSION_INT >> 8) {
133 char ver_req[128] =
"";
134 char ver_lib[128] =
"";
135 strncpy(ver_req, gpujpeg_version_to_string(GPUJPEG_VERSION_INT),
sizeof ver_req - 1);
136 strncpy(ver_lib, gpujpeg_version_to_string(gpujpeg_version()),
sizeof ver_lib - 1);
137 log_msg(
LOG_LEVEL_WARNING,
"GPUJPEG API version mismatch! (compiled: %s, library present: %s, required same minor version)\n",
144 printf(
"Initializing CUDA device %d...\n",
cuda_devices[0]);
178 gpujpeg_decoder_destroy(s->
decoder);
185 struct gpujpeg_image_parameters image_params = { 0 };
186 gpujpeg_image_set_default_parameters(&image_params);
187#if GPUJPEG_VERSION_INT >= GPUJPEG_MK_VERSION_INT(0, 20, 0)
188 struct gpujpeg_parameters
params;
189 gpujpeg_set_default_parameters(&
params);
190 params.restart_interval = 0;
192 if (gpujpeg_decoder_get_image_info(buffer,
len, &image_params, &
params, NULL) != 0) {
200 internal_prop->
depth = 8;
202 switch (image_params.color_space) {
206 internal_prop->
rgb =
true;
209 case GPUJPEG_YCBCR_BT601:
210 case GPUJPEG_YCBCR_BT601_256LVLS:
211 case GPUJPEG_YCBCR_BT709:
212 internal_prop->
rgb =
false;
216 switch (image_params.pixel_format) {
217 case GPUJPEG_PIXFMT_NONE:
222 case GPUJPEG_422_U8_P1020:
223 case GPUJPEG_422_U8_P0P1P2:
226 case GPUJPEG_420_U8_P0P1P2:
229 case GPUJPEG_444_U8_P012:
230 case GPUJPEG_444_U8_P0P1P2:
231#if !defined NEW_PARAM_IMG_NO_COMP_COUNT
232 case GPUJPEG_444_U8_P012Z:
236#ifdef NEW_PARAM_IMG_NO_COMP_COUNT
237 case GPUJPEG_4444_U8_P0123:
239 case GPUJPEG_444_U8_P012A:
257 struct gpujpeg_decoder_output decoder_output;
271 gpujpeg_decoder_output_set_custom(&decoder_output, dst);
274 ret = gpujpeg_decoder_decode(s->
decoder, (uint8_t*) buffer, src_len, &decoder_output);
277 unsigned char *line_src, *line_dst;
279 gpujpeg_decoder_output_set_default(&decoder_output);
280 decoder_output.type = GPUJPEG_DECODER_OUTPUT_INTERNAL_BUFFER;
283 ret = gpujpeg_decoder_decode(s->
decoder, (uint8_t*) buffer, src_len, &decoder_output);
288 line_src = decoder_output.data;
289 for (
unsigned i = 0u; i < s->
desc.
height; i++) {
295 memcpy(line_dst, line_src, linesize);
298 line_dst += s->
pitch;
314 if(*
len >=
sizeof(
int)) {
332 gpujpeg_decoder_destroy(s->
decoder);
338 if (compression !=
JPEG && compression !=
MJPG) {
343 return compression ==
JPEG ? 50 : 90;
353 if (compression ==
JPEG) {
354 if (internal.depth == 0) {
357 return internal.rgb == out_rgb ? 200 : 500;
362 if (internal.depth == 0) {
365 return internal.rgb == out_rgb ? 600 : 800;
int vc_get_linesize(unsigned int width, codec_t codec)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_INFO
normal reporting
#define LOG_LEVEL_ERROR
general errors
#define LOG_LEVEL_VERBOSE
#define LOG_LEVEL_WARNING
less severe errors
static int configure_with(struct state_decompress_gpujpeg *s, struct video_desc desc)
static decompress_status gpujpeg_probe_internal_codec(unsigned char *buffer, size_t len, struct pixfmt_desc *internal_prop)
static void gpujpeg_decompress_done(void *state)
static int gpujpeg_decompress_reconfigure(void *state, struct video_desc desc, int rshift, int gshift, int bshift, int pitch, codec_t out_codec)
static int gpujpeg_decompress_get_property(void *state, int property, void *val, size_t *len)
static void * gpujpeg_decompress_init(void)
static const struct video_decompress_info gpujpeg_info
static decompress_status gpujpeg_decompress(void *state, unsigned char *dst, unsigned char *buffer, unsigned int src_len, int frame_seq, struct video_frame_callbacks *callbacks, struct pixfmt_desc *internal_prop)
#define NEW_PARAM_IMG_NO_COMP_COUNT
static int gpujpeg_decompress_get_priority(codec_t compression, struct pixfmt_desc internal, codec_t ugc)
#define DECOMPRESS_PROPERTY_ACCEPTS_CORRUPTED_FRAME
@ DECODER_GOT_CODEC
Internal pixel format was determined.
unsigned int cuda_devices[MAX_CUDA_DEVICES]
@ LIBRARY_CLASS_VIDEO_DECOMPRESS
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
decoder_func_t vc_copylineRGBtoRGBA
int depth
bit depth; 0 means that whole struct is undefined
int subsampling
in 'JabA' format, eg. '4444'
struct gpujpeg_decoder * decoder
unsigned int width
width of every tile (!)
unsigned int height
height of every tile (!)
Struct containing callbacks of a video_frame.
@ RGB
RGB 8-bit (packed into 24-bit word)
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
@ VIDEO_CODEC_NONE
dummy color spec
@ JPEG
JPEG image, restart intervals may be used. Compatible with GPUJPEG.
@ MJPG
JPEG image, without restart intervals.
@ RGBA
RGBA 8-bit, big-endian.
This is an umbrella header for video functions.
bool codec_is_a_rgb(codec_t codec)
Returns TRUE if specified pixelformat is some form of RGB (not YUV).
API for video decompress drivers.
#define VIDEO_DECOMPRESS_ABI_VERSION
bool video_desc_eq_excl_param(struct video_desc a, struct video_desc b, unsigned int excluded_params)
Compares two video descriptions.
#define PARAM_INTERLACING