Documentation
¶
Overview ¶
Package codec implements the bitmap codecs that RDP servers use to encode bitmap update and surface command payloads.
A compressed bitmap update whose flags say the payload is codec-encoded begins with a one byte codec id (MS-RDPBCGR 2.2.9.1.1.3.1.2.2). Codec id zero means the payload is plain RLE; the other ids select an implementation in this package.
Index ¶
- Constants
- Variables
- func DecodeRFX(data []byte, width, height int, mode RLGRMode) ([]byte, error)
- func Decompress(codecID uint8, data []byte, width, height, bpp int) ([]byte, error)
- func NSCodec(data []byte, width, height int) ([]byte, error)
- type AVCAccessUnit
- type AVCQuantQuality
- type AVCStream
- type RLGRMode
- type RegionRect
- type ZGFX
Constants ¶
const ( CodecIDNone = 0x00 // data is not encoded CodecIDNSCODEC = 0x01 CodecIDRemoteFX = 0x03 CodecIDImageRemoteFX = 0x04 CodecIDX264 = 0x05 CodecIDX264Image = 0x06 )
Bitmap codec ids (MS-RDPBCGR 2.2.9.2.1.1, TS_BITMAP_DATA_EX.codecID).
Variables ¶
var ErrUnsupported = errors.New("codec: unsupported bitmap codec")
ErrUnsupported reports a codec id this package cannot decode yet.
var RFXMode = RLGR1
RFXMode is the entropy coder used for RemoteFX payloads. RemoteFX data does not say which coder it used, so this has to match what was negotiated: a client advertises both ICAPs and the server picks one. RLGR1 is the safer default because every server supports it.
Change it before decoding if the session negotiated RLGR3.
Functions ¶
func DecodeRFX ¶
DecodeRFX decodes a RemoteFX message (MS-RDPRFX) and returns the pixels as BGRA, top-down, matching the other decoders in this package.
width and height describe the destination surface; tiles are clipped to it and to the rectangles the message declares.
func Decompress ¶
Decompress decodes a codec-encoded bitmap payload. codecID comes from TS_BITMAP_DATA_EX, or from the header of a cache bitmap revision 3 or EGFX surface command. A codec id of none means the payload is already raw pixels and is returned unchanged.
The result is BGRA unless the codec documents otherwise. Callers that only need to display the pixels should treat a nil error as "bpp is now 32".
func NSCodec ¶
NSCodec decodes a bitmap compressed with NSCodec (MS-RDPNSC).
The encoded form is a TS_NSC_DATA header followed by four run-length encoded planes: Y, Co, Cg and A. Colour is reconstructed with the YCoCg transform. The result is BGRA, 4 bytes per pixel, rows top to bottom, which is the layout the bitmap update path uses for 32bpp data.
Types ¶
type AVCAccessUnit ¶ added in v0.6.0
type AVCAccessUnit struct {
// LC is the AVC444 Luma/Chroma selector: the top two bits of
// cbAvc420EncodedBitstream1. It is 0 for AVC420, where there is only one
// stream and no selector.
LC uint8
// Streams holds the sub-streams in wire order.
Streams []AVCStream
}
AVCAccessUnit is one parsed AVC420 or AVC444 surface update.
AVC420 carries a single stream. AVC444 carries either two streams (LC == 0: luma first, then a chroma layer, the chroma being the lower resolution 4:2:0 sub-layer) or one (LC == 1: luma only, LC == 2: chroma only). Streams is in wire order, so for LC == 2 Streams[0] is the chroma layer.
func ParseAVC420 ¶ added in v0.6.0
func ParseAVC420(data []byte) (*AVCAccessUnit, error)
ParseAVC420 parses the bitmap data of a WireToSurface command carrying RDPGFX_CODECID_AVC420 (MS-RDPEGFX 2.2.4.4). The result carries one stream: the region list, the per-region quantisation and the bitstream, which runs to the end of the message.
func ParseAVC444 ¶ added in v0.6.0
func ParseAVC444(data []byte) (*AVCAccessUnit, error)
ParseAVC444 parses the bitmap data of a WireToSurface command carrying RDPGFX_CODECID_AVC444 (0x0E) or AVC444v2 (0x0F), whose framing is identical (MS-RDPEGFX 2.2.4.5).
The message starts with a uint32 whose top two bits are the LC selector and whose low 30 bits, cbAvc420EncodedBitstream1, size the first sub-stream. A second sub-stream follows only when LC is 0.
type AVCQuantQuality ¶ added in v0.6.0
type AVCQuantQuality struct {
// QP is the quantisation parameter: bits 0 to 5 of qpVal.
QP uint8
// R is bit 6 and P is bit 7 of qpVal.
R, P uint8
// Quality is the separate qualityVal byte.
Quality uint8
}
AVCQuantQuality is the per-region quantisation an AVC420 stream carries. The wire field qpVal packs the quantisation parameter into its low six bits and two flags above it; qualityVal is a separate byte.
type AVCStream ¶ added in v0.6.0
type AVCStream struct {
// Regions is the region rectangle list, one entry per coded region.
Regions []RegionRect
// Quant carries one entry per region, parallel to Regions.
Quant []AVCQuantQuality
// Data is the H.264 bitstream exactly as the server sent it. It is an
// opaque Annex B stream, with no per-NAL length framing: FreeRDP hands
// these bytes straight to its H.264 decoder without scanning them, so the
// start codes are the decoder's business, not this parser's. The length is
// bounded by the message that carried it.
Data []byte
}
AVCStream is one H.264 sub-stream: the region list it updates, the quantisation for each region, and the bitstream itself.
type RLGRMode ¶
type RLGRMode int
RLGRMode selects the entropy coder used inside a tileset.
const ( // RLGR1 is the simpler, Golomb-Rice-only mode. RLGR1 RLGRMode = iota // RLGR3 additionally splits each coefficient into two values. RLGR3 )
The two entropy coder modes, MS-RDPRFX 3.1.8. RemoteFX data does not say which one produced it, so the session's choice has to be passed to the decoder.
type RegionRect ¶ added in v0.6.0
type RegionRect struct {
Left, Top, Right, Bottom uint16
}
RegionRect is a rectangle in surface coordinates, as carried by the AVC420 and AVC444 region lists. It is the same 16 bit RDPGFX_RECT16 the other surface commands use, so a region is relative to the surface, not to the update's destination rectangle.
type ZGFX ¶ added in v0.3.0
type ZGFX struct {
// contains filtered or unexported fields
}
ZGFX is the bulk compression that wraps EGFX graphics data (MS-RDPEGFX 3.1.8). The graphics channel does not carry raw RDPGFX PDUs: every message is a ZGFX stream, whether or not it is actually compressed.
The format is LZ77 with a fixed token table. A stream is one or more segments; each segment is decoded independently but they share one history buffer, which also persists across messages for the life of the channel. A decoder therefore has to be kept for as long as the connection lasts, and it has to be fed every message in order.