Skip to content

Commit

Permalink
work on multimonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorg71 committed Oct 2, 2023
1 parent 433bd92 commit d67296c
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 84 deletions.
9 changes: 4 additions & 5 deletions xorgxrdp_helper/xorgxrdp_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ xorg_process_message_61(struct xorgxrdp_info *xi, struct stream *s)
static int
gfx_wiretosurface1(struct xorgxrdp_info *xi, struct stream *s)
{
void * addr;
void *addr;
int surface_id;
int codec_id;
int pixel_format;
Expand All @@ -197,7 +197,6 @@ gfx_wiretosurface1(struct xorgxrdp_info *xi, struct stream *s)
char *flags_pointer;
char *final_pointer;

(void)flags;
(void)pixel_format;
(void)codec_id;
(void)surface_id;
Expand Down Expand Up @@ -226,7 +225,7 @@ gfx_wiretosurface1(struct xorgxrdp_info *xi, struct stream *s)
in_uint32_le(s, flags);
LOG_DEVEL(LOG_LEVEL_INFO, "gfx_wiretosurface1: surface_id %d codec_id %d "
"pixel_format %d flags %d",
surface_id, codec_id, pixel_format, flags);
surface_id, codec_id, pixel_format, flags);
in_uint16_le(s, num_rects_d);
if ((num_rects_d < 1) || (num_rects_d > 16 * 1024) ||
(!s_check_rem(s, num_rects_d * 8)))
Expand Down Expand Up @@ -315,7 +314,7 @@ xorg_process_message_62(struct xorgxrdp_info *xi, struct stream *s)
"total_cmd_bytes %d",
total_cmd_bytes);
if ((total_cmd_bytes < 1) || (total_cmd_bytes > 32 * 1024) ||
(!s_check_rem(s, total_cmd_bytes)))
(!s_check_rem(s, total_cmd_bytes)))
{
return 1;
}
Expand All @@ -335,7 +334,7 @@ xorg_process_message_62(struct xorgxrdp_info *xi, struct stream *s)
"cmd_id %d cmd_bytes %d",
cmd_id, cmd_bytes);
if ((cmd_bytes < 8) || (cmd_bytes > 32 * 1024) ||
(!s_check_rem(s, cmd_bytes - 8)))
(!s_check_rem(s, cmd_bytes - 8)))
{
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions xrdp/xrdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ server_paint_rects_ex(struct xrdp_mod *mod, int num_drects, short *drects,
int num_crects, short *crects,
char *data, int left, int top,
int width, int height,
int twidth, int theight,
int flags, int frame_id,
void *shmem_ptr, int shmem_bytes);
int
Expand Down
95 changes: 64 additions & 31 deletions xrdp/xrdp_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,13 @@ process_enc_rfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
rfxrects[index].cy = cy;
}

//g_memset(enc->u.sc.data, 0xFF, 1024 * 32);
out_data_bytes = self->max_compressed_bytes;
tiles_written = rfxcodec_encode(self->codec_handle_rfx,
out_data + XRDP_SURCMD_PREFIX_BYTES,
&out_data_bytes, enc->u.sc.data,
enc->u.sc.width, enc->u.sc.height,
enc->u.sc.width * 4,
&out_data_bytes,
enc->u.sc.data,
enc->u.sc.twidth, enc->u.sc.theight,
enc->u.sc.twidth * 4,
rfxrects, enc->u.sc.num_drects,
tiles, enc->u.sc.num_crects,
self->quants, self->num_quants);
Expand All @@ -527,8 +527,8 @@ process_enc_rfx(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
enc_done->pad_bytes = XRDP_SURCMD_PREFIX_BYTES;
enc_done->comp_pad_data = out_data;
enc_done->enc = enc;
enc_done->cx = self->mm->wm->screen->width;
enc_done->cy = self->mm->wm->screen->height;
enc_done->cx = enc->u.sc.twidth;
enc_done->cy = enc->u.sc.theight;

enc_done->continuation = all_tiles_written > 0;
if (tiles_written > 0)
Expand Down Expand Up @@ -672,16 +672,13 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
struct stream ls;
struct stream *s;
int comp_bytes_pre;
int scr_width;
int scr_height;
int session_id;
int codec_flags;

LOG(LOG_LEVEL_DEBUG, "process_enc_x264:");
LOG(LOG_LEVEL_DEBUG, "process_enc_x264: num_crects %d num_drects %d",
enc->u.sc.num_crects, enc->u.sc.num_drects);

scr_width = self->mm->wm->screen->width;
scr_height = self->mm->wm->screen->height;

fifo_processed = self->fifo_processed;
mutex = self->mutex;
event_processed = self->xrdp_encoder_event_processed;
Expand All @@ -707,8 +704,12 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
ls.data = out_data + 256;
ls.p = ls.data;

out_uint32_le(s, 0); /* flags */
out_uint32_le(s, 0); /* session id */
session_id = (enc->u.sc.flags >> 28) & 0xF;

codec_flags = 0;
s_push_layer(s, mcs_hdr, 0);
out_uint32_le(s, 0); /* flags, updated later */
out_uint32_le(s, session_id);
out_uint16_le(s, enc->u.sc.width); /* src_width */
out_uint16_le(s, enc->u.sc.height); /* src_height */
out_uint16_le(s, enc->u.sc.width); /* dst_width */
Expand All @@ -720,6 +721,8 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
y = rrects[index * 4 + 1];
cx = rrects[index * 4 + 2];
cy = rrects[index * 4 + 3];
x -= enc->u.sc.left;
y -= enc->u.sc.top;
out_uint16_le(s, x);
out_uint16_le(s, y);
out_uint16_le(s, cx);
Expand Down Expand Up @@ -748,12 +751,18 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
else
{
#if defined(XRDP_X264)
error = xrdp_encoder_x264_encode(self->codec_handle_h264, 0,
enc->u.sc.width, enc->u.sc.height, 0,
enc->u.sc.data,
s->p, &out_data_bytes);
error = xrdp_encoder_x264_encode(self->codec_handle_h264, session_id,
enc->u.sc.left, enc->u.sc.top,
enc->u.sc.width, enc->u.sc.height,
enc->u.sc.twidth, enc->u.sc.theight,
0, enc->u.sc.data, rrects, rcount,
s->p, &out_data_bytes, &codec_flags);
#endif
}
s_push_layer(s, sec_hdr, 0);
s_pop_layer(s, mcs_hdr);
out_uint32_le(s, codec_flags);
s_pop_layer(s, sec_hdr);
LOG_DEVEL(LOG_LEVEL_TRACE,
"process_enc_h264: xrdp_encoder_x264_encode rv %d "
"out_data_bytes %d width %d height %d",
Expand All @@ -768,11 +777,8 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
}
s->end = s->p + out_data_bytes;

if (s->iso_hdr != NULL)
{
s_pop_layer(s, iso_hdr);
out_uint32_le(s, out_data_bytes);
}
s_pop_layer(s, iso_hdr);
out_uint32_le(s, out_data_bytes);

#if SAVE_VIDEO
n_save_data(s->p, out_data_bytes, enc->width, enc->height);
Expand All @@ -788,8 +794,10 @@ process_enc_h264(struct xrdp_encoder *self, XRDP_ENC_DATA *enc)
enc_done->comp_pad_data = out_data;
enc_done->enc = enc;
enc_done->last = 1;
enc_done->cx = scr_width;
enc_done->cy = scr_height;
enc_done->x = enc->u.sc.left;
enc_done->y = enc->u.sc.top;
enc_done->cx = enc->u.sc.width;
enc_done->cy = enc->u.sc.height;
enc_done->frame_id = enc->u.sc.frame_id;

/* done with msg */
Expand Down Expand Up @@ -834,6 +842,8 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
short top;
short width;
short height;
short twidth;
short theight;
int bitmap_data_length;
int flags;
struct xrdp_egfx_rect *d_rects;
Expand All @@ -842,6 +852,7 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
int error;
struct stream ls;
struct stream *s;
short *crects;

if (self->codec_handle_gfx[1] == NULL)
{
Expand Down Expand Up @@ -911,6 +922,15 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
g_free(d_rects);
return NULL;
}
crects = g_new(short, num_rects_c * 4);
if (crects == NULL)
{
g_free(s->data);
g_free(c_rects);
g_free(d_rects);
return NULL;
}
g_memcpy(crects, in_s->p, num_rects_c * 2 * 4);
for (index = 0; index < num_rects_c; index++)
{
in_uint16_le(in_s, left);
Expand All @@ -922,17 +942,20 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
c_rects[index].x2 = left + width;
c_rects[index].y2 = top + height;
}
if (!s_check_rem(in_s, 8))
if (!s_check_rem(in_s, 12))
{
g_free(s->data);
g_free(c_rects);
g_free(d_rects);
g_free(crects);
return NULL;
}
in_uint16_le(in_s, left);
in_uint16_le(in_s, top);
in_uint16_le(in_s, width);
in_uint16_le(in_s, height);
in_uint16_le(in_s, twidth);
in_uint16_le(in_s, theight);
dst_rect.x1 = left;
dst_rect.y1 = top;
dst_rect.x2 = left + width;
Expand All @@ -944,6 +967,7 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
g_free(s->data);
g_free(c_rects);
g_free(d_rects);
g_free(crects);
return NULL;
}

Expand All @@ -958,23 +982,27 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
else
{
/* assume NV12 format */
if (width * height * 3 / 2 > enc_gfx_cmd->data_bytes)
if (twidth * theight * 3 / 2 > enc_gfx_cmd->data_bytes)
{
g_free(s->data);
g_free(crects);
return NULL;
}
bitmap_data_length = s_rem_out(s);
error = xrdp_encoder_x264_encode(self->codec_handle_gfx[1], 0,
width, height, 0,
left, top,
width, height, twidth, theight, 0,
enc_gfx_cmd->data,
s->p, &bitmap_data_length);
crects, num_rects_c,
s->p, &bitmap_data_length, NULL);
if (error == 0)
{
xstream_seek(s, bitmap_data_length);
}
else
{
g_free(s->data);
g_free(crects);
return NULL;
}
}
Expand All @@ -985,6 +1013,7 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
pixel_format, &dst_rect,
s->data, bitmap_data_length);
g_free(s->data);
g_free(crects);
return rv;
#else
(void)self;
Expand Down Expand Up @@ -1014,6 +1043,8 @@ gfx_wiretosurface2(struct xrdp_encoder *self,
short top;
short width;
short height;
short twidth;
short theight;
char *bitmap_data;
int bitmap_data_length;
struct rfx_tile *tiles;
Expand Down Expand Up @@ -1090,7 +1121,7 @@ gfx_wiretosurface2(struct xrdp_encoder *self,
tiles[index].quant_cb = self->quant_idx_u;
tiles[index].quant_cr = self->quant_idx_v;
}
if (!s_check_rem(in_s, 8))
if (!s_check_rem(in_s, 12))
{
g_free(tiles);
g_free(rfxrects);
Expand All @@ -1100,6 +1131,8 @@ gfx_wiretosurface2(struct xrdp_encoder *self,
in_uint16_le(in_s, top);
in_uint16_le(in_s, width);
in_uint16_le(in_s, height);
in_uint16_le(in_s, twidth);
in_uint16_le(in_s, theight);
do_free = 0;
do_send = 0;
if (ENC_IS_BIT_SET(flags, 0))
Expand All @@ -1124,8 +1157,8 @@ gfx_wiretosurface2(struct xrdp_encoder *self,
bitmap_data,
&bitmap_data_length,
enc_gfx_cmd->data,
width, height,
width * 4,
twidth, theight,
twidth * 4,
rfxrects, num_rects_d,
tiles, num_rects_c,
self->quants, self->num_quants);
Expand Down
2 changes: 2 additions & 0 deletions xrdp/xrdp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct xrdp_enc_surface_command
int top;
int width;
int height;
int twidth;
int theight;
int flags;
int frame_id;
};
Expand Down
Loading

0 comments on commit d67296c

Please sign in to comment.