2014-05-26 11:01:13 +04:00
|
|
|
/*
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* Video Redirection Virtual Channel - GStreamer Decoder X11 specifics
|
|
|
|
*
|
|
|
|
* (C) Copyright 2014 Thincast Technologies GmbH
|
|
|
|
* (C) Copyright 2014 Armin Novak <armin.novak@thincast.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.
|
2019-11-06 17:24:51 +03:00
|
|
|
*/
|
2014-05-26 11:01:13 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
2017-02-10 18:06:20 +03:00
|
|
|
#ifndef __CYGWIN__
|
2014-05-23 15:46:37 +04:00
|
|
|
#include <sys/syscall.h>
|
2017-02-10 18:06:20 +03:00
|
|
|
#endif
|
2014-05-23 15:46:37 +04:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2015-03-17 05:10:58 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2014-05-23 15:46:37 +04:00
|
|
|
#include <winpr/thread.h>
|
2015-07-03 14:26:15 +03:00
|
|
|
#include <winpr/string.h>
|
2014-05-23 15:46:37 +04:00
|
|
|
|
2017-08-29 10:09:38 +03:00
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wparentheses-equality"
|
|
|
|
#endif /* __clang__ */
|
2014-05-25 00:22:33 +04:00
|
|
|
#include <gst/gst.h>
|
2017-08-29 10:09:38 +03:00
|
|
|
#if __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif /* __clang__ */
|
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2014-05-23 15:46:37 +04:00
|
|
|
#include <gst/video/videooverlay.h>
|
2014-05-25 00:22:33 +04:00
|
|
|
#else
|
|
|
|
#include <gst/interfaces/xoverlay.h>
|
|
|
|
#endif
|
2014-05-23 15:46:37 +04:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/Xrandr.h>
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
|
|
|
|
#include <freerdp/channels/tsmf.h>
|
|
|
|
|
|
|
|
#include "tsmf_platform.h"
|
|
|
|
#include "tsmf_constants.h"
|
|
|
|
#include "tsmf_decoder.h"
|
|
|
|
|
|
|
|
#if !defined(WITH_XEXT)
|
|
|
|
#warning "Building TSMF without shape extension support"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct X11Handle
|
|
|
|
{
|
|
|
|
int shmid;
|
2019-11-06 17:24:51 +03:00
|
|
|
int* xfwin;
|
2014-05-23 15:46:37 +04:00
|
|
|
#if defined(WITH_XEXT)
|
|
|
|
BOOL has_shape;
|
|
|
|
#endif
|
2019-11-06 17:24:51 +03:00
|
|
|
Display* disp;
|
2014-05-23 15:46:37 +04:00
|
|
|
Window subwin;
|
2015-07-08 00:39:29 +03:00
|
|
|
BOOL subwinMapped;
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
GstVideoOverlay* overlay;
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
GstXOverlay* overlay;
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
int subwinWidth;
|
|
|
|
int subwinHeight;
|
|
|
|
int subwinX;
|
|
|
|
int subwinY;
|
2014-05-23 15:46:37 +04:00
|
|
|
};
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
static const char* get_shm_id()
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-03-17 05:10:58 +03:00
|
|
|
static char shm_id[128];
|
2015-07-03 14:26:15 +03:00
|
|
|
sprintf_s(shm_id, sizeof(shm_id), "/com.freerdp.xfreerdp.tsmf_%016X", GetCurrentProcessId());
|
2014-05-23 15:46:37 +04:00
|
|
|
return shm_id;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static GstBusSyncReply tsmf_platform_bus_sync_handler(GstBus* bus, GstMessage* message,
|
|
|
|
gpointer user_data)
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
struct X11Handle* hdl;
|
|
|
|
|
|
|
|
TSMFGstreamerDecoder* decoder = user_data;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_ELEMENT)
|
2015-07-08 00:39:29 +03:00
|
|
|
return GST_BUS_PASS;
|
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gst_is_video_overlay_prepare_window_handle_message(message))
|
2015-07-08 21:10:21 +03:00
|
|
|
return GST_BUS_PASS;
|
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gst_structure_has_name(message->structure, "prepare-xwindow-id"))
|
2015-07-08 00:39:29 +03:00
|
|
|
return GST_BUS_PASS;
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
if (hdl->subwin)
|
|
|
|
{
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl->overlay = GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(message));
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_video_overlay_set_window_handle(hdl->overlay, hdl->subwin);
|
2019-06-18 14:43:44 +03:00
|
|
|
gst_video_overlay_handle_events(hdl->overlay, FALSE);
|
2015-07-08 00:39:29 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl->overlay = GST_X_OVERLAY(GST_MESSAGE_SRC(message));
|
|
|
|
#if GST_CHECK_VERSION(0, 10, 31)
|
2015-07-08 21:10:21 +03:00
|
|
|
gst_x_overlay_set_window_handle(hdl->overlay, hdl->subwin);
|
2017-06-27 18:12:23 +03:00
|
|
|
#else
|
|
|
|
gst_x_overlay_set_xwindow_id(hdl->overlay, hdl->subwin);
|
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
gst_x_overlay_handle_events(hdl->overlay, TRUE);
|
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (hdl->subwinWidth != -1 && hdl->subwinHeight != -1 && hdl->subwinX != -1 &&
|
|
|
|
hdl->subwinY != -1)
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->subwinWidth,
|
|
|
|
hdl->subwinHeight))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not resize overlay!");
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_video_overlay_expose(hdl->overlay);
|
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!gst_x_overlay_set_render_rectangle(hdl->overlay, 0, 0, hdl->subwinWidth,
|
|
|
|
hdl->subwinHeight))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not resize overlay!");
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_x_overlay_expose(hdl->overlay);
|
|
|
|
#endif
|
2015-09-16 20:46:45 +03:00
|
|
|
XLockDisplay(hdl->disp);
|
2019-11-06 17:24:51 +03:00
|
|
|
XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth,
|
|
|
|
hdl->subwinHeight);
|
2015-07-08 00:39:29 +03:00
|
|
|
XSync(hdl->disp, FALSE);
|
2015-09-16 20:46:45 +03:00
|
|
|
XUnlockDisplay(hdl->disp);
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning("Window was not available before retrieving the overlay!");
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_message_unref(message);
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
return GST_BUS_DROP;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
const char* tsmf_platform_get_video_sink(void)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
return "autovideosink";
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
const char* tsmf_platform_get_audio_sink(void)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
|
|
|
return "autoaudiosink";
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_platform_create(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
struct X11Handle* hdl;
|
|
|
|
|
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (decoder->platform)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
hdl = calloc(1, sizeof(struct X11Handle));
|
2014-05-25 00:22:33 +04:00
|
|
|
if (!hdl)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Could not allocate handle.");
|
2014-05-23 15:46:37 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
decoder->platform = hdl;
|
2015-03-17 05:10:58 +03:00
|
|
|
hdl->shmid = shm_open(get_shm_id(), (O_RDWR | O_CREAT), (PROT_READ | PROT_WRITE));
|
2015-05-02 06:26:08 +03:00
|
|
|
if (hdl->shmid == -1)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "failed to get access to shared memory - shmget(%s): %i - %s", get_shm_id(),
|
|
|
|
errno, strerror(errno));
|
2014-05-23 15:46:37 +04:00
|
|
|
return -2;
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl->xfwin = mmap(0, sizeof(void*), PROT_READ | PROT_WRITE, MAP_SHARED, hdl->shmid, 0);
|
2015-05-02 06:26:08 +03:00
|
|
|
if (hdl->xfwin == MAP_FAILED)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "shmat failed!");
|
2014-05-23 15:46:37 +04:00
|
|
|
return -3;
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
hdl->disp = XOpenDisplay(NULL);
|
2014-05-25 00:22:33 +04:00
|
|
|
if (!hdl->disp)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Failed to open display");
|
2014-05-23 15:46:37 +04:00
|
|
|
return -4;
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
hdl->subwinMapped = FALSE;
|
|
|
|
hdl->subwinX = -1;
|
|
|
|
hdl->subwinY = -1;
|
|
|
|
hdl->subwinWidth = -1;
|
|
|
|
hdl->subwinHeight = -1;
|
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_platform_set_format(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (decoder->media_type == TSMF_MAJOR_TYPE_VIDEO)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_platform_register_handler(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
GstBus* bus;
|
|
|
|
|
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!decoder->pipe)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus(GST_PIPELINE(decoder->pipe));
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_bus_set_sync_handler(bus, (GstBusSyncHandler)tsmf_platform_bus_sync_handler, decoder, NULL);
|
2015-07-08 21:10:21 +03:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_bus_set_sync_handler(bus, (GstBusSyncHandler)tsmf_platform_bus_sync_handler, decoder);
|
2015-07-08 21:10:21 +03:00
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
if (!bus)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "gst_pipeline_get_bus failed!");
|
2014-05-23 15:46:37 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
gst_object_unref(bus);
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_platform_free(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
struct X11Handle* hdl = decoder->platform;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (!hdl)
|
2014-05-23 15:46:37 +04:00
|
|
|
return -1;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (hdl->disp)
|
2014-05-23 15:46:37 +04:00
|
|
|
XCloseDisplay(hdl->disp);
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (hdl->xfwin)
|
2014-11-10 22:02:54 +03:00
|
|
|
munmap(0, sizeof(void*));
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (hdl->shmid >= 0)
|
2014-05-23 15:46:37 +04:00
|
|
|
close(hdl->shmid);
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
free(hdl);
|
|
|
|
decoder->platform = NULL;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_window_create(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
struct X11Handle* hdl;
|
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
if (decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
|
|
|
decoder->ready = TRUE;
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!decoder->platform)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (!hdl->subwin)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-09-16 20:46:45 +03:00
|
|
|
XLockDisplay(hdl->disp);
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl->subwin = XCreateSimpleWindow(hdl->disp, *(int*)hdl->xfwin, 0, 0, 1, 1, 0, 0, 0);
|
2015-09-16 20:46:45 +03:00
|
|
|
XUnlockDisplay(hdl->disp);
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (!hdl->subwin)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Could not create subwindow!");
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
tsmf_window_map(decoder);
|
|
|
|
|
|
|
|
decoder->ready = TRUE;
|
|
|
|
#if defined(WITH_XEXT)
|
2019-11-06 17:24:51 +03:00
|
|
|
int event, error;
|
|
|
|
XLockDisplay(hdl->disp);
|
|
|
|
hdl->has_shape = XShapeQueryExtension(hdl->disp, &event, &error);
|
|
|
|
XUnlockDisplay(hdl->disp);
|
2014-05-25 00:22:33 +04:00
|
|
|
#endif
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2015-07-08 00:39:29 +03:00
|
|
|
|
|
|
|
return 0;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, int height,
|
|
|
|
int nr_rects, RDP_RECT* rects)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
struct X11Handle* hdl;
|
|
|
|
|
2017-01-26 12:44:19 +03:00
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
2014-05-25 00:22:33 +04:00
|
|
|
if (decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
|
2014-11-10 22:02:54 +03:00
|
|
|
{
|
2014-05-23 15:46:37 +04:00
|
|
|
return -3;
|
2014-11-10 22:02:54 +03:00
|
|
|
}
|
2015-06-29 16:21:53 +03:00
|
|
|
|
|
|
|
if (!decoder->platform)
|
|
|
|
return -1;
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2015-06-29 16:21:53 +03:00
|
|
|
DEBUG_TSMF("resize: x=%d, y=%d, w=%d, h=%d", x, y, width, height);
|
2014-11-10 22:02:54 +03:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
if (hdl->overlay)
|
|
|
|
{
|
2014-05-25 00:22:33 +04:00
|
|
|
#if GST_VERSION_MAJOR > 0
|
|
|
|
|
2015-09-03 20:58:16 +03:00
|
|
|
if (!gst_video_overlay_set_render_rectangle(hdl->overlay, 0, 0, width, height))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not resize overlay!");
|
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-09-03 20:58:16 +03:00
|
|
|
gst_video_overlay_expose(hdl->overlay);
|
2014-05-25 00:22:33 +04:00
|
|
|
#else
|
2015-09-03 20:58:16 +03:00
|
|
|
if (!gst_x_overlay_set_render_rectangle(hdl->overlay, 0, 0, width, height))
|
2015-07-08 00:39:29 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Could not resize overlay!");
|
|
|
|
}
|
2014-05-25 01:21:05 +04:00
|
|
|
|
2015-09-03 20:58:16 +03:00
|
|
|
gst_x_overlay_expose(hdl->overlay);
|
2014-05-25 00:22:33 +04:00
|
|
|
#endif
|
2015-07-08 00:39:29 +03:00
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-06-29 16:21:53 +03:00
|
|
|
if (hdl->subwin)
|
|
|
|
{
|
2015-07-08 00:39:29 +03:00
|
|
|
hdl->subwinX = x;
|
|
|
|
hdl->subwinY = y;
|
|
|
|
hdl->subwinWidth = width;
|
|
|
|
hdl->subwinHeight = height;
|
2015-09-16 20:46:45 +03:00
|
|
|
|
|
|
|
XLockDisplay(hdl->disp);
|
2019-11-06 17:24:51 +03:00
|
|
|
XMoveResizeWindow(hdl->disp, hdl->subwin, hdl->subwinX, hdl->subwinY, hdl->subwinWidth,
|
|
|
|
hdl->subwinHeight);
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-09-16 20:46:45 +03:00
|
|
|
/* Unmap the window if there are no visibility rects */
|
|
|
|
if (nr_rects == 0)
|
|
|
|
tsmf_window_unmap(decoder);
|
|
|
|
else
|
|
|
|
tsmf_window_map(decoder);
|
|
|
|
|
|
|
|
#if defined(WITH_XEXT)
|
2015-06-29 16:21:53 +03:00
|
|
|
if (hdl->has_shape)
|
|
|
|
{
|
|
|
|
int i;
|
2019-11-06 17:24:51 +03:00
|
|
|
XRectangle* xrects = NULL;
|
2015-06-29 16:21:53 +03:00
|
|
|
|
2015-09-16 20:46:45 +03:00
|
|
|
if (nr_rects == 0)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-09-16 20:46:45 +03:00
|
|
|
xrects = calloc(1, sizeof(XRectangle));
|
|
|
|
xrects->x = x;
|
|
|
|
xrects->y = y;
|
|
|
|
xrects->width = width;
|
|
|
|
xrects->height = height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xrects = calloc(nr_rects, sizeof(XRectangle));
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2015-09-16 20:46:45 +03:00
|
|
|
if (xrects)
|
|
|
|
{
|
|
|
|
for (i = 0; i < nr_rects; i++)
|
|
|
|
{
|
|
|
|
xrects[i].x = rects[i].x - x;
|
|
|
|
xrects[i].y = rects[i].y - y;
|
|
|
|
xrects[i].width = rects[i].width;
|
|
|
|
xrects[i].height = rects[i].height;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XShapeCombineRectangles(hdl->disp, hdl->subwin, ShapeBounding, x, y, xrects,
|
|
|
|
nr_rects, ShapeSet, 0);
|
2015-09-16 20:46:45 +03:00
|
|
|
free(xrects);
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
|
|
|
}
|
2015-06-29 16:21:53 +03:00
|
|
|
#endif
|
|
|
|
XSync(hdl->disp, FALSE);
|
2015-09-16 20:46:45 +03:00
|
|
|
XUnlockDisplay(hdl->disp);
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2015-06-29 16:21:53 +03:00
|
|
|
|
|
|
|
return 0;
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
int tsmf_window_map(TSMFGstreamerDecoder* decoder)
|
|
|
|
{
|
|
|
|
struct X11Handle* hdl;
|
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* Only need to map the window if it is not currently mapped */
|
2015-07-08 00:39:29 +03:00
|
|
|
if ((hdl->subwin) && (!hdl->subwinMapped))
|
|
|
|
{
|
|
|
|
XLockDisplay(hdl->disp);
|
|
|
|
XMapWindow(hdl->disp, hdl->subwin);
|
|
|
|
hdl->subwinMapped = TRUE;
|
|
|
|
XSync(hdl->disp, FALSE);
|
|
|
|
XUnlockDisplay(hdl->disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tsmf_window_unmap(TSMFGstreamerDecoder* decoder)
|
|
|
|
{
|
|
|
|
struct X11Handle* hdl;
|
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2015-07-08 00:39:29 +03:00
|
|
|
|
2015-07-08 21:10:21 +03:00
|
|
|
/* only need to unmap window if it is currently mapped */
|
2015-07-08 00:39:29 +03:00
|
|
|
if ((hdl->subwin) && (hdl->subwinMapped))
|
|
|
|
{
|
|
|
|
XLockDisplay(hdl->disp);
|
|
|
|
XUnmapWindow(hdl->disp, hdl->subwin);
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl->subwinMapped = FALSE;
|
|
|
|
XSync(hdl->disp, FALSE);
|
2015-07-08 00:39:29 +03:00
|
|
|
XUnlockDisplay(hdl->disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
int tsmf_window_destroy(TSMFGstreamerDecoder* decoder)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2014-11-10 22:02:54 +03:00
|
|
|
struct X11Handle* hdl;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!decoder)
|
|
|
|
return -1;
|
|
|
|
|
2017-02-17 14:52:21 +03:00
|
|
|
decoder->ready = FALSE;
|
|
|
|
|
2017-01-26 12:44:19 +03:00
|
|
|
if (decoder->media_type != TSMF_MAJOR_TYPE_VIDEO)
|
|
|
|
return -3;
|
|
|
|
|
2014-11-10 22:02:54 +03:00
|
|
|
if (!decoder->platform)
|
|
|
|
return -1;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hdl = (struct X11Handle*)decoder->platform;
|
2014-05-25 00:22:33 +04:00
|
|
|
|
|
|
|
if (hdl->subwin)
|
2014-05-23 15:46:37 +04:00
|
|
|
{
|
2015-09-16 20:46:45 +03:00
|
|
|
XLockDisplay(hdl->disp);
|
2014-05-23 15:46:37 +04:00
|
|
|
XDestroyWindow(hdl->disp, hdl->subwin);
|
|
|
|
XSync(hdl->disp, FALSE);
|
2015-09-16 20:46:45 +03:00
|
|
|
XUnlockDisplay(hdl->disp);
|
2014-05-23 15:46:37 +04:00
|
|
|
}
|
2014-05-25 00:22:33 +04:00
|
|
|
|
2015-07-08 00:39:29 +03:00
|
|
|
hdl->overlay = NULL;
|
2014-05-23 15:46:37 +04:00
|
|
|
hdl->subwin = 0;
|
2015-07-08 00:39:29 +03:00
|
|
|
hdl->subwinMapped = FALSE;
|
|
|
|
hdl->subwinX = -1;
|
|
|
|
hdl->subwinY = -1;
|
|
|
|
hdl->subwinWidth = -1;
|
|
|
|
hdl->subwinHeight = -1;
|
2014-05-23 15:46:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|