demux: ts: only seek on pcr for current program
[vlc.git] / modules / spu / remoteosd_rfbproto.h
blobc8ca85b017189863ffd31edf0f8dd228f51e1f89
1 /*
2 * Copyright (C) 2002 RealVNC Ltd. All Rights Reserved.
3 * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
22 * rfbproto.h - header file for the RFB protocol version 3.3
24 * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
25 * integer (for n = 8, 16 and 32).
27 * All multiple byte integers are in big endian (network) order (most
28 * significant byte first). Unless noted otherwise there is no special
29 * alignment of protocol structures.
32 * Once the initial handshaking is done, all messages start with a type byte,
33 * (usually) followed by message-specific data. The order of definitions in
34 * this file is as follows:
36 * (1) Structures used in several types of message.
37 * (2) Structures used in the initial handshaking.
38 * (3) Message types.
39 * (4) Encoding types.
40 * (5) For each message type, the form of the data following the type byte.
41 * Sometimes this is defined by a single structure but the more complex
42 * messages have to be explained by comments.
45 /*****************************************************************************
47 * Structures used in several messages
49 *****************************************************************************/
51 #include "inttypes.h"
52 #define CARD8 uint8_t
53 #define CARD16 uint16_t
54 #define CARD32 uint32_t
56 /*-----------------------------------------------------------------------------
57 * Structure used to specify a rectangle. This structure is a multiple of 4
58 * bytes so that it can be interspersed with 32-bit pixel data without
59 * affecting alignment.
61 typedef struct {
62 CARD16 x;
63 CARD16 y;
64 CARD16 w;
65 CARD16 h;
66 } rfbRectangle;
68 #define sz_rfbRectangle 8
71 /*-----------------------------------------------------------------------------
72 * Structure used to specify pixel format.
75 typedef struct {
77 CARD8 bitsPerPixel; /* 8,16,32 only */
79 CARD8 depth; /* 8 to 32 */
81 CARD8 bigEndian; /* True if multi-byte pixels are interpreted
82 as big endian, or if single-bit-per-pixel
83 has most significant bit of the byte
84 corresponding to first (leftmost) pixel. Of
85 course this is meaningless for 8 bits/pix */
87 CARD8 trueColour; /* If false then we need a "colour map" to
88 convert pixels to RGB. If true, xxxMax and
89 xxxShift specify bits used for red, green
90 and blue */
92 /* the following fields are only meaningful if trueColour is true */
94 CARD16 redMax; /* maximum red value (= 2^n - 1 where n is the
95 number of bits used for red). Note this
96 value is always in big endian order. */
98 CARD16 greenMax; /* similar for green */
100 CARD16 blueMax; /* and blue */
102 CARD8 redShift; /* number of shifts needed to get the red
103 value in a pixel to the least significant
104 bit. To find the red value from a given
105 pixel, do the following:
106 1) Swap pixel value according to bigEndian
107 (e.g. if bigEndian is false and host byte
108 order is big endian, then swap).
109 2) Shift right by redShift.
110 3) AND with redMax (in host byte order).
111 4) You now have the red value between 0 and
112 redMax. */
114 CARD8 greenShift; /* similar for green */
116 CARD8 blueShift; /* and blue */
118 CARD8 pad1;
119 CARD16 pad2;
121 } rfbPixelFormat;
123 #define sz_rfbPixelFormat 16
127 /*****************************************************************************
129 * Initial handshaking messages
131 *****************************************************************************/
133 /*-----------------------------------------------------------------------------
134 * Protocol Version
136 * The server always sends 12 bytes to start which identifies the latest RFB
137 * protocol version number which it supports. These bytes are interpreted
138 * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
139 * xxx and yyy are the major and minor version numbers (for version 3.3
140 * this is "RFB 003.003\n").
142 * The client then replies with a similar 12-byte message giving the version
143 * number of the protocol which should actually be used (which may be different
144 * to that quoted by the server).
146 * It is intended that both clients and servers may provide some level of
147 * backwards compatibility by this mechanism. Servers in particular should
148 * attempt to provide backwards compatibility, and even forwards compatibility
149 * to some extent. For example if a client demands version 3.1 of the
150 * protocol, a 3.0 server can probably assume that by ignoring requests for
151 * encoding types it doesn't understand, everything will still work OK. This
152 * will probably not be the case for changes in the major version number.
154 * The format string below can be used in sprintf or sscanf to generate or
155 * decode the version string respectively.
158 #define rfbProtocolVersionFormat "RFB %03d.%03d\n"
159 #define rfbProtocolMajorVersion 3
160 #define rfbProtocolMinorVersion 3
162 typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
164 #define sz_rfbProtocolVersionMsg 12
167 /*-----------------------------------------------------------------------------
168 * Authentication
170 * Once the protocol version has been decided, the server then sends a 32-bit
171 * word indicating whether any authentication is needed on the connection.
172 * The value of this word determines the authentication scheme in use. For
173 * version 3.0 of the protocol this may have one of the following values:
176 #define rfbConnFailed 0
177 #define rfbNoAuth 1
178 #define rfbVncAuth 2
181 * rfbConnFailed: For some reason the connection failed (e.g. the server
182 * cannot support the desired protocol version). This is
183 * followed by a string describing the reason (where a
184 * string is specified as a 32-bit length followed by that
185 * many ASCII characters).
187 * rfbNoAuth: No authentication is needed.
189 * rfbVncAuth: The VNC authentication scheme is to be used. A 16-byte
190 * challenge follows, which the client encrypts as
191 * appropriate using the password and sends the resulting
192 * 16-byte response. If the response is correct, the
193 * server sends the 32-bit word rfbVncAuthOK. If a simple
194 * failure happens, the server sends rfbVncAuthFailed and
195 * closes the connection. If the server decides that too
196 * many failures have occurred, it sends rfbVncAuthTooMany
197 * and closes the connection. In the latter case, the
198 * server should not allow an immediate reconnection by
199 * the client.
202 #define rfbVncAuthOK 0
203 #define rfbVncAuthFailed 1
204 #define rfbVncAuthTooMany 2
207 /*-----------------------------------------------------------------------------
208 * Client Initialisation Message
210 * Once the client and server are sure that they're happy to talk to one
211 * another, the client sends an initialisation message. At present this
212 * message only consists of a boolean indicating whether the server should try
213 * to share the desktop by leaving other clients connected, or give exclusive
214 * access to this client by disconnecting all other clients.
217 typedef struct {
218 CARD8 shared;
219 } rfbClientInitMsg;
221 #define sz_rfbClientInitMsg 1
224 /*-----------------------------------------------------------------------------
225 * Server Initialisation Message
227 * After the client initialisation message, the server sends one of its own.
228 * This tells the client the width and height of the server's framebuffer,
229 * its pixel format and the name associated with the desktop.
232 typedef struct {
233 CARD16 framebufferWidth;
234 CARD16 framebufferHeight;
235 rfbPixelFormat format; /* the server's preferred pixel format */
236 CARD32 nameLength;
237 /* followed by char name[nameLength] */
238 } rfbServerInitMsg;
240 #define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
244 * Following the server initialisation message it's up to the client to send
245 * whichever protocol messages it wants. Typically it will send a
246 * SetPixelFormat message and a SetEncodings message, followed by a
247 * FramebufferUpdateRequest. From then on the server will send
248 * FramebufferUpdate messages in response to the client's
249 * FramebufferUpdateRequest messages. The client should send
250 * FramebufferUpdateRequest messages with incremental set to true when it has
251 * finished processing one FramebufferUpdate and is ready to process another.
252 * With a fast client, the rate at which FramebufferUpdateRequests are sent
253 * should be regulated to avoid hogging the network.
258 /*****************************************************************************
260 * Message types
262 *****************************************************************************/
264 /* server -> client */
266 #define rfbFramebufferUpdate 0
267 #define rfbSetColourMapEntries 1
268 #define rfbBell 2
269 #define rfbServerCutText 3
270 #define rfbReSizeFrameBuffer 0xF
273 /* client -> server */
275 #define rfbSetPixelFormat 0
276 #define rfbFixColourMapEntries 1 /* not currently supported */
277 #define rfbSetEncodings 2
278 #define rfbFramebufferUpdateRequest 3
279 #define rfbKeyEvent 4
280 #define rfbPointerEvent 5
281 #define rfbClientCutText 6
282 #define rfbSetScaleFactor 0xF
287 /*****************************************************************************
289 * Encoding types
291 *****************************************************************************/
293 #define rfbEncodingRaw 0
294 #define rfbEncodingCopyRect 1
295 #define rfbEncodingRRE 2
296 #define rfbEncodingCoRRE 4
297 #define rfbEncodingHextile 5
298 #define rfbEncodingZRLE 16
302 /*****************************************************************************
304 * Server -> client message definitions
306 *****************************************************************************/
309 /*-----------------------------------------------------------------------------
310 * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
312 * This message consists of a header giving the number of rectangles of pixel
313 * data followed by the rectangles themselves. The header is padded so that
314 * together with the type byte it is an exact multiple of 4 bytes (to help
315 * with alignment of 32-bit pixels):
318 typedef struct {
319 CARD8 type; /* always rfbFramebufferUpdate */
320 CARD8 pad;
321 CARD16 nRects;
322 /* followed by nRects rectangles */
323 } rfbFramebufferUpdateMsg;
325 #define sz_rfbFramebufferUpdateMsg 4
328 * Each rectangle of pixel data consists of a header describing the position
329 * and size of the rectangle and a type word describing the encoding of the
330 * pixel data, followed finally by the pixel data. Note that if the client has
331 * not sent a SetEncodings message then it will only receive raw pixel data.
332 * Also note again that this structure is a multiple of 4 bytes.
335 typedef struct {
336 rfbRectangle r;
337 CARD32 encoding; /* one of the encoding types rfbEncoding... */
338 } rfbFramebufferUpdateRectHeader;
340 #define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
343 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
344 * Raw Encoding. Pixels are sent in top-to-bottom scanline order,
345 * left-to-right within a scanline with no padding in between.
349 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
350 * CopyRect Encoding. The pixels are specified simply by the x and y position
351 * of the source rectangle.
354 typedef struct {
355 CARD16 srcX;
356 CARD16 srcY;
357 } rfbCopyRect;
359 #define sz_rfbCopyRect 4
362 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
363 * RRE - Rise-and-Run-length Encoding. We have an rfbRREHeader structure
364 * giving the number of subrectangles following. Finally the data follows in
365 * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
366 * [<pixel><rfbRectangle>].
369 typedef struct {
370 CARD32 nSubrects;
371 } rfbRREHeader;
373 #define sz_rfbRREHeader 4
376 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
377 * CoRRE - Compact RRE Encoding. We have an rfbRREHeader structure giving
378 * the number of subrectangles following. Finally the data follows in the form
379 * [<bgpixel><subrect><subrect>...] where each <subrect> is
380 * [<pixel><rfbCoRRERectangle>]. This means that
381 * the whole rectangle must be at most 255x255 pixels.
384 typedef struct {
385 CARD8 x;
386 CARD8 y;
387 CARD8 w;
388 CARD8 h;
389 } rfbCoRRERectangle;
391 #define sz_rfbCoRRERectangle 4
394 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
395 * Hextile Encoding. The rectangle is divided up into "tiles" of 16x16 pixels,
396 * starting at the top left going in left-to-right, top-to-bottom order. If
397 * the width of the rectangle is not an exact multiple of 16 then the width of
398 * the last tile in each row will be correspondingly smaller. Similarly if the
399 * height is not an exact multiple of 16 then the height of each tile in the
400 * final row will also be smaller. Each tile begins with a "subencoding" type
401 * byte, which is a mask made up of a number of bits. If the Raw bit is set
402 * then the other bits are irrelevant; w*h pixel values follow (where w and h
403 * are the width and height of the tile). Otherwise the tile is encoded in a
404 * similar way to RRE, except that the position and size of each subrectangle
405 * can be specified in just two bytes. The other bits in the mask are as
406 * follows:
408 * BackgroundSpecified - if set, a pixel value follows which specifies
409 * the background colour for this tile. The first non-raw tile in a
410 * rectangle must have this bit set. If this bit isn't set then the
411 * background is the same as the last tile.
413 * ForegroundSpecified - if set, a pixel value follows which specifies
414 * the foreground colour to be used for all subrectangles in this tile.
415 * If this bit is set then the SubrectsColoured bit must be zero.
417 * AnySubrects - if set, a single byte follows giving the number of
418 * subrectangles following. If not set, there are no subrectangles (i.e.
419 * the whole tile is just solid background colour).
421 * SubrectsColoured - if set then each subrectangle is preceded by a pixel
422 * value giving the colour of that subrectangle. If not set, all
423 * subrectangles are the same colour, the foreground colour; if the
424 * ForegroundSpecified bit wasn't set then the foreground is the same as
425 * the last tile.
427 * The position and size of each subrectangle is specified in two bytes. The
428 * Pack macros below can be used to generate the two bytes from x, y, w, h,
429 * and the Extract macros can be used to extract the x, y, w, h values from
430 * the two bytes.
433 #define rfbHextileRaw (1 << 0)
434 #define rfbHextileBackgroundSpecified (1 << 1)
435 #define rfbHextileForegroundSpecified (1 << 2)
436 #define rfbHextileAnySubrects (1 << 3)
437 #define rfbHextileSubrectsColoured (1 << 4)
439 #define rfbHextilePackXY(x,y) (((x) << 4) | (y))
440 #define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
441 #define rfbHextileExtractX(byte) ((byte) >> 4)
442 #define rfbHextileExtractY(byte) ((byte) & 0xf)
443 #define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
444 #define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
447 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
448 * ZRLE - encoding combining Zlib compression, tiling, palettisation and
449 * run-length encoding.
452 typedef struct {
453 CARD32 length;
454 } rfbZRLEHeader;
456 #define sz_rfbZRLEHeader 4
458 #define rfbZRLETileWidth 64
459 #define rfbZRLETileHeight 64
462 /*-----------------------------------------------------------------------------
463 * SetColourMapEntries - these messages are only sent if the pixel
464 * format uses a "colour map" (i.e. trueColour false) and the client has not
465 * fixed the entire colour map using FixColourMapEntries. In addition they
466 * will only start being sent after the client has sent its first
467 * FramebufferUpdateRequest. So if the client always tells the server to use
468 * trueColour then it never needs to process this type of message.
471 typedef struct {
472 CARD8 type; /* always rfbSetColourMapEntries */
473 CARD8 pad;
474 CARD16 firstColour;
475 CARD16 nColours;
477 /* Followed by nColours * 3 * CARD16
478 r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
480 } rfbSetColourMapEntriesMsg;
482 #define sz_rfbSetColourMapEntriesMsg 6
486 /*-----------------------------------------------------------------------------
487 * Bell - ring a bell on the client if it has one.
490 typedef struct {
491 CARD8 type; /* always rfbBell */
492 } rfbBellMsg;
494 #define sz_rfbBellMsg 1
498 /*-----------------------------------------------------------------------------
499 * ServerCutText - the server has new text in its cut buffer.
502 typedef struct {
503 CARD8 type; /* always rfbServerCutText */
504 CARD8 pad1;
505 CARD16 pad2;
506 CARD32 length;
507 /* followed by char text[length] */
508 } rfbServerCutTextMsg;
510 #define sz_rfbServerCutTextMsg 8
512 /*-----------------------------------------------------------------------------
513 * ReSizeFrameBuffer - tell the RFB client to alter its framebuffer, either
514 * due to a resize of the server desktop or a client-requested scaling factor.
515 * The pixel format remains unchanged.
518 typedef struct {
519 CARD8 type; /* always rfbReSizeFrameBuffer */
520 CARD8 pad1;
521 CARD16 desktop_w; /* Desktop width */
522 CARD16 desktop_h; /* Desktop height */
523 CARD16 buffer_w; /* FrameBuffer width */
524 CARD16 buffer_h; /* Framebuffer height */
525 CARD16 pad2;
527 } rfbReSizeFrameBufferMsg;
529 #define sz_rfbReSizeFrameBufferMsg (12)
533 /*-----------------------------------------------------------------------------
534 * Union of all server->client messages.
537 typedef union {
538 CARD8 type;
539 rfbFramebufferUpdateMsg fu;
540 rfbSetColourMapEntriesMsg scme;
541 rfbBellMsg b;
542 rfbServerCutTextMsg sct;
543 rfbReSizeFrameBufferMsg rsfb;
544 } rfbServerToClientMsg;
548 /*****************************************************************************
550 * Message definitions (client -> server)
552 *****************************************************************************/
555 /*-----------------------------------------------------------------------------
556 * SetPixelFormat - tell the RFB server the format in which the client wants
557 * pixels sent.
560 typedef struct {
561 CARD8 type; /* always rfbSetPixelFormat */
562 CARD8 pad1;
563 CARD16 pad2;
564 rfbPixelFormat format;
565 } rfbSetPixelFormatMsg;
567 #define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
570 /*-----------------------------------------------------------------------------
571 * FixColourMapEntries - when the pixel format uses a "colour map", fix
572 * read-only colour map entries.
574 * ***************** NOT CURRENTLY SUPPORTED *****************
577 typedef struct {
578 CARD8 type; /* always rfbFixColourMapEntries */
579 CARD8 pad;
580 CARD16 firstColour;
581 CARD16 nColours;
583 /* Followed by nColours * 3 * CARD16
584 r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
586 } rfbFixColourMapEntriesMsg;
588 #define sz_rfbFixColourMapEntriesMsg 6
591 /*-----------------------------------------------------------------------------
592 * SetEncodings - tell the RFB server which encoding types we accept. Put them
593 * in order of preference, if we have any. We may always receive raw
594 * encoding, even if we don't specify it here.
597 typedef struct {
598 CARD8 type; /* always rfbSetEncodings */
599 CARD8 pad;
600 CARD16 nEncodings;
601 /* followed by nEncodings * CARD32 encoding types */
602 } rfbSetEncodingsMsg;
604 #define sz_rfbSetEncodingsMsg 4
606 /*-----------------------------------------------------------------------------
607 * SetScaleFactor - tell the RFB server to alter the scale factor for the
608 * client buffer.
611 typedef struct {
612 CARD8 type; /* always rfbSetScaleFactor */
613 CARD8 scale; /* Scale factor (positive non-zero integer) */
614 CARD16 pad2;
615 } rfbSetScaleFactorMsg;
617 #define sz_rfbSetScaleFactorMsg (4)
619 /*-----------------------------------------------------------------------------
620 * FramebufferUpdateRequest - request for a framebuffer update. If incremental
621 * is true then the client just wants the changes since the last update. If
622 * false then it wants the whole of the specified rectangle.
625 typedef struct {
626 CARD8 type; /* always rfbFramebufferUpdateRequest */
627 CARD8 incremental;
628 CARD16 x;
629 CARD16 y;
630 CARD16 w;
631 CARD16 h;
632 } rfbFramebufferUpdateRequestMsg;
634 #define sz_rfbFramebufferUpdateRequestMsg 10
637 /*-----------------------------------------------------------------------------
638 * KeyEvent - key press or release
640 * Keys are specified using the "keysym" values defined by the X Window System.
641 * For most ordinary keys, the keysym is the same as the corresponding ASCII
642 * value. Other common keys are:
644 * BackSpace 0xff08
645 * Tab 0xff09
646 * Return or Enter 0xff0d
647 * Escape 0xff1b
648 * Insert 0xff63
649 * Delete 0xffff
650 * Home 0xff50
651 * End 0xff57
652 * Page Up 0xff55
653 * Page Down 0xff56
654 * Left 0xff51
655 * Up 0xff52
656 * Right 0xff53
657 * Down 0xff54
658 * F1 0xffbe
659 * F2 0xffbf
660 * ... ...
661 * F12 0xffc9
662 * Shift 0xffe1
663 * Control 0xffe3
664 * Meta 0xffe7
665 * Alt 0xffe9
668 typedef struct {
669 CARD8 type; /* always rfbKeyEvent */
670 CARD8 down; /* true if down (press), false if up */
671 CARD16 pad;
672 CARD32 key; /* key is specified as an X keysym */
673 } rfbKeyEventMsg;
675 #define sz_rfbKeyEventMsg 8
678 /*-----------------------------------------------------------------------------
679 * PointerEvent - mouse/pen move and/or button press.
682 typedef struct {
683 CARD8 type; /* always rfbPointerEvent */
684 CARD8 buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */
685 CARD16 x;
686 CARD16 y;
687 } rfbPointerEventMsg;
689 #define rfbButton1Mask 1
690 #define rfbButton2Mask 2
691 #define rfbButton3Mask 4
692 #define rfbButton4Mask 8
693 #define rfbButton5Mask 16
694 #define rfbWheelUpMask rfbButton4Mask
695 #define rfbWheelDownMask rfbButton5Mask
697 #define sz_rfbPointerEventMsg 6
701 /*-----------------------------------------------------------------------------
702 * ClientCutText - the client has new text in its cut buffer.
705 typedef struct {
706 CARD8 type; /* always rfbClientCutText */
707 CARD8 pad1;
708 CARD16 pad2;
709 CARD32 length;
710 /* followed by char text[length] */
711 } rfbClientCutTextMsg;
713 #define sz_rfbClientCutTextMsg 8
715 /*-----------------------------------------------------------------------------
716 * Union of all client->server messages.
719 typedef union {
720 CARD8 type;
721 rfbSetPixelFormatMsg spf;
722 rfbSetScaleFactorMsg ssf;
723 rfbFixColourMapEntriesMsg fcme;
724 rfbSetEncodingsMsg se;
725 rfbFramebufferUpdateRequestMsg fur;
726 rfbKeyEventMsg ke;
727 rfbPointerEventMsg pe;
728 rfbClientCutTextMsg cct;
729 } rfbClientToServerMsg;