Skip to content

Commit

Permalink
assign functions for h264 encoders, indent
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorg71 committed Nov 11, 2024
1 parent febb84b commit ce7a187
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
46 changes: 17 additions & 29 deletions xrdp/xrdp_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ xrdp_encoder_create(struct xrdp_mm *mm)
/* make sure frames_in_flight is at least 1 */
self->frames_in_flight = MAX(self->frames_in_flight, 1);

#if defined(XRDP_X264)
self->xrdp_encoder_h264_create = xrdp_encoder_x264_create;
self->xrdp_encoder_h264_delete = xrdp_encoder_x264_delete;
self->xrdp_encoder_h264_encode = xrdp_encoder_x264_encode;
#endif

#if defined(XRDP_OPENH264)
self->xrdp_encoder_h264_create = xrdp_encoder_openh264_create;
self->xrdp_encoder_h264_delete = xrdp_encoder_openh264_delete;
self->xrdp_encoder_h264_encode = xrdp_encoder_openh264_encode;
#endif

/* create thread to process messages */
tc_thread_create(proc_enc_msg, self);

Expand Down Expand Up @@ -358,31 +370,17 @@ xrdp_encoder_delete(struct xrdp_encoder *self)
}
#endif

#if defined(XRDP_X264)
for (index = 0; index < 16; index++)
{
if (self->codec_handle_h264_gfx[index] != NULL)
{
xrdp_encoder_x264_delete(self->codec_handle_h264_gfx[index]);
}
}
if (self->codec_handle_h264 != NULL)
{
xrdp_encoder_x264_delete(self->codec_handle_h264);
}
#endif

#if defined(XRDP_OPENH264)
#if defined(XRDP_X264) || defined(XRDP_OPENH264)
for (index = 0; index < 16; index++)
{
if (self->codec_handle_h264_gfx[index] != NULL)
{
xrdp_encoder_openh264_delete(self->codec_handle_h264_gfx[index]);
self->xrdp_encoder_h264_delete(self->codec_handle_h264_gfx[index]);
}
}
if (self->codec_handle_h264 != NULL)
{
xrdp_encoder_openh264_delete(self->codec_handle_h264);
self->xrdp_encoder_h264_delete(self->codec_handle_h264);
}
#endif

Expand Down Expand Up @@ -919,25 +917,15 @@ gfx_wiretosurface1(struct xrdp_encoder *self,
if (self->codec_handle_h264_gfx[mon_index] == NULL)
{
self->codec_handle_h264_gfx[mon_index] =
#if defined(XRDP_X264)
xrdp_encoder_x264_create();
#endif
#if defined(XRDP_OPENH264)
xrdp_encoder_openh264_create();
#endif
self->xrdp_encoder_h264_create();
if (self->codec_handle_h264_gfx[mon_index] == NULL)
{
g_free(s->data);
g_free(crects);
return NULL;
}
}
#if defined(XRDP_X264)
error = xrdp_encoder_x264_encode(
#endif
#if defined(XRDP_OPENH264)
error = xrdp_encoder_openh264_encode(
#endif
error = self->xrdp_encoder_h264_encode(
self->codec_handle_h264_gfx[mon_index], 0,
0, 0,
width, height, twidth, theight, 0,
Expand Down
13 changes: 13 additions & 0 deletions xrdp/xrdp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

struct xrdp_enc_data;

typedef void *(*xrdp_encoder_h264_create_proc)(void);
typedef int (*xrdp_encoder_h264_delete_proc)(void *handle);
typedef int (*xrdp_encoder_h264_encode_proc)(
void *handle, int session, int left, int top,
int width, int height, int twidth, int theight,
int format, const char *data,
short *crects, int num_crects,
char *cdata, int *cdata_bytes,
int connection_type, int *flags_ptr);

/* for codec mode operations */
struct xrdp_encoder
{
Expand Down Expand Up @@ -46,6 +56,9 @@ struct xrdp_encoder
int quant_idx_y;
int quant_idx_u;
int quant_idx_v;
xrdp_encoder_h264_create_proc xrdp_encoder_h264_create;
xrdp_encoder_h264_delete_proc xrdp_encoder_h264_delete;
xrdp_encoder_h264_encode_proc xrdp_encoder_h264_encode;
};

/* cmd_id = 0 */
Expand Down
26 changes: 13 additions & 13 deletions xrdp/xrdp_encoder_openh264.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) Jay Sorg 2016-2024
* Copyright (C) Christopher Pitstick 2023-2024
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -50,7 +50,7 @@ struct openh264_global
{
struct openh264_encoder encoders[OPENH264_MAX_ENCODERS];
struct xrdp_tconfig_gfx_openh264_param
openh264_param[NUM_CONNECTION_TYPES];
openh264_param[NUM_CONNECTION_TYPES];
};

/*****************************************************************************/
Expand All @@ -65,7 +65,7 @@ xrdp_encoder_openh264_create(void)
tconfig_load_gfx(GFX_CONF, &gfxconfig);
memcpy(&og->openh264_param, &gfxconfig.openh264_param,
sizeof(struct xrdp_tconfig_gfx_openh264_param) *
NUM_CONNECTION_TYPES);
NUM_CONNECTION_TYPES);
return og;

}
Expand Down Expand Up @@ -163,12 +163,12 @@ xrdp_encoder_openh264_encode(void *handle, int session, int left, int top,
{
LOG(LOG_LEVEL_ERROR, "Failed to create H.264 encoder");
return 1;
}
}
LOG(LOG_LEVEL_INFO, "xrdp_encoder_openh264_encode: "
"WelsCreateSVCEncoder rv %p for width %d height %d",
oe->openh264_enc_han, width, height);
status = (*oe->openh264_enc_han)->GetDefaultParams(
oe->openh264_enc_han, &encParamExt);
oe->openh264_enc_han, &encParamExt);
LOG(LOG_LEVEL_INFO, "xrdp_encoder_openh264_encode: "
"GetDefaultParams rv %d", status);
if (status == 0)
Expand All @@ -186,7 +186,7 @@ xrdp_encoder_openh264_encode(void *handle, int session, int left, int top,
slc->iSpatialBitrate = encParamExt.iTargetBitrate;
slc->iMaxSpatialBitrate = encParamExt.iMaxBitrate;
status = (*oe->openh264_enc_han)->InitializeExt(
oe->openh264_enc_han, &encParamExt);
oe->openh264_enc_han, &encParamExt);
LOG(LOG_LEVEL_INFO, "xrdp_encoder_openh264_encode: "
"InitializeExt rv %d", status);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ xrdp_encoder_openh264_encode(void *handle, int session, int left, int top,
pic1.pData[0] = (unsigned char *) (oe->yuvdata);
pic1.pData[1] = pic1.pData[0] + pic1.iPicWidth * pic1.iPicHeight;
pic1.pData[2] = pic1.pData[1] + (pic1.iPicWidth / 2) *
(pic1.iPicHeight / 2);
(pic1.iPicHeight / 2);
for (index = 0; index < num_crects; index++)
{
src8 = data;
Expand Down Expand Up @@ -265,17 +265,17 @@ xrdp_encoder_openh264_encode(void *handle, int session, int left, int top,
}
g_memset(&info, 0, sizeof(info));
status = (*oe->openh264_enc_han)->EncodeFrame(oe->openh264_enc_han,
&pic1, &info);
&pic1, &info);
if (status != 0)
{
LOG(LOG_LEVEL_INFO, "Failed to encode frame");
return 3;
}
if (info.eFrameType == videoFrameTypeSkip)
{
LOG(LOG_LEVEL_INFO, "frame was skipped!");
return 4;
}
LOG(LOG_LEVEL_INFO, "frame was skipped!");
return 4;
}
lcdata_bytes = 0;
for (index = 0; index < info.iLayerNum; index++)
{
Expand All @@ -284,8 +284,8 @@ xrdp_encoder_openh264_encode(void *handle, int session, int left, int top,
for (jndex = 0; jndex < layer->iNalCount; jndex++)
{
write_location = cdata + lcdata_bytes;
payload = layer->pBsBuf + layer_position;
size = layer->pNalLengthInByte[jndex];
payload = layer->pBsBuf + layer_position;
size = layer->pNalLengthInByte[jndex];
g_memcpy(write_location, payload, size);
layer_position += size;
lcdata_bytes += size;
Expand Down
2 changes: 1 addition & 1 deletion xrdp/xrdp_tconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct xrdp_tconfig_gfx
/* store x264 parameters for each connection type */
struct xrdp_tconfig_gfx_x264_param x264_param[NUM_CONNECTION_TYPES];
struct xrdp_tconfig_gfx_openh264_param
openh264_param[NUM_CONNECTION_TYPES];
openh264_param[NUM_CONNECTION_TYPES];
};

static const char *const rdpbcgr_connection_type_names[] =
Expand Down

0 comments on commit ce7a187

Please sign in to comment.