Skip to content

Commit b5ba8fe

Browse files
committed
libvncserver: add h264 support
1 parent cddc62e commit b5ba8fe

File tree

5 files changed

+841
-3
lines changed

5 files changed

+841
-3
lines changed

include/rfb/rfb.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ typedef UINT32 in_addr_t;
6666

6767
#include <rfb/threading.h>
6868

69+
#ifdef LIBVNCSERVER_HAVE_LIBAVCODEC
70+
struct AVCodecContext;
71+
struct AVFrame;
72+
struct AVPacket;
73+
#ifdef LIBVNCSERVER_HAVE_LIBSWSCALE
74+
struct SwsContext;
75+
#endif
76+
#endif
77+
6978
/* if you use pthreads, but don't define LIBVNCSERVER_HAVE_LIBPTHREAD, the structs
7079
get all mixed up. So this gives a linker error reminding you to compile
7180
the library and your application (at least the parts including rfb.h)
@@ -582,6 +591,25 @@ typedef struct _rfbClientRec {
582591
int rawBytesEquivalent;
583592
int bytesSent;
584593

594+
#ifdef LIBVNCSERVER_HAVE_LIBAVCODEC
595+
struct AVCodecContext *h264Encoder;
596+
struct AVFrame *h264Frame;
597+
struct AVPacket *h264Packet;
598+
#ifdef LIBVNCSERVER_HAVE_LIBSWSCALE
599+
struct SwsContext *h264SwsContext;
600+
#endif
601+
uint8_t *h264RgbBuffer;
602+
size_t h264RgbBufferSize;
603+
uint8_t *h264EncodeBuffer;
604+
size_t h264EncodeBufferSize;
605+
int h264CodecWidth;
606+
int h264CodecHeight;
607+
int64_t h264FramePts;
608+
rfbBool h264ForceKeyframe;
609+
rfbBool h264SentConfig;
610+
int64_t h264BitRate;
611+
#endif
612+
585613
#ifdef LIBVNCSERVER_HAVE_LIBZ
586614
/* zlib encoding -- necessary compression state info per client */
587615

@@ -824,6 +852,12 @@ extern void rfbClientConnFailed(rfbClientPtr cl, const char *reason);
824852
extern void rfbNewUDPConnection(rfbScreenInfoPtr rfbScreen,rfbSocket sock);
825853
extern void rfbProcessUDPInput(rfbScreenInfoPtr rfbScreen);
826854
extern rfbBool rfbSendFramebufferUpdate(rfbClientPtr cl, sraRegionPtr updateRegion);
855+
#ifdef LIBVNCSERVER_HAVE_LIBAVCODEC
856+
extern rfbBool rfbSendRectEncodingH264(rfbClientPtr cl, int x, int y, int w, int h);
857+
extern void rfbClientH264SetBitrate(rfbClientPtr cl, int64_t bitRate);
858+
void rfbClientH264ReleaseEncoder(rfbClientPtr cl);
859+
#endif
860+
827861
extern rfbBool rfbSendRectEncodingRaw(rfbClientPtr cl, int x,int y,int w,int h);
828862
extern rfbBool rfbSendUpdateBuf(rfbClientPtr cl);
829863
extern void rfbSendServerCutText(rfbScreenInfoPtr rfbScreen,char *str, int len);

include/rfb/rfbproto.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ typedef struct {
460460
#define rfbEncodingZRLE 16
461461
#define rfbEncodingZYWRLE 17
462462

463-
#define rfbEncodingH264 0x48323634
463+
#define rfbEncodingH264 50
464464

465465
/* Cache & XOR-Zlib - rdv@2002 */
466466
#define rfbEncodingCache 0xFFFF0000
@@ -891,6 +891,22 @@ typedef struct {
891891

892892
#endif
893893

894+
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
895+
* h264 - h264 encoding. We have an rfbH264Header structure giving the number
896+
* of bytes following and control flags. Finally the data that follows is an
897+
* H.264 encoded frame stream for the rectangle.
898+
*/
899+
900+
typedef struct {
901+
uint32_t length;
902+
uint32_t flags;
903+
} rfbH264Header;
904+
905+
#define sz_rfbH264Header 8
906+
907+
#define rfbH264FlagNone 0u
908+
#define rfbH264FlagResetContext 1u
909+
894910
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
895911
* XCursor encoding. This is a special encoding used to transmit X-style
896912
* cursor shapes from server to clients. Note that for this encoding,

0 commit comments

Comments
 (0)