Blog

Ready before the stream: a virtual display sized once per connection

By Robert Brandt, QuadChroma

Published .

Abstract

A client device, such as a phone or a tablet, describes the screen area that the picture is to fill once per connection, during the set-up exchange and before any picture is sent: its width and height in pixels, long side first. The host creates a virtual display of exactly that pixel size, waits a limited time until it is in place, and signals readiness without describing any display. Only then does the video begin. For the rest of the connection the description is neither sent again nor sent back, and how the device is held changes nothing in the connection: the picture keeps a fixed landscape position on the device's screen. A change at the host that would affect the display ends the connection with a restart message, a last message whose only content is a restart reason; the device reconnects on its own with its unchanged description, and a hold-off period kept by the host limits such restarts. When a connection ends, in whatever way, the host removes the display created for it. A different screen at the device applies from the next connection the user starts. The scale of the desktop is a setting of the host. Fallbacks cover hosts that cannot provide the display in time.

Technical field: remote access to the desktop of a host computer from phones, tablets and other client devices; preparing a virtual display on the host before a video stream starts.

Summary

A phone or tablet shows a computer's desktop most clearly when the computer draws its desktop with exactly the pixel size that the device describes: each pixel of the picture then lands on one pixel of the screen. A virtual display, a display that exists only in software, makes this possible. The hard part is timing. If the display appears only after the video has started, the video has to move to it.

This article describes how to settle the display once, at the start of each connection and before the first picture, and to keep it unchanged for the rest of the connection. Changes take effect through a new connection. The article describes the method in enough detail for a developer familiar with remote-desktop software to build it, and publishes it as prior art.

Background: host, client device and virtual display

The host is the computer whose desktop is shown; the host software is the program on it that carries out the method. The client device, in short the device, is the phone, tablet or other device that shows the desktop and operates it. The host captures the picture of one of its displays, compresses it into a video stream and sends it to the device, which sends back touch, pointer, pen and keyboard input. The method applies to remote access to a desktop as well as to desktop and game streaming.

A connection begins with a set-up exchange (a handshake): a few messages in which the two sides identify each other, agree on keys and pass initial data before any picture is sent. Every new connection, including one that the device opens on its own, begins with a new set-up exchange.

A virtual display is a display that the host's operating system treats like a connected screen, although no screen is attached. Programs draw on it, and the host captures it, like any other display. Its width and height in pixels are chosen when it is created.

Text, windows and controls are sized in points, also called logical pixels. The scale says how many pixels make one point in each direction: at 1× one pixel is one point; at 2× two pixels make one point, so everything looks larger and less fits on the screen. A display's mode is the setting it currently runs in, including its pixel size and its scale.

A display message is any message, apart from the video itself, that describes a display, for example its size, its scale or another setting. The video has the pixel size of the display it comes from; it is not a display message.

The problem

If the host's display has a different size or shape than the device's screen, the device scales the picture, which blurs it, or shows it with empty borders (black bars).

A virtual display of a requested pixel size avoids that, but it raises three questions. When is it created? If the video starts before the display is in place, the video begins on another display and then jumps. What happens when the device is turned or its screen changes? If the host's display changes while the video runs, windows move, the desktop rearranges itself, and the picture can go dark for a moment. Phones are turned often. And what should happen when something changes at the host, for example a setting that makes text larger?

The solution

The device describes its screen once per connection, during the set-up exchange. The host creates a display of exactly that pixel size before the first picture and signals readiness without describing any display. For the rest of the connection, neither side sends a display message. Every change takes effect through a new connection.

This keeps the conditions fixed for the whole connection: nothing that either side sends can make the host rebuild the desktop while it is shown.

The core of the method is the description sent once in the set-up exchange, the display in place before the first picture, and no display messages for the rest of the connection. The sections below describe the core and further elements; each further element can be added individually or in any combination with the others.

The display description

  • The display description is a short record. It holds the width W and the height H, in pixels, of the area that the picture is to fill on the device, usually the whole screen. W and H count the screen's physical pixels, not points.
  • The long side always comes first, so W is at least H. A phone whose screen has 2400 × 1080 pixels sends 2400 × 1080, whether it is held upright or sideways.
  • The device reads its screen only when the user starts a connection, and then freezes the description for that connection. Every automatic retry, including the reconnection after a restart message from the host, sends the identical description.
  • The description travels once per connection inside a set-up message that also carries other initial data, for example the name of the device. When the set-up exchange is encrypted and authenticated, so is the description.
  • In some embodiments, that is, in some ways of carrying out the method, it is an optional element in type-length-value form that also carries a format version, placed after the other data of the message, so that a host that does not know it ignores it. A description that is cut off or damaged counts as absent. If a message holds several, only the first one counts.
  • The host accepts a description only if W is at least H and both values lie within fixed limits, for example at least 200 pixels per side and at most 10 000 pixels on the long side. A square is allowed. A description in portrait is rejected; in a variant the host swaps the two values.
  • Without a valid description, the host creates no virtual display for the connection.

Before the first picture

  1. The host reads and checks the description during the set-up exchange.
  2. It decides whether to create a virtual display for the connection; the conditions are listed under "Fallbacks".
  3. It creates a virtual display of exactly W × H pixels and asks for the scale from the host's own setting.
  4. It waits until the display is in place: the operating system lists it, and its current mode has exactly W × H pixels. The host waits at most a fixed time limit, for example 2 seconds, counted from the moment it begins to prepare the display.
  5. It sets up capture so that only the new display is captured. Other displays of the host are not part of the video. How the new display is placed in relation to the host's other displays is not part of the method.
  6. It signals readiness. The ready signal is not a display message: it carries no size, no scale and no setting. In some embodiments it is a short message of its own; in others the first picture itself is the signal, and no separate message is sent.
  7. The video begins. The first picture the device receives already comes from the new display.

The device waits for readiness up to a time limit of its own, for example 15 seconds, counted from sending its set-up message; when that limit expires, it ends the attempt. The host's limit is chosen well below the device's, so that the device normally receives either the video of the new display or a fallback before it gives up.

During the connection

  • For the rest of the connection, neither side sends a display message. The device does not read its screen again and reports nothing about it; the host neither asks for a description nor confirms one.
  • During set-up the host indicates that it accepts no display descriptions during the connection; any that arrives anyway is discarded.
  • The picture keeps a fixed landscape position. It fills the device's screen with its long side along the screen's long side, however the device is held; the device's own controls may stay locked in that orientation. The desktop is never laid out anew for portrait: held upright, the device shows the landscape desktop turned by 90 degrees, always in the same direction. Input positions are mapped with the same fixed orientation. Holding the device differently changes nothing in the connection: nothing is read, sent or negotiated.
  • Nothing the device does changes the display at the host, and the host itself does not change it during the connection.

Changes at the host

A change at the host can make the display unsuitable for the connection, for example:

  • the host's user changes the setting that the host applies to the display, such as the scale;
  • a program or the system settings change the display's mode from outside;
  • another condition at the host would otherwise require creating, changing, removing or re-creating the display while the video runs, for example when the host's desktop is locked or unlocked, or when the virtual-display function is switched on or off. This includes the case where a connection runs on a fallback and the condition that prevented the display ends.

The host then does not change the display inside the running connection. Instead:

  1. It checks whether the change actually affects the display for this connection. For example, it works out what the display would become under the new condition (its pixel size and scale, or whether there would be one at all) and compares that with the current state. If the change does not affect the display, nothing happens.
  2. It sends a short restart message: the last message of the connection, whose only content is a reason meaning restart. Restart here means that the connection is set up again; neither the host nor the device is restarted. The restart message is not a display message: it carries no size, no scale and no setting.
  3. It closes the connection and removes the display.
  4. On the restart message, the device starts reconnecting on its own at once; it shows a short notice that it is reconnecting and sends its unchanged description. Each attempt is a new connection with its own set-up exchange and the device's own time limit for readiness; between attempts the device pauses briefly, for example 1 second. Reconnecting has succeeded when readiness arrives. The device keeps trying for at most a time limit, for example 1 minute, counted from the restart message; if it expires, the device shows an error and waits for the user. When the host ends a connection for another reason, for example because the host's user ended it, the device does not reconnect on its own.
  5. The host creates a new display for the new connection according to the setting then in force, or uses a fallback if a fallback condition applies.

If the host's setting changes while a connection is being set up, the host checks again right after the first picture: if the setting in force differs from the one used to create the display and the difference affects the display, it proceeds as above. A mode changed from outside is recognised whenever the operating system reports a change to the host's displays: the host then compares the display's current mode with W × H pixels and with the scale the display had at the first picture. If the operating system chose a different scale while creating the display, that scale is the starting point for this check and does not count as a change.

To prevent loops, the host sends at most one restart message per trigger within a hold-off period, for example 2 minutes, counted from its last restart message for that trigger. The host keeps these periods across connections: they belong to the host, not to a connection, so the reconnection that follows a restart message does not start them anew. The setting, outside mode changes and each other condition count as separate triggers; locking and unlocking count as separate conditions. If a trigger occurs again within the hold-off period, the connection continues and the host does not change the display; when the period has ended, the host sends the restart message, provided the change still affects the display. If the connection has ended before, the change applies with the next connection.

Changes at the device

  • The device reads the area that the picture is to fill once, when the user starts a connection. A change after that, including one before the first picture has arrived, applies from the next connection the user starts. The device never sends a second description within one connection.
  • The same holds for a different screen, for example the other screen of a foldable device or an external screen the device is connected to. The device does not read its screen again during the connection, and a different screen never causes a reconnection.

Scale at the host

  • The scale is a setting of the host, not of the device. The host offers it in steps, for example 1× and 2×, plus a default of the host software, which applies as long as the host's user has not chosen a step.
  • The display always keeps the pixel size W × H from the description; only the number of pixels per point changes. A tablet that describes 2400 × 1600 pixels gets a desktop of 2400 × 1600 points at 1× and of 1200 × 800 points at 2×.
  • The device never sends a scale. A change of the setting during a connection is handled as a change at the host.

Fallbacks

The host creates no virtual display for a connection, for example when:

  • no valid description has arrived;
  • the virtual-display function is switched off at the host, or the host's system does not allow such displays;
  • the host's desktop is locked;
  • the description lies outside the sizes the host can create or use exactly;
  • a display of this size has already once failed to be in place within the host's time limit since the host software was last started;
  • creating displays has failed a set number of times in a row, for example twice; the host then creates no more of them until the host software is next started.

If the host creates no virtual display, it sends the picture of one of its physical screens unchanged, for example the one it would show without this method, and signals readiness as usual; the device fits the picture into its screen using the size of the video itself, with borders where the shapes differ. In a variant the host ends the set-up with a notice shown on the device instead. The same fallback applies when the display is not in place within the host's time limit.

Further aspects

  • Input. Input from the device goes to the new display. The device sends positions as positions on the received picture, for example as fractions of its width and height or in its pixels; the host converts them into points on the display, taking the scale into account.
  • A physical screen of this size. Before creating a virtual display, the host may check whether one of its physical screens already runs at exactly W × H pixels in its current mode; if so, it may show that screen unchanged instead of creating a display.
  • End of a connection. When a connection ends, in whatever way, the host removes the virtual display created for it. Before the host removes a display, it stops capturing from it and directs input to another display.
  • Route. The method works the same whether the connection is direct or runs through an intermediary server.

Sequence: setting up a connection

Sequence: setting up a connectionClient device, Host. Client device: the user starts a connection, the device reads its screen once; Client device → Host: set-up message with the display description, width × height, long side first; Host: checks the description; Host: creates a virtual display of exactly width × height pixels; Host: waits until the display is in place, at most a time limit, otherwise the fallback applies; Host → Client device: ready, no display message, or the first picture serves as the signal; Host → Client device: video of the new display; Client device, Host: no display messages for the rest of the connection; Client device: the picture keeps a fixed landscape position, nothing is read or sent.the user starts a connection, the device readsits screen onceset-up message with the display description, width× height, long side firstchecks the descriptioncreates a virtual display of exactly width ×height pixelswaits until the display is in place, at most a timelimit, otherwise the fallback appliesready, no display message, or the first pictureserves as the signalvideo of the new displayno display messages for the rest of the connectionthe picture keeps a fixed landscape position,nothing is read or sentClient deviceHostSequence: setting up a connectionClient device, Host. Client device: the user starts a connection, the device reads its screen once; Client device → Host: set-up message with the display description, width × height, long side first; Host: checks the description; Host: creates a virtual display of exactly width × height pixels; Host: waits until the display is in place, at most a time limit, otherwise the fallback applies; Host → Client device: ready, no display message, or the first picture serves as the signal; Host → Client device: video of the new display; Client device, Host: no display messages for the rest of the connection; Client device: the picture keeps a fixed landscape position, nothing is read or sent.the user starts a connection,the device reads its screenonceset-up message with the displaydescription, width × height, longside firstchecks the descriptioncreates a virtual display ofexactly width × height pixelswaits until the display is inplace, at most a time limit,otherwise the fallback appliesready, no display message, orthe first picture serves as thesignalvideo of the new displayno display messages for the rest of the connectionthe picture keeps a fixedlandscape position, nothing isread or sentClient deviceHost

Sequence: a change at the host

Sequence: a change at the hostClient device, Host. Host: a change at the host would affect the display for this connection; Host → Client device: restart message, no size; Host: closes the connection and removes the display; Client device: reconnects on its own; Client device → Host: set-up message with the unchanged display description; Host: creates a display according to the setting now in force; Host → Client device: ready, no display message; Host → Client device: video of the new display.a change at the host would affect the display forthis connectionrestart message, no sizecloses the connection and removes the displayreconnects on its ownset-up message with the unchanged displaydescriptioncreates a display according to the setting now inforceready, no display messagevideo of the new displayClient deviceHostSequence: a change at the hostClient device, Host. Host: a change at the host would affect the display for this connection; Host → Client device: restart message, no size; Host: closes the connection and removes the display; Client device: reconnects on its own; Client device → Host: set-up message with the unchanged display description; Host: creates a display according to the setting now in force; Host → Client device: ready, no display message; Host → Client device: video of the new display.a change at the host wouldaffect the display for thisconnectionrestart message, no sizecloses the connection andremoves the displayreconnects on its ownset-up message with theunchanged display descriptioncreates a display according tothe setting now in forceready, no display messagevideo of the new displayClient deviceHost

Steps

On the device:

  1. When the user starts a connection, read W and H of the area the picture is to fill, long side first, and freeze them as the description.
  2. Send the description once, inside a set-up message.
  3. Wait for readiness, at most the device's time limit.
  4. Show the video in a fixed landscape position and map input with the same orientation. Send no display messages.
  5. On a restart message, reconnect on its own with the same description, for at most the reconnection time limit.

At the host:

  1. Read and check the description during set-up; without a valid one, create no virtual display for the connection.
  2. Unless a fallback condition applies, create a virtual display of exactly W × H pixels, asking for the scale from the host's setting.
  3. Wait until it is in place, at most the host's time limit; otherwise use the fallback.
  4. Signal readiness, or let the first picture serve as the signal, and start the video from the new display only.
  5. Accept no display description for the rest of the connection.
  6. If a change at the host would affect the display, send the restart message and close the connection; within the hold-off period, do so when the period has ended. Keep the hold-off periods across connections.
  7. When the connection ends, in whatever way, stop capturing from the virtual display created for it and remove it.

Keywords

virtual display; virtual monitor; virtual screen; software display; headless display; display created on demand; display of a requested pixel size; client screen size; screen resolution; landscape; long side first; fixed orientation; orientation lock; fixed orientation of the picture; input coordinate mapping; handshake; connection set-up; display description sent once per connection; frozen display description; type-length-value element; ready signal; readiness before the stream; display message; no display messages during the connection; late display descriptions discarded; host-initiated reconnection; restart message; restart reason; close reason; automatic reconnection; reconnection loop guard; hold-off period; display removed when the connection ends; host-side scale setting; scale steps; points and pixels; fallback to a physical screen; black bars; remote desktop; remote access; desktop streaming; game streaming; phone; tablet; foldable device; external screen.

Variants

The method is part of this publication in all of the following variants, individually or in any combination; in every form, no display message is sent during the connection.

  1. Where the description travels:
    • in any message of the set-up exchange before the first picture, together with other initial data such as the device name or access credentials;
    • in a separate request ahead of the picture path, the part of the connection that carries the video: the host answers only with the ready signal and a one-time token for this set-up, the device then opens the picture path with that token within a short time limit, and request and picture path together form one set-up exchange and one connection; if no picture path follows within the limit, the host removes the display;
    • over a direct connection or through an intermediary server.
  2. What the description covers: the whole screen, a window or a part of the screen; a description in portrait is rejected by the host, or the host swaps the two values.
  3. Readiness:
    • a short message of its own, or the first picture itself without a separate message;
    • the device opening the picture path only after readiness;
    • after the host's time limit, the picture of a physical screen sent unchanged, or the set-up ended with a notice shown on the device.
  4. Validity of the description: frozen for one connection; or stored on the device and read again only when the user asks for it, while still being sent with every connection.
  5. Changes at the host:
    • the connection ended with a restart message, followed by a reconnection with the unchanged description;
    • the host's user asked to confirm before the connection is ended;
    • the change noted and applied only with the next connection, without interrupting the current one.
  6. Orientation: the picture kept in one fixed position on the device's screen, turned by a multiple of 90 degrees from the screen's natural orientation so that its long side lies along the screen's long side; the device's own controls locked in that orientation or not; input positions mapped with the same fixed orientation; never a message about the orientation.
  7. Presentation at the host: scale steps such as 1×, 1.5×, 2× and 3×, with the number of points rounded to a whole number where the pixel size does not divide evenly; a text size setting; or a default of the host software; a change made elsewhere at the host taking effect with the next connection or through a restart message.
  8. Devices: phones, tablets, foldable devices with two screens, devices connected to an external screen, and any other client device.
  9. Independence of connections: each connection set up on its own, with its description valid only for it; late display descriptions discarded by the host, which indicates this during set-up.
  10. Numbers: the host waits 0.5 to 10 s for the display to be in place; the device waits 3 to 60 s for readiness, always longer than the host; the lower limit for each side of the description lies between 100 and 480 pixels, the upper limit for the long side between 4 000 and 16 000 pixels; after a separate request, the picture path follows within 1 to 60 s; after a restart message the device keeps trying to reconnect for 10 s to 10 min, pausing 0.5 to 10 s between attempts; the hold-off period lasts 10 s to 30 min, with one restart per trigger; the host stops creating displays after 1 to 10 failures in a row.

We publish the method and all of its variants: from the date above it is on public record.

Text licence: CC BY 4.0.