server: proxy: remove old session capture code
This commit is contained in:
parent
67d4560e86
commit
44c50ff1d5
@ -53,8 +53,6 @@ set(${MODULE_PREFIX}_SRCS
|
|||||||
pf_cliprdr.h
|
pf_cliprdr.h
|
||||||
pf_rdpsnd.c
|
pf_rdpsnd.c
|
||||||
pf_rdpsnd.h
|
pf_rdpsnd.h
|
||||||
pf_capture.c
|
|
||||||
pf_capture.h
|
|
||||||
pf_log.h
|
pf_log.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,168 +0,0 @@
|
|||||||
/**
|
|
||||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
||||||
* FreeRDP Proxy Server Session Capture
|
|
||||||
*
|
|
||||||
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <winpr/image.h>
|
|
||||||
#include <winpr/sysinfo.h>
|
|
||||||
#include <winpr/path.h>
|
|
||||||
#include <winpr/file.h>
|
|
||||||
|
|
||||||
#include "pf_capture.h"
|
|
||||||
|
|
||||||
static BOOL pf_capture_create_dir_if_not_exists(const char* path)
|
|
||||||
{
|
|
||||||
if (PathFileExistsA(path))
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return CreateDirectoryA(path, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL pf_capture_create_user_captures_dir(const char* base_dir, const char* username)
|
|
||||||
{
|
|
||||||
int rc;
|
|
||||||
size_t size;
|
|
||||||
char* buf = NULL;
|
|
||||||
BOOL ret = FALSE;
|
|
||||||
|
|
||||||
/* create sub-directory in base captures directory for current username, if it doesn't already
|
|
||||||
* exists. */
|
|
||||||
rc = _snprintf(NULL, 0, "%s/%s", base_dir, username);
|
|
||||||
if (rc < 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
size = (size_t)rc;
|
|
||||||
|
|
||||||
buf = malloc(size + 1);
|
|
||||||
if (!buf)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
rc = sprintf(buf, "%s/%s", base_dir, username);
|
|
||||||
if (rc < 0 || (size_t)rc != size)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!pf_capture_create_dir_if_not_exists(buf))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(buf);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL pf_capture_create_current_session_captures_dir(pClientContext* pc)
|
|
||||||
{
|
|
||||||
proxyConfig* config = pc->pdata->config;
|
|
||||||
rdpSettings* settings = pc->context.settings;
|
|
||||||
const char* fmt = "%s/%s/%s_%02u-%02u-%" PRIu16 "_%02u-%02u-%02u-%03u";
|
|
||||||
int rc;
|
|
||||||
size_t size;
|
|
||||||
SYSTEMTIME localTime;
|
|
||||||
|
|
||||||
GetLocalTime(&localTime);
|
|
||||||
|
|
||||||
/* create sub-directory in current user's captures directory, for the specific session. */
|
|
||||||
rc = _snprintf(NULL, 0, fmt, config->CapturesDirectory, settings->Username,
|
|
||||||
settings->ServerHostname, localTime.wDay, localTime.wMonth, localTime.wYear,
|
|
||||||
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
|
|
||||||
|
|
||||||
if (rc < 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
size = (size_t)rc;
|
|
||||||
|
|
||||||
/* `pc->frames_dir` will be used by proxy client for saving frames to storage. */
|
|
||||||
pc->frames_dir = malloc(size + 1);
|
|
||||||
if (!pc->frames_dir)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
rc = sprintf(pc->frames_dir, fmt, config->CapturesDirectory, settings->Username,
|
|
||||||
settings->ServerHostname, localTime.wDay, localTime.wMonth, localTime.wYear,
|
|
||||||
localTime.wHour, localTime.wMinute, localTime.wSecond, localTime.wMilliseconds);
|
|
||||||
|
|
||||||
if (rc < 0 || (size_t)rc != size)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!pf_capture_create_dir_if_not_exists(pc->frames_dir))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
error:
|
|
||||||
free(pc->frames_dir);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* creates a directory to store captured session frames.
|
|
||||||
*
|
|
||||||
* @context: current session.
|
|
||||||
*
|
|
||||||
* directory path will be: base_dir/username/session-start-date.
|
|
||||||
*
|
|
||||||
* it is important to call this function only after the connection is fully established, as it uses
|
|
||||||
* settings->Username and settings->ServerHostname values to create the directory. After the
|
|
||||||
* connection established, we know that those values are valid.
|
|
||||||
*/
|
|
||||||
BOOL pf_capture_create_session_directory(pClientContext* pc)
|
|
||||||
{
|
|
||||||
proxyConfig* config = pc->pdata->config;
|
|
||||||
rdpSettings* settings = pc->context.settings;
|
|
||||||
|
|
||||||
if (!pf_capture_create_user_captures_dir(config->CapturesDirectory, settings->Username))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!pf_capture_create_current_session_captures_dir(pc))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* saves a captured frame in a BMP format. */
|
|
||||||
BOOL pf_capture_save_frame(pClientContext* pc, const BYTE* frame)
|
|
||||||
{
|
|
||||||
rdpSettings* settings = pc->context.settings;
|
|
||||||
int rc;
|
|
||||||
const char* fmt = "%s/%" PRIu64 ".bmp";
|
|
||||||
char* file_path = NULL;
|
|
||||||
size_t size;
|
|
||||||
|
|
||||||
if (!pc->frames_dir)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
rc = _snprintf(NULL, 0, fmt, pc->frames_dir, pc->frames_count++);
|
|
||||||
if (rc < 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
size = (size_t)rc;
|
|
||||||
file_path = malloc(size + 1);
|
|
||||||
if (!file_path)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
rc = sprintf(file_path, fmt, pc->frames_dir, pc->frames_count++);
|
|
||||||
if (rc < 0 || (size_t)rc != size)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
rc = winpr_bitmap_write(file_path, frame, settings->DesktopWidth, settings->DesktopHeight,
|
|
||||||
settings->ColorDepth);
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(file_path);
|
|
||||||
return rc;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
/**
|
|
||||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
||||||
* FreeRDP Proxy Server Session Capture
|
|
||||||
*
|
|
||||||
* Copyright 2019 Kobi Mizrachi <kmizrachi18@gmail.com>
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef FREERDP_SERVER_PROXY_CAPTURE_H
|
|
||||||
#define FREERDP_SERVER_PROXY_CAPTURE_H
|
|
||||||
|
|
||||||
#include "pf_context.h"
|
|
||||||
|
|
||||||
BOOL pf_capture_create_session_directory(pClientContext* context);
|
|
||||||
BOOL pf_capture_save_frame(pClientContext* pc, const BYTE* frame);
|
|
||||||
|
|
||||||
#endif /* FREERDP_SERVER_PROXY_CAPTURE_H */
|
|
@ -35,7 +35,6 @@
|
|||||||
#include "pf_update.h"
|
#include "pf_update.h"
|
||||||
#include "pf_log.h"
|
#include "pf_log.h"
|
||||||
#include "pf_modules.h"
|
#include "pf_modules.h"
|
||||||
#include "pf_capture.h"
|
|
||||||
|
|
||||||
#define TAG PROXY_TAG("client")
|
#define TAG PROXY_TAG("client")
|
||||||
|
|
||||||
@ -301,17 +300,6 @@ static BOOL pf_client_post_connect(freerdp* instance)
|
|||||||
if (!pf_modules_run_hook(HOOK_TYPE_CLIENT_POST_CONNECT, pc->pdata))
|
if (!pf_modules_run_hook(HOOK_TYPE_CLIENT_POST_CONNECT, pc->pdata))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (config->SessionCapture)
|
|
||||||
{
|
|
||||||
if (!pf_capture_create_session_directory(pc))
|
|
||||||
{
|
|
||||||
LOG_ERR(TAG, pc, "pf_capture_create_session_directory failed!");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_ERR(TAG, pc, "frames dir created: %s", pc->frames_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
|
if (!gdi_init(instance, PIXEL_FORMAT_BGRA32))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
#include "pf_modules.h"
|
#include "pf_modules.h"
|
||||||
#include "pf_update.h"
|
#include "pf_update.h"
|
||||||
#include "pf_capture.h"
|
|
||||||
#include "pf_context.h"
|
#include "pf_context.h"
|
||||||
#include "pf_log.h"
|
#include "pf_log.h"
|
||||||
|
|
||||||
@ -71,7 +70,6 @@ static BOOL pf_client_end_paint(rdpContext* context)
|
|||||||
pClientContext* pc = (pClientContext*)context;
|
pClientContext* pc = (pClientContext*)context;
|
||||||
proxyData* pdata = pc->pdata;
|
proxyData* pdata = pc->pdata;
|
||||||
rdpContext* ps = (rdpContext*)pdata->ps;
|
rdpContext* ps = (rdpContext*)pdata->ps;
|
||||||
rdpGdi* gdi = context->gdi;
|
|
||||||
|
|
||||||
WLog_DBG(TAG, __FUNCTION__);
|
WLog_DBG(TAG, __FUNCTION__);
|
||||||
|
|
||||||
@ -82,20 +80,6 @@ static BOOL pf_client_end_paint(rdpContext* context)
|
|||||||
if (!pf_modules_run_hook(HOOK_TYPE_CLIENT_END_PAINT, pdata))
|
if (!pf_modules_run_hook(HOOK_TYPE_CLIENT_END_PAINT, pdata))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!pdata->config->SessionCapture)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (gdi->suppressOutput)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (gdi->primary->hdc->hwnd->ninvalid < 1)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (!pf_capture_save_frame(pc, gdi->primary_buffer))
|
|
||||||
WLog_ERR(TAG, "failed to save captured frame!");
|
|
||||||
|
|
||||||
gdi->primary->hdc->hwnd->invalid->null = TRUE;
|
|
||||||
gdi->primary->hdc->hwnd->ninvalid = 0;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
import os
|
|
||||||
import argparse
|
|
||||||
import time
|
|
||||||
import cv2
|
|
||||||
from os.path import join, getmtime
|
|
||||||
|
|
||||||
def get_image_size(path):
|
|
||||||
img = cv2.imread(path)
|
|
||||||
height, width, _ = img.shape
|
|
||||||
return (width, height)
|
|
||||||
|
|
||||||
def generate_video(output, frames, size, fps):
|
|
||||||
out = cv2.VideoWriter(
|
|
||||||
args.output, cv2.VideoWriter_fourcc(*'DIVX'), args.fps, size)
|
|
||||||
|
|
||||||
for frame in frames:
|
|
||||||
img = cv2.imread(frame)
|
|
||||||
out.write(img)
|
|
||||||
|
|
||||||
out.release()
|
|
||||||
|
|
||||||
def main(args):
|
|
||||||
# Load input frames, sorted by creation time.
|
|
||||||
files = [join(args.input, f) for f in os.listdir(
|
|
||||||
args.input) if os.path.isfile(join(args.input, f))]
|
|
||||||
files.sort(key=lambda x: getmtime(x))
|
|
||||||
|
|
||||||
print('Generating video...')
|
|
||||||
print(f'Frame count: {len(files)}')
|
|
||||||
|
|
||||||
start = time.time()
|
|
||||||
generate_video(args.output, files, get_image_size(files[0]), args.fps)
|
|
||||||
|
|
||||||
print(
|
|
||||||
f'Output file {args.output} generated in {time.time() - start} seconds.')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
"-i", "--input", help="path to a directory containing all frames")
|
|
||||||
parser.add_argument(
|
|
||||||
"-o", "--output", help="avi output file path", default="video.avi")
|
|
||||||
parser.add_argument("-f", "--fps", type=int, help="frames per second", default=8)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
main(args)
|
|
@ -1 +0,0 @@
|
|||||||
opencv-python==4.1.0.25
|
|
Loading…
Reference in New Issue
Block a user