UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
video_codec.h File Reference
#include "types.h"
#include "pixfmt_conv.h"
Include dependency graph for video_codec.h:

Go to the source code of this file.

Macros

#define MAX_BPS   8 /* for Y416 */
 maximal (average) number of pixels per know pixel formats (up-round if needed)
 
#define MAX_PADDING   64
 
#define MAX_PFB_SIZE   8
 maximal pixfmt block size (R12L - 8 B)
 
#define PIX_BLOCK_LCM   24
 least common multiple of all pixfmt block sizes in pixels (codec_info_t::block_size/codec_info_t::bpp). "contributors:" 8 R12L, 6 v210
 

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) __attribute__((const))
 
bool codec_is_const_size (codec_t codec) __attribute__((const))
 
bool codec_is_hw_accelerated (codec_t codec) __attribute__((const))
 
bool codec_is_in_set (codec_t codec, const codec_t *set) __attribute__((pure))
 
bool codec_is_planar (codec_t codec) __attribute__((const))
 
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) __attribute__((const))
 
double get_bpp (codec_t codec) __attribute__((const))
 
const char * get_codec_file_extension (codec_t codec) __attribute__((const))
 
codec_t get_codec_from_fcc (uint32_t fourcc) __attribute__((const))
 
codec_t get_codec_from_file_extension (const char *ext) __attribute__((const))
 
codec_t get_codec_from_name (const char *name) __attribute__((const))
 
const char * get_codec_name (codec_t codec) __attribute__((const))
 
const char * get_codec_name_long (codec_t codec) __attribute__((const))
 
uint32_t get_fourcc (codec_t codec) __attribute__((const))
 
int get_pf_block_bytes (codec_t codec) __attribute__((const))
 
int get_pf_block_pixels (codec_t codec) __attribute__((const))
 
const char * get_pixdesc_desc (struct pixfmt_desc)
 
struct pixfmt_desc get_pixfmt_desc (codec_t pixfmt)
 
int get_subsampling (codec_t codec) __attribute__((const))
 
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) __attribute__((const))
 
bool is_codec_opaque (codec_t codec) __attribute__((const))
 
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) __attribute__((const))
 
int vc_get_linesize (unsigned int width, codec_t codec) __attribute__((const))
 
int vc_get_size (unsigned int width, codec_t codec) __attribute__((const))
 
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)
 

Detailed Description

Macro Definition Documentation

◆ MAX_BPS

#define MAX_BPS   8 /* for Y416 */

maximal (average) number of pixels per know pixel formats (up-round if needed)

Definition at line 62 of file video_codec.h.

Referenced by benchmark(), decompress_thread(), and display_ndi_reconfigure().

◆ MAX_PADDING

#define MAX_PADDING   64

maximal padding in bytes that may be needed to align to pixfmt block size for Y416->R12L: 64 = vc_linesize(8 /*maximal block pix count (R12L)*‍/, Y416 /*codec with maximal lenght of 1st arg-sized block*‍/)

Definition at line 63 of file video_codec.h.

Referenced by interlaced_video_pattern_generator::interlaced_video_pattern_generator(), benchmark(), display_ndi_reconfigure(), do_av_to_uv_convert(), filter(), filter(), video_frame_pool::impl::get_frame(), to_lavc_vid_conv_init(), vf_alloc_desc_data(), and vidcap_testcard2_thread().

◆ MAX_PFB_SIZE

#define MAX_PFB_SIZE   8

maximal pixfmt block size (R12L - 8 B)

Definition at line 65 of file video_codec.h.

◆ PIX_BLOCK_LCM

#define PIX_BLOCK_LCM   24

least common multiple of all pixfmt block sizes in pixels (codec_info_t::block_size/codec_info_t::bpp). "contributors:" 8 R12L, 6 v210

Definition at line 66 of file video_codec.h.

Referenced by get_packet_sizes().

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) const

◆ codec_is_const_size()

bool codec_is_const_size ( codec_t codec) const

◆ codec_is_hw_accelerated()

bool codec_is_hw_accelerated ( codec_t codec) const

◆ 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) const

◆ 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()

int get_bits_per_component ( codec_t codec) const
Returns
number of bits per color component

◆ get_bpp()

double get_bpp ( codec_t codec) const
Returns
number of bytes per pixel

◆ get_codec_file_extension()

const char * get_codec_file_extension ( codec_t codec) const

◆ get_codec_from_fcc()

codec_t get_codec_from_fcc ( uint32_t fourcc) const

◆ get_codec_from_file_extension()

codec_t get_codec_from_file_extension ( const char * ext) const

◆ get_codec_from_name()

codec_t get_codec_from_name ( const char * name) const

◆ get_codec_name()

const char * get_codec_name ( codec_t codec) const

◆ get_codec_name_long()

const char * get_codec_name_long ( codec_t codec) const

◆ get_fourcc()

uint32_t get_fourcc ( codec_t codec) const

◆ get_pf_block_bytes()

int get_pf_block_bytes ( codec_t codec) const

◆ get_pf_block_pixels()

int get_pf_block_pixels ( codec_t codec) const

◆ 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()

struct pixfmt_desc get_pixfmt_desc ( codec_t pixfmt)

Definition at line 1125 of file video_codec.c.

1126{
1127 assert(pixfmt >= VIDEO_CODEC_FIRST && pixfmt < VIDEO_CODEC_END);
1128 struct pixfmt_desc ret = { 0 };
1129 ret.depth = codec_info[pixfmt].bits_per_channel;
1130 ret.subsampling = codec_info[pixfmt].subsampling;
1131 ret.rgb = codec_info[pixfmt].rgb;
1132 return ret;
1133}
int subsampling
Decimal representation of subsampling in format 'JabA', eg. 4440 (last number is alpha),...
unsigned rgb
Whether pixelformat is RGB.
int bits_per_channel
Number of bits per color channel.
@ VIDEO_CODEC_FIRST
Definition types.h:68
@ VIDEO_CODEC_END
Definition types.h:111
static const struct codec_info_t codec_info[]

References codec_info_t::bits_per_channel, codec_info, pixfmt_desc::depth, codec_info_t::rgb, pixfmt_desc::rgb, codec_info_t::subsampling, pixfmt_desc::subsampling, VIDEO_CODEC_END, and VIDEO_CODEC_FIRST.

Referenced by get_av_to_uv_conversion(), get_available_pix_fmts(), get_best_decoder_from(), get_decoder_from_uv_to_uv(), pick_av_convertible_to_ug(), probe_internal(), probe_internal_cineform(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), QSORT_S_COMP_DEFINE(), set_convertible_formats(), to_lavc_vid_conv_init(), and video_decoder_order_output_codecs().

◆ get_subsampling()

int get_subsampling ( codec_t codec) const

◆ 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) const

◆ is_codec_opaque()

bool is_codec_opaque ( codec_t codec) const

◆ 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}
const char * name
Definition settings.cpp:193

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 ) const

◆ vc_get_linesize()

int vc_get_linesize ( unsigned int width,
codec_t codec ) const

◆ vc_get_size()

int vc_get_size ( unsigned int width,
codec_t codec ) const

◆ 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().