Skip to content

Commit

Permalink
Progressive RFX for EGFX protocol
Browse files Browse the repository at this point in the history
Largely a consolidation of the work by jsorg71, with a few minor bug
fixes.
  • Loading branch information
jsorg71 authored and Nexarian committed Mar 22, 2022
1 parent d8f126a commit c0e6938
Show file tree
Hide file tree
Showing 26 changed files with 1,844 additions and 65 deletions.
1 change: 1 addition & 0 deletions include/rfxcodec_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define RFX_FLAGS_OPT1 (1 << 3)
#define RFX_FLAGS_OPT2 (1 << 4)
#define RFX_FLAGS_NOACCEL (1 << 6)
#define RFX_FLAGS_PRO1 (1 << 7)

#define RFX_FLAGS_RLGR3 0 /* default */
#define RFX_FLAGS_RLGR1 1
Expand Down
4 changes: 2 additions & 2 deletions include/rfxcodec_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ typedef int (*rfxencode_differential_proc)(short *buffer, int buffer_size);
typedef int (*rfxencode_quantization_proc)(short *buffer, const char *quantization_values);
typedef int (*rfxencode_dwt_2d_proc)(const unsigned char *in_buffer, short *buffer, short *dwt_buffer);

typedef int (*rfxencode_diff_rlgr1_proc)(short *coef, unsigned char *cdata, int cdata_size);
typedef int (*rfxencode_diff_rlgr3_proc)(short *coef, unsigned char *cdata, int cdata_size);
typedef int (*rfxencode_diff_rlgr1_proc)(short *coef, unsigned char *cdata, int cdata_size, int diff_bytes);
typedef int (*rfxencode_diff_rlgr3_proc)(short *coef, unsigned char *cdata, int cdata_size, int diff_bytes);

typedef int (*rfxencode_dwt_shift_x86_sse2_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
typedef int (*rfxencode_dwt_shift_x86_sse41_proc)(const char *qtable, const unsigned char *data, short *dwt_buffer1, short *dwt_buffer);
Expand Down
8 changes: 6 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ noinst_HEADERS = \
rfxencode_tile.h \
rfxencode_diff_rlgr1.h \
rfxencode_diff_rlgr3.h \
rfxencode_rgb_to_yuv.h
rfxencode_rgb_to_yuv.h \
rfxencode_dwt_rem.h \
rfxencode_dwt_shift_rem.h

lib_LTLIBRARIES = librfxencode.la

Expand All @@ -41,4 +43,6 @@ librfxencode_la_SOURCES = $(noinst_HEADERS) rfxencode.c \
rfxencode_quantization.c rfxencode_differential.c \
rfxencode_rlgr1.c rfxencode_rlgr3.c rfxencode_alpha.c \
rfxencode_diff_rlgr1.c rfxencode_diff_rlgr3.c \
rfxencode_rgb_to_yuv.c
rfxencode_rgb_to_yuv.c \
rfxencode_dwt_rem.c \
rfxencode_dwt_shift_rem.c
8 changes: 4 additions & 4 deletions src/amd64/rfxencode_tile_amd64.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ rfx_encode_component_rlgr1_amd64_sse2(struct rfxencode *enc, const char *qtable,
{
return 1;
}
*size = rfx_encode_diff_rlgr1(enc->dwt_buffer1, buffer, buffer_size);
*size = rfx_encode_diff_rlgr1(enc->dwt_buffer1, buffer, buffer_size, 64);
return 0;
}

Expand All @@ -69,7 +69,7 @@ rfx_encode_component_rlgr3_amd64_sse2(struct rfxencode *enc, const char *qtable,
{
return 1;
}
*size = rfx_encode_diff_rlgr3(enc->dwt_buffer1, buffer, buffer_size);
*size = rfx_encode_diff_rlgr3(enc->dwt_buffer1, buffer, buffer_size, 64);
return 0;
}

Expand All @@ -85,7 +85,7 @@ rfx_encode_component_rlgr1_amd64_sse41(struct rfxencode *enc, const char *qtable
{
return 1;
}
*size = rfx_encode_diff_rlgr1(enc->dwt_buffer1, buffer, buffer_size);
*size = rfx_encode_diff_rlgr1(enc->dwt_buffer1, buffer, buffer_size, 64);
return 0;
}

Expand All @@ -101,6 +101,6 @@ rfx_encode_component_rlgr3_amd64_sse41(struct rfxencode *enc, const char *qtable
{
return 1;
}
*size = rfx_encode_diff_rlgr3(enc->dwt_buffer1, buffer, buffer_size);
*size = rfx_encode_diff_rlgr3(enc->dwt_buffer1, buffer, buffer_size, 64);
return 0;
}
3 changes: 3 additions & 0 deletions src/rfxcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ typedef struct _STREAM STREAM;
} while (0)
#endif

#define stream_read(_s, _b, _n) do { memcpy(_b, (_s)->p, _n); (_s)->p += _n; } while (0)
#define stream_write(_s, _b, _n) do { memcpy((_s)->p, _b, _n); (_s)->p += _n; } while (0)

#define stream_seek(_s, _n) (_s)->p += _n
#define stream_seek_uint8(_s) (_s)->p += 1
#define stream_seek_uint16(_s) (_s)->p += 2
Expand Down
16 changes: 16 additions & 0 deletions src/rfxconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ enum _RLGR_MODE
#define CBT_TILESET 0xCAC2
#define CBT_TILE 0xCAC3

/* progressive blockType */
#define PRO_WBT_SYNC 0xCCC0
#define PRO_WBT_FRAME_BEGIN 0xCCC1
#define PRO_WBT_FRAME_END 0xCCC2
#define PRO_WBT_CONTEXT 0xCCC3
#define PRO_WBT_REGION 0xCCC4
#define PRO_WBT_TILE_SIMPLE 0xCCC5
#define PRO_WBT_TILE_PROGRESSIVE_FIRST 0xCCC6
#define PRO_WBT_TILE_PROGRESSIVE_UPGRADE 0xCCC7

#define RFX_SUBBAND_DIFFING 0x01

#define RFX_DWT_REDUCE_EXTRAPOLATE 0x01

#define RFX_TILE_DIFFERENCE 0x01

/* tileSize */
#define CT_TILE_64x64 0x0040

Expand Down
85 changes: 84 additions & 1 deletion src/rfxencode.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ rfxcodec_encode_create_ex(int width, int height, int format, int flags,
enc->dwt_buffer = (sint16 *) (((size_t) (enc->dwt_buffer_a)) & ~15);
enc->dwt_buffer1 = (sint16 *) (((size_t) (enc->dwt_buffer1_a)) & ~15);
enc->dwt_buffer2 = (sint16 *) (((size_t) (enc->dwt_buffer2_a)) & ~15);
enc->dwt_buffer3 = (sint16 *) (((size_t) (enc->dwt_buffer3_a)) & ~15);
enc->dwt_buffer4 = (sint16 *) (((size_t) (enc->dwt_buffer4_a)) & ~15);
enc->dwt_buffer5 = (sint16 *) (((size_t) (enc->dwt_buffer5_a)) & ~15);
enc->dwt_buffer6 = (sint16 *) (((size_t) (enc->dwt_buffer6_a)) & ~15);

#if defined(RFX_USE_ACCEL_X86)
cpuid_x86(1, 0, &ax, &bx, &cx, &dx);
Expand Down Expand Up @@ -157,7 +161,11 @@ rfxcodec_encode_create_ex(int width, int height, int format, int flags,
enc->rfx_encode_rgb_to_yuv = rfx_encode_rgb_to_yuv;
enc->rfx_encode_argb_to_yuva = rfx_encode_argb_to_yuva;
/* assign encoding functions */
if (flags & RFX_FLAGS_NOACCEL)
if (flags & RFX_FLAGS_PRO1)
{
enc->pro_ver = 1;
}
else if (flags & RFX_FLAGS_NOACCEL)
{
if (enc->mode == RLGR3)
{
Expand Down Expand Up @@ -295,12 +303,21 @@ int
rfxcodec_encode_destroy(void *handle)
{
struct rfxencode *enc;
int index;
int jndex;

enc = (struct rfxencode *) handle;
if (enc == NULL)
{
return 0;
}
for (index = 0; index < 64; index++)
{
for (jndex = 0; jndex < 64; jndex++)
{
free(enc->rbs[index][jndex]);
}
}
free(enc);
return 0;
}
Expand All @@ -323,6 +340,27 @@ rfxcodec_encode_ex(void *handle, char *cdata, int *cdata_bytes,
s.p = s.data;
s.size = *cdata_bytes;

if (enc->pro_ver > 0)
{
/* Only the first frame should send the RemoteFX header */
if ((enc->frame_idx == 0) && (enc->header_processed == 0))
{
if (rfx_pro_compose_message_header(enc, &s) != 0)
{
return 1;
}
}
if (rfx_pro_compose_message_data(enc, &s, regions, num_regions,
buf, width, height, stride_bytes,
tiles, num_tiles, quants, num_quants,
flags) != 0)
{
return 1;
}
*cdata_bytes = (int) (s.p - s.data);
return 0;
}

/* Only the first frame should send the RemoteFX header */
if ((enc->frame_idx == 0) && (enc->header_processed == 0))
{
Expand Down Expand Up @@ -374,3 +412,48 @@ rfxcodec_encode_get_internals(struct rfxcodec_encode_internals *internals)
#endif
return 0;
}

/*****************************************************************************/
/* produce a hex dump */
void
rfxcodec_hexdump(const void *p, int len)
{
unsigned char *line;
int i;
int thisline;
int offset;

line = (unsigned char *)p;
offset = 0;

while (offset < len)
{
printf("%04x ", offset);
thisline = len - offset;

if (thisline > 16)
{
thisline = 16;
}

for (i = 0; i < thisline; i++)
{
printf("%02x ", line[i]);
}

for (; i < 16; i++)
{
printf(" ");
}

for (i = 0; i < thisline; i++)
{
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
}

printf("%s", "\n");
offset += thisline;
line += thisline;
}
}

28 changes: 27 additions & 1 deletion src/rfxencode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ typedef int (*rfx_encode_proc)(struct rfxencode *enc, const char *qtable,
const uint8 *data,
uint8 *buffer, int buffer_size, int *size);

struct rfx_rb
{
sint16 y[4096];
sint16 u[4096];
sint16 v[4096];
};


#define RFX_MAX_RB_X 64
#define RFX_MAX_RB_Y 64

struct rfxencode
{
int width;
Expand All @@ -44,7 +55,8 @@ struct rfxencode
int flags;
int bits_per_pixel;
int format;
int pad0[7];
int pro_ver;
int pad0[6];

uint8 a_buffer[4096];
uint8 y_r_buffer[4096];
Expand All @@ -54,13 +66,24 @@ struct rfxencode
sint16 dwt_buffer_a[4096];
sint16 dwt_buffer1_a[4096];
sint16 dwt_buffer2_a[4096];
sint16 dwt_buffer3_a[4096];
sint16 dwt_buffer4_a[4096];
sint16 dwt_buffer5_a[4096];
sint16 dwt_buffer6_a[4096];
uint8 pad2[16];
sint16 *dwt_buffer;
sint16 *dwt_buffer1;
sint16 *dwt_buffer2;
sint16 *dwt_buffer3;
sint16 *dwt_buffer4;
sint16 *dwt_buffer5;
sint16 *dwt_buffer6;
rfx_encode_proc rfx_encode;
rfx_encode_rgb_to_yuv_proc rfx_encode_rgb_to_yuv;
rfx_encode_argb_to_yuva_proc rfx_encode_argb_to_yuva;
rfx_encode_proc rfx_rem_encode;

struct rfx_rb * rbs[RFX_MAX_RB_X][RFX_MAX_RB_Y];

int got_sse2;
int got_sse3;
Expand All @@ -72,4 +95,7 @@ struct rfxencode
int got_neon;
};

void
rfxcodec_hexdump(const void *p, int len);

#endif
Loading

0 comments on commit c0e6938

Please sign in to comment.