UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_codec.c File Reference

This file contains video codec-related functions. More...

#include "config_unix.h"
#include "config_win32.h"
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "color.h"
#include "compat/qsort_s.h"
#include "debug.h"
#include "host.h"
#include "hwaccel_vdpau.h"
#include "hwaccel_drm.h"
#include "utils/macros.h"
#include "video_codec.h"
Include dependency graph for video_codec.c:

Go to the source code of this file.

Classes

struct  alternative_codec_name
 
struct  alternative_fourcc
 
struct  codec_info_t
 
struct  pixfmt_plane_info_t
 for planar pixel formats More...
 

Macros

#define __STDC_WANT_LIB_EXT1__   1
 
#define BYTE_SWAP(x)
 
#define HW_VDPAU_FRAME_SZ   0
 

Functions

bool clear_video_buffer (unsigned char *data, size_t linesize, size_t pitch, size_t height, codec_t color_spec)
 
void codec_get_planes_subsampling (codec_t pix_fmt, int *sub)
 
bool codec_is_420 (codec_t pix_fmt)
 
bool codec_is_a_rgb (codec_t codec)
 Returns TRUE if specified pixelformat is some form of RGB (not YUV).
 
bool codec_is_const_size (codec_t codec)
 Returns TRUE if specified pixelformat has constant size regardles of resolution. If so the block_size value represents the size.
 
bool codec_is_hw_accelerated (codec_t codec)
 
bool codec_is_in_set (codec_t codec, const codec_t *set)
 
bool codec_is_planar (codec_t codec)
 
int compare_pixdesc (const struct pixfmt_desc *desc_a, const struct pixfmt_desc *desc_b, const struct pixfmt_desc *src_desc)
 
int get_bits_per_component (codec_t codec)
 
double get_bpp (codec_t codec)
 
const char * get_codec_file_extension (codec_t codec)
 
codec_t get_codec_from_fcc (uint32_t fourcc)
 
codec_t get_codec_from_file_extension (const char *ext)
 
codec_t get_codec_from_name (const char *name)
 
static codec_t get_codec_from_name_wo_alias (const char *name)
 
const char * get_codec_name (codec_t codec)
 
const char * get_codec_name_long (codec_t codec)
 
uint32_t get_fourcc (codec_t codec)
 
int get_pf_block_bytes (codec_t codec)
 returns codec_info_t::block_size_bytes
 
int get_pf_block_pixels (codec_t codec)
 returns codec_info_t::block_size_pixels
 
const char * get_pixdesc_desc (struct pixfmt_desc desc)
 
struct pixfmt_desc get_pixfmt_desc (codec_t pixfmt)
 
int get_subsampling (codec_t codec)
 
void i420_16_to_y416 (int width, int height, const unsigned char *in, unsigned char *out, int in_depth)
 
void i420_8_to_uyvy (int width, int height, const unsigned char *in, unsigned char *out)
 
void i422_16_to_y416 (int width, int height, const unsigned char *in, unsigned char *out, int in_depth)
 
void i422_8_to_uyvy (int width, int height, const unsigned char *in, unsigned char *out)
 
void i444_16_to_y416 (int width, int height, const unsigned char *in, unsigned char *out, int in_depth)
 
void i444_8_to_uyvy (int width, int height, const unsigned char *in, unsigned char *out)
 
bool is_codec_interframe (codec_t codec)
 
bool is_codec_opaque (codec_t codec)
 
bool pixdesc_equals (struct pixfmt_desc desc_a, struct pixfmt_desc desc_b)
 
void show_codec_help (const char *module, const codec_t *codecs8, const codec_t *codecs10, const codec_t *codecs_ge12)
 Prints list of suppored codecs for video module.
 
void uyvy_to_i422 (int width, int height, const unsigned char *in, unsigned char *out)
 
void vc_deinterlace (unsigned char *src, long src_linesize, int lines)
 Deinterlaces framebuffer.
 
bool vc_deinterlace_ex (codec_t codec, unsigned char *src, size_t src_linesize, unsigned char *dst, size_t dst_pitch, size_t lines)
 
size_t vc_get_datalen (unsigned int width, unsigned int height, codec_t codec)
 
int vc_get_linesize (unsigned int width, codec_t codec)
 
int vc_get_size (unsigned int width, codec_t codec)
 
void watch_pixfmt_degrade (const char *mod_name, struct pixfmt_desc desc_src, struct pixfmt_desc desc_dst)
 
void y416_to_i444 (int width, int height, const unsigned char *in, unsigned char *out, int depth)
 

Variables

static const struct codec_info_t codec_info []
 
static const struct alternative_codec_name codec_name_aliases []
 
static const struct alternative_fourcc fourcc_aliases []
 
char pixfmt_conv_pref [] = "dsc"
 bitdepth, subsampling, color space
 
static const struct pixfmt_plane_info_t pixfmt_plane_info []
 

Detailed Description

This file contains video codec-related functions.

Author
Martin Benes marti.nosp@m.nben.nosp@m.esh@g.nosp@m.mail.nosp@m..com
Lukas Hejtmanek xhejt.nosp@m.man@.nosp@m.ics.m.nosp@m.uni..nosp@m.cz
Petr Holub hopet.nosp@m.@ics.nosp@m..muni.nosp@m..cz
Milos Liska xlisk.nosp@m.a@fi.nosp@m..muni.nosp@m..cz
Jiri Matela matel.nosp@m.a@ic.nosp@m.s.mun.nosp@m.i.cz
Dalibor Matura 25589.nosp@m.9@ma.nosp@m.il.mu.nosp@m.ni.c.nosp@m.z
Ian Wesley-Smith iwsmi.nosp@m.th@c.nosp@m.ct.ls.nosp@m.u.ed.nosp@m.u

This file contains video codecs' metadata and helper functions as well as pixelformat converting functions.

Definition in file video_codec.c.

Macro Definition Documentation

◆ __STDC_WANT_LIB_EXT1__

#define __STDC_WANT_LIB_EXT1__   1

Definition at line 53 of file video_codec.c.

◆ BYTE_SWAP

#define BYTE_SWAP ( x)
Value:
x

Definition at line 85 of file video_codec.c.

◆ HW_VDPAU_FRAME_SZ

#define HW_VDPAU_FRAME_SZ   0

Definition at line 118 of file video_codec.c.

Function Documentation

◆ clear_video_buffer()

bool clear_video_buffer ( unsigned char * data,
size_t linesize,
size_t pitch,
size_t height,
codec_t color_spec )

Definition at line 862 of file video_codec.c.

863{
864 uint32_t pattern[4];
865
866 switch (color_spec) {
867 case BGR:
868 case RGB:
869 case RGBA:
870 memset(pattern, 0, sizeof(pattern));
871 break;
872 case UYVY:
873 for (int i = 0; i < 4; i++) {
874 pattern[i] = 0x00800080;
875 }
876 break;
877 case v210:
878 pattern[0] = 0x20000200;
879 pattern[1] = 0x00080000;
880 pattern[2] = 0x20000200;
881 pattern[3] = 0x00080000;
882 break;
883#ifdef HWACC_VDPAU
884 case HW_VDPAU:
885 memset(data, 0,sizeof(hw_vdpau_frame));
886 return true;
887#endif
888 default:
889 return false;
890 }
891
892 for (size_t y = 0; y < height; ++y) {
893 uintptr_t i;
894 for( i = 0; i < (linesize & (~15)); i+=16)
895 {
896 memcpy(data + i, pattern, 16);
897 }
898 for( ; i < linesize; i++ )
899 {
900 ((char*)data)[i] = ((char*)pattern)[i&15];
901 }
902
903 data += pitch;
904 }
905
906 return true;
907}
pattern
Definition testcard.c:94
@ RGB
RGB 8-bit (packed into 24-bit word)
Definition types.h:80
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ BGR
8-bit BGR
Definition types.h:88
@ HW_VDPAU
VDPAU hardware surface.
Definition types.h:91
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
Definition types.h:75

References BGR, HW_VDPAU, RGB, RGBA, UYVY, and v210.

Referenced by vf_clear().

◆ codec_get_planes_subsampling()

void codec_get_planes_subsampling ( codec_t pix_fmt,
int * sub )

Returns subsampling of individual planes of planar pixel format

Undefined if pix_fmt is not a planar pixel format

Parameters
[out]subsubsampling, allocated array must be able to hold 8 members

Definition at line 924 of file video_codec.c.

924 {
925 for (size_t i = 0; i < 8; ++i) {
926 *sub++ = pixfmt_plane_info[pix_fmt].plane_info[i];
927 }
928}
int plane_info[8]
[1st comp H subsamp, 1st comp V subs., 2nd comp H....]
static const struct pixfmt_plane_info_t pixfmt_plane_info[]

References pixfmt_plane_info, and pixfmt_plane_info_t::plane_info.

Referenced by buf_get_linesizes(), buf_get_planes(), same_linesizes(), to_lavc_vid_conv(), and vc_get_datalen().

◆ codec_is_420()

bool codec_is_420 ( codec_t pix_fmt)

Definition at line 930 of file video_codec.c.

931{
932 return pixfmt_plane_info[pix_fmt].plane_info[0] == 1 &&
933 pixfmt_plane_info[pix_fmt].plane_info[1] == 1 &&
934 pixfmt_plane_info[pix_fmt].plane_info[2] == 2 &&
935 pixfmt_plane_info[pix_fmt].plane_info[3] == 2 &&
936 pixfmt_plane_info[pix_fmt].plane_info[4] == 2 &&
937 pixfmt_plane_info[pix_fmt].plane_info[5] == 2;
938}

References pixfmt_plane_info, and pixfmt_plane_info_t::plane_info.

◆ codec_is_a_rgb()

bool codec_is_a_rgb ( codec_t codec)

Returns TRUE if specified pixelformat is some form of RGB (not YUV).

Unspecified for compressed codecs.

Return values
TRUEif pixelformat is RGB
FALSEif pixelformat is not a RGB

Definition at line 463 of file video_codec.c.

464{
465 unsigned int i = (unsigned int) codec;
466
467 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
468 return codec_info[i].rgb;
469 }
470 return false;
471}
unsigned rgb
Whether pixelformat is RGB.
static const struct codec_info_t codec_info[]

References codec_info, and codec_info_t::rgb.

Referenced by check_duration(), cleanup_screen(), compute_dst_rect(), configure_with(), display_decklink_reconfigure(), display_frame(), display_sdl_reconfigure_real(), gpujpeg_decompress_get_priority(), j2k_decompress_get_priority(), libavcodec_decompress_get_priority(), print_pixel_formats(), and save_video_frame().

◆ codec_is_const_size()

bool codec_is_const_size ( codec_t codec)

Returns TRUE if specified pixelformat has constant size regardles of resolution. If so the block_size value represents the size.

Unspecified for compressed codecs.

Return values
TRUEif pixelformat is const size
FALSEif pixelformat is not const size

Definition at line 479 of file video_codec.c.

480{
481 unsigned int i = (unsigned int) codec;
482
483 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
484 return codec_info[i].const_size;
485 }
486 return false;
487}
unsigned const_size
Indicates if data length is constant for all resolutions (hw surfaces)

References codec_info, and codec_info_t::const_size.

Referenced by av_to_uv_convert(), vf_alloc_desc(), and vf_alloc_desc_data().

◆ codec_is_hw_accelerated()

bool codec_is_hw_accelerated ( codec_t codec)

Definition at line 489 of file video_codec.c.

489 {
490 return codec == HW_VDPAU;
491}

References HW_VDPAU.

Referenced by video_decoder_order_output_codecs().

◆ codec_is_in_set()

bool codec_is_in_set ( codec_t codec,
const codec_t * set )

Tries to find specified codec in set of video codecs. The set must by ended by VIDEO_CODEC_NONE.

Definition at line 851 of file video_codec.c.

852{
853 assert (codec != VIDEO_CODEC_NONE);
854 assert (set != NULL);
855 while (*set != VIDEO_CODEC_NONE) {
856 if (*(set++) == codec)
857 return true;
858 }
859 return false;
860}
@ VIDEO_CODEC_NONE
dummy color spec
Definition types.h:66

References VIDEO_CODEC_NONE.

Referenced by check_for_slave_format_change(), get_best_decoder_from(), load_texture(), reconfigure_if_needed(), and select_display_codec().

◆ codec_is_planar()

bool codec_is_planar ( codec_t codec)

◆ compare_pixdesc()

int compare_pixdesc ( const struct pixfmt_desc * desc_a,
const struct pixfmt_desc * desc_b,
const struct pixfmt_desc * src_desc )

qsort(_s)-compatible comparator

Definition at line 1138 of file video_codec.c.

1139{
1140 for (char *feature = pixfmt_conv_pref; *feature != '\0'; ++feature) {
1141 switch (*feature) {
1142 case 'd':
1143 if (desc_a->depth != desc_b->depth &&
1144 (desc_a->depth < src_desc->depth || desc_b->depth < src_desc->depth)) { // either a or b is lower than orig - sort higher bit depth first
1145 return desc_b->depth - desc_a->depth;
1146 }
1147 break;
1148 case 's':
1149 if (desc_a->subsampling != desc_b->subsampling &&
1150 (desc_a->subsampling < src_desc->subsampling || desc_b->subsampling < src_desc->subsampling)) {
1151 return desc_b->subsampling - desc_a->subsampling; // return better subs
1152 }
1153 break;
1154 case 'c':
1155 if (desc_a->rgb != desc_b->rgb) {
1156 return desc_a->rgb == src_desc->rgb ? -1 : 1;
1157 }
1158 break;
1159 }
1160 }
1161
1162 // if both A and B are either undistinguishable or better than src, return closer ("worse") pixfmt
1163 for (char *feature = pixfmt_conv_pref; *feature != '\0'; ++feature) {
1164 switch (*feature) {
1165 case 'd':
1166 if (desc_a->depth != desc_b->depth) {
1167 return desc_a->depth - desc_b->depth;
1168 }
1169 break;
1170 case 's':
1171 if (desc_a->subsampling != desc_b->subsampling) {
1172 return desc_a->subsampling - desc_b->subsampling;
1173 }
1174 break;
1175 case 'c':
1176 // will be a tie here
1177 break;
1178 }
1179 }
1180
1181 return 0;
1182}
int depth
bit depth; 0 means that whole struct is undefined
Definition types.h:140
bool rgb
Definition types.h:142
int subsampling
in 'JabA' format, eg. '4444'
Definition types.h:141
char pixfmt_conv_pref[]
bitdepth, subsampling, color space
Definition video_codec.c:80

References pixfmt_desc::depth, pixfmt_conv_pref, pixfmt_desc::rgb, and pixfmt_desc::subsampling.

Referenced by lavc_compare_convs_inner(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), and set_convertible_formats().

◆ get_bits_per_component()

◆ get_bpp()

double get_bpp ( codec_t codec)

Definition at line 301 of file video_codec.c.

302{
303 unsigned int i = (unsigned int) codec;
304 double bpp = 0;
305
306 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
307 bpp = (double) codec_info[i].block_size_bytes /
308 codec_info[i].block_size_pixels;
309 }
310 assert(bpp != 0);
311 return bpp;
312}

References codec_info.

Referenced by border_postprocess(), crop_postprocess(), crop_postprocess_reconfigure(), display_frame(), filter(), ipc_frame_from_ug_frame(), ipc_frame_from_ug_frame_hq(), j2k_decompress_reconfigure(), reconfigure(), vf_split(), vidcap_dvs_init(), and vidcap_testcard2_thread().

◆ get_codec_file_extension()

const char * get_codec_file_extension ( codec_t codec)

Definition at line 406 of file video_codec.c.

407{
408 unsigned int i = (unsigned int) codec;
409
410 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
411 return codec_info[i].file_extension;
412 } else {
413 return 0;
414 }
415}
const char * file_extension
Extension that should be added to name if frame is saved to file.

References codec_info, and codec_info_t::file_extension.

Referenced by get_tile_count(), save_video_frame(), video_export(), and video_reading_thread().

◆ get_codec_from_fcc()

codec_t get_codec_from_fcc ( uint32_t fourcc)

Definition at line 350 of file video_codec.c.

351{
352 for (unsigned int i = 0; i < sizeof codec_info / sizeof(struct codec_info_t); ++i) {
353 if (fourcc == codec_info[i].fcc)
354 return i;
355 }
356
357 // try to look through aliases
358 for (size_t i = 0; i < sizeof(fourcc_aliases) / sizeof(struct alternative_fourcc); ++i) {
359 if (fourcc == fourcc_aliases[i].alias) {
360 for (unsigned int j = 0; j < sizeof codec_info / sizeof(struct codec_info_t); ++j) {
361 if (fourcc_aliases[i].primary_fcc == codec_info[j].fcc)
362 return j;
363 }
364 }
365 }
366 return VIDEO_CODEC_NONE;
367}
uint32_t fcc
FourCC.
static const struct alternative_fourcc fourcc_aliases[]

References alternative_fourcc::alias, codec_info, codec_info_t::fcc, fourcc_aliases, and VIDEO_CODEC_NONE.

Referenced by display_sage_init(), parse_video_desc_info(), and parse_video_hdr().

◆ get_codec_from_file_extension()

codec_t get_codec_from_file_extension ( const char * ext)

Definition at line 417 of file video_codec.c.

418{
419 for (unsigned int i = 0; i < sizeof codec_info / sizeof(struct codec_info_t); ++i) {
420 if (codec_info[i].file_extension && strcasecmp(codec_info[i].file_extension, ext) == 0) {
421 return i;
422 }
423 }
424
425 return VIDEO_CODEC_NONE;
426}

References codec_info, codec_info_t::file_extension, and VIDEO_CODEC_NONE.

Referenced by testcard_load_from_file(), and write_to_container().

◆ get_codec_from_name()

codec_t get_codec_from_name ( const char * name)

Definition at line 387 of file video_codec.c.

388{
390 if (ret != VIDEO_CODEC_NONE) {
391 return ret;
392 }
393
394 // try to find if this is not an alias
395 for (size_t i = 0; i < sizeof(codec_name_aliases) / sizeof(struct alternative_codec_name); ++i) {
396 if (strcasecmp(name, codec_name_aliases[i].alias) == 0) {
398 if (ret != VIDEO_CODEC_NONE) {
399 return ret;
400 }
401 }
402 }
403 return VIDEO_CODEC_NONE;
404}
const char * name
Definition settings.cpp:193
const char * primary_name
codec_t
Definition types.h:65
static codec_t get_codec_from_name_wo_alias(const char *name)
static const struct alternative_codec_name codec_name_aliases[]

References alternative_codec_name::alias, codec_name_aliases, get_codec_from_name_wo_alias(), name, alternative_codec_name::primary_name, and VIDEO_CODEC_NONE.

Here is the call graph for this function:

◆ get_codec_from_name_wo_alias()

static codec_t get_codec_from_name_wo_alias ( const char * name)
static

Helper codec finding function

Iterates through codec list and finds appropriate codec.

Returns
codec

Definition at line 376 of file video_codec.c.

377{
378 for (unsigned int i = 0; i < sizeof codec_info / sizeof(struct codec_info_t); ++i) {
379 if (codec_info[i].name && strcasecmp(codec_info[i].name, name) == 0) {
380 return i;
381 }
382 }
383
384 return VIDEO_CODEC_NONE;
385}

References codec_info, name, and VIDEO_CODEC_NONE.

Referenced by get_codec_from_name().

◆ get_codec_name()

const char * get_codec_name ( codec_t codec)

Definition at line 326 of file video_codec.c.

327{
328 unsigned int i = (unsigned int) codec;
329 const char *name = NULL;
330
331 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
332 name = codec_info[i].name;
333 }
334 assert(name != NULL);
335 return name;
336}
const char * name
displayed name

References codec_info, codec_info_t::name, and name.

◆ get_codec_name_long()

const char * get_codec_name_long ( codec_t codec)

Definition at line 338 of file video_codec.c.

339{
340 unsigned int i = (unsigned int) codec;
341 const char *name_long = NULL;
342
343 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
344 name_long = codec_info[i].name_long;
345 }
346 assert(name_long != NULL);
347 return name_long;
348}
const char * name_long
more descriptive name

References codec_info, and codec_info_t::name_long.

Referenced by print_pixel_formats(), print_video_codecs(), and testcard_show_codec_help().

◆ get_fourcc()

uint32_t get_fourcc ( codec_t codec)

Definition at line 314 of file video_codec.c.

315{
316 unsigned int i = (unsigned int) codec;
317 uint32_t fourcc = 0;
318
319 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
320 fourcc = codec_info[i].fcc;
321 }
322 assert(fourcc != 0);
323 return fourcc;
324}

References codec_info, and codec_info_t::fcc.

Referenced by configure_with(), format_video_header(), and output_summary().

◆ get_pf_block_bytes()

int get_pf_block_bytes ( codec_t codec)

returns codec_info_t::block_size_bytes

Definition at line 556 of file video_codec.c.

557{
558 unsigned int i = (unsigned int) codec;
559
560 if (i >= sizeof codec_info / sizeof(struct codec_info_t)) {
561 abort();
562 }
563 assert(codec_info[i].block_size_bytes > 0);
565}
int block_size_bytes
Bytes per pixel block (packed pixelformats only, otherwise set to 1)

References codec_info_t::block_size_bytes, and codec_info.

Referenced by crop_postprocess(), crop_postprocess_reconfigure(), display_dummy_putf(), filter(), filter(), get_packet_sizes(), reconfigure_decoder(), upload_to_cuda_buf(), vf_alloc_desc(), and vf_alloc_desc_data().

◆ get_pf_block_pixels()

int get_pf_block_pixels ( codec_t codec)

returns codec_info_t::block_size_pixels

Definition at line 568 of file video_codec.c.

569{
570 unsigned int i = (unsigned int) codec;
571
572 if (i >= sizeof codec_info / sizeof(struct codec_info_t)) {
573 abort();
574 }
575 assert(codec_info[i].block_size_pixels > 0);
577}
int block_size_pixels
Bytes per pixel block (packed pixelformats only, otherwise set to 1)

References codec_info_t::block_size_pixels, and codec_info.

Referenced by get_packet_sizes(), ipc_frame_from_ug_frame(), ipc_frame_from_ug_frame_hq(), and reconfigure_decoder().

◆ get_pixdesc_desc()

const char * get_pixdesc_desc ( struct pixfmt_desc desc)

Definition at line 1203 of file video_codec.c.

1204{
1205 if (desc.depth == 0) {
1206 return "(undefined)";
1207 }
1208 _Thread_local static char buf[128];
1209 snprintf(buf, sizeof buf, "%s %d:%d:%d", desc.rgb ? "RGB" : "YCbCr", desc.subsampling / 1000, desc.subsampling % 1000 / 100, desc.subsampling % 100 / 10);
1210 if (desc.subsampling % 10 != 0) {
1211 snprintf(buf + strlen(buf), sizeof buf - strlen(buf), ":%d", desc.subsampling % 10);
1212 }
1213 snprintf(buf + strlen(buf), sizeof buf - strlen(buf), " %d bit", desc.depth);
1214 return buf;
1215}
struct video_desc desc

References desc.

Referenced by choose_codec_and_decoder(), decompress_thread(), j2k_probe_internal_codec(), and video_decoder_order_output_codecs().

◆ get_pixfmt_desc()

◆ get_subsampling()

int get_subsampling ( codec_t codec)
Returns
subsampling in format (int) JabA (A is alpha), eg 4440

Definition at line 291 of file video_codec.c.

292{
293 int subsampling = 0;
294 if (codec < sizeof codec_info / sizeof(struct codec_info_t)) {
296 }
297 assert(subsampling != 0);
298 return subsampling;
299}
subsampling
Definition types.h:132

References codec_info, and codec_info_t::subsampling.

◆ i420_16_to_y416()

void i420_16_to_y416 ( int width,
int height,
const unsigned char * in,
unsigned char * out,
int in_depth )

Definition at line 1022 of file video_codec.c.

1024{
1025 enum { ALPHA16_OPAQUE = 0xFFFF };
1026 const uint16_t *in_y1 = (const void *) in;
1027 const uint16_t *in_y2 = in_y1 + width;
1028 const uint16_t *in_cb =
1029 (const uint16_t *) (const void *) in + (ptrdiff_t) width * height;
1030 const uint16_t *in_cr =
1031 in_cb + (ptrdiff_t) ((width + 1) / 2) * ((height + 1) / 2);
1032 const size_t out_line_len = vc_get_linesize(width, Y416) / 2;
1033 uint16_t *outp1 = (void *) out;
1034 uint16_t *outp2 = outp1 + out_line_len;
1035 for (int y = 0; y < (height + 1) / 2; ++y) {
1036 for (int x = 0; x < (width + 1) / 2; ++x) {
1037 *outp1++ = *in_cb << (DEPTH16 - in_depth);
1038 *outp1++ = *in_y1++ << (DEPTH16 - in_depth);
1039 *outp1++ = *in_cr << (DEPTH16 - in_depth);
1040 *outp1++ = ALPHA16_OPAQUE;
1041
1042 *outp2++ = *in_cb << (DEPTH16 - in_depth);
1043 *outp2++ = *in_y2++ << (DEPTH16 - in_depth);
1044 *outp2++ = *in_cr << (DEPTH16 - in_depth);
1045 *outp2++ = ALPHA16_OPAQUE;
1046
1047 *outp1++ = *in_cb << (DEPTH16 - in_depth);
1048 *outp1++ = *in_y1++ << (DEPTH16 - in_depth);
1049 *outp1++ = *in_cr << (DEPTH16 - in_depth);
1050 *outp1++ = ALPHA16_OPAQUE;
1051
1052 *outp2++ = *in_cb++ << (DEPTH16 - in_depth);
1053 *outp2++ = *in_y2++ << (DEPTH16 - in_depth);
1054 *outp2++ = *in_cr++ << (DEPTH16 - in_depth);
1055 *outp2++ = ALPHA16_OPAQUE;
1056 }
1057 outp1 += out_line_len;
1058 outp2 += out_line_len;
1059 in_y1 += width;
1060 in_y2 += width;
1061 }
1062}
@ DEPTH16
Definition types.h:129
@ Y416
interleaved little-endian YCbCr 4444 16-bit - UYVA
Definition types.h:99
int vc_get_linesize(unsigned int width, codec_t codec)

References DEPTH16, vc_get_linesize(), and Y416.

Referenced by testcard_load_from_file_y4m().

Here is the call graph for this function:

◆ i420_8_to_uyvy()

void i420_8_to_uyvy ( int width,
int height,
const unsigned char * in,
unsigned char * out )

Definition at line 1064 of file video_codec.c.

1065{
1066 const int uyvy_linesize = vc_get_linesize(width, UYVY);
1067 const unsigned char *const cb = in + (ptrdiff_t) width * height;
1068 const unsigned char *const cr =
1069 cb + (ptrdiff_t) (width / 2) * (height / 2);
1070
1071 for (ptrdiff_t y = 0; y < height; ++y) {
1072 const unsigned char *src_y = in + width * y;
1073 const unsigned char *src_cb = cb + (width / 2) * (y / 2);
1074 const unsigned char *src_cr = cr + (width / 2) * (y / 2);
1075 unsigned char *dst = out + y * uyvy_linesize;
1076
1077 OPTIMIZED_FOR(int x = 0; x < width / 2; ++x)
1078 {
1079 *dst++ = *src_cb++;
1080 *dst++ = *src_y++;
1081 *dst++ = *src_cr++;
1082 *dst++ = *src_y++;
1083 }
1084 }
1085}
#define OPTIMIZED_FOR
Definition macros.h:127

References OPTIMIZED_FOR, UYVY, and vc_get_linesize().

Referenced by i420_decompress(), and testcard_load_from_file_y4m().

Here is the call graph for this function:

◆ i422_16_to_y416()

void i422_16_to_y416 ( int width,
int height,
const unsigned char * in,
unsigned char * out,
int in_depth )

Definition at line 999 of file video_codec.c.

1001{
1002 enum { ALPHA16_OPAQUE = 0xFFFF };
1003 const uint16_t *in_y = (const uint16_t *) (const void *) in;
1004 const uint16_t *in_cb = in_y + (ptrdiff_t) width * height;
1005 const uint16_t *in_cr = in_cb + (ptrdiff_t) ((width + 1) / 2) * height;
1006 uint16_t *outp = (void *) out;
1007 for (int y = 0; y < height; ++y) {
1008 for (int x = 0; x < (width + 1) / 2; ++x) {
1009 *outp++ = *in_cb << (DEPTH16 - in_depth);
1010 *outp++ = *in_y++ << (DEPTH16 - in_depth);
1011 *outp++ = *in_cr << (DEPTH16 - in_depth);
1012 *outp++ = ALPHA16_OPAQUE;
1013 *outp++ = *in_cb++ << (DEPTH16 - in_depth);
1014 *outp++ = *in_y++ << (DEPTH16 - in_depth);
1015 *outp++ = *in_cr++ << (DEPTH16 - in_depth);
1016 *outp++ = ALPHA16_OPAQUE;
1017 }
1018 }
1019}

References DEPTH16.

Referenced by testcard_load_from_file_y4m().

◆ i422_8_to_uyvy()

void i422_8_to_uyvy ( int width,
int height,
const unsigned char * in,
unsigned char * out )

Definition at line 1088 of file video_codec.c.

1090{
1091 const unsigned char *in_y = in;
1092 const unsigned char *in_cb = in + width * height;
1093 const unsigned char *in_cr = in_cb + (((width + 1) / 2) * height);
1094 unsigned char *outp = out;
1095 for (int y = 0; y < height; ++y) {
1096 for (int x = 0; x < (width + 1) / 2; ++x) {
1097 *outp++ = *in_cb++;
1098 *outp++ = *in_y++;
1099 *outp++ = *in_cr++;
1100 *outp++ = *in_y++;
1101 }
1102 }
1103}

Referenced by testcard_load_from_file_y4m().

◆ i444_16_to_y416()

void i444_16_to_y416 ( int width,
int height,
const unsigned char * in,
unsigned char * out,
int in_depth )

Definition at line 981 of file video_codec.c.

983{
984 const uint16_t *in_y = (const uint16_t *)(const void *) in;
985 const uint16_t *in_cb = (const uint16_t *)(const void *) in + width * height;
986 const uint16_t *in_cr = (const uint16_t *)(const void *) in + 2 * width * height;
987 uint16_t *outp = (uint16_t *)(void *) out;
988 for (int y = 0; y < height; ++y) {
989 for (int x = 0; x < width; ++x) {
990 *outp++ = *in_cb++ << (16 - in_depth);
991 *outp++ = *in_y++ << (16 - in_depth);
992 *outp++ = *in_cr++ << (16 - in_depth);
993 *outp++ = 0xFFFFU; // alpha
994 }
995 }
996}

Referenced by testcard_load_from_file_y4m().

◆ i444_8_to_uyvy()

void i444_8_to_uyvy ( int width,
int height,
const unsigned char * in,
unsigned char * out )

Definition at line 1106 of file video_codec.c.

1108{
1109 const unsigned char *in_y = in;
1110 const unsigned char *in_cb = in + width * height;
1111 const unsigned char *in_cr = in_cb + width * height;
1112 unsigned char *outp = out;
1113 for (int y = 0; y < height; ++y) {
1114 for (int x = 0; x < (width + 1) / 2; ++x) {
1115 *outp++ = *in_cb;
1116 *outp++ = *in_y++;
1117 *outp++ = *in_cr;
1118 *outp++ = *in_y++;
1119 in_cb += 2;
1120 in_cr += 2;
1121 }
1122 }
1123}

Referenced by testcard_load_from_file_y4m().

◆ is_codec_interframe()

bool is_codec_interframe ( codec_t codec)

Returns whether specified codec is an interframe compression. Not defined for pixelformats

Return values
TRUEif compression is interframe
FALSEif compression is not interframe

Definition at line 448 of file video_codec.c.

449{
450 unsigned int i = (unsigned int) codec;
451
452 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
453 return codec_info[i].interframe;
454 }
455 return false;
456}
unsigned interframe
Indicates if compression is interframe.

References codec_info, and codec_info_t::interframe.

Referenced by print_video_codecs().

◆ is_codec_opaque()

bool is_codec_opaque ( codec_t codec)
Return values
TRUEif codec is compressed
FALSEif codec is pixelformat

Definition at line 432 of file video_codec.c.

433{
434 unsigned int i = (unsigned int) codec;
435
436 if (i < sizeof codec_info / sizeof(struct codec_info_t)) {
437 return codec_info[i].opaque;
438 }
439 return false;
440}
unsigned opaque
If codec is opaque (= compressed)

References codec_info, and codec_info_t::opaque.

Referenced by avg_lines(), display_dump_getf(), display_dump_reconfigure(), get_codecs(), get_packet_sizes(), print_pixel_formats(), print_video_codecs(), probe_cuda_ug_to_av(), save_video_frame(), h264_sdp_video_rxtx::send_frame(), testcard_show_codec_help(), vc_deinterlace_ex(), vidcap_dshow_grab(), vidcap_dshow_init(), vidcap_dshow_probe_internal(), vidcap_ndi_grab(), and write_mode().

◆ pixdesc_equals()

bool pixdesc_equals ( struct pixfmt_desc desc_a,
struct pixfmt_desc desc_b )

Definition at line 1217 of file video_codec.c.

1217 {
1218 return desc_a.depth == desc_b.depth &&
1219 desc_a.subsampling == desc_b.subsampling &&
1220 desc_a.rgb == desc_b.rgb;
1221}

References pixfmt_desc::depth, pixfmt_desc::rgb, and pixfmt_desc::subsampling.

Referenced by reconfigure_if_needed(), and video_decoder_order_output_codecs().

◆ show_codec_help()

void show_codec_help ( const char * module,
const codec_t * codecs8,
const codec_t * codecs10,
const codec_t * codecs_ge12 )

Prints list of suppored codecs for video module.

Definition at line 250 of file video_codec.c.

251{
252 printf("Supported codecs (%s):\n", module);
253
254 if (codecs8) {
255 printf("\t8bits\n");
256
257 while (*codecs8 != VIDEO_CODEC_NONE) {
258 printf("\t\t'%s' - %s\n", codec_info[*codecs8].name, codec_info[*codecs8].name_long);
259 codecs8++;
260 }
261 }
262
263 if (codecs10) {
264 printf("\t10bits\n");
265 while (*codecs10 != VIDEO_CODEC_NONE) {
266 printf("\t\t'%s' - %s\n", codec_info[*codecs10].name, codec_info[*codecs10].name_long);
267 codecs10++;
268 }
269 }
270
271 if (codecs_ge12) {
272 printf("\t12+ bits\n");
273 while (*codecs_ge12 != VIDEO_CODEC_NONE) {
274 printf("\t\t'%s' - %s\n", codec_info[*codecs_ge12].name, codec_info[*codecs_ge12].name_long);
275 codecs_ge12++;
276 }
277 }
278}

References codec_info, name, and VIDEO_CODEC_NONE.

Referenced by show_help().

◆ uyvy_to_i422()

void uyvy_to_i422 ( int width,
int height,
const unsigned char * in,
unsigned char * out )

Definition at line 941 of file video_codec.c.

942{
943 unsigned char *out_y = out;
944 unsigned char *out_cb = out + width * height;
945 unsigned char *out_cr =
946 out + width * height + ((width + 1) / 2) * height;
947 for (int y = 0; y < height; ++y) {
948 for (int x = 0; x < width / 2; ++x) {
949 *out_cb++ = *in++;
950 *out_y++ = *in++;
951 *out_cr++ = *in++;
952 *out_y++ = *in++;
953 }
954 if (width % 2 == 1) {
955 *out_cb++ = *in++;
956 *out_y++ = *in++;
957 *out_cr++ = *in++;
958 }
959 }
960}

Referenced by save_video_frame_as_y4m().

◆ vc_deinterlace()

void vc_deinterlace ( unsigned char * src,
long src_linesize,
int lines )

Deinterlaces framebuffer.

vc_deinterlace performs linear blend deinterlace on a framebuffer.

Parameters
[in,out]srcframebuffer to be deinterlaced
[in]src_linesizelength of a line (bytes)
[in]linesnumber of lines
See also
vc_deinterlace_aligned
vc_deinterlace_unaligned

Definition at line 588 of file video_codec.c.

589{
590#ifdef __SSE2__
591 if(((uintptr_t) src & 0x0Fu) == 0u && src_linesize % 16 == 0) {
592 vc_deinterlace_aligned(src, src_linesize, lines);
593 } else {
594 vc_deinterlace_unaligned(src, src_linesize, lines);
595 }
596#else
597 for (int y = 0; y < lines; y += 2) {
598 for (int x = 0; x < src_linesize; ++x) {
599 int val = (*src + src[src_linesize] + 1) >> 1;
600 *src = src[src_linesize] = val;
601 src++;
602 }
603 src += src_linesize;
604 }
605#endif
606}
int void * val

References val.

Referenced by display_frame(), display_sage_run(), and slave_worker().

◆ vc_deinterlace_ex()

bool vc_deinterlace_ex ( codec_t codec,
unsigned char * src,
size_t src_linesize,
unsigned char * dst,
size_t dst_pitch,
size_t lines )

Extended version of vc_deinterlace(). The former version was in-place only. This allows to output to a different buffer while it can still be used in-place.

Returns
false on unsupported codecs

Definition at line 713 of file video_codec.c.

714{
716 return false;
717 }
718 if (lines == 1) {
719 memcpy(dst, src, src_linesize);
720 return true;
721 }
723 int bpp = get_bits_per_component(codec);
724 for (size_t y = 0; y < lines - 1; y += 1) {
725 unsigned char *s = src + y * src_linesize;
726 unsigned char *d = dst + y * dst_pitch;
727 if (bpp == 8 || bpp == 16) {
728 size_t x = 0;
729#ifdef __SSSE3__
730 if (bpp == 8) {
731 for ( ; x < src_linesize / 16; ++x) {
732 __m128i i1 = _mm_lddqu_si128((__m128i const*)(const void *) s);
733 __m128i i2 = _mm_lddqu_si128((__m128i const*)(const void *) (s + src_linesize));
734 __m128i res = _mm_avg_epu8(i1, i2);
735 _mm_storeu_si128((__m128i *)(void *) d, res);
736 s += 16;
737 d += 16;
738 }
739 } else {
740 for ( ; x < src_linesize / 16; ++x) {
741 __m128i i1 = _mm_lddqu_si128((__m128i const*)(const void *) s);
742 __m128i i2 = _mm_lddqu_si128((__m128i const*)(const void *) (s + src_linesize));
743 __m128i res = _mm_avg_epu16(i1, i2);
744 _mm_storeu_si128((__m128i *)(void *) d, res);
745 s += 16;
746 d += 16;
747 }
748 }
749#endif
750 x *= 16;
751 if (bpp == 8) {
752 for ( ; x < src_linesize; ++x) {
753 int val = (*s + s[src_linesize] + 1) >> 1;
754 *d++ = val;
755 s++;
756 }
757 } else {
758 uint16_t *d16 = (void *) d;
759 uint16_t *s16 = (void *) s;
760 for ( ; x < src_linesize / 2; ++x) {
761 int val = (*s16 + s16[src_linesize / 2] + 1) >> 1;
762 *d16++ = val;
763 s16++;
764 }
765 }
766 } else if (codec == v210) {
767 uint32_t *s32 = (void *) s;
768 uint32_t *d32 = (void *) d;
769 for (size_t x = 0; x < src_linesize / 16; ++x) {
770 #pragma GCC unroll 4
771 for (size_t y = 0; y < 4; ++y) {
772 uint32_t v1 = *s32;
773 uint32_t v2 = s32[src_linesize / 4];
774 uint32_t out =
775 (((v1 >> 20 ) + (v2 >> 20 ) + 1) / 2) << 20 |
776 (((v1 >> 10 & 0x3ff) + (v2 >> 10 & 0x3ff) + 1) / 2) << 10 |
777 (((v1 & 0x3ff) + (v2 & 0x3ff) + 1) / 2);
778 *d32++ = out;
779 s32++;
780 }
781 }
782 } else if (codec == R10k) {
783 uint32_t *s32 = (void *) s;
784 uint32_t *d32 = (void *) d;
785 for (size_t x = 0; x < src_linesize / 16; ++x) {
786 #pragma GCC unroll 4
787 for (size_t y = 0; y < 4; ++y) {
788 uint32_t v1 = ntohl(*s32);
789 uint32_t v2 = ntohl(s32[src_linesize / 4]);
790 uint32_t out =
791 (((v1 >> 22 ) + (v2 >> 22 ) + 1) / 2) << 22 |
792 (((v1 >> 12 & 0x3ff) + (v2 >> 12 & 0x3ff) + 1) / 2) << 12 |
793 (((v1 >> 2 & 0x3ff) + (v2 >> 2 & 0x3ff) + 1) / 2) << 2;
794 *d32++ = htonl(out);
795 s32++;
796 }
797 }
798 } else if (codec == R12L) {
799 uint32_t *s32 = (void *) s;
800 uint32_t *d32 = (void *) d;
801 int shift = 0;
802 uint32_t remain1 = 0;
803 uint32_t remain2 = 0;
804 uint32_t out = 0;
805 for (size_t x = 0; x < src_linesize / 36; ++x) {
806 #pragma GCC unroll 8
807 for (size_t y = 0; y < 8; ++y) {
808 uint32_t in1 = *s32;
809 uint32_t in2 = s32[src_linesize / 4];
810 if (shift > 0) {
811 remain1 = remain1 | (in1 & ((1<<((shift + 12) % 32)) - 1)) << (32-shift);
812 remain2 = remain2 | (in2 & ((1<<((shift + 12) % 32)) - 1)) << (32-shift);
813 uint32_t ret = (remain1 + remain2 + 1) / 2;
814 out |= ret << shift;
815 *d32++ = out;
816 out = ret >> (32-shift);
817 shift = (shift + 12) % 32;
818 in1 >>= shift;
819 in2 >>= shift;
820 }
821 while (shift <= 32 - 12) {
822 out |= ((((in1 & 0xfff) + (in2 & 0xfff)) + 1) / 2) << shift;
823 in1 >>= 12;
824 in2 >>= 12;
825 shift += 12;
826 }
827 if (shift == 32) {
828 *d32++ = out;
829 out = 0;
830 shift = 0;
831 } else {
832 remain1 = in1;
833 remain2 = in2;
834 }
835 s32++;
836 }
837 }
838 } else {
839 return false;
840 }
841 }
842 memcpy(dst + (lines - 1) * dst_pitch, dst + (lines - 2) * dst_pitch, src_linesize); // last line
844 return true;
845}
#define DEBUG_TIMER_START(name)
Definition debug.h:324
#define DEBUG_TIMER_STOP(name)
Definition debug.h:325
@ R10k
RGB 10-bit packed - RGBX, big-endian (2 bit padding)
Definition types.h:73
@ R12L
RGB 12-bit packed, little-endian.
Definition types.h:74
bool is_codec_opaque(codec_t codec)
bool vc_deinterlace_ex(codec_t codec, unsigned char *src, size_t src_linesize, unsigned char *dst, size_t dst_pitch, size_t lines)
bool codec_is_planar(codec_t codec)
int get_bits_per_component(codec_t codec)

References codec_is_planar(), DEBUG_TIMER_START, DEBUG_TIMER_STOP, get_bits_per_component(), is_codec_opaque(), R10k, R12L, v210, val, and vc_deinterlace_ex().

Referenced by deinterlace_postprocess(), display_frame(), perform_df(), and vc_deinterlace_ex().

Here is the call graph for this function:

◆ vc_get_datalen()

size_t vc_get_datalen ( unsigned int width,
unsigned int height,
codec_t codec )

Returns storage requirements for given parameters

Definition at line 534 of file video_codec.c.

535{
536 if (!codec_is_planar(codec)) {
537 return vc_get_linesize(width, codec) * height;
538 }
539
540 assert(get_bits_per_component(codec) == 8);
541 size_t ret = 0;
542 int sub[8];
544 for (int i = 0; i < 4; ++i) {
545 if (sub[i * 2] == 0) { // less than 4 planes
546 break;
547 }
548 ret += ((width + sub[i * 2] - 1) / sub[i * 2])
549 * ((height + sub[i * 2 + 1] - 1) / sub[i * 2 + 1]);
550 }
551
552 return ret;
553}
void codec_get_planes_subsampling(codec_t pix_fmt, int *sub)

References codec_get_planes_subsampling(), codec_is_planar(), get_bits_per_component(), and vc_get_linesize().

Referenced by still_image_video_pattern_generator::still_image_video_pattern_generator(), SampleGrabberCallback::BufferCB(), codec_conversion_test_testcard_uyvy_to_i420(), do_av_to_uv_convert(), get_16_bit_pnm_data(), j2k_compress_push(), main(), r12l_postprocessor_get_sz(), save_video_frame_as_y4m(), testcard_load_from_file(), testcard_load_from_file_pam(), testcard_load_from_file_y4m(), vf_alloc_desc(), vidcap_dshow_grab(), vidcap_testcard2_init(), and vidcap_testcard2_thread().

Here is the call graph for this function:

◆ vc_get_linesize()

int vc_get_linesize ( unsigned int width,
codec_t codec )
Returns
aligned linesize according to pixelformat specification (in bytes)
See also
vc_get_size that should be used eg. as decoder_t linesize parameter instead

Definition at line 498 of file video_codec.c.

499{
500 if (codec >= sizeof codec_info / sizeof(struct codec_info_t)) {
501 return 0;
502 }
503
504 if (codec_info[codec].h_align) {
505 width =
506 ((width + codec_info[codec].h_align -
507 1) / codec_info[codec].h_align) *
508 codec_info[codec].h_align;
509 }
511 return (width + pixs - 1) / pixs * codec_info[codec].block_size_bytes;
512}
int h_align
Number of pixels each line is aligned to.

References codec_info_t::block_size_bytes, codec_info_t::block_size_pixels, codec_info, and codec_info_t::h_align.

Referenced by i420_16_to_y416(), i420_8_to_uyvy(), and vc_get_datalen().

◆ vc_get_size()

int vc_get_size ( unsigned int width,
codec_t codec )
Returns
size of "width" pixels in codec excluding line padding

This differs from vc_get_linesize for v210, eg. for width=1 that function returns 128, while this function 16. Also for R10k, lines are aligned to 256 B (64 pixels), while single pixel is only 4 B.

Definition at line 521 of file video_codec.c.

522{
523 if (codec >= sizeof codec_info / sizeof(struct codec_info_t)) {
524 return 0;
525 }
526
528 return (width + pixs - 1) / pixs * codec_info[codec].block_size_bytes;
529}

References codec_info_t::block_size_bytes, codec_info_t::block_size_pixels, and codec_info.

Referenced by do_av_to_uv_convert(), draw_frame(), testcard_convert_buffer(), and to_lavc_memcpy_data().

◆ watch_pixfmt_degrade()

void watch_pixfmt_degrade ( const char * mod_name,
struct pixfmt_desc desc_src,
struct pixfmt_desc desc_dst )

Definition at line 1184 of file video_codec.c.

1185{
1186 char message[1024];
1187 message[0] = '\0';
1188 if (desc_dst.depth < desc_src.depth) {
1189 snprintf(message, sizeof message, "conversion is reducing bit depth from %d to %d", desc_src.depth, desc_dst.depth);
1190 }
1191 if (desc_dst.subsampling < desc_src.subsampling) {
1192 if (strlen(message) > 0) {
1193 snprintf(message + strlen(message), sizeof message - strlen(message), " and subsampling from %d to %d", desc_src.subsampling, desc_dst.subsampling);
1194 } else {
1195 snprintf(message, sizeof message, "conversion is reducing subsampling from %d to %d", desc_src.subsampling, desc_dst.subsampling);
1196 }
1197 }
1198 if (strlen(message) > 0) {
1199 log_msg(LOG_LEVEL_WARNING, "%s%s\n", mod_name, message);
1200 }
1201}
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60

References pixfmt_desc::depth, LOG_LEVEL_WARNING, log_msg(), and pixfmt_desc::subsampling.

Referenced by get_av_to_uv_conversion(), and to_lavc_vid_conv_init().

Here is the call graph for this function:

◆ y416_to_i444()

void y416_to_i444 ( int width,
int height,
const unsigned char * in,
unsigned char * out,
int depth )

Definition at line 963 of file video_codec.c.

965{
966 const uint16_t *inp = (const uint16_t *) (const void *) in;
967 uint16_t *out_y = (uint16_t *) (void *) out;
968 uint16_t *out_cb = (uint16_t *) (void *) out + width * height;
969 uint16_t *out_cr = (uint16_t *) (void *) out + 2 * width * height;
970 for (int y = 0; y < height; ++y) {
971 for (int x = 0; x < width; ++x) {
972 *out_cb++ = *inp++ >> (16 - depth);
973 *out_y++ = *inp++ >> (16 - depth);
974 *out_cr++ = *inp++ >> (16 - depth);
975 inp++; // alpha
976 }
977 }
978}
depth
Definition types.h:125

Referenced by save_video_frame_as_y4m().

Variable Documentation

◆ codec_info

const struct codec_info_t codec_info[]
static

Definition at line 121 of file video_codec.c.

121 {
122 [VIDEO_CODEC_NONE] = {"(none)", "Undefined Codec",
123 0, 0, 0.0, 0, 0, FALSE, FALSE, FALSE, FALSE, 0, NULL},
124 [RGBA] = {"RGBA", "Red Green Blue Alpha 32bit",
125 to_fourcc('R','G','B','A'), 4, 1, 1, 8, TRUE, FALSE, FALSE, FALSE, 4444, "rgba"},
126 [UYVY] = {"UYVY", "YUV 4:2:2",
127 to_fourcc('U','Y','V','Y'), 4, 2, 2, 8, FALSE, FALSE, FALSE, FALSE, 4220, "yuv"},
128 [YUYV] = {"YUYV", "YUV 4:2:2",
129 to_fourcc('Y','U','Y','V'), 4, 2, 2, 8, FALSE, FALSE, FALSE, FALSE, 4220, "yuv"},
130 [R10k] = {"R10k", "10-bit RGB 4:4:4", // called 'R10b' in BMD SDK
131 to_fourcc('R','1','0','k'), 4, 1, 64, 10, TRUE, FALSE, FALSE, FALSE, 4440, "r10k"},
132 [R12L] = {"R12L", "12-bit packed RGB 4:4:4 little-endian", // SMPTE 268M DPX v1, Annex C, Method C4
133 to_fourcc('R','1','2','l'), 36, 8, 8, 12, TRUE, FALSE, FALSE, FALSE, 4440, "r12l"},
134 [v210] = {"v210", "10-bit YUV 4:2:2",
135 to_fourcc('v','2','1','0'), 16, 6, 48, 10, FALSE, FALSE, FALSE, FALSE, 4220, "v210"},
136 [DVS10] = {"DVS10", "Centaurus 10bit YUV 4:2:2",
137 to_fourcc('D','S','1','0'), 16, 6, 48, 10, FALSE, FALSE, FALSE, FALSE, 4220, "dvs10"},
138 [DXT1] = {"DXT1", "S3 Compressed Texture DXT1",
139 to_fourcc('D','X','T','1'), 1, 2, 0, 2, TRUE, TRUE, FALSE, FALSE, 0, "dxt1"},
140 [DXT1_YUV] = {"DXT1_YUV", "S3 Compressed Texture DXT1 YUV",
141 to_fourcc('D','X','T','Y'), 1, 2, 0, 2, FALSE, TRUE, FALSE, FALSE, 0, "dxt1y"}, /* packet YCbCr inside DXT1 channels */
142 [DXT5] = {"DXT5", "S3 Compressed Texture DXT5 YCoCg",
143 to_fourcc('D','X','T','5'), 1, 1, 0, 4, FALSE, TRUE, FALSE, FALSE, 0, "yog"},/* DXT5 YCoCg */
144 [RGB] = {"RGB", "Red Green Blue 24bit",
145 to_fourcc('R','G','B','2'), 3, 1, 1, 8, TRUE, FALSE, FALSE, FALSE, 4440, "rgb"},
146 [JPEG] = {"JPEG", "JPEG",
147 to_fourcc('J','P','E','G'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "jpg"},
148 [RAW] = {"raw", "Raw SDI video",
149 to_fourcc('r','a','w','s'), 1, 1, 0, 0, FALSE, TRUE, FALSE, FALSE, 0, "raw"}, /* raw SDI */
150 [H264] = {"H.264", "H.264/AVC",
151 to_fourcc('A','V','C','1'), 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "h264"},
152 [H265] = {"H.265", "H.265/HEVC",
153 to_fourcc('H','E','V','C'), 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "h265"},
154 [MJPG] = {"MJPEG", "MJPEG",
155 to_fourcc('M','J','P','G'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "jpg"},
156 [VP8] = {"VP8", "Google VP8",
157 to_fourcc('V','P','8','0'), 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "vp8"},
158 [VP9] = {"VP9", "Google VP9",
159 to_fourcc('V','P','9','0'), 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "vp9"},
160 [BGR] = {"BGR", "Blue Green Red 24bit",
161 to_fourcc('B','G','R','2'), 3, 1, 1, 8, TRUE, FALSE, FALSE, FALSE, 4440, "bgr"},
162 [J2K] = {"J2K", "JPEG 2000",
163 to_fourcc('M','J','2','C'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "j2k"},
164 [J2KR] = {"J2KR", "JPEG 2000 RGB",
165 to_fourcc('M','J','2','R'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "j2k"},
166 [HW_VDPAU] = {"HW_VDPAU", "VDPAU hardware surface",
167 to_fourcc('V', 'D', 'P', 'S'), HW_VDPAU_FRAME_SZ, 1, 0, 8, FALSE, TRUE, FALSE, TRUE, 4440, "vdpau"},
168 [HFYU] = {"HFYU", "HuffYUV",
169 to_fourcc('H','F','Y','U'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "hfyu"},
170 [FFV1] = {"FFV1", "FFV1",
171 to_fourcc('F','F','V','1'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "ffv1"},
172 [CFHD] = {"CFHD", "Cineform",
173 to_fourcc('C','F','H','D'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "cfhd"},
174 [RG48] = {"RG48", "16-bit RGB little-endian",
175 to_fourcc('R','G','4','8'), 6, 1, 1, 16, TRUE, FALSE, FALSE, FALSE, 4440, "rg48"},
176 [AV1] = {"AV1", "AOMedia Video 1",
177 to_fourcc('a','v','0','1'), 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "av1"},
178 [I420] = {"I420", "planar YUV 4:2:0",
179 to_fourcc('I','4','2','0'), 3, 2, 2, 8, FALSE, FALSE, FALSE, FALSE, 4200, "yuv"},
180 [Y216] = {"Y216", "Packed 16-bit YUV 4:2:2 little-endian",
181 to_fourcc('Y','2','1','6'), 8, 2, 2, 16, FALSE, FALSE, FALSE, FALSE, 4220, "y216"},
182 [Y416] = {"Y416", "Packed 16-bit YUV 4:4:4:4 little-endian",
183 to_fourcc('Y','4','1','6'), 8, 1, 1, 16, FALSE, FALSE, FALSE, FALSE, 4444, "y416"},
184 [PRORES] = {"PRORES", "Apple ProRes",
185 0, 1, 1, 0, 8, FALSE, TRUE, TRUE, FALSE, 0, "pror"},
186 [PRORES_4444] = {"PRORES_4444", "Apple ProRes 4444",
187 to_fourcc('a','p','4','h'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "ap4h"},
188 [PRORES_4444_XQ] = {"PRORES_4444_XQ", "Apple ProRes 4444 (XQ)",
189 to_fourcc('a','p','4','x'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "ap4x"},
190 [PRORES_422_HQ] = {"PRORES_422_HQ", "Apple ProRes 422 (HQ)",
191 to_fourcc('a','p','c','h'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "apch"},
192 [PRORES_422] = {"PRORES_422", "Apple ProRes 422",
193 to_fourcc('a','p','c','n'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "apcn"},
194 [PRORES_422_PROXY] = {"PRORES_422_PROXY", "Apple ProRes 422 (Proxy)",
195 to_fourcc('a','p','c','o'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "apco"},
196 [PRORES_422_LT] = {"PRORES_422_LT", "Apple ProRes 422 (LT)",
197 to_fourcc('a','p','c','s'), 1, 1, 0, 8, FALSE, TRUE, FALSE, FALSE, 0, "apcs"},
198 [DRM_PRIME] = {"DRM_PRIME", "DRM Prime buffer",
199 to_fourcc('D', 'R', 'M', 'P'), sizeof(struct drm_prime_frame), 1, 0, 8, FALSE, TRUE, FALSE, TRUE, 0, "drm_prime"},
200};
#define TRUE
#define FALSE
#define to_fourcc(a, b, c, d)
Creates FourCC word.
Definition macros.h:114
@ YUYV
YCbCr 422 8-bit - Y0 Cb Y1 Cr.
Definition types.h:72
@ VP8
VP8 frame.
Definition types.h:86
@ DXT1
S3 Texture Compression DXT1.
Definition types.h:77
@ PRORES_422_LT
Apple ProRes 422 (LT)
Definition types.h:106
@ PRORES
abstract Apple ProRes, must not be used in transmit
Definition types.h:100
@ PRORES_422_PROXY
Apple ProRes 422 (Proxy)
Definition types.h:105
@ RG48
16-bit RGB little-endian (RlRhGl...)
Definition types.h:95
@ AV1
AOMedia Video 1.
Definition types.h:96
@ J2KR
JPEG 2000 RGB.
Definition types.h:90
@ CFHD
Cineform.
Definition types.h:94
@ J2K
JPEG 2000.
Definition types.h:89
@ PRORES_422_HQ
Apple ProRes 422 (HQ)
Definition types.h:103
@ Y216
YCbCr 422 16-bit little-endian - Y0 Cb Y1 Cr.
Definition types.h:98
@ PRORES_4444
Apple ProRes 4444.
Definition types.h:101
@ JPEG
JPEG image, restart intervals may be used. Compatible with GPUJPEG.
Definition types.h:81
@ HFYU
HuffYUV.
Definition types.h:92
@ MJPG
JPEG image, without restart intervals.
Definition types.h:85
@ FFV1
FFV1.
Definition types.h:93
@ PRORES_422
Apple ProRes 422.
Definition types.h:104
@ DRM_PRIME
DRM Prime buffer, data contains struct drm_prime_frame.
Definition types.h:107
@ RAW
RAW HD-SDI frame.
Definition types.h:82
@ H264
H.264 frame.
Definition types.h:83
@ DVS10
DVS 10-bit format.
Definition types.h:76
@ VP9
VP9 frame.
Definition types.h:87
@ H265
H.264 frame.
Definition types.h:84
@ DXT5
S3 Texture Compression DXT5.
Definition types.h:79
@ I420
planar YCbCr 4:2:0
Definition types.h:97
@ PRORES_4444_XQ
Apple ProRes 4444 (XQ)
Definition types.h:102
@ DXT1_YUV
Structure same as DXT1, instead of RGB, YCbCr values are stored.
Definition types.h:78
#define HW_VDPAU_FRAME_SZ

Referenced by codec_is_a_rgb(), codec_is_const_size(), get_bits_per_component(), get_bpp(), get_cineform_module_info(), get_cmpto_j2k_module_info(), get_codec_file_extension(), get_codec_from_fcc(), get_codec_from_file_extension(), get_codec_from_name_wo_alias(), get_codec_name(), get_codec_name_long(), get_fourcc(), get_pf_block_bytes(), get_pf_block_pixels(), get_pixfmt_desc(), get_subsampling(), is_codec_interframe(), is_codec_opaque(), show_codec_help(), vc_get_linesize(), and vc_get_size().

◆ codec_name_aliases

const struct alternative_codec_name codec_name_aliases[]
static
Initial value:
= {
{"2vuy", "UYVY"},
{"AVC", "H.264"},
{"H264", "H.264"},
{"HEVC", "H.265"},
}

Definition at line 243 of file video_codec.c.

243 {
244 {"2vuy", "UYVY"},
245 {"AVC", "H.264"},
246 {"H264", "H.264"},
247 {"HEVC", "H.265"},
248};

Referenced by get_codec_from_name().

◆ fourcc_aliases

const struct alternative_fourcc fourcc_aliases[]
static
Initial value:
= {
{to_fourcc('A', 'B', 'G', 'R'), to_fourcc('R', 'G', 'B', 'A')},
{to_fourcc('2', 'B', 'G', 'R'), to_fourcc('R', 'G', 'B', '2')},
{to_fourcc('M', 'J', 'P', 'G'), to_fourcc('J', 'P', 'E', 'G')},
{to_fourcc('2', 'V', 'u', 'y'), to_fourcc('U', 'Y', 'V', 'Y')},
{to_fourcc('2', 'v', 'u', 'y'), to_fourcc('U', 'Y', 'V', 'Y')},
{to_fourcc('d', 'v', 's', '8'), to_fourcc('U', 'Y', 'V', 'Y')},
{to_fourcc('D', 'V', 'S', '8'), to_fourcc('U', 'Y', 'V', 'Y')},
{to_fourcc('y', 'u', 'v', '2'), to_fourcc('U', 'Y', 'V', 'Y')},
{to_fourcc('y', 'u', 'V', '2'), to_fourcc('U', 'Y', 'V', 'Y')},
}

This array contains FourCC aliases mapping

Definition at line 223 of file video_codec.c.

223 {
224 // the following two are here because it was sent with wrong endiannes in past
225 {to_fourcc('A', 'B', 'G', 'R'), to_fourcc('R', 'G', 'B', 'A')},
226 {to_fourcc('2', 'B', 'G', 'R'), to_fourcc('R', 'G', 'B', '2')},
227 // following ones are rather for further compatibility (proposed codecs rename)
228 {to_fourcc('M', 'J', 'P', 'G'), to_fourcc('J', 'P', 'E', 'G')},
229
230 {to_fourcc('2', 'V', 'u', 'y'), to_fourcc('U', 'Y', 'V', 'Y')},
231 {to_fourcc('2', 'v', 'u', 'y'), to_fourcc('U', 'Y', 'V', 'Y')},
232 {to_fourcc('d', 'v', 's', '8'), to_fourcc('U', 'Y', 'V', 'Y')},
233 {to_fourcc('D', 'V', 'S', '8'), to_fourcc('U', 'Y', 'V', 'Y')},
234 {to_fourcc('y', 'u', 'v', '2'), to_fourcc('U', 'Y', 'V', 'Y')},
235 {to_fourcc('y', 'u', 'V', '2'), to_fourcc('U', 'Y', 'V', 'Y')},
236};

Referenced by get_codec_from_fcc().

◆ pixfmt_conv_pref

char pixfmt_conv_pref[] = "dsc"

bitdepth, subsampling, color space

Definition at line 80 of file video_codec.c.

Referenced by compare_pixdesc(), and set_pixfmt_conv_policy().

◆ pixfmt_plane_info

const struct pixfmt_plane_info_t pixfmt_plane_info[]
static
Initial value:
= {
[I420] = {{1, 1, 2, 2, 2, 2, 0, 0}},
[VIDEO_CODEC_END] = {{0}},
}

Definition at line 207 of file video_codec.c.

207 {
208 [I420] = {{1, 1, 2, 2, 2, 2, 0, 0}},
209 [VIDEO_CODEC_END] = {{0}}, // end must be present to all codecs to have the metadata defined
210};

Referenced by codec_get_planes_subsampling(), codec_is_420(), and codec_is_planar().