2016-04-17 16:20:14 +02:00
|
|
|
/****************************************************************************
|
2021-12-31 09:22:11 +01:00
|
|
|
* drivers/video/vnc/vnc_updater.c
|
2016-04-17 16:20:14 +02:00
|
|
|
*
|
2020-03-29 19:57:53 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you 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.
|
2016-04-17 16:20:14 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2016-04-20 22:05:32 +02:00
|
|
|
#include <string.h>
|
2016-04-17 16:20:14 +02:00
|
|
|
#include <sched.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <assert.h>
|
2016-04-17 20:26:03 +02:00
|
|
|
#include <errno.h>
|
2016-04-17 16:20:14 +02:00
|
|
|
|
2016-04-23 17:06:39 +02:00
|
|
|
#if defined(CONFIG_VNCSERVER_DEBUG) && !defined(CONFIG_DEBUG_GRAPHICS)
|
2016-06-11 22:14:08 +02:00
|
|
|
# undef CONFIG_DEBUG_ERROR
|
|
|
|
# undef CONFIG_DEBUG_WARN
|
2016-06-11 19:50:18 +02:00
|
|
|
# undef CONFIG_DEBUG_INFO
|
2019-03-17 18:34:45 +01:00
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_ERROR
|
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_WARN
|
|
|
|
# undef CONFIG_DEBUG_GRAPHICS_INFO
|
|
|
|
# define CONFIG_DEBUG_ERROR 1
|
|
|
|
# define CONFIG_DEBUG_WARN 1
|
|
|
|
# define CONFIG_DEBUG_INFO 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_ERROR 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_WARN 1
|
|
|
|
# define CONFIG_DEBUG_GRAPHICS_INFO 1
|
2016-04-23 17:06:39 +02:00
|
|
|
#endif
|
|
|
|
#include <debug.h>
|
|
|
|
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#ifdef VNCSERVER_SEM_DEBUG
|
|
|
|
# include <nuttx/mutex.h>
|
|
|
|
#endif
|
2022-09-25 17:08:38 +02:00
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
#include "vnc_server.h"
|
|
|
|
|
2016-04-19 23:39:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-04-23 22:27:32 +02:00
|
|
|
#undef VNCSERVER_SEM_DEBUG /* Define to dump queue/semaphore state */
|
|
|
|
#undef VNCSERVER_SEM_DEBUG_SILENT /* Define to dump only suspicious conditions */
|
2016-04-19 23:39:58 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef VNCSERVER_SEM_DEBUG
|
2022-09-06 08:18:45 +02:00
|
|
|
static mutex_t g_errlock = NXMUTEX_INITIALIZER;
|
2016-04-19 23:39:58 +02:00
|
|
|
#endif
|
|
|
|
|
2016-04-21 17:47:26 +02:00
|
|
|
/* A rectangle represent the entire local framebuffer */
|
|
|
|
|
2021-12-30 18:55:40 +01:00
|
|
|
static const struct fb_area_s g_wholescreen =
|
2016-04-21 17:47:26 +02:00
|
|
|
{
|
2021-12-30 18:55:40 +01:00
|
|
|
0, 0, CONFIG_VNCSERVER_SCREENWIDTH, CONFIG_VNCSERVER_SCREENHEIGHT
|
2016-04-21 17:47:26 +02:00
|
|
|
};
|
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-04-19 23:39:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_sem_debug
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dump information about the freesem to verify that it is sync.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - A reference to the VNC session structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-NULL structure pointer should always be returned. This function
|
|
|
|
* will wait if no structure is available.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef VNCSERVER_SEM_DEBUG
|
|
|
|
static void vnc_sem_debug(FAR struct vnc_session_s *session,
|
|
|
|
FAR const char *msg, unsigned int unattached)
|
|
|
|
{
|
|
|
|
FAR struct vnc_fbupdate_s *update;
|
2016-04-23 22:27:32 +02:00
|
|
|
int nqueued;
|
|
|
|
int nfree;
|
|
|
|
int freesem;
|
|
|
|
int queuesem;
|
|
|
|
int freecount;
|
|
|
|
int queuecount;
|
|
|
|
int freewaiting;
|
|
|
|
int queuewaiting;
|
2020-03-29 19:57:53 +02:00
|
|
|
int ret;
|
2016-04-19 23:39:58 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&g_errlock);
|
2020-03-29 19:57:53 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Should happen only on task cancellation */
|
|
|
|
|
|
|
|
DEBUGASSERT(ret == -ECANCELED);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-19 23:39:58 +02:00
|
|
|
|
|
|
|
/* Count structures in the list */
|
|
|
|
|
2016-04-23 22:27:32 +02:00
|
|
|
nqueued = sq_count(&session->updqueue);
|
|
|
|
nfree = sq_count(&session->updfree);
|
2016-04-19 23:39:58 +02:00
|
|
|
|
2016-04-23 22:27:32 +02:00
|
|
|
freesem = session->freesem.semcount;
|
|
|
|
queuesem = session->queuesem.semcount;
|
2016-04-19 23:39:58 +02:00
|
|
|
|
2016-04-23 22:27:32 +02:00
|
|
|
freecount = freesem > 0 ? freesem : 0;
|
|
|
|
queuecount = queuesem > 0 ? queuesem : 0;
|
|
|
|
|
|
|
|
freewaiting = freesem < 0 ? -freesem : 0;
|
|
|
|
queuewaiting = queuesem < 0 ? -queuesem : 0;
|
|
|
|
|
|
|
|
#ifdef VNCSERVER_SEM_DEBUG_SILENT
|
|
|
|
/* This dumps most false alarms in the case where:
|
|
|
|
*
|
|
|
|
* - Updater was waiting on a semaphore (count is -1)
|
|
|
|
* - New update added to the queue (queue count is 1)
|
|
|
|
* - queuesem posted. Wakes up Updater and the count is 0.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((nqueued + nfree) != (freecount + queuecount))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
syslog(LOG_INFO, "FREESEM DEBUG: %s\n", msg);
|
|
|
|
syslog(LOG_INFO, " Free list:\n");
|
|
|
|
syslog(LOG_INFO, " semcount: %d\n", freecount);
|
|
|
|
syslog(LOG_INFO, " queued nodes: %u\n", nfree);
|
|
|
|
syslog(LOG_INFO, " waiting: %u\n", freewaiting);
|
|
|
|
syslog(LOG_INFO, " Qeued Updates:\n");
|
|
|
|
syslog(LOG_INFO, " semcount: %d\n", queuecount);
|
|
|
|
syslog(LOG_INFO, " queued nodes: %u\n", nqueued);
|
|
|
|
syslog(LOG_INFO, " waiting: %u\n", queuewaiting);
|
|
|
|
syslog(LOG_INFO, " Unqueued: %u\n", unattached);
|
|
|
|
}
|
2016-04-19 23:39:58 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&g_errlock);
|
2016-04-19 23:39:58 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define vnc_sem_debug(s,m,u)
|
|
|
|
#endif
|
|
|
|
|
2016-04-18 00:48:30 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_alloc_update
|
|
|
|
*
|
|
|
|
* Description:
|
2016-04-19 23:39:58 +02:00
|
|
|
* Allocate one update structure by taking it from the freelist.
|
2016-04-18 00:48:30 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - A reference to the VNC session structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-NULL structure pointer should always be returned. This function
|
|
|
|
* will wait if no structure is available.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct vnc_fbupdate_s *
|
|
|
|
vnc_alloc_update(FAR struct vnc_session_s *session)
|
|
|
|
{
|
|
|
|
FAR struct vnc_fbupdate_s *update;
|
|
|
|
|
|
|
|
/* Reserve one element from the free list. Lock the scheduler to assure
|
2017-10-04 23:22:27 +02:00
|
|
|
* that the sq_remfirst() and the successful return from nxsem_wait are
|
2016-04-18 00:48:30 +02:00
|
|
|
* atomic. Of course, the scheduler will be unlocked while we wait.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
2016-04-19 23:39:58 +02:00
|
|
|
vnc_sem_debug(session, "Before alloc", 0);
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_wait_uninterruptible(&session->freesem);
|
2016-04-18 00:48:30 +02:00
|
|
|
|
|
|
|
/* It is reserved.. go get it */
|
|
|
|
|
|
|
|
update = (FAR struct vnc_fbupdate_s *)sq_remfirst(&session->updfree);
|
2016-04-19 23:39:58 +02:00
|
|
|
|
|
|
|
vnc_sem_debug(session, "After alloc", 1);
|
2016-04-18 00:48:30 +02:00
|
|
|
sched_unlock();
|
|
|
|
|
|
|
|
DEBUGASSERT(update != NULL);
|
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_free_update
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Free one update structure by returning it from the freelist.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-04-18 02:09:04 +02:00
|
|
|
* session - A reference to the VNC session structure.
|
2016-04-18 00:48:30 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2016-04-18 02:09:04 +02:00
|
|
|
* None
|
2016-04-18 00:48:30 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void vnc_free_update(FAR struct vnc_session_s *session,
|
|
|
|
FAR struct vnc_fbupdate_s *update)
|
|
|
|
{
|
|
|
|
/* Reserve one element from the free list. Lock the scheduler to assure
|
2017-10-03 23:35:24 +02:00
|
|
|
* that the sq_addlast() and the nxsem_post() are atomic.
|
2016-04-18 00:48:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
2016-04-19 23:39:58 +02:00
|
|
|
vnc_sem_debug(session, "Before free", 1);
|
2016-04-18 00:48:30 +02:00
|
|
|
|
|
|
|
/* Put the entry into the free list */
|
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)update, &session->updfree);
|
|
|
|
|
|
|
|
/* Post the semaphore to indicate the availability of one more update */
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&session->freesem);
|
2016-04-19 23:39:58 +02:00
|
|
|
|
|
|
|
vnc_sem_debug(session, "After free", 0);
|
2016-04-18 02:09:04 +02:00
|
|
|
DEBUGASSERT(session->freesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_remove_queue
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Remove one entry from the list of queued rectangles, waiting if
|
|
|
|
* necessary if the queue is empty.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - A reference to the VNC session structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2022-02-15 08:07:42 +01:00
|
|
|
* A structure pointer should always be returned. If the return value is
|
|
|
|
* NULL, that means connection lost, no frame update request anymore.
|
2016-04-18 02:09:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct vnc_fbupdate_s *
|
|
|
|
vnc_remove_queue(FAR struct vnc_session_s *session)
|
|
|
|
{
|
|
|
|
FAR struct vnc_fbupdate_s *rect;
|
|
|
|
|
|
|
|
/* Reserve one element from the list of queued rectangle. Lock the
|
|
|
|
* scheduler to assure that the sq_remfirst() and the successful return
|
2017-10-04 23:22:27 +02:00
|
|
|
* from nxsem_wait are atomic. Of course, the scheduler will be unlocked
|
2016-04-18 02:09:04 +02:00
|
|
|
* while we wait.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
2016-04-19 23:39:58 +02:00
|
|
|
vnc_sem_debug(session, "Before remove", 0);
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_wait_uninterruptible(&session->queuesem);
|
2016-04-18 02:09:04 +02:00
|
|
|
|
|
|
|
/* It is reserved.. go get it */
|
|
|
|
|
|
|
|
rect = (FAR struct vnc_fbupdate_s *)sq_remfirst(&session->updqueue);
|
2016-04-23 22:27:32 +02:00
|
|
|
|
|
|
|
vnc_sem_debug(session, "After remove", 0);
|
2022-02-15 08:07:42 +01:00
|
|
|
|
|
|
|
if (NULL == rect)
|
|
|
|
{
|
|
|
|
goto errout;
|
|
|
|
}
|
2016-04-21 20:38:36 +02:00
|
|
|
|
|
|
|
/* Check if we just removed the whole screen update from the queue */
|
|
|
|
|
|
|
|
if (session->nwhupd > 0 && rect->whupd)
|
|
|
|
{
|
|
|
|
session->nwhupd--;
|
2016-06-11 19:59:51 +02:00
|
|
|
updinfo("Whole screen update: nwhupd=%d\n", session->nwhupd);
|
2016-04-21 20:38:36 +02:00
|
|
|
}
|
2016-04-19 23:39:58 +02:00
|
|
|
|
2022-02-15 08:07:42 +01:00
|
|
|
errout:
|
2016-04-18 02:09:04 +02:00
|
|
|
sched_unlock();
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_add_queue
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add one rectangle entry to the list of queued rectangles to be updated.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2016-04-18 18:42:44 +02:00
|
|
|
* session - A reference to the VNC session structure.
|
|
|
|
* rect - The rectangle to be added to the queue.
|
2016-04-18 02:09:04 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void vnc_add_queue(FAR struct vnc_session_s *session,
|
2016-04-18 18:42:44 +02:00
|
|
|
FAR struct vnc_fbupdate_s *rect)
|
2016-04-18 02:09:04 +02:00
|
|
|
{
|
2017-10-03 23:35:24 +02:00
|
|
|
/* Lock the scheduler to assure that the sq_addlast() and the nxsem_post()
|
2016-04-18 02:09:04 +02:00
|
|
|
* are atomic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sched_lock();
|
2016-04-19 23:39:58 +02:00
|
|
|
vnc_sem_debug(session, "Before add", 1);
|
2016-04-18 02:09:04 +02:00
|
|
|
|
|
|
|
/* Put the entry into the list of queued rectangles. */
|
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)rect, &session->updqueue);
|
|
|
|
|
|
|
|
/* Post the semaphore to indicate the availability of one more rectangle
|
|
|
|
* in the queue. This may wakeup the updater.
|
|
|
|
*/
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&session->queuesem);
|
2016-04-19 23:39:58 +02:00
|
|
|
|
|
|
|
vnc_sem_debug(session, "After add", 0);
|
2016-04-18 02:09:04 +02:00
|
|
|
DEBUGASSERT(session->queuesem.semcount <= CONFIG_VNCSERVER_NUPDATES);
|
2016-04-18 00:48:30 +02:00
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
}
|
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_updater
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the "updater" thread. It is the sender of all Server-to-Client
|
|
|
|
* messages
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Standard pthread arguments.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* NULL is always returned.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR void *vnc_updater(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct vnc_session_s *session = (FAR struct vnc_session_s *)arg;
|
2016-04-18 02:09:04 +02:00
|
|
|
FAR struct vnc_fbupdate_s *srcrect;
|
2016-04-20 22:05:32 +02:00
|
|
|
int ret;
|
2021-12-22 09:59:11 +01:00
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
int val;
|
|
|
|
#endif
|
2016-04-18 18:42:44 +02:00
|
|
|
|
2016-04-19 02:55:36 +02:00
|
|
|
DEBUGASSERT(session != NULL);
|
2016-06-11 19:59:51 +02:00
|
|
|
ginfo("Updater running for Display %d\n", session->display);
|
2016-04-19 02:55:36 +02:00
|
|
|
|
2016-04-20 17:47:02 +02:00
|
|
|
/* Loop, processing updates until we are asked to stop.
|
2016-04-18 18:42:44 +02:00
|
|
|
* REVISIT: Probably need some kind of signal mechanism to wake up
|
|
|
|
* vnc_remove_queue() in order to stop. Or perhaps a special STOP
|
|
|
|
* message in the queue?
|
|
|
|
*/
|
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
while (session->state == VNCSERVER_RUNNING)
|
|
|
|
{
|
2016-04-18 02:09:04 +02:00
|
|
|
/* Get the next queued rectangle update. This call will block until an
|
2020-02-23 09:50:23 +01:00
|
|
|
* update is available for the case where the update queue is empty.
|
2016-04-18 02:09:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
srcrect = vnc_remove_queue(session);
|
2022-02-15 08:07:42 +01:00
|
|
|
|
|
|
|
/* If connect lost, exit this updater loop */
|
|
|
|
|
|
|
|
if (session->state == VNCSERVER_STOPPING)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-18 02:09:04 +02:00
|
|
|
DEBUGASSERT(srcrect != NULL);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
updinfo("Dequeued {(%d, %d),(%d, %d)}\n",
|
2021-12-30 18:55:40 +01:00
|
|
|
srcrect->rect.x, srcrect->rect.y,
|
|
|
|
srcrect->rect.w, srcrect->rect.h);
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2016-04-21 01:01:48 +02:00
|
|
|
/* Attempt to use RRE encoding */
|
2016-04-18 02:09:04 +02:00
|
|
|
|
2016-04-21 01:01:48 +02:00
|
|
|
ret = vnc_rre(session, &srcrect->rect);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Perform the framebuffer update using the default RAW encoding */
|
|
|
|
|
|
|
|
ret = vnc_raw(session, &srcrect->rect);
|
|
|
|
}
|
2016-04-18 02:09:04 +02:00
|
|
|
|
2016-04-20 22:05:32 +02:00
|
|
|
/* Release the update structure */
|
2016-04-18 02:09:04 +02:00
|
|
|
|
2016-04-20 22:05:32 +02:00
|
|
|
vnc_free_update(session, srcrect);
|
2016-04-18 02:09:04 +02:00
|
|
|
|
2021-12-22 09:59:11 +01:00
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
ret = nxsem_get_value(&session->vsyncsem, &val);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: Get vsync sem failed: %d\n", ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sq_count(&session->updqueue) == 0 && val <= 0)
|
|
|
|
{
|
|
|
|
nxsem_post(&session->vsyncsem);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-20 22:05:32 +02:00
|
|
|
/* Break out and terminate the server if the encoding failed */
|
2016-04-18 02:09:04 +02:00
|
|
|
|
2016-04-20 22:05:32 +02:00
|
|
|
if (ret < 0)
|
2016-04-18 03:23:39 +02:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
gerr("ERROR: Encoding failed: %d\n", ret);
|
2016-04-20 22:05:32 +02:00
|
|
|
break;
|
2016-04-18 02:09:04 +02:00
|
|
|
}
|
2016-04-17 16:20:14 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 18:42:44 +02:00
|
|
|
session->state = VNCSERVER_STOPPED;
|
2016-04-17 20:26:03 +02:00
|
|
|
return NULL;
|
2016-04-17 16:20:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_start_updater
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Start the updater thread
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - An instance of the session structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int vnc_start_updater(FAR struct vnc_session_s *session)
|
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
struct sched_param param;
|
|
|
|
int status;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ginfo("Starting updater for Display %d\n", session->display);
|
2016-04-19 02:55:36 +02:00
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
/* Create thread that is gonna send rectangles to the client */
|
|
|
|
|
|
|
|
session->state = VNCSERVER_RUNNING;
|
|
|
|
|
|
|
|
DEBUGVERIFY(pthread_attr_init(&attr));
|
2020-03-29 19:57:53 +02:00
|
|
|
DEBUGVERIFY(pthread_attr_setstacksize(&attr,
|
|
|
|
CONFIG_VNCSERVER_UPDATER_STACKSIZE));
|
2016-04-17 16:20:14 +02:00
|
|
|
|
|
|
|
param.sched_priority = CONFIG_VNCSERVER_UPDATER_PRIO;
|
|
|
|
DEBUGVERIFY(pthread_attr_setschedparam(&attr, ¶m));
|
|
|
|
|
|
|
|
status = pthread_create(&session->updater, &attr, vnc_updater,
|
|
|
|
(pthread_addr_t)session);
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
return -status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_stop_updater
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Stop the updater thread
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - An instance of the session structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int vnc_stop_updater(FAR struct vnc_session_s *session)
|
|
|
|
{
|
|
|
|
pthread_addr_t result;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* Is the update thread running? */
|
|
|
|
|
|
|
|
if (session->state == VNCSERVER_RUNNING)
|
|
|
|
{
|
|
|
|
/* Yes.. ask it to please stop */
|
|
|
|
|
|
|
|
session->state = VNCSERVER_STOPPING;
|
|
|
|
|
2022-02-15 08:07:42 +01:00
|
|
|
/* Notify updater thread we stopped */
|
|
|
|
|
|
|
|
nxsem_post(&session->queuesem);
|
|
|
|
|
2016-04-17 16:20:14 +02:00
|
|
|
/* Wait for the thread to comply with our request */
|
|
|
|
|
|
|
|
status = pthread_join(session->updater, &result);
|
|
|
|
if (status != 0)
|
|
|
|
{
|
|
|
|
return -status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return what the thread returned */
|
|
|
|
|
|
|
|
return (int)((intptr_t)result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not running? Just say we stopped the thread successfully. */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2016-04-17 20:26:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: vnc_update_rectangle
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Queue an update of the specified rectangular region on the display.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* session - An instance of the session structure.
|
|
|
|
* rect - The rectanglular region to be updated.
|
2016-04-23 18:22:54 +02:00
|
|
|
* change - True: Frame buffer data has changed
|
2016-04-17 20:26:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int vnc_update_rectangle(FAR struct vnc_session_s *session,
|
2021-12-30 18:55:40 +01:00
|
|
|
FAR const struct fb_area_s *rect, bool change)
|
2016-04-17 20:26:03 +02:00
|
|
|
{
|
2016-04-18 00:48:30 +02:00
|
|
|
FAR struct vnc_fbupdate_s *update;
|
2021-12-30 18:55:40 +01:00
|
|
|
struct fb_area_s intersection;
|
2016-04-21 20:38:36 +02:00
|
|
|
bool whupd;
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2021-12-30 18:55:40 +01:00
|
|
|
intersection.x = rect->x;
|
|
|
|
intersection.y = rect->y;
|
|
|
|
|
2016-04-21 17:47:26 +02:00
|
|
|
/* Clip rectangle to the screen dimensions */
|
2016-04-17 20:26:03 +02:00
|
|
|
|
2021-12-30 18:55:40 +01:00
|
|
|
if (rect->w < g_wholescreen.w)
|
|
|
|
{
|
|
|
|
intersection.w = rect->w;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intersection.w = g_wholescreen.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rect->h < g_wholescreen.h)
|
|
|
|
{
|
|
|
|
intersection.h = rect->h;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
intersection.h = g_wholescreen.h;
|
|
|
|
}
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2021-12-30 18:55:40 +01:00
|
|
|
/* Make sure that the clipped rectangle has an area */
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2021-12-30 18:55:40 +01:00
|
|
|
if (intersection.w && intersection.h)
|
2016-04-18 00:48:30 +02:00
|
|
|
{
|
2016-04-21 17:47:26 +02:00
|
|
|
/* Check for a whole screen update. The RealVNC client sends a lot
|
|
|
|
* of these (especially when it is confused)
|
|
|
|
*/
|
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
whupd = (memcmp(&intersection, &g_wholescreen,
|
2021-12-30 18:55:40 +01:00
|
|
|
sizeof(struct fb_area_s)) == 0);
|
2016-04-21 20:38:36 +02:00
|
|
|
|
2016-04-23 18:22:54 +02:00
|
|
|
/* Ignore any client update requests if there have been no changes to
|
|
|
|
* the framebuffer since the last whole screen update.
|
|
|
|
*/
|
2016-04-21 20:38:36 +02:00
|
|
|
|
2016-04-21 17:47:26 +02:00
|
|
|
sched_lock();
|
2016-04-23 18:22:54 +02:00
|
|
|
if (!change && !session->change)
|
|
|
|
{
|
|
|
|
/* No.. ignore the client update. We have nothing new to report. */
|
|
|
|
|
|
|
|
sched_unlock();
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore all updates if there is a queued whole screen update */
|
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
if (session->nwhupd == 0)
|
2016-04-21 17:47:26 +02:00
|
|
|
{
|
2016-04-23 18:22:54 +02:00
|
|
|
/* No whole screen updates in the queue. Is this a new whole
|
|
|
|
* screen update?
|
|
|
|
*/
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
if (whupd)
|
|
|
|
{
|
2016-04-23 18:22:54 +02:00
|
|
|
/* Yes.. Discard all of the previously queued updates */
|
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
FAR struct vnc_fbupdate_s *curr;
|
|
|
|
FAR struct vnc_fbupdate_s *next;
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
updinfo("New whole screen update...\n");
|
2016-04-21 17:47:26 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
curr = (FAR struct vnc_fbupdate_s *)session->updqueue.head;
|
|
|
|
sq_init(&session->updqueue);
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_reset(&session->queuesem, 0);
|
2016-04-21 20:38:36 +02:00
|
|
|
|
|
|
|
for (; curr != NULL; curr = next)
|
|
|
|
{
|
|
|
|
next = curr->flink;
|
|
|
|
vnc_free_update(session, curr);
|
|
|
|
}
|
|
|
|
|
2016-04-23 18:22:54 +02:00
|
|
|
/* One whole screen update will be queued. There have been
|
|
|
|
* no frame buffer data changes since this update was queued.
|
|
|
|
*/
|
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
session->nwhupd = 1;
|
2016-04-23 18:22:54 +02:00
|
|
|
session->change = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We are not updating the whole screen. Remember if this
|
|
|
|
* update (OR a preceding update) was due to a data change.
|
|
|
|
*/
|
|
|
|
|
|
|
|
session->change |= change;
|
2016-04-21 17:47:26 +02:00
|
|
|
}
|
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
/* Allocate an update structure... waiting if necessary */
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
update = vnc_alloc_update(session);
|
|
|
|
DEBUGASSERT(update != NULL);
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
/* Copy the clipped rectangle into the update structure */
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
update->whupd = whupd;
|
2021-12-30 18:55:40 +01:00
|
|
|
memcpy(&update->rect, &intersection, sizeof(intersection));
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2019-05-03 18:45:38 +02:00
|
|
|
/* Add the update to the end of the update queue. */
|
2016-04-21 01:01:48 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
vnc_add_queue(session, update);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
updinfo("Queued {(%d, %d),(%d, %d)}\n",
|
2021-12-30 18:55:40 +01:00
|
|
|
intersection.x, intersection.y,
|
|
|
|
intersection.w, intersection.h);
|
2016-04-21 20:38:36 +02:00
|
|
|
}
|
2016-04-18 00:48:30 +02:00
|
|
|
|
2016-04-21 20:38:36 +02:00
|
|
|
sched_unlock();
|
2016-04-18 00:48:30 +02:00
|
|
|
}
|
2016-04-17 20:26:03 +02:00
|
|
|
|
2019-05-03 18:45:38 +02:00
|
|
|
/* Since we ignore bad rectangles and wait for update structures, there is
|
2016-04-19 21:25:10 +02:00
|
|
|
* really no way a failure can occur.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
2016-04-17 20:26:03 +02:00
|
|
|
}
|