├── vendor ├── github.com │ └── google │ │ └── gousb │ │ ├── .gitignore │ │ ├── appveyor.yml │ │ ├── AUTHORS │ │ ├── fixlibusb_darwin.sh │ │ ├── usb.c │ │ ├── .travis.yml │ │ ├── debug.go │ │ ├── CONTRIBUTING.md │ │ ├── misc.go │ │ ├── endpoint_stream.go │ │ ├── transfer.c │ │ ├── README.md │ │ ├── error.go │ │ ├── interface.go │ │ ├── config.go │ │ ├── transfer.go │ │ ├── endpoint.go │ │ ├── fakelibusb_devices.go │ │ ├── usb.go │ │ ├── constants.go │ │ ├── device.go │ │ ├── transfer_stream.go │ │ └── LICENSE ├── golang.org │ └── x │ │ └── net │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── websocket │ │ ├── dial.go │ │ ├── client.go │ │ ├── server.go │ │ └── websocket.go │ │ ├── PATENTS │ │ └── LICENSE └── modules.txt ├── pcap ├── bitstream.pcapng ├── usb-init.pcapng └── usb-init-clean.pcapng ├── decompress-avi ├── include │ ├── lib.o │ ├── libfrmgrab.a │ ├── v2u_lib.h │ ├── v2u_pack_off.h │ ├── v2u_version.h │ ├── v2u_pack_on.h │ ├── v2u_save.h │ ├── v2u_ioctl.h │ ├── v2u_sys.h │ ├── v2u_compression.h │ ├── v2u_dshow.h │ ├── v2u_util.h │ └── v2u_id.h ├── EVERYTHING.syso ├── README.md ├── main.go └── wrapper.c ├── .gitignore ├── go.mod ├── go.sum ├── README.md ├── driver ├── res.go ├── websocket-server.go ├── webpage.go └── main.go ├── Makefile └── utils └── tcpdump-to-arrays └── main.go /vendor/github.com/google/gousb/.gitignore: -------------------------------------------------------------------------------- 1 | *.sw[op] 2 | .idea/ 3 | -------------------------------------------------------------------------------- /pcap/bitstream.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/pcap/bitstream.pcapng -------------------------------------------------------------------------------- /pcap/usb-init.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/pcap/usb-init.pcapng -------------------------------------------------------------------------------- /pcap/usb-init-clean.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/pcap/usb-init-clean.pcapng -------------------------------------------------------------------------------- /decompress-avi/include/lib.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/decompress-avi/include/lib.o -------------------------------------------------------------------------------- /decompress-avi/EVERYTHING.syso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/decompress-avi/EVERYTHING.syso -------------------------------------------------------------------------------- /decompress-avi/include/libfrmgrab.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benjojo/userspace-vga2usb/HEAD/decompress-avi/include/libfrmgrab.a -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | decompress-avi/decompress-avi 2 | /.GOPATH 3 | /bin 4 | *.csv 5 | *.pcap 6 | *.pcapng 7 | *.pcapng.* 8 | utils/tcpdump-to-arrays/tcpdump-to-arrays 9 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/benjojo/userspace-vga2usb 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750 7 | golang.org/x/net v0.0.0-20191112182307-2180aed22343 8 | ) 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750 2 | ## explicit 3 | github.com/google/gousb 4 | # golang.org/x/net v0.0.0-20191112182307-2180aed22343 5 | ## explicit; go 1.11 6 | golang.org/x/net/websocket 7 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/appveyor.yml: -------------------------------------------------------------------------------- 1 | platform: x64 2 | 3 | clone_folder: C:\msys64\go\src\github.com\google\gousb 4 | 5 | install: 6 | - C:\msys64\usr\bin\bash.exe -lc "cd /go/src/github.com/google/gousb/ && .appveyor/./install.sh" 7 | 8 | build: off 9 | -------------------------------------------------------------------------------- /decompress-avi/README.md: -------------------------------------------------------------------------------- 1 | decompress-avi 2 | === 3 | 4 | This is a API copy of the `v2u_dec.exe` functions, except in Cgo. This code never got used in the end. But took significant effort to make work. 5 | 6 | Since I am likely going to do more cused mapping of Cgo in the future, I am keeping this code public, publish and most critically searchable by 7 | github for when that time comes again. -------------------------------------------------------------------------------- /decompress-avi/include/v2u_lib.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_lib.h 7764 2009-10-04 07:41:00Z monich $ 4 | * 5 | * Copyright (C) 2003-2007 Epiphan Systems, Inc. All rights reserved. 6 | * 7 | * v2u_lib master include file. 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _V2U_LIB_H_ 12 | #define _V2U_LIB_H_ 1 13 | 14 | #include "v2u_sys.h" 15 | #include "v2u_util.h" 16 | #include "v2u_save.h" 17 | 18 | #endif /* _V2U_LIB_H_ */ 19 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_pack_off.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_pack_off.h 23083 2013-07-16 19:44:46Z monich $ 4 | * 5 | * Copyright (C) 2003-2013 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Structure packing tweaks 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifdef V2U_PACK_ON 12 | # undef V2U_PACK_ON 13 | # ifdef _WIN32 14 | /* Restore previous packing */ 15 | # include 16 | # endif 17 | #else 18 | # error "packing already off" 19 | #endif /* V2U_PACK_ON */ 20 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_version.h 31951 2015-09-28 17:39:25Z zhilin $ 4 | * 5 | * Copyright (C) 2004-2015 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Version information 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _VGA2USB_VERSION_H_ 12 | #define _VGA2USB_VERSION_H_ 1 13 | 14 | #define V2U_VERSION_MAJOR 3 15 | #define V2U_VERSION_MINOR 30 16 | #define V2U_VERSION_MICRO 2 17 | #define V2U_VERSION_NANO 10 18 | 19 | #endif /* _VGA2USB_VERSION_H_ */ 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/websocket/dial.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package websocket 6 | 7 | import ( 8 | "crypto/tls" 9 | "net" 10 | ) 11 | 12 | func dialWithDialer(dialer *net.Dialer, config *Config) (conn net.Conn, err error) { 13 | switch config.Location.Scheme { 14 | case "ws": 15 | conn, err = dialer.Dial("tcp", parseAuthority(config.Location)) 16 | 17 | case "wss": 18 | conn, err = tls.DialWithDialer(dialer, "tcp", parseAuthority(config.Location), config.TlsConfig) 19 | 20 | default: 21 | err = ErrBadScheme 22 | } 23 | return 24 | } 25 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750 h1:DVKHLo3yE4psTjD9aM2pY7EHoicaQbgmaxxvvHC6ZSM= 2 | github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750/go.mod h1:Tl4HdAs1ThE3gECkNwz+1MWicX6FXddhJEw7L8jRDiI= 3 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 4 | golang.org/x/net v0.0.0-20191112182307-2180aed22343 h1:00ohfJ4K98s3m6BGUoBd8nyfp4Yl0GoIKvw5abItTjI= 5 | golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 6 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 7 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 8 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_pack_on.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_pack_on.h 23083 2013-07-16 19:44:46Z monich $ 4 | * 5 | * Copyright (C) 2003-2013 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Structure packing tweaks 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef V2U_PACKED 12 | # ifdef __GNUC__ 13 | # define V2U_PACKED __attribute__((packed)) 14 | # else 15 | # define V2U_PACKED 16 | # endif 17 | #endif 18 | 19 | #ifndef V2U_PACK_ON 20 | # define V2U_PACK_ON 21 | # ifdef _WIN32 22 | # include 23 | # endif 24 | #else 25 | # error "packing already on" 26 | #endif /* V2U_PACK_ON */ 27 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/AUTHORS: -------------------------------------------------------------------------------- 1 | This is the list of gousb authors for copyright purposes. 2 | # 3 | # This does not necessarily list everyone who has contributed code, since in 4 | # some cases, their employer may be the copyright holder. To see the full list 5 | # of contributors, see the revision history in source control. 6 | Google Inc. 7 | Kyle Lemons 8 | Sebastian Zagrodzki 9 | Pieter Joost van de Sande 10 | Ivan Krasin 11 | Jirawat I. 12 | Thordur Bjornsson 13 | Vincent Serpoul 14 | Josef Filzmaier 15 | Nico MT 16 | Deomid "rojer" Ryabkov 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | userspace-vga2usb 2 | === 3 | 4 | This is a userspace driver that uses libusb to replace some of the basic function of the offical driver for the Epiphan VGA2USB LR. 5 | 6 | ![Device](https://blog.benjojo.co.uk/asset/HxOiDPsE83) 7 | 8 | You can find a better write up on the process of writing this here: https://blog.benjojo.co.uk/post/userspace-usb-drivers 9 | 10 | 11 | --- 12 | 13 | Notes on OSX compatibility: 14 | 15 | Despite me writing this driver entirely on Linux, I managed to test it at the time of completion on a Macbook with no issues in either building or run time. 16 | 17 | To me this seems like a massive fluke, and you may need to install VirtualBox to have a working libusb that is signed or something. I've done very little testing 18 | on OSX, other than it works on a OSX machine I had on hand. -------------------------------------------------------------------------------- /decompress-avi/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // #cgo LDFLAGS: -lm 4 | // extern int decompress_frames(int framel, char* blob, char* deblob); 5 | import "C" 6 | import ( 7 | "encoding/binary" 8 | "flag" 9 | "io/ioutil" 10 | "log" 11 | "os" 12 | "time" 13 | "unsafe" 14 | ) 15 | 16 | func main() { 17 | // fmt.Printf("I'm about to segfault") 18 | flag.Parse() 19 | filename := flag.Arg(0) 20 | f, _ := os.Open(filename) 21 | 22 | framelen := uint32(0) 23 | binary.Read(f, binary.BigEndian, framelen) 24 | log.Printf("framelen %d", framelen) 25 | 26 | buf, _ := ioutil.ReadAll(f) 27 | buf2 := make([]byte, 2048*2048*3) 28 | 29 | start := time.Now() 30 | // buf := make([]byte, 100) 31 | _ = C.decompress_frames(C.int(len(buf)), (*C.char)(unsafe.Pointer(&buf[0])), (*C.char)(unsafe.Pointer(&buf2[0]))) 32 | 33 | log.Printf("took %s", time.Since(start)) 34 | log.Printf("%x", buf2[:60]) 35 | } 36 | -------------------------------------------------------------------------------- /driver/res.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "math" 5 | ) 6 | 7 | type xy struct { 8 | X, Y int 9 | } 10 | 11 | var payloadSizeSamples = map[int]xy{ 12 | 480000: xy{X: 800, Y: 600}, 13 | 614400: xy{X: 1024, Y: 600}, 14 | 786432: xy{X: 1024, Y: 768}, 15 | 768000: xy{X: 1280, Y: 600}, 16 | 921600: xy{X: 1280, Y: 720}, 17 | 983040: xy{X: 1280, Y: 768}, 18 | 1310720: xy{X: 1280, Y: 1024}, 19 | 1049088: xy{X: 1366, Y: 768}, 20 | 307200: xy{X: 640, Y: 480}, 21 | } 22 | 23 | func GuessTheRes(size int) xy { 24 | bestGuess := xy{X: 0, Y: 0} 25 | closeNess := 10000000 26 | for bytes, res := range payloadSizeSamples { 27 | close := int(math.Abs(float64((bytes)*3 - size))) 28 | // fmt.Printf("%#v is close by %d - best close is %d\n", res, close, closeNess) 29 | if close < closeNess { 30 | bestGuess = res 31 | closeNess = close 32 | } 33 | } 34 | 35 | return bestGuess 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/fixlibusb_darwin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function die { 4 | echo "$@" 5 | exit 1 6 | } 7 | 8 | FILE="$1" 9 | if [[ -z "$FILE" ]]; then 10 | die "Usage: $0 " 11 | fi 12 | 13 | if [[ $(gcc --version | grep -i "llvm") == "" ]]; then 14 | die "Error: This change is unnecessary unless your gcc uses llvm" 15 | fi 16 | 17 | BACKUP="${FILE}.orig" 18 | if [[ -f "$BACKUP" ]]; then 19 | die "It looks like you've already run this script ($BACKUP exists)" 20 | fi 21 | 22 | cp $FILE $BACKUP || die "Could not create backup" 23 | 24 | { 25 | echo 'H' # Turn on error printing 26 | echo 'g/\[0\].*non-standard/s/\[0\]/[1]/' # Use [1] instead of [0] so the size is unambiguous 27 | echo 'g/\[.\].*non-standard/p' # Print the lines changed 28 | echo 'w' # Write output 29 | } | ed $FILE 30 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/usb.c: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2018 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include 17 | 18 | void gousb_set_debug(libusb_context *ctx, int lvl) { 19 | // TODO(sebek): remove libusb_debug entirely in 2.1 or 3.0, 20 | // require libusb >= 1.0.22. libusb 1.0.22 sets API version 0x01000106. 21 | #if LIBUSB_API_VERSION >= 0x01000106 22 | libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, lvl); 23 | #else 24 | libusb_set_debug(ctx, lvl); 25 | #endif 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | dist: trusty 3 | 4 | go: 5 | - 1.7.x 6 | - 1.8.x 7 | - 1.9.x 8 | - 1.10.x 9 | - tip 10 | 11 | addons: 12 | apt: 13 | packages: 14 | libusb-1.0-0-dev 15 | 16 | install: 17 | - go get golang.org/x/tools/cmd/cover 18 | # Golint requires Go 1.9 or later. 19 | - if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.7\.([0-9]+|x)$ || "$TRAVIS_GO_VERSION" =~ ^1\.8\.([0-9]+|x)$ ]]; then go get golang.org/x/lint/golint; fi 20 | - go get github.com/mattn/goveralls 21 | 22 | script: 23 | # a workaround for go test not supporting coverage for multiple packages in a single invocation. 24 | # If goveralls upload fails, ignore the result. 25 | # Golint requires Go 1.9 or later. 26 | - if ! [[ "$TRAVIS_GO_VERSION" =~ ^1\.7\.([0-9]+|x)+$ || "$TRAVIS_GO_VERSION" =~ ^1\.8\.([0-9]+|x)$ ]]; then $HOME/gopath/bin/golint ./...; fi 27 | - |- 28 | echo 'mode: count' > coverage.merged && go list ./... | xargs -n1 -I{} sh -c ': > coverage.tmp; go test -v -covermode=count -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.merged' && rm coverage.tmp 29 | - |- 30 | $HOME/gopath/bin/goveralls -coverprofile=coverage.merged -service=travis-ci -ignore libusb.go,error.go || true 31 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/debug.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | // To enable internal debugging, set the GOUSB_DEBUG environment variable. 19 | 20 | import ( 21 | "io" 22 | "io/ioutil" 23 | "log" // TODO(kevlar): make a logger 24 | "os" 25 | ) 26 | 27 | var debug *log.Logger 28 | 29 | const debugEnvVarName = "GOUSB_DEBUG" 30 | 31 | func init() { 32 | out := io.Writer(ioutil.Discard) 33 | if os.Getenv(debugEnvVarName) != "" { 34 | out = os.Stderr 35 | } 36 | debug = log.New(out, "gousb: ", log.LstdFlags|log.Lshortfile) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Want to contribute? Great! First, read this page (including the small print at 2 | the end). 3 | 4 | ### Before you contribute 5 | Before we can use your code, you must sign the 6 | [Google Individual Contributor License Agreement] 7 | (https://cla.developers.google.com/about/google-individual) 8 | (CLA), which you can do online. The CLA is necessary mainly because you own the 9 | copyright to your changes, even after your contribution becomes part of our 10 | codebase, so we need your permission to use and distribute your code. We also 11 | need to be sure of various other things—for instance that you'll tell us if you 12 | know that your code infringes on other people's patents. You don't have to sign 13 | the CLA until after you've submitted your code for review and a member has 14 | approved it, but you must do it before we can put your code into our codebase. 15 | Before you start working on a larger contribution, you should get in touch with 16 | us first through the issue tracker with your idea so that we can help out and 17 | possibly guide you. Coordinating up front makes it much easier to avoid 18 | frustration later on. 19 | 20 | ### Code reviews 21 | All submissions, including submissions by project members, require review. We 22 | use Github pull requests for this purpose. 23 | 24 | ### The small print 25 | Contributions made by corporations are covered by a different agreement than 26 | the one above, the 27 | [Software Grant and Corporate Contributor License Agreement] 28 | (https://cla.developers.google.com/about/google-corporate). 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/misc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "fmt" 20 | ) 21 | 22 | // BCD is a binary-coded decimal version number. Its first 8 bits represent 23 | // the major version number, its last 8 bits represent the minor version number. 24 | // Major and minor are composed of 4+4 bits, where each 4 bits represents 25 | // a decimal digit. 26 | // Example: BCD(0x1234) means major 12 (decimal) and minor 34 (decimal). 27 | type BCD uint16 28 | 29 | // Major is the major number of the BCD. 30 | func (s BCD) Major() uint8 { 31 | maj := uint8(s >> 8) 32 | return 10*(maj>>4) + maj&0x0f 33 | } 34 | 35 | // Minor is the minor number of the BCD. 36 | func (s BCD) Minor() uint8 { 37 | min := uint8(s & 0xff) 38 | return 10*(min>>4) + min&0x0f 39 | } 40 | 41 | // String returns a dotted representation of the BCD (major.minor). 42 | func (s BCD) String() string { 43 | return fmt.Sprintf("%d.%02d", s.Major(), s.Minor()) 44 | } 45 | 46 | // Version returns a BCD version number with given major/minor. 47 | func Version(major, minor uint8) BCD { 48 | return (BCD(major)/10)<<12 | (BCD(major)%10)<<8 | (BCD(minor)/10)<<4 | BCD(minor)%10 49 | } 50 | 51 | // ID represents a vendor or product ID. 52 | type ID uint16 53 | 54 | // String returns a hexadecimal ID. 55 | func (id ID) String() string { 56 | return fmt.Sprintf("%04x", int(id)) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/endpoint_stream.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the gousb Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package gousb 16 | 17 | func (e *endpoint) newStream(size, count int) (*stream, error) { 18 | var ts []transferIntf 19 | for i := 0; i < count; i++ { 20 | t, err := newUSBTransfer(e.ctx, e.h, &e.Desc, size) 21 | if err != nil { 22 | for _, t := range ts { 23 | t.free() 24 | } 25 | return nil, err 26 | } 27 | ts = append(ts, t) 28 | } 29 | return newStream(ts), nil 30 | } 31 | 32 | // NewStream prepares a new read stream that will keep reading data from 33 | // the endpoint until closed or until an error or timeout is encountered. 34 | // Size defines a buffer size for a single read transaction and count 35 | // defines how many transactions should be active at any time. 36 | // By keeping multiple transfers active at the same time, a Stream reduces 37 | // the latency between subsequent transfers and increases reading throughput. 38 | func (e *InEndpoint) NewStream(size, count int) (*ReadStream, error) { 39 | s, err := e.newStream(size, count) 40 | if err != nil { 41 | return nil, err 42 | } 43 | s.submitAll() 44 | return &ReadStream{s: s}, nil 45 | } 46 | 47 | // NewStream prepares a new write stream that will write data in the 48 | // background. Size defines a buffer size for a single write transaction and 49 | // count defines how many transactions may be active at any time. By buffering 50 | // the writes, a Stream reduces the latency between subsequent transfers and 51 | // increases writing throughput. 52 | func (e *OutEndpoint) NewStream(size, count int) (*WriteStream, error) { 53 | s, err := e.newStream(size, count) 54 | if err != nil { 55 | return nil, err 56 | } 57 | return &WriteStream{s: s}, nil 58 | } 59 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_save.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_save.h 10816 2010-09-02 07:58:50Z monich $ 4 | * 5 | * Copyright (C) 2003-2010 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Functions for saving image into a file 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _V2U_SAVE_H_ 12 | #define _V2U_SAVE_H_ 1 13 | 14 | #include "v2u_defs.h" 15 | #include 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif /* __cplusplus */ 20 | 21 | /* Palettes entry, compatible with RGBQUAD type on Windows */ 22 | typedef struct _BmpPalEntry { 23 | V2U_UINT8 rgbBlue; 24 | V2U_UINT8 rgbGreen; 25 | V2U_UINT8 rgbRed; 26 | V2U_UINT8 rgbReserved; 27 | } BmpPalEntry; 28 | 29 | /* VGA2USB palettes */ 30 | extern const BmpPalEntry v2u_palette_4bpp[16]; 31 | extern const BmpPalEntry v2u_palette_8bpp[256]; 32 | extern const BmpPalEntry v2u_palette_y8[256]; 33 | 34 | /* And 16bpp RGB masks */ 35 | extern const V2U_UINT32 v2u_mask_bgr16[3]; 36 | extern const V2U_UINT32 v2u_mask_rgb16[3]; 37 | 38 | /* 39 | * Writes the image file to the specified stream. Returns V2U_FALSE on failure, 40 | * V2U_TRUE on success. The fmt parameter defined the input pixel format. 41 | * The following formats are supported: 42 | * 43 | * V2U_GRABFRAME_FORMAT_Y8 44 | * V2U_GRABFRAME_FORMAT_RGB4 45 | * V2U_GRABFRAME_FORMAT_RGB8 46 | * V2U_GRABFRAME_FORMAT_RGB16 47 | * V2U_GRABFRAME_FORMAT_BGR16 48 | * V2U_GRABFRAME_FORMAT_RGB24 49 | * V2U_GRABFRAME_FORMAT_BGR24 50 | * V2U_GRABFRAME_FORMAT_ARGB32 51 | * V2U_GRABFRAME_FORMAT_YUY2 52 | * V2U_GRABFRAME_FORMAT_2VUY 53 | * V2U_GRABFRAME_FORMAT_YV12 54 | * V2U_GRABFRAME_FORMAT_I420 55 | * 56 | * possibly, with V2U_GRABFRAME_BOTTOM_UP_FLAG bit set. The pixels are assumed 57 | * to be tightly packed, i.e. the line size is NOT aligned at 32-bit boundary. 58 | */ 59 | typedef V2U_BOOL (*V2U_SAVE_PROC)(FILE* f,int w,int h,int fmt, const void* b); 60 | extern V2U_BOOL v2u_write_bmp(FILE* f, int w, int h, int fmt, const void* b); 61 | extern V2U_BOOL v2u_write_jpeg(FILE* f, int w, int h, int fmt, const void* b); 62 | extern V2U_BOOL v2u_write_png(FILE* f, int w, int h, int fmt, const void* b); 63 | 64 | #ifdef __cplusplus 65 | } /* end of extern "C" */ 66 | #endif /* __cplusplus */ 67 | 68 | #endif /* _V2U_SAVE_H_ */ 69 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # The import path is where your repository can be found. 2 | # To import subpackages, always prepend the full import path. 3 | # If you change this, run `make clean`. Read more: https://git.io/vM7zV 4 | IMPORT_PATH := github.com/benjojo/userspace-vga2usb 5 | 6 | # V := 1 # When V is set, print commands and build progress. 7 | 8 | # Space separated patterns of packages to skip in list, test, format. 9 | IGNORED_PACKAGES := /vendor/ 10 | 11 | .PHONY: all 12 | all: build 13 | 14 | .PHONY: build 15 | build: 16 | $Q go build -o bin/driver $(if $V,-v) $(VERSION_FLAGS) $(IMPORT_PATH)/driver 17 | $Q go test $(if $V,-v) $(VERSION_FLAGS) $(IMPORT_PATH)/driver 18 | 19 | .PHONY: install 20 | install: 21 | $Q go install $(if $V,-v) $(VERSION_FLAGS) $(IMPORT_PATH)/driver 22 | 23 | ##### ^^^^^^ EDIT ABOVE ^^^^^^ ##### 24 | 25 | ##### =====> Utility targets <===== ##### 26 | 27 | .PHONY: clean 28 | clean: 29 | $Q rm -rf bin driver/driver 30 | 31 | ##### =====> Internals <===== ##### 32 | 33 | VERSION := $(shell git describe --tags --always --dirty="-dev") 34 | DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC') 35 | AUTHORLIST := $(shell git log --format='%aN' | sort -u | tr '\n' ',') 36 | VERSION_FLAGS := -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)" -X "main.AuthorList=$(AUTHORLIST)"' 37 | 38 | Q := $(if $V,,@) 39 | 40 | # Based on https://github.com/cloudflare/hellogopher - v1.1 - MIT License 41 | # 42 | # Copyright (c) 2017 Cloudflare 43 | # 44 | # Permission is hereby granted, free of charge, to any person obtaining a copy 45 | # of this software and associated documentation files (the "Software"), to deal 46 | # in the Software without restriction, including without limitation the rights 47 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 48 | # copies of the Software, and to permit persons to whom the Software is 49 | # furnished to do so, subject to the following conditions: 50 | # 51 | # The above copyright notice and this permission notice shall be included in all 52 | # copies or substantial portions of the Software. 53 | # 54 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 60 | # SOFTWARE. 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/websocket/client.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package websocket 6 | 7 | import ( 8 | "bufio" 9 | "io" 10 | "net" 11 | "net/http" 12 | "net/url" 13 | ) 14 | 15 | // DialError is an error that occurs while dialling a websocket server. 16 | type DialError struct { 17 | *Config 18 | Err error 19 | } 20 | 21 | func (e *DialError) Error() string { 22 | return "websocket.Dial " + e.Config.Location.String() + ": " + e.Err.Error() 23 | } 24 | 25 | // NewConfig creates a new WebSocket config for client connection. 26 | func NewConfig(server, origin string) (config *Config, err error) { 27 | config = new(Config) 28 | config.Version = ProtocolVersionHybi13 29 | config.Location, err = url.ParseRequestURI(server) 30 | if err != nil { 31 | return 32 | } 33 | config.Origin, err = url.ParseRequestURI(origin) 34 | if err != nil { 35 | return 36 | } 37 | config.Header = http.Header(make(map[string][]string)) 38 | return 39 | } 40 | 41 | // NewClient creates a new WebSocket client connection over rwc. 42 | func NewClient(config *Config, rwc io.ReadWriteCloser) (ws *Conn, err error) { 43 | br := bufio.NewReader(rwc) 44 | bw := bufio.NewWriter(rwc) 45 | err = hybiClientHandshake(config, br, bw) 46 | if err != nil { 47 | return 48 | } 49 | buf := bufio.NewReadWriter(br, bw) 50 | ws = newHybiClientConn(config, buf, rwc) 51 | return 52 | } 53 | 54 | // Dial opens a new client connection to a WebSocket. 55 | func Dial(url_, protocol, origin string) (ws *Conn, err error) { 56 | config, err := NewConfig(url_, origin) 57 | if err != nil { 58 | return nil, err 59 | } 60 | if protocol != "" { 61 | config.Protocol = []string{protocol} 62 | } 63 | return DialConfig(config) 64 | } 65 | 66 | var portMap = map[string]string{ 67 | "ws": "80", 68 | "wss": "443", 69 | } 70 | 71 | func parseAuthority(location *url.URL) string { 72 | if _, ok := portMap[location.Scheme]; ok { 73 | if _, _, err := net.SplitHostPort(location.Host); err != nil { 74 | return net.JoinHostPort(location.Host, portMap[location.Scheme]) 75 | } 76 | } 77 | return location.Host 78 | } 79 | 80 | // DialConfig opens a new client connection to a WebSocket with a config. 81 | func DialConfig(config *Config) (ws *Conn, err error) { 82 | var client net.Conn 83 | if config.Location == nil { 84 | return nil, &DialError{config, ErrBadWebSocketLocation} 85 | } 86 | if config.Origin == nil { 87 | return nil, &DialError{config, ErrBadWebSocketOrigin} 88 | } 89 | dialer := config.Dialer 90 | if dialer == nil { 91 | dialer = &net.Dialer{} 92 | } 93 | client, err = dialWithDialer(dialer, config) 94 | if err != nil { 95 | goto Error 96 | } 97 | ws, err = NewClient(config, client) 98 | if err != nil { 99 | client.Close() 100 | goto Error 101 | } 102 | return 103 | 104 | Error: 105 | return nil, &DialError{config, err} 106 | } 107 | -------------------------------------------------------------------------------- /driver/websocket-server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | 7 | "golang.org/x/net/websocket" 8 | ) 9 | 10 | var globalPNGBroker *pngBroker 11 | 12 | func startWebserver(frameFeed chan []byte) { 13 | log.Print("Listening on :3723 for HTTP/Websocket connections") 14 | 15 | http.HandleFunc("/", serveRootPage) 16 | http.Handle("/ws", websocket.Handler(handlePNGwebsocket)) 17 | 18 | globalPNGBroker = newpngBroker() 19 | go globalPNGBroker.Start() 20 | 21 | go func() { 22 | for { 23 | if *debugLogging { 24 | log.Printf("Waiting for frame") 25 | } 26 | frame := <-frameFeed 27 | globalPNGBroker.Publish(frame) 28 | if *debugLogging { 29 | log.Printf("Published frame(!)") 30 | } 31 | } 32 | }() 33 | 34 | err := http.ListenAndServe(":3723", nil) 35 | if err != nil { 36 | log.Fatalf("failed to listen on 3723, %s", err.Error()) 37 | } 38 | } 39 | 40 | func serveRootPage(w http.ResponseWriter, r *http.Request) { 41 | w.Write([]byte(webPage)) 42 | } 43 | 44 | func handlePNGwebsocket(ws *websocket.Conn) { 45 | inputch := globalPNGBroker.Subscribe() 46 | defer globalPNGBroker.Unsubscribe(inputch) 47 | 48 | bframe, _ := ws.NewFrameWriter(websocket.BinaryFrame) 49 | 50 | for { 51 | frame := <-inputch 52 | 53 | _, err := bframe.Write(frame.([]byte)) 54 | if err != nil { 55 | break 56 | } 57 | } 58 | } 59 | 60 | /* 61 | History suggests that I (Ben Cartwright-Cox) has never written a channel 62 | broadcaster without messing it up, so I will instead copy and paste one 63 | off Stackoverflow (https://stackoverflow.com/questions/36417199/how-to-broadcast-message-using-channel) 64 | instead of suffering more than I already do writing these kinds of programs. 65 | */ 66 | 67 | type pngBroker struct { 68 | stopCh chan struct{} 69 | publishCh chan interface{} 70 | subCh chan chan interface{} 71 | unsubCh chan chan interface{} 72 | } 73 | 74 | func newpngBroker() *pngBroker { 75 | return &pngBroker{ 76 | stopCh: make(chan struct{}), 77 | publishCh: make(chan interface{}, 1), 78 | subCh: make(chan chan interface{}, 1), 79 | unsubCh: make(chan chan interface{}, 1), 80 | } 81 | } 82 | 83 | func (b *pngBroker) Start() { 84 | subs := map[chan interface{}]struct{}{} 85 | for { 86 | select { 87 | case <-b.stopCh: 88 | return 89 | case msgCh := <-b.subCh: 90 | subs[msgCh] = struct{}{} 91 | case msgCh := <-b.unsubCh: 92 | delete(subs, msgCh) 93 | case msg := <-b.publishCh: 94 | for msgCh := range subs { 95 | // msgCh is buffered, use non-blocking send to protect the broker: 96 | select { 97 | case msgCh <- msg: 98 | default: 99 | } 100 | } 101 | } 102 | } 103 | } 104 | 105 | func (b *pngBroker) Stop() { 106 | close(b.stopCh) 107 | } 108 | 109 | func (b *pngBroker) Subscribe() chan interface{} { 110 | msgCh := make(chan interface{}, 5) 111 | b.subCh <- msgCh 112 | return msgCh 113 | } 114 | 115 | func (b *pngBroker) Unsubscribe(msgCh chan interface{}) { 116 | b.unsubCh <- msgCh 117 | } 118 | 119 | func (b *pngBroker) Publish(msg interface{}) { 120 | b.publishCh <- msg 121 | } 122 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_ioctl.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_ioctl.h 19092 2012-10-31 02:04:10Z monich $ 4 | * 5 | * Copyright (C) 2003-2012 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Defines IOCTL interface to the VGA2USB driver. Included by the driver 8 | * and by the user level code. 9 | * 10 | ****************************************************************************/ 11 | 12 | #ifndef _VGA2USB_IOCTL_H_ 13 | #define _VGA2USB_IOCTL_H_ 1 14 | 15 | #include "v2u_defs.h" 16 | 17 | /* Platform specific magic */ 18 | #ifdef _WIN32 19 | # define FILE_DEVICE_VGA2USB FILE_DEVICE_UNKNOWN 20 | # define _IOCTL_VGA2USB(x,a) CTL_CODE(FILE_DEVICE_VGA2USB,x,METHOD_NEITHER,a) 21 | # define IOCTL_VGA2USB(x) _IOCTL_VGA2USB(x,FILE_ANY_ACCESS) 22 | # define IOCTL_VGA2USB_R(x,type) _IOCTL_VGA2USB(x,FILE_READ_ACCESS) 23 | # define IOCTL_VGA2USB_W(x,type) _IOCTL_VGA2USB(x,FILE_WRITE_ACCESS) 24 | # define IOCTL_VGA2USB_WR(x,type) _IOCTL_VGA2USB(x,FILE_ANY_ACCESS) 25 | #else /* Unix */ 26 | # define IOCTL_VGA2USB(x) _IO('V',x) 27 | # define IOCTL_VGA2USB_R(x,type) _IOR('V',x,type) 28 | # define IOCTL_VGA2USB_W(x,type) _IOW('V',x,type) 29 | # define IOCTL_VGA2USB_WR(x,type) _IOWR('V',x,type) 30 | #endif /* Unix */ 31 | 32 | /* IOCTL definitions */ 33 | 34 | /* 35 | * IOCTL_VGA2USB_VIDEOMODE 36 | * 37 | * Detects video mode. If cable is disconnected, width and height are zero. 38 | * Note that the vertical refresh rate is measured in milliHertz. 39 | * That is, the number 59900 represents 59.9 Hz. 40 | * 41 | * Support: Linux, Windows, MacOS X 42 | */ 43 | 44 | #define IOCTL_VGA2USB_VIDEOMODE IOCTL_VGA2USB_R(9,V2U_VideoMode) 45 | 46 | /* 47 | * IOCTL_VGA2USB_GETPARAMS 48 | * IOCTL_VGA2USB_SETPARAMS 49 | * 50 | * Support: Linux, Windows, MacOS X 51 | */ 52 | 53 | /* Legacy flags names */ 54 | #define GRAB_BMP_BOTTOM_UP V2U_GRAB_BMP_BOTTOM_UP 55 | #define GRAB_PREFER_WIDE_MODE V2U_GRAB_PREFER_WIDE_MODE 56 | #define GRAB_YCRCB V2U_GRAB_YCRCB 57 | 58 | #define IOCTL_VGA2USB_GETPARAMS IOCTL_VGA2USB_R(6,V2U_GrabParameters) 59 | #define IOCTL_VGA2USB_SETPARAMS IOCTL_VGA2USB_W(8,V2U_GrabParameters) 60 | 61 | /* 62 | * IOCTL_VGA2USB_GRABFRAME 63 | * 64 | * For pixel format check V2U_GRABFRAME_FORMAT_XXX constants in v2u_defs.h 65 | * 66 | * Support: Linux, Windows, MacOS X 67 | */ 68 | 69 | #define IOCTL_VGA2USB_GRABFRAME IOCTL_VGA2USB_WR(10,V2U_GrabFrame) 70 | #define IOCTL_VGA2USB_GRABFRAME2 IOCTL_VGA2USB_WR(20,V2U_GrabFrame2) 71 | 72 | /* 73 | * IOCTL_VGA2USB_GETSN 74 | * 75 | * Support: Windows, Linux, MacOS X 76 | */ 77 | 78 | typedef struct ioctl_getsn { 79 | char sn[V2U_SN_BUFSIZ]; /* OUT serial number string */ 80 | } V2U_PACKED V2U_GetSN; 81 | 82 | #define IOCTL_VGA2USB_GETSN IOCTL_VGA2USB_R(7,V2U_GetSN) 83 | 84 | /* 85 | * IOCTL_VGA2USB_SENDPS2 (KVM2USB capable products only) 86 | * 87 | * Support: Windows, Linux, MacOS X 88 | */ 89 | 90 | #define IOCTL_VGA2USB_SENDPS2 IOCTL_VGA2USB_W(16,V2U_SendPS2) 91 | 92 | /* 93 | * IOCTL_VGA2USB_GET_PROPERTY 94 | * IOCTL_VGA2USB_SET_PROPERTY 95 | * 96 | * Get or set the value of the specified property. 97 | * 98 | * Support: Windows, Linux, MacOS X 99 | * Required driver version: 3.6.22 or later. 100 | */ 101 | 102 | #define IOCTL_VGA2USB_GET_PROPERTY IOCTL_VGA2USB_WR(18,V2U_Property) 103 | #define IOCTL_VGA2USB_SET_PROPERTY IOCTL_VGA2USB_W(19,V2U_Property) 104 | 105 | #endif /* _VGA2USB_IOCTL_H_ */ 106 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/transfer.c: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | void print_xfer(struct libusb_transfer *xfer); 22 | void xferCallback(struct libusb_transfer*); 23 | 24 | int submit(struct libusb_transfer *xfer) { 25 | xfer->callback = (libusb_transfer_cb_fn)(&xferCallback); 26 | xfer->status = -1; 27 | return libusb_submit_transfer(xfer); 28 | } 29 | 30 | void print_xfer(struct libusb_transfer *xfer) { 31 | int i; 32 | 33 | printf("Transfer:\n"); 34 | printf(" dev_handle: %p\n", xfer->dev_handle); 35 | printf(" flags: %08x\n", xfer->flags); 36 | printf(" endpoint: %x\n", xfer->endpoint); 37 | printf(" type: %x\n", xfer->type); 38 | printf(" timeout: %dms\n", xfer->timeout); 39 | printf(" status: %x\n", xfer->status); 40 | printf(" length: %d (act: %d)\n", xfer->length, xfer->actual_length); 41 | printf(" callback: %p\n", xfer->callback); 42 | printf(" user_data: %p\n", xfer->user_data); 43 | printf(" buffer: %p\n", xfer->buffer); 44 | printf(" num_iso_pkts: %d\n", xfer->num_iso_packets); 45 | printf(" packets:\n"); 46 | for (i = 0; i < xfer->num_iso_packets; i++) { 47 | printf(" [%04d] %d (act: %d) %x\n", i, 48 | xfer->iso_packet_desc[i].length, 49 | xfer->iso_packet_desc[i].actual_length, 50 | xfer->iso_packet_desc[i].status); 51 | } 52 | } 53 | 54 | // compact the data in an isochronous transfer. The contents of individual 55 | // iso packets are shifted left, so that no gaps are left between them. 56 | // Status is set to the first non-zero status of an iso packet. 57 | int gousb_compact_iso_data(struct libusb_transfer *xfer, unsigned char *status) { 58 | int i; 59 | int sum = 0; 60 | unsigned char *in = xfer->buffer; 61 | unsigned char *out = xfer->buffer; 62 | for (i = 0; i < xfer->num_iso_packets; i++) { 63 | struct libusb_iso_packet_descriptor pkt = xfer->iso_packet_desc[i]; 64 | if (pkt.status != 0) { 65 | *status = pkt.status; 66 | break; 67 | } 68 | // Copy the data 69 | int len = pkt.actual_length; 70 | memmove(out, in, len); 71 | // Increment offsets 72 | sum += len; 73 | in += pkt.length; 74 | out += len; 75 | } 76 | return sum; 77 | } 78 | 79 | // allocates a libusb transfer and a buffer for packet data. 80 | struct libusb_transfer *gousb_alloc_transfer_and_buffer(int bufLen, int isoPackets) { 81 | struct libusb_transfer *xfer = libusb_alloc_transfer(isoPackets); 82 | if (xfer == NULL) { 83 | return NULL; 84 | } 85 | xfer->buffer = (unsigned char*)malloc(bufLen); 86 | if (xfer->buffer == NULL) { 87 | libusb_free_transfer(xfer); 88 | return NULL; 89 | } 90 | xfer->length = bufLen; 91 | return xfer; 92 | } 93 | 94 | // frees a libusb transfer and its buffer. The buffer of the given 95 | // libusb_transfer must have been allocated with alloc_transfer_and_buffer. 96 | void gousb_free_transfer_and_buffer(struct libusb_transfer *xfer) { 97 | free(xfer->buffer); 98 | xfer->length = 0; 99 | libusb_free_transfer(xfer); 100 | } 101 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/websocket/server.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package websocket 6 | 7 | import ( 8 | "bufio" 9 | "fmt" 10 | "io" 11 | "net/http" 12 | ) 13 | 14 | func newServerConn(rwc io.ReadWriteCloser, buf *bufio.ReadWriter, req *http.Request, config *Config, handshake func(*Config, *http.Request) error) (conn *Conn, err error) { 15 | var hs serverHandshaker = &hybiServerHandshaker{Config: config} 16 | code, err := hs.ReadHandshake(buf.Reader, req) 17 | if err == ErrBadWebSocketVersion { 18 | fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) 19 | fmt.Fprintf(buf, "Sec-WebSocket-Version: %s\r\n", SupportedProtocolVersion) 20 | buf.WriteString("\r\n") 21 | buf.WriteString(err.Error()) 22 | buf.Flush() 23 | return 24 | } 25 | if err != nil { 26 | fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) 27 | buf.WriteString("\r\n") 28 | buf.WriteString(err.Error()) 29 | buf.Flush() 30 | return 31 | } 32 | if handshake != nil { 33 | err = handshake(config, req) 34 | if err != nil { 35 | code = http.StatusForbidden 36 | fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) 37 | buf.WriteString("\r\n") 38 | buf.Flush() 39 | return 40 | } 41 | } 42 | err = hs.AcceptHandshake(buf.Writer) 43 | if err != nil { 44 | code = http.StatusBadRequest 45 | fmt.Fprintf(buf, "HTTP/1.1 %03d %s\r\n", code, http.StatusText(code)) 46 | buf.WriteString("\r\n") 47 | buf.Flush() 48 | return 49 | } 50 | conn = hs.NewServerConn(buf, rwc, req) 51 | return 52 | } 53 | 54 | // Server represents a server of a WebSocket. 55 | type Server struct { 56 | // Config is a WebSocket configuration for new WebSocket connection. 57 | Config 58 | 59 | // Handshake is an optional function in WebSocket handshake. 60 | // For example, you can check, or don't check Origin header. 61 | // Another example, you can select config.Protocol. 62 | Handshake func(*Config, *http.Request) error 63 | 64 | // Handler handles a WebSocket connection. 65 | Handler 66 | } 67 | 68 | // ServeHTTP implements the http.Handler interface for a WebSocket 69 | func (s Server) ServeHTTP(w http.ResponseWriter, req *http.Request) { 70 | s.serveWebSocket(w, req) 71 | } 72 | 73 | func (s Server) serveWebSocket(w http.ResponseWriter, req *http.Request) { 74 | rwc, buf, err := w.(http.Hijacker).Hijack() 75 | if err != nil { 76 | panic("Hijack failed: " + err.Error()) 77 | } 78 | // The server should abort the WebSocket connection if it finds 79 | // the client did not send a handshake that matches with protocol 80 | // specification. 81 | defer rwc.Close() 82 | conn, err := newServerConn(rwc, buf, req, &s.Config, s.Handshake) 83 | if err != nil { 84 | return 85 | } 86 | if conn == nil { 87 | panic("unexpected nil conn") 88 | } 89 | s.Handler(conn) 90 | } 91 | 92 | // Handler is a simple interface to a WebSocket browser client. 93 | // It checks if Origin header is valid URL by default. 94 | // You might want to verify websocket.Conn.Config().Origin in the func. 95 | // If you use Server instead of Handler, you could call websocket.Origin and 96 | // check the origin in your Handshake func. So, if you want to accept 97 | // non-browser clients, which do not send an Origin header, set a 98 | // Server.Handshake that does not check the origin. 99 | type Handler func(*Conn) 100 | 101 | func checkOrigin(config *Config, req *http.Request) (err error) { 102 | config.Origin, err = Origin(config, req) 103 | if err == nil && config.Origin == nil { 104 | return fmt.Errorf("null origin") 105 | } 106 | return err 107 | } 108 | 109 | // ServeHTTP implements the http.Handler interface for a WebSocket 110 | func (h Handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { 111 | s := Server{Handler: h, Handshake: checkOrigin} 112 | s.serveWebSocket(w, req) 113 | } 114 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/README.md: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | [![Build Status][ciimg]][ci] 5 | [![GoDoc][docimg]][doc] 6 | [![Coverage Status][coverimg]][cover] 7 | [![Build status][appveimg]][appveyor] 8 | 9 | 10 | The gousb package is an attempt at wrapping the libusb library into a Go-like binding. 11 | 12 | Supported platforms include: 13 | 14 | - linux 15 | - darwin 16 | - windows 17 | 18 | This is the release 2.0 of the package [github.com/kylelemons/gousb](https://github.com/kylelemons/gousb). 19 | Its API is not backwards-compatible with version 1.0. 20 | As of 2017-07-13 the 2.0 API is considered stable and 1.0 is deprecated. 21 | 22 | [coverimg]: https://coveralls.io/repos/github/google/gousb/badge.svg 23 | [cover]: https://coveralls.io/github/google/gousb 24 | [ciimg]: https://travis-ci.org/google/gousb.svg 25 | [ci]: https://travis-ci.org/google/gousb 26 | [docimg]: https://godoc.org/github.com/google/gousb?status.svg 27 | [doc]: https://godoc.org/github.com/google/gousb 28 | [appveimg]: https://ci.appveyor.com/api/projects/status/661qp7x33o3wqe4o?svg=true 29 | [appveyor]: https://ci.appveyor.com/project/zagrodzki/gousb 30 | 31 | Documentation 32 | ============= 33 | The documentation can be viewed via local godoc or via the excellent [godoc.org](http://godoc.org/): 34 | 35 | - [usb](http://godoc.org/github.com/google/gousb) 36 | - [usbid](http://godoc.org/pkg/github.com/google/gousb/usbid) 37 | 38 | Installation 39 | ============ 40 | 41 | Dependencies 42 | ------------ 43 | You must first install [libusb-1.0](https://github.com/libusb/libusb/wiki). This is pretty straightforward on linux and darwin. The cgo package should be able to find it if you install it in the default manner or use your distribution's package manager. How to tell cgo how to find one installed in a non-default place is beyond the scope of this README. 44 | 45 | *Note*: If you are installing this on darwin, you will probably need to run `fixlibusb_darwin.sh /usr/local/lib/libusb-1.0/libusb.h` because of an LLVM incompatibility. It shouldn't break C programs, though I haven't tried it in anger. 46 | 47 | Example: lsusb 48 | -------------- 49 | The gousb project provides a simple but useful example: lsusb. This binary will list the USB devices connected to your system and various interesting tidbits about them, their configurations, endpoints, etc. To install it, run the following command: 50 | 51 | go get -v github.com/google/gousb/lsusb 52 | 53 | gousb 54 | ----- 55 | If you installed the lsusb example, both libraries below are already installed. 56 | 57 | Installing the primary gousb package is really easy: 58 | 59 | go get -v github.com/google/gousb 60 | 61 | There is also a `usbid` package that will not be installed by default by this command, but which provides useful information including the human-readable vendor and product codes for detected hardware. It's not installed by default and not linked into the `gousb` package by default because it adds ~400kb to the resulting binary. If you want both, they can be installed thus: 62 | 63 | go get -v github.com/google/gousb{,/usbid} 64 | 65 | Notes for installation on Windows 66 | --------------------------------- 67 | 68 | You'll need: 69 | 70 | - Gcc - tested on [Win-Builds](http://win-builds.org/) and MSYS/MINGW 71 | - pkg-config - see http://www.mingw.org/wiki/FAQ, "How do I get pkg-config installed?" 72 | - [libusb-1.0](http://sourceforge.net/projects/libusb/files/libusb-1.0/). 73 | 74 | Make sure the `libusb-1.0.pc` pkg-config file from libusb was installed 75 | and that the result of the `pkg-config --cflags libusb-1.0` command shows the 76 | correct include path for installed libusb. 77 | 78 | After that you can continue with instructions for lsusb/gousb above. 79 | 80 | Contributing 81 | ============ 82 | Contributing to this project will require signing the [Google CLA][cla]. 83 | This is the same agreement that is required for contributing to Go itself, so if you have 84 | already filled it out for that, you needn't fill it out again. 85 | 86 | [cla]: https://cla.developers.google.com/ 87 | 88 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "fmt" 20 | ) 21 | 22 | // #include 23 | import "C" 24 | 25 | // Error is an error code from a USB operation. See the list of Error constants below. 26 | type Error C.int 27 | 28 | // Error implements the error interface. 29 | func (e Error) Error() string { 30 | return fmt.Sprintf("libusb: %s [code %d]", errorString[e], e) 31 | } 32 | 33 | func fromErrNo(errno C.int) error { 34 | err := Error(errno) 35 | if err == Success { 36 | return nil 37 | } 38 | return err 39 | } 40 | 41 | // Defined result codes. 42 | const ( 43 | Success Error = C.LIBUSB_SUCCESS 44 | ErrorIO Error = C.LIBUSB_ERROR_IO 45 | ErrorInvalidParam Error = C.LIBUSB_ERROR_INVALID_PARAM 46 | ErrorAccess Error = C.LIBUSB_ERROR_ACCESS 47 | ErrorNoDevice Error = C.LIBUSB_ERROR_NO_DEVICE 48 | ErrorNotFound Error = C.LIBUSB_ERROR_NOT_FOUND 49 | ErrorBusy Error = C.LIBUSB_ERROR_BUSY 50 | ErrorTimeout Error = C.LIBUSB_ERROR_TIMEOUT 51 | // ErrorOverflow indicates that the device tried to send more data than was 52 | // requested and that could fit in the packet buffer. 53 | ErrorOverflow Error = C.LIBUSB_ERROR_OVERFLOW 54 | ErrorPipe Error = C.LIBUSB_ERROR_PIPE 55 | ErrorInterrupted Error = C.LIBUSB_ERROR_INTERRUPTED 56 | ErrorNoMem Error = C.LIBUSB_ERROR_NO_MEM 57 | ErrorNotSupported Error = C.LIBUSB_ERROR_NOT_SUPPORTED 58 | ErrorOther Error = C.LIBUSB_ERROR_OTHER 59 | ) 60 | 61 | var errorString = map[Error]string{ 62 | Success: "success", 63 | ErrorIO: "i/o error", 64 | ErrorInvalidParam: "invalid param", 65 | ErrorAccess: "bad access", 66 | ErrorNoDevice: "no device", 67 | ErrorNotFound: "not found", 68 | ErrorBusy: "device or resource busy", 69 | ErrorTimeout: "timeout", 70 | ErrorOverflow: "overflow", 71 | ErrorPipe: "pipe error", 72 | ErrorInterrupted: "interrupted", 73 | ErrorNoMem: "out of memory", 74 | ErrorNotSupported: "not supported", 75 | ErrorOther: "unknown error", 76 | } 77 | 78 | // TransferStatus contains information about the result of a transfer. 79 | type TransferStatus uint8 80 | 81 | // Defined Transfer status values. 82 | const ( 83 | TransferCompleted TransferStatus = C.LIBUSB_TRANSFER_COMPLETED 84 | TransferError TransferStatus = C.LIBUSB_TRANSFER_ERROR 85 | TransferTimedOut TransferStatus = C.LIBUSB_TRANSFER_TIMED_OUT 86 | TransferCancelled TransferStatus = C.LIBUSB_TRANSFER_CANCELLED 87 | TransferStall TransferStatus = C.LIBUSB_TRANSFER_STALL 88 | TransferNoDevice TransferStatus = C.LIBUSB_TRANSFER_NO_DEVICE 89 | TransferOverflow TransferStatus = C.LIBUSB_TRANSFER_OVERFLOW 90 | ) 91 | 92 | var transferStatusDescription = map[TransferStatus]string{ 93 | TransferCompleted: "transfer completed without error", 94 | TransferError: "transfer failed", 95 | TransferTimedOut: "transfer timed out", 96 | TransferCancelled: "transfer was cancelled", 97 | TransferStall: "halt condition detected (endpoint stalled) or control request not supported", 98 | TransferNoDevice: "device was disconnected", 99 | TransferOverflow: "device sent more data than requested", 100 | } 101 | 102 | // String returns a human-readable transfer status. 103 | func (ts TransferStatus) String() string { 104 | return transferStatusDescription[ts] 105 | } 106 | 107 | // Error implements the error interface. 108 | func (ts TransferStatus) Error() string { 109 | return ts.String() 110 | } 111 | -------------------------------------------------------------------------------- /utils/tcpdump-to-arrays/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "encoding/hex" 6 | "flag" 7 | "fmt" 8 | "log" 9 | "os" 10 | "regexp" 11 | "strconv" 12 | "strings" 13 | ) 14 | 15 | type usbControlPacket struct { 16 | ignore bool 17 | RequestType uint8 18 | BRequest uint8 19 | WValue uint16 20 | WIndex uint16 21 | Data []byte 22 | } 23 | 24 | func main() { 25 | tcpdumpfile := flag.String("tcpdump", "", "the path to the tcpdump output") 26 | tsharkfile := flag.String("tshark", "", "the path to the tshark output") 27 | flag.Parse() 28 | 29 | tcpdumpfd, err := os.Open(*tcpdumpfile) 30 | if err != nil { 31 | log.Fatalf("Unable to open input text file %s", err.Error()) 32 | } 33 | tsharkfd, err := os.Open(*tsharkfile) 34 | if err != nil { 35 | log.Fatalf("Unable to open input text file %s", err.Error()) 36 | } 37 | 38 | tcpdumpbufio := bufio.NewReader(tcpdumpfd) 39 | tsharkbufio := bufio.NewReader(tsharkfd) 40 | 41 | for { 42 | uCP := usbControlPacket{ 43 | Data: make([]byte, 0), 44 | } 45 | 46 | err := readTshark(tsharkbufio, &uCP) 47 | if err != nil { 48 | break 49 | } 50 | 51 | err = readTCPDump(tcpdumpbufio, &uCP) 52 | if err != nil { 53 | break 54 | } 55 | 56 | if !uCP.ignore { 57 | fmt.Printf("%#v\n", uCP) 58 | } 59 | 60 | } 61 | } 62 | 63 | // Frame 1: 64 bytes on wire (512 bits), 64 bytes captured (512 bits) on interface 0 64 | var tsharkHeader = regexp.MustCompilePOSIX(`^Frame `) 65 | 66 | // bmRequestType: 0x40 67 | var tsharkbmRequestType = regexp.MustCompilePOSIX(`^ bmRequestType: 0x([0-9A-Fa-f]{2})`) 68 | 69 | // bRequest: 160 70 | var tsharkbRequest = regexp.MustCompilePOSIX(`^ bRequest: ([0-9]+)`) 71 | 72 | // wValue: 0x25fd 73 | var tsharkwValue = regexp.MustCompilePOSIX(`^ wValue: 0x([0-9A-Fa-f]{4})`) 74 | 75 | // wIndex: 0 (0x0000) 76 | var tsharkwIndex = regexp.MustCompilePOSIX(`^ wValue: ([0-9]+) `) 77 | 78 | func readTshark(in *bufio.Reader, input *usbControlPacket) error { 79 | for { 80 | line, toobig, err := in.ReadLine() 81 | if err != nil { 82 | return err 83 | } 84 | if toobig { 85 | log.Fatalf("Packet too big") 86 | } 87 | 88 | // fmt.Printf("honk '%s'\n", line) 89 | if tsharkHeader.Match(line) { 90 | return nil 91 | } 92 | 93 | sline := string(line) 94 | if strings.Contains(sline, "URB_COMPLETE") { 95 | // It's an ack, who cares 96 | input.ignore = true 97 | } 98 | 99 | if tsharkbmRequestType.Match(line) { 100 | result := extractHexNumberOutOfRegexMatch(line, tsharkbmRequestType) 101 | input.RequestType = uint8(result) 102 | } 103 | 104 | if tsharkbRequest.Match(line) { 105 | result := extractNumberOutOfRegexMatch(line, tsharkbRequest) 106 | input.BRequest = uint8(result) 107 | } 108 | 109 | if tsharkwValue.Match(line) { 110 | result := extractHexNumberOutOfRegexMatch(line, tsharkwValue) 111 | input.WValue = uint16(result) 112 | } 113 | 114 | if tsharkwIndex.Match(line) { 115 | result := extractNumberOutOfRegexMatch(line, tsharkwIndex) 116 | input.WIndex = uint16(result) 117 | } 118 | 119 | } 120 | } 121 | 122 | func extractHexNumberOutOfRegexMatch(data []byte, re *regexp.Regexp) int { 123 | res := re.FindAllStringSubmatch(string(data), 1) 124 | i, err := strconv.ParseInt(res[0][1], 16, 64) 125 | if err != nil { 126 | log.Fatalf("blah") 127 | } 128 | 129 | return int(i) 130 | } 131 | 132 | func extractNumberOutOfRegexMatch(data []byte, re *regexp.Regexp) int { 133 | res := re.FindAllStringSubmatch(string(data), 1) 134 | i, err := strconv.ParseInt(res[0][1], 10, 64) 135 | if err != nil { 136 | log.Fatalf("blah") 137 | } 138 | 139 | return int(i) 140 | } 141 | 142 | // 20:40:59.021126 CONTROL SUBMIT to 3:10:0 143 | var tcpdumpHeader = regexp.MustCompilePOSIX(`^[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+ .+ to [0-9]+:[0-9]+:[0-9]+`) 144 | 145 | // 0x0000: 1201 0002 ffff ff40 5555 8233 0000 0000 146 | var tcpdumpData = regexp.MustCompilePOSIX(`^ 0x[0-9a-f]+: (.+)`) 147 | 148 | func readTCPDump(in *bufio.Reader, input *usbControlPacket) error { 149 | for { 150 | line, toobig, err := in.ReadLine() 151 | if err != nil { 152 | return err 153 | } 154 | if toobig { 155 | log.Fatalf("Packet too big") 156 | } 157 | 158 | if tcpdumpHeader.Match(line) { 159 | return nil 160 | } 161 | 162 | if tcpdumpData.Match(line) { 163 | spacedHex := tcpdumpData.FindAllStringSubmatch(string(line), 1)[0][1] 164 | // spacedHex now has '0193 60bc a3ff 543f 30e5 0954 1ffe e493' 165 | spacedHex = strings.Replace(spacedHex, " ", "", -1) 166 | // spacedHex now has '019360bca3ff543f30e509541ffee493' 167 | b, err := hex.DecodeString(spacedHex) 168 | if err != nil { 169 | log.Fatalf("shit this isnt hex? %s \n %s", err.Error(), spacedHex) 170 | } 171 | 172 | input.Data = append(input.Data, b...) 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /driver/webpage.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const webPage = ` 4 | 5 | 6 | VGA2USB Userspace Liveview 7 | 8 | 9 |

This is a very basic live view, Please don't expect anything great

10 |

Not Connecting

11 | This needs canvas, maybe upgrade browser if you can see this 12 | 13 | 14 | 15 | 111 | 153 | 154 | 155 | ` 156 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "fmt" 20 | "sort" 21 | ) 22 | 23 | // InterfaceDesc contains information about a USB interface, extracted from 24 | // the descriptor. 25 | type InterfaceDesc struct { 26 | // Number is the number of this interface, a zero-based index in the array 27 | // of interfaces supported by the device configuration. 28 | Number int 29 | // AltSettings is a list of alternate settings supported by the interface. 30 | AltSettings []InterfaceSetting 31 | } 32 | 33 | // String returns a human-readable description of the interface descriptor and 34 | // its alternate settings. 35 | func (i InterfaceDesc) String() string { 36 | return fmt.Sprintf("Interface %d (%d alternate settings)", i.Number, len(i.AltSettings)) 37 | } 38 | 39 | // InterfaceSetting contains information about a USB interface with a particular 40 | // alternate setting, extracted from the descriptor. 41 | type InterfaceSetting struct { 42 | // Number is the number of this interface, the same as in InterfaceDesc. 43 | Number int 44 | // Alternate is the number of this alternate setting. 45 | Alternate int 46 | // Class is the USB-IF (Implementers Forum) class code, as defined by the USB spec. 47 | Class Class 48 | // SubClass is the USB-IF (Implementers Forum) subclass code, as defined by the USB spec. 49 | SubClass Class 50 | // Protocol is USB protocol code, as defined by the USB spe.c 51 | Protocol Protocol 52 | // Endpoints enumerates the endpoints available on this interface with 53 | // this alternate setting. 54 | Endpoints map[EndpointAddress]EndpointDesc 55 | 56 | iInterface int // index of a string descriptor describing this interface. 57 | } 58 | 59 | func (a InterfaceSetting) sortedEndpointIds() []string { 60 | var eps []string 61 | for _, ei := range a.Endpoints { 62 | eps = append(eps, fmt.Sprintf("%s(%d,%s)", ei.Address, ei.Number, ei.Direction)) 63 | } 64 | sort.Strings(eps) 65 | return eps 66 | } 67 | 68 | // String returns a human-readable description of the particular 69 | // alternate setting of an interface. 70 | func (a InterfaceSetting) String() string { 71 | return fmt.Sprintf("Interface %d alternate setting %d (available endpoints: %v)", a.Number, a.Alternate, a.sortedEndpointIds()) 72 | } 73 | 74 | // Interface is a representation of a claimed interface with a particular setting. 75 | // To access device endpoints use InEndpoint() and OutEndpoint() methods. 76 | // The interface should be Close()d after use. 77 | type Interface struct { 78 | Setting InterfaceSetting 79 | 80 | config *Config 81 | } 82 | 83 | func (i *Interface) String() string { 84 | return fmt.Sprintf("%s,if=%d,alt=%d", i.config, i.Setting.Number, i.Setting.Alternate) 85 | } 86 | 87 | // Close releases the interface. 88 | func (i *Interface) Close() { 89 | if i.config == nil { 90 | return 91 | } 92 | i.config.dev.ctx.libusb.release(i.config.dev.handle, uint8(i.Setting.Number)) 93 | i.config.mu.Lock() 94 | defer i.config.mu.Unlock() 95 | delete(i.config.claimed, i.Setting.Number) 96 | i.config = nil 97 | } 98 | 99 | func (i *Interface) openEndpoint(epAddr EndpointAddress) (*endpoint, error) { 100 | var ep EndpointDesc 101 | ep, ok := i.Setting.Endpoints[epAddr] 102 | if !ok { 103 | return nil, fmt.Errorf("%s does not have endpoint with address %s. Available endpoints: %v", i, epAddr, i.Setting.sortedEndpointIds()) 104 | } 105 | return &endpoint{ 106 | InterfaceSetting: i.Setting, 107 | Desc: ep, 108 | h: i.config.dev.handle, 109 | ctx: i.config.dev.ctx, 110 | }, nil 111 | } 112 | 113 | // InEndpoint prepares an IN endpoint for transfer. 114 | func (i *Interface) InEndpoint(epNum int) (*InEndpoint, error) { 115 | if i.config == nil { 116 | return nil, fmt.Errorf("InEndpoint(%d) called on %s after Close", epNum, i) 117 | } 118 | ep, err := i.openEndpoint(EndpointAddress(0x80 | epNum)) 119 | if err != nil { 120 | return nil, err 121 | } 122 | return &InEndpoint{ 123 | endpoint: ep, 124 | }, nil 125 | } 126 | 127 | // OutEndpoint prepares an OUT endpoint for transfer. 128 | func (i *Interface) OutEndpoint(epNum int) (*OutEndpoint, error) { 129 | if i.config == nil { 130 | return nil, fmt.Errorf("OutEndpoint(%d) called on %s after Close", epNum, i) 131 | } 132 | ep, err := i.openEndpoint(EndpointAddress(epNum)) 133 | if err != nil { 134 | return nil, err 135 | } 136 | return &OutEndpoint{ 137 | endpoint: ep, 138 | }, nil 139 | } 140 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_sys.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_sys.h 28626 2014-11-07 23:08:42Z zhilin $ 4 | * 5 | * Copyright (C) 2003-2013 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * System specific functions. 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _V2U_SYS_H_ 12 | #define _V2U_SYS_H_ 1 13 | 14 | #include "v2u_ioctl.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif /* __cplusplus */ 19 | 20 | /* Maximum number of VGA2USB devices */ 21 | #define MAX_VGA2USB_DEVICE_COUNT 64 22 | 23 | /* OS specific device prefix */ 24 | #ifdef _WIN32 25 | # define V2U_DEV_PREFIX "\\\\.\\" 26 | # define V2U_DEV_PREFIX_LEN (4) 27 | #else 28 | # define V2U_DEV_PREFIX "/dev/" 29 | # define V2U_DEV_PREFIX_LEN (5) 30 | #endif 31 | 32 | /* Handle to the driver */ 33 | typedef struct _V2U_DRIVER *V2U_DRIVER_HANDLE, *V2U_HANDLE; 34 | 35 | /** 36 | * Opens the driver, returns NULL if fails. 37 | */ 38 | extern V2U_HANDLE v2u_open_driver(void); 39 | 40 | /** 41 | * Opens the driver, returns NULL if fails. 42 | */ 43 | extern V2U_HANDLE v2u_open_driver_device(const char* dev); 44 | 45 | /** 46 | * Opens the driver, returns NULL if fails. 47 | */ 48 | extern V2U_HANDLE v2u_open_driver_idx(int idx); 49 | 50 | /** 51 | * Opens the driver, returns NULL if fails. 52 | */ 53 | extern V2U_HANDLE v2u_open_driver_sn(const char* sn); 54 | 55 | /** 56 | * Opens all available devices (up to maxcount), returns number of devices 57 | * found. 58 | */ 59 | extern int v2u_open_all_devices(V2U_HANDLE* handles, int maxcount); 60 | 61 | /** 62 | * Returns number of available VGA2USB devices. 63 | */ 64 | #define v2u_count_devices() v2u_open_all_devices(NULL,MAX_VGA2USB_DEVICE_COUNT) 65 | 66 | /** 67 | * Returns OS file descriptor for the existing handle. 68 | */ 69 | extern int v2u_get_fd(V2U_HANDLE handle); 70 | 71 | /** 72 | * Returns OS specific name of the existing handle that identifies it in the 73 | * device namespace (basically, the file name with OS-specific prefix removed). 74 | */ 75 | extern const char* v2u_get_dev(V2U_HANDLE handle); 76 | 77 | /** 78 | * Sends ioctl to the driver. Returns zero on failure, non-zero on success. 79 | * Ioctl codes are defined in v2u_ioctl.h 80 | */ 81 | extern V2U_BOOL v2u_ioctl(V2U_HANDLE handle, unsigned long code, void* buf, 82 | unsigned int size); 83 | 84 | /** 85 | * Returns serial number of the VGA2USB device 86 | */ 87 | extern V2U_BOOL v2u_getsn(V2U_HANDLE handle, char* buf, int buflen); 88 | 89 | /** 90 | * Returns the property type, V2UPropType_Invalid if key is unknown 91 | */ 92 | extern V2UPropertyType v2u_get_property_type(V2UPropertyKey key); 93 | 94 | /** 95 | * Reads the device property. 96 | */ 97 | extern V2U_BOOL v2u_get_property(V2U_HANDLE handle, V2UPropertyKey key, 98 | V2UPropertyValue* value); 99 | 100 | /** 101 | * Sets the device property. 102 | */ 103 | extern V2U_BOOL v2u_set_property(V2U_HANDLE handle, V2UPropertyKey key, 104 | const V2UPropertyValue* value); 105 | 106 | /** 107 | * Returns the hardware type, V2UProductOther on error. 108 | */ 109 | extern V2UProductType v2u_get_product_type(V2U_HANDLE handle); 110 | 111 | /** 112 | * Detects video mode. 113 | * Returns zero on failure, non-zero on success. 114 | */ 115 | extern V2U_BOOL v2u_detect_videomode(V2U_HANDLE handle, V2U_VideoMode * vm); 116 | 117 | /** 118 | * Queries grab parameters. 119 | * Returns zero on failure, non-zero on success. 120 | */ 121 | extern V2U_BOOL v2u_get_grabparams(V2U_HANDLE handle, V2U_GrabParameters* gp); 122 | 123 | /** 124 | * Sets grab parameters. 125 | * Returns zero on failure, non-zero on success. 126 | */ 127 | extern V2U_BOOL v2u_set_grabparams(V2U_HANDLE handle, const V2U_GrabParameters* gp); 128 | 129 | /** 130 | * Grabs one full frame. Return V2U_GrabFrame structure on success, 131 | * NULL on failure. 132 | */ 133 | extern V2U_GrabFrame * v2u_grab_frame(V2U_HANDLE handle, int format); 134 | 135 | /** 136 | * Grabs the part of the frame specified by the crop rectangle. 137 | * Returns V2U_GrabFrame2 structure on success, NULL on failure. 138 | */ 139 | extern V2U_GrabFrame2* v2u_grab_frame2(V2U_HANDLE h, const V2URect* crop, int format); 140 | 141 | /** 142 | * Deallocates V2U_GrabFrame structure allocated by v2u_grab_frame 143 | */ 144 | extern void v2u_free_frame(V2U_GrabFrame* f); 145 | 146 | /** 147 | * Deallocates V2U_GrabFrame2 structure allocated by v2u_grab_frame2 148 | */ 149 | extern void v2u_free_frame2(V2U_GrabFrame2* f); 150 | 151 | /* 152 | * Closes the handle to the driver 153 | */ 154 | extern void v2u_close_driver(V2U_HANDLE handle); 155 | 156 | /** 157 | * Returns current time in milliseconds since January 1st 1970, 00:00 GMT 158 | */ 159 | extern V2U_TIME v2u_time(void); 160 | 161 | /** 162 | * Sleeps for specified amount of time (ms) 163 | */ 164 | extern void v2u_sleep(int ms); 165 | 166 | #ifdef __cplusplus 167 | } /* end of extern "C" */ 168 | #endif /* __cplusplus */ 169 | 170 | #endif /* _V2U_SYS_H_ */ 171 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/config.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "fmt" 20 | "sync" 21 | ) 22 | 23 | // ConfigDesc contains the information about a USB device configuration, 24 | // extracted from the device descriptor. 25 | type ConfigDesc struct { 26 | // Number is the configuration number. 27 | Number int 28 | // SelfPowered is true if the device is powered externally, i.e. not 29 | // drawing power from the USB bus. 30 | SelfPowered bool 31 | // RemoteWakeup is true if the device supports remote wakeup, i.e. 32 | // an external signal that will wake up a suspended USB device. An example 33 | // might be a keyboard that can wake up through a keypress after 34 | // the host put it in suspend mode. Note that gousb does not support 35 | // device power management, RemoteWakeup only refers to the reported device 36 | // capability. 37 | RemoteWakeup bool 38 | // MaxPower is the maximum current the device draws from the USB bus 39 | // in this configuration. 40 | MaxPower Milliamperes 41 | // Interfaces has a list of USB interfaces available in this configuration. 42 | Interfaces []InterfaceDesc 43 | 44 | iConfiguration int // index of a string descriptor describing this configuration 45 | } 46 | 47 | // String returns the human-readable description of the configuration descriptor. 48 | func (c ConfigDesc) String() string { 49 | return fmt.Sprintf("Configuration %d", c.Number) 50 | } 51 | 52 | func (c ConfigDesc) intfDesc(num, alt int) (*InterfaceSetting, error) { 53 | if num < 0 || num >= len(c.Interfaces) { 54 | return nil, fmt.Errorf("interface %d not found, available interfaces 0..%d", num, len(c.Interfaces)-1) 55 | } 56 | ifInfo := c.Interfaces[num] 57 | if alt < 0 || alt >= len(ifInfo.AltSettings) { 58 | return nil, fmt.Errorf("alternate setting %d not found for %s, available alt settings 0..%d", alt, ifInfo, len(ifInfo.AltSettings)-1) 59 | } 60 | return &ifInfo.AltSettings[alt], nil 61 | } 62 | 63 | // Config represents a USB device set to use a particular configuration. 64 | // Only one Config of a particular device can be used at any one time. 65 | // To access device endpoints, claim an interface and it's alternate 66 | // setting number through a call to Interface(). 67 | type Config struct { 68 | Desc ConfigDesc 69 | 70 | dev *Device 71 | 72 | // Claimed interfaces 73 | mu sync.Mutex 74 | claimed map[int]bool 75 | } 76 | 77 | // Close releases the underlying device, allowing the caller to switch the device to a different configuration. 78 | func (c *Config) Close() error { 79 | if c.dev == nil { 80 | return nil 81 | } 82 | c.mu.Lock() 83 | defer c.mu.Unlock() 84 | if len(c.claimed) > 0 { 85 | var ifs []int 86 | for k := range c.claimed { 87 | ifs = append(ifs, k) 88 | } 89 | return fmt.Errorf("failed to release %s, interfaces %v are still open", c, ifs) 90 | } 91 | c.dev.mu.Lock() 92 | defer c.dev.mu.Unlock() 93 | c.dev.claimed = nil 94 | c.dev = nil 95 | return nil 96 | } 97 | 98 | // String returns the human-readable description of the configuration. 99 | func (c *Config) String() string { 100 | return fmt.Sprintf("%s,config=%d", c.dev.String(), c.Desc.Number) 101 | } 102 | 103 | // Interface claims and returns an interface on a USB device. 104 | // num specifies the number of an interface to claim, and alt specifies the 105 | // alternate setting number for that interface. 106 | func (c *Config) Interface(num, alt int) (*Interface, error) { 107 | if c.dev == nil { 108 | return nil, fmt.Errorf("Interface(%d, %d) called on %s after Close", num, alt, c) 109 | } 110 | 111 | altInfo, err := c.Desc.intfDesc(num, alt) 112 | if err != nil { 113 | return nil, fmt.Errorf("descriptor of interface (%d, %d) in %s: %v", num, alt, c, err) 114 | } 115 | 116 | c.mu.Lock() 117 | defer c.mu.Unlock() 118 | if c.claimed[num] { 119 | return nil, fmt.Errorf("interface %d on %s is already claimed", num, c) 120 | } 121 | 122 | // Claim the interface 123 | if err := c.dev.ctx.libusb.claim(c.dev.handle, uint8(num)); err != nil { 124 | return nil, fmt.Errorf("failed to claim interface %d on %s: %v", num, c, err) 125 | } 126 | 127 | // Select an alternate setting if needed (device has multiple alternate settings). 128 | if len(c.Desc.Interfaces[num].AltSettings) > 1 { 129 | if err := c.dev.ctx.libusb.setAlt(c.dev.handle, uint8(num), uint8(alt)); err != nil { 130 | c.dev.ctx.libusb.release(c.dev.handle, uint8(num)) 131 | return nil, fmt.Errorf("failed to set alternate config %d on interface %d of %s: %v", alt, num, c, err) 132 | } 133 | } 134 | 135 | c.claimed[num] = true 136 | return &Interface{ 137 | Setting: *altInfo, 138 | config: c, 139 | }, nil 140 | } 141 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 the gousb Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package gousb 16 | 17 | import ( 18 | "context" 19 | "errors" 20 | "runtime" 21 | "sync" 22 | ) 23 | 24 | type usbTransfer struct { 25 | // mu protects the transfer state. 26 | mu sync.Mutex 27 | // xfer is the allocated libusb_transfer. 28 | xfer *libusbTransfer 29 | // buf is the buffer allocated for the transfer. The underlying memory 30 | // is allocated by the C code, both buf and xfer.buffer point to the same 31 | // memory. 32 | buf []byte 33 | // done is blocking until the transfer is complete and data and transfer 34 | // status are available. 35 | done chan struct{} 36 | // submitted is true if submit() was called on this transfer. 37 | submitted bool 38 | // ctx is the Context that created this transfer. 39 | ctx *Context 40 | } 41 | 42 | // submits the transfer. After submit() the transfer is in flight and is owned by libusb. 43 | // It's not safe to access the contents of the transfer until wait() returns. 44 | // Once wait() returns, it's ok to re-use the same transfer structure by calling submit() again. 45 | func (t *usbTransfer) submit() error { 46 | t.mu.Lock() 47 | defer t.mu.Unlock() 48 | if t.submitted { 49 | return errors.New("transfer was already submitted and is not finished yet") 50 | } 51 | if err := t.ctx.libusb.submit(t.xfer); err != nil { 52 | return err 53 | } 54 | t.submitted = true 55 | return nil 56 | } 57 | 58 | // waits for libusb to signal the release of transfer data. 59 | // After wait returns, the transfer contents are safe to access 60 | // via t.buf. The number returned by wait indicates how many bytes 61 | // of the buffer were read or written by libusb, and it can be 62 | // smaller than the length of t.buf. 63 | func (t *usbTransfer) wait(ctx context.Context) (n int, err error) { 64 | t.mu.Lock() 65 | defer t.mu.Unlock() 66 | if !t.submitted { 67 | return 0, nil 68 | } 69 | select { 70 | case <-ctx.Done(): 71 | t.ctx.libusb.cancel(t.xfer) 72 | // after the transfer is cancelled, it will run a callback 73 | // that triggers the activation of t.done. 74 | <-t.done 75 | case <-t.done: 76 | } 77 | t.submitted = false 78 | n, status := t.ctx.libusb.data(t.xfer) 79 | if status != TransferCompleted { 80 | return n, status 81 | } 82 | return n, err 83 | } 84 | 85 | // cancel aborts a submitted transfer. The transfer is cancelled 86 | // asynchronously and the user still needs to wait() to return. 87 | func (t *usbTransfer) cancel() error { 88 | t.mu.Lock() 89 | defer t.mu.Unlock() 90 | if !t.submitted { 91 | return nil 92 | } 93 | err := t.ctx.libusb.cancel(t.xfer) 94 | if err == ErrorNotFound { 95 | // transfer already completed 96 | return nil 97 | } 98 | return err 99 | } 100 | 101 | // free releases the memory allocated for the transfer. 102 | // free should be called only if the transfer is not used by libusb, 103 | // i.e. it should not be called after submit() and before wait() returns. 104 | func (t *usbTransfer) free() error { 105 | t.mu.Lock() 106 | defer t.mu.Unlock() 107 | if t.submitted { 108 | return errors.New("free() cannot be called on a submitted transfer until wait() returns") 109 | } 110 | if t.xfer == nil { 111 | return nil 112 | } 113 | t.ctx.libusb.free(t.xfer) 114 | t.xfer = nil 115 | t.buf = nil 116 | t.done = nil 117 | return nil 118 | } 119 | 120 | // data returns the slice containing transfer buffer. 121 | func (t *usbTransfer) data() []byte { 122 | return t.buf 123 | } 124 | 125 | // newUSBTransfer allocates a new transfer structure and a new buffer for 126 | // communication with a given device/endpoint. 127 | func newUSBTransfer(ctx *Context, dev *libusbDevHandle, ei *EndpointDesc, bufLen int) (*usbTransfer, error) { 128 | var isoPackets, isoPktSize int 129 | if ei.TransferType == TransferTypeIsochronous { 130 | isoPktSize = ei.MaxPacketSize 131 | if bufLen < isoPktSize { 132 | isoPktSize = bufLen 133 | } 134 | if isoPktSize > 0 { 135 | isoPackets = bufLen / isoPktSize 136 | } else { 137 | isoPackets = 1 138 | } 139 | debug.Printf("New isochronous transfer - buffer length %d, using %d packets of %d bytes each", bufLen, isoPackets, isoPktSize) 140 | } 141 | 142 | done := make(chan struct{}, 1) 143 | xfer, err := ctx.libusb.alloc(dev, ei, isoPackets, bufLen, done) 144 | if err != nil { 145 | return nil, err 146 | } 147 | 148 | if ei.TransferType == TransferTypeIsochronous { 149 | ctx.libusb.setIsoPacketLengths(xfer, uint32(isoPktSize)) 150 | } 151 | 152 | t := &usbTransfer{ 153 | xfer: xfer, 154 | buf: ctx.libusb.buffer(xfer), 155 | done: done, 156 | ctx: ctx, 157 | } 158 | runtime.SetFinalizer(t, func(t *usbTransfer) { 159 | t.cancel() 160 | t.wait(context.Background()) 161 | t.free() 162 | }) 163 | return t, nil 164 | } 165 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_compression.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_compression.h 8063 2009-11-19 23:11:46Z rekjanov $ 4 | * 5 | * Copyright (C) 2007-2009 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Defines and implements decompression library for EPIPHAN VGA2USB compression 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _VGA2USB_COMPRESSION_H_ 12 | #define _VGA2USB_COMPRESSION_H_ 1 13 | 14 | #include "v2u_defs.h" 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif /* __cplusplus */ 19 | 20 | #ifndef V2UDEC_API 21 | #ifdef _WIN32 22 | #ifdef V2UDEC_EXPORTS 23 | #define V2UDEC_API __declspec(dllexport) 24 | #else 25 | #define V2UDEC_API __declspec(dllimport) 26 | #endif 27 | #else 28 | #define V2UDEC_API 29 | #endif 30 | #endif 31 | 32 | /** 33 | * Error codes used as a part of compression SDK 34 | */ 35 | #ifndef EPROTO 36 | # define EPROTO 105 37 | #endif 38 | 39 | #ifndef ENOSR 40 | # define ENOSR 106 41 | #endif 42 | 43 | #ifndef EOK 44 | # define EOK 0 45 | #endif 46 | 47 | /**************************************************************************** 48 | * 49 | * 50 | * Public interface to the decompression engine 51 | * 52 | * 53 | ****************************************************************************/ 54 | 55 | /** 56 | * Version of the library and files generatated by the compression algorithm 57 | */ 58 | #define V2U_COMPRESSION_LIB_VERSION 0x00000100 59 | 60 | 61 | 62 | /** 63 | * Context of the files sequence 64 | * Compression algorithm internaly keeps key frame. Therefore to decode 65 | * sequence of frames common context must be created and used during decoding 66 | * of consiquently captured frames 67 | */ 68 | typedef struct v2udec_ctx* V2U_DECOMPRESSION_LIB_CONTEXT; 69 | V2UDEC_API V2U_DECOMPRESSION_LIB_CONTEXT v2udec_init_context( void ); 70 | V2UDEC_API void v2udec_deinit_context( V2U_DECOMPRESSION_LIB_CONTEXT uctx ); 71 | 72 | /** 73 | * Functions to obtain information about the compressed frame 74 | */ 75 | 76 | /** 77 | * Minimum header size. 78 | * Useful when reading in bytestream. After receiving this number of bytes 79 | * additional information about the frame can be obtained from 80 | * v2udec_get_framelen() et al. 81 | * This value can be different for different versions of V2U libraries. 82 | */ 83 | V2UDEC_API V2U_UINT32 84 | v2udec_get_minheaderlen(V2U_DECOMPRESSION_LIB_CONTEXT uctx); 85 | 86 | /** 87 | * Actual header size. 88 | * Add this to v2udec_get_framelen() to obtain required buffer size to 89 | * hold one compressed frame. 90 | * @return 0 on error. 91 | */ 92 | V2UDEC_API V2U_UINT32 93 | v2udec_get_headerlen( 94 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 95 | const unsigned char * framebuf, 96 | int framebuflen); 97 | 98 | 99 | /** Timestamp (in milliseconds) of the frame in the framebuf */ 100 | V2UDEC_API V2U_TIME 101 | v2udec_get_timestamp( 102 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 103 | const unsigned char * framebuf, 104 | int framebuflen); 105 | 106 | // Length of the single compressed frame in the framebuf (excluding compression 107 | // header) 108 | V2UDEC_API V2U_UINT32 109 | v2udec_get_framelen( 110 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 111 | const unsigned char * framebuf, 112 | int framebuflen); 113 | 114 | // Size of the buffer required to decompress the frame in the framebuf 115 | // (function of frame resolution and palette) 116 | V2UDEC_API int 117 | v2udec_get_decompressed_framelen( 118 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 119 | const unsigned char * framebuf, 120 | int framebuflen); 121 | 122 | // Palette of the frame in the framebuf (currently RGB24 or YUY2) 123 | V2UDEC_API V2U_UINT32 124 | v2udec_get_palette( 125 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 126 | const unsigned char * framebuf, 127 | int framebuflen); 128 | 129 | // Palette of the frame in the framebuf before decompression 130 | V2UDEC_API V2U_UINT32 131 | v2udec_get_cpalette( 132 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 133 | const unsigned char * framebuf, 134 | int framebuflen); 135 | 136 | // Set desired palette for the frame in the framebuf 137 | V2UDEC_API V2U_BOOL 138 | v2udec_set_palette( 139 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 140 | const unsigned char * framebuf, 141 | int framebuflen, 142 | V2U_UINT32 palette); 143 | 144 | // Resolution of the frame in the framebuf 145 | V2UDEC_API void 146 | v2udec_get_frameres( 147 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 148 | const unsigned char * framebuf, 149 | int framebuflen, 150 | V2URect * rect); 151 | 152 | // Video mode of the frame in the framebuf, 153 | // that is width and height before cropping 154 | // and vertical refresh rate. 155 | V2UDEC_API void 156 | v2udec_get_videomode( 157 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 158 | const unsigned char * framebuf, 159 | int framebuflen, 160 | V2U_VideoMode * vmode); 161 | 162 | 163 | // Keyframe if not 0 164 | V2UDEC_API int 165 | v2udec_is_keyframe( 166 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 167 | const unsigned char * framebuf, 168 | int framebuflen); 169 | 170 | // Ordered if not 0 171 | V2UDEC_API int 172 | v2udec_is_ordered( 173 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 174 | const unsigned char * framebuf, 175 | int framebuflen); 176 | 177 | /** 178 | * Decompression functions 179 | */ 180 | V2UDEC_API int 181 | v2udec_decompress_frame( 182 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 183 | const unsigned char * framebuf, 184 | int framebuflen, 185 | unsigned char * bufout, // user-allocated buffer for decompressed frame 186 | int bufoutlen); 187 | 188 | V2UDEC_API int 189 | v2udec_decompress_frame2( 190 | V2U_DECOMPRESSION_LIB_CONTEXT uctx, 191 | const unsigned char * framebuf, 192 | int framebuflen, 193 | unsigned char * bufout, 194 | int bufoutlen, 195 | const unsigned char *prev_frame, 196 | int prev_frame_len, 197 | int just_key_data); 198 | 199 | #ifdef __cplusplus 200 | } /* end of extern "C" */ 201 | #endif /* __cplusplus */ 202 | 203 | #endif //_VGA2USB_COMPRESSION_H_ 204 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/endpoint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "context" 20 | "fmt" 21 | "strings" 22 | "time" 23 | ) 24 | 25 | // EndpointAddress is a unique identifier for the endpoint, combining the endpoint number and direction. 26 | type EndpointAddress uint8 27 | 28 | // String implements the Stringer interface. 29 | func (a EndpointAddress) String() string { 30 | return fmt.Sprintf("0x%02x", uint8(a)) 31 | } 32 | 33 | // EndpointDesc contains the information about an interface endpoint, extracted 34 | // from the descriptor. 35 | type EndpointDesc struct { 36 | // Address is the unique identifier of the endpoint within the interface. 37 | Address EndpointAddress 38 | // Number represents the endpoint number. Note that the endpoint number is different from the 39 | // address field in the descriptor - address 0x82 means endpoint number 2, 40 | // with endpoint direction IN. 41 | // The device can have up to two endpoints with the same number but with 42 | // different directions. 43 | Number int 44 | // Direction defines whether the data is flowing IN or OUT from the host perspective. 45 | Direction EndpointDirection 46 | // MaxPacketSize is the maximum USB packet size for a single frame/microframe. 47 | MaxPacketSize int 48 | // TransferType defines the endpoint type - bulk, interrupt, isochronous. 49 | TransferType TransferType 50 | // PollInterval is the maximum time between transfers for interrupt and isochronous transfer, 51 | // or the NAK interval for a control transfer. See endpoint descriptor bInterval documentation 52 | // in the USB spec for details. 53 | PollInterval time.Duration 54 | // IsoSyncType is the isochronous endpoint synchronization type, as defined by USB spec. 55 | IsoSyncType IsoSyncType 56 | // UsageType is the isochronous or interrupt endpoint usage type, as defined by USB spec. 57 | UsageType UsageType 58 | } 59 | 60 | // String returns the human-readable description of the endpoint. 61 | func (e EndpointDesc) String() string { 62 | ret := make([]string, 0, 3) 63 | ret = append(ret, fmt.Sprintf("ep #%d %s (address %s) %s", e.Number, e.Direction, e.Address, e.TransferType)) 64 | switch e.TransferType { 65 | case TransferTypeIsochronous: 66 | ret = append(ret, fmt.Sprintf("- %s %s", e.IsoSyncType, e.UsageType)) 67 | case TransferTypeInterrupt: 68 | ret = append(ret, fmt.Sprintf("- %s", e.UsageType)) 69 | } 70 | ret = append(ret, fmt.Sprintf("[%d bytes]", e.MaxPacketSize)) 71 | return strings.Join(ret, " ") 72 | } 73 | 74 | type endpoint struct { 75 | h *libusbDevHandle 76 | 77 | InterfaceSetting 78 | Desc EndpointDesc 79 | 80 | ctx *Context 81 | } 82 | 83 | // String returns a human-readable description of the endpoint. 84 | func (e *endpoint) String() string { 85 | return e.Desc.String() 86 | } 87 | 88 | func (e *endpoint) transfer(ctx context.Context, buf []byte) (int, error) { 89 | t, err := newUSBTransfer(e.ctx, e.h, &e.Desc, len(buf)) 90 | if err != nil { 91 | return 0, err 92 | } 93 | defer t.free() 94 | if e.Desc.Direction == EndpointDirectionOut { 95 | copy(t.data(), buf) 96 | } 97 | 98 | if err := t.submit(); err != nil { 99 | return 0, err 100 | } 101 | 102 | n, err := t.wait(ctx) 103 | if e.Desc.Direction == EndpointDirectionIn { 104 | copy(buf, t.data()) 105 | } 106 | if err != nil { 107 | return n, err 108 | } 109 | return n, nil 110 | } 111 | 112 | // InEndpoint represents an IN endpoint open for transfer. 113 | // InEndpoint implements the io.Reader interface. 114 | // For high-throughput transfers, consider creating a bufffered read stream 115 | // through InEndpoint.ReadStream. 116 | type InEndpoint struct { 117 | *endpoint 118 | } 119 | 120 | // Read reads data from an IN endpoint. Read returns number of bytes obtained 121 | // from the endpoint. Read may return non-zero length even if 122 | // the returned error is not nil (partial read). 123 | func (e *InEndpoint) Read(buf []byte) (int, error) { 124 | return e.transfer(context.Background(), buf) 125 | } 126 | 127 | // ReadContext reads data from an IN endpoint. ReadContext returns number of 128 | // bytes obtained from the endpoint. ReadContext may return non-zero length 129 | // even if the returned error is not nil (partial read). 130 | // The passed context can be used to control the cancellation of the read. If 131 | // the context is cancelled, ReadContext will cancel the underlying transfers, 132 | // resulting in TransferCancelled error. 133 | func (e *InEndpoint) ReadContext(ctx context.Context, buf []byte) (int, error) { 134 | return e.transfer(ctx, buf) 135 | } 136 | 137 | // OutEndpoint represents an OUT endpoint open for transfer. 138 | type OutEndpoint struct { 139 | *endpoint 140 | } 141 | 142 | // Write writes data to an OUT endpoint. Write returns number of bytes comitted 143 | // to the endpoint. Write may return non-zero length even if the returned error 144 | // is not nil (partial write). 145 | func (e *OutEndpoint) Write(buf []byte) (int, error) { 146 | return e.transfer(context.Background(), buf) 147 | } 148 | 149 | // WriteContext writes data to an OUT endpoint. WriteContext returns number of 150 | // bytes comitted to the endpoint. WriteContext may return non-zero length even 151 | // if the returned error is not nil (partial write). 152 | // The passed context can be used to control the cancellation of the write. If 153 | // the context is cancelled, WriteContext will cancel the underlying transfers, 154 | // resulting in TransferCancelled error. 155 | func (e *OutEndpoint) WriteContext(ctx context.Context, buf []byte) (int, error) { 156 | return e.transfer(ctx, buf) 157 | } 158 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_dshow.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_dshow.h 26853 2014-06-05 12:55:22Z srozin $ 4 | * 5 | * Copyright (C) 2009-2014 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * VGA2USB driver for Windows. 8 | * Declaration of VGA2USB proprietary property set 9 | * 10 | ****************************************************************************/ 11 | 12 | #ifndef _VGA2USB_V2U_DSHOW_H_ 13 | #define _VGA2USB_V2U_DSHOW_H_ 1 14 | 15 | /* {9B2C649F-CAE6-4745-8D09-413DF0562C4B} */ 16 | #define STATIC_PROPSETID_V2U_PROPSET \ 17 | 0x9b2c649fL, 0xcae6, 0x4745, 0x8d, 0x09, 0x41, 0x3d, 0xf0, 0x56, 0x2c, 0x4b 18 | 19 | /* 20 | * Map between DirectShow PROP_GET properties and V2U properties. 21 | * This map is full. 22 | */ 23 | #define V2U_DSHOW_PROP_MAP(m) \ 24 | m( V2U_DSHOW_PROP_GET_DSFLAGS, V2UKey_DirectShowFlags ) \ 25 | m( V2U_DSHOW_PROP_GET_DSFIXRES, V2UKey_DirectShowFixRes ) \ 26 | m( V2U_DSHOW_PROP_GET_DSBITMAP, V2UKey_DirectShowDefaultBmp ) \ 27 | m( V2U_DSHOW_PROP_GET_DSSCALEMODE, V2UKey_DirectShowScaleMode ) \ 28 | m( V2U_DSHOW_PROP_GET_DSMAXRATE, V2UKey_DirectShowMaxFps ) \ 29 | m( V2U_DSHOW_PROP_GET_USERDATA, V2UKey_UserData ) \ 30 | m( V2U_DSHOW_PROP_GET_PROD_ID, V2UKey_UsbProductID ) \ 31 | m( V2U_DSHOW_PROP_GET_PROD_TYPE, V2UKey_ProductType ) \ 32 | m( V2U_DSHOW_PROP_GET_PROD_NAME, V2UKey_ProductName ) \ 33 | m( V2U_DSHOW_PROP_GET_VGAMODE_INFO, V2UKey_ModeMeasurmentsDump ) \ 34 | m( V2U_DSHOW_PROP_GET_HW_COMPRESSION, V2UKey_HardwareCompression ) \ 35 | m( V2U_DSHOW_PROP_GET_ADJ_RANGE, V2UKey_AdjustmentsRange ) \ 36 | m( V2U_DSHOW_PROP_GET_VERSION, V2UKey_Version ) \ 37 | m( V2U_DSHOW_PROP_GET_EDID, V2UKey_EDID ) \ 38 | m( V2U_DSHOW_PROP_GET_KVM_SUPPORT, V2UKey_KVMCapable ) \ 39 | m( V2U_DSHOW_PROP_GET_VGAMODE_ENTRY, V2UKey_VGAMode ) \ 40 | m( V2U_DSHOW_PROP_GET_VGAMODE, V2UKey_CurrentVGAMode ) \ 41 | m( V2U_DSHOW_PROP_GET_MEASURE_INTERVAL, V2UKey_ModeMeasureInterval ) \ 42 | m( V2U_DSHOW_PROP_GET_EDID_SUPPORT, V2UKey_EDIDSupport ) \ 43 | m( V2U_DSHOW_PROP_GET_TUNE_INTERVAL, V2UKey_TuneInterval ) \ 44 | m( V2U_DSHOW_PROP_GET_SN, V2UKey_SerialNumber ) \ 45 | m( V2U_DSHOW_PROP_GET_SIGNAL_TYPE, V2UKey_InputSignalType ) \ 46 | m( V2U_DSHOW_PROP_GET_DVIMODE_DETECT, V2UKey_DigitalModeDetect ) \ 47 | m( V2U_DSHOW_PROP_GET_NOISE_FILTER, V2UKey_NoiseFilter ) \ 48 | m( V2U_DSHOW_PROP_GET_HSYNC_THRESHOLD, V2UKey_HSyncThreshold ) \ 49 | m( V2U_DSHOW_PROP_GET_VSYNC_THRESHOLD, V2UKey_VSyncThreshold ) \ 50 | m( V2U_DSHOW_PROP_GET_DEVICE_CAPS, V2UKey_DeviceCaps ) \ 51 | m( V2U_DSHOW_PROP_GET_DSBITMAP2, V2UKey_DirectShowDefaultBmp2) \ 52 | m( V2U_DSHOW_PROP_GET_BUS_TYPE, V2UKey_BusType ) \ 53 | m( V2U_DSHOW_PROP_GET_GRABBER_ID, V2UKey_GrabberId ) \ 54 | m( V2U_DSHOW_PROP_GET_VIDEO_FORMAT, V2UKey_VideoFormat ) 55 | /* DO NOT ADD ANY MORE PROPERTIES HERE */ 56 | 57 | /* 58 | * Second range of properties (add new ones to the end) 59 | */ 60 | #define V2U_DSHOW_PROP_MAP2(m) \ 61 | m( V2U_DSHOW_PROP_GET_DSHOW_COMPAT_MODE, V2UKey_DShowCompatMode ) \ 62 | m( V2U_DSHOW_PROP_GET_EEDID, V2UKey_EEDID ) \ 63 | m( V2U_DSHOW_PROP_LOG_LEVEL, V2UKey_LogLevel ) \ 64 | m( V2U_DSHOW_PROP_MAX_LOG_LEVEL, V2UKey_MaxLogLevel ) \ 65 | m( V2U_DSHOW_PROP_USB_SPEED, V2UKey_UsbSpeed ) \ 66 | m( V2U_DSHOW_PROP_BUILD_DATE, V2UKey_BuildDate ) \ 67 | m( V2U_DSHOW_PROP_BUILD_TIME, V2UKey_BuildTime ) \ 68 | m( V2U_DSHOW_PROP_BOARD_ID, V2UKey_BoardId ) \ 69 | m( V2U_DSHOW_PROP_GET_TEMPERATURE, V2UKey_Temperature ) \ 70 | m( V2U_DSHOW_PROP_GET_INPUTNAME, V2UKey_InputName ) 71 | 72 | /* We have run out of these */ 73 | #define V2U_DSHOW_PROP_RESERVE(r) 74 | 75 | /* More reserved slots before V2U_DSHOW_PROP_GET_DSHOW_COMPAT_MODE */ 76 | #define V2U_DSHOW_PROP_RESERVE2(r) \ 77 | r( V2U_DSHOW_PROP_RESERVED_1, -1 ) \ 78 | r( V2U_DSHOW_PROP_RESERVED_2, -1 ) \ 79 | r( V2U_DSHOW_PROP_RESERVED_3, -1 ) \ 80 | r( V2U_DSHOW_PROP_RESERVED_4, -1 ) \ 81 | r( V2U_DSHOW_PROP_RESERVED_5, -1 ) \ 82 | r( V2U_DSHOW_PROP_RESERVED_6, -1 ) \ 83 | r( V2U_DSHOW_PROP_RESERVED_7, -1 ) \ 84 | r( V2U_DSHOW_PROP_RESERVED_8, -1 ) \ 85 | r( V2U_DSHOW_PROP_RESERVED_9, -1 ) \ 86 | r( V2U_DSHOW_PROP_RESERVED_10, -1 ) \ 87 | r( V2U_DSHOW_PROP_RESERVED_11, -1 ) \ 88 | r( V2U_DSHOW_PROP_RESERVED_12, -1 ) \ 89 | r( V2U_DSHOW_PROP_RESERVED_13, -1 ) \ 90 | r( V2U_DSHOW_PROP_RESERVED_14, -1 ) \ 91 | r( V2U_DSHOW_PROP_RESERVED_15, -1 ) \ 92 | r( V2U_DSHOW_PROP_RESERVED_16, -1 ) \ 93 | r( V2U_DSHOW_PROP_RESERVED_17, -1 ) \ 94 | r( V2U_DSHOW_PROP_RESERVED_18, -1 ) \ 95 | r( V2U_DSHOW_PROP_RESERVED_19, -1 ) \ 96 | r( V2U_DSHOW_PROP_RESERVED_20, -1 ) 97 | 98 | /** 99 | * Property IDs 100 | */ 101 | #undef V2U_DSHOW_PROP_DEFINE_ID 102 | #define V2U_DSHOW_PROP_DEFINE_ID(id,key) id, 103 | 104 | typedef enum _V2U_DSHOW_PROP { 105 | V2U_DSHOW_PROP_DETECT_VIDEO_MODE, /* V2U_VideoMode */ 106 | V2U_DSHOW_PROP_SET_PROPERTY, /* Any property */ 107 | 108 | V2U_DSHOW_PROP_MAP(V2U_DSHOW_PROP_DEFINE_ID) 109 | V2U_DSHOW_PROP_RESERVE(V2U_DSHOW_PROP_DEFINE_ID) 110 | 111 | V2U_DSHOW_PROP_GRAB_PARAMETERS, /* V2U_GrabParameters */ 112 | V2U_DSHOW_PROP_DSHOW_ACTIVE_COMPAT_MODE,/* V2UKey_DShowActiveCompatMode */ 113 | 114 | V2U_DSHOW_PROP_RESERVE2(V2U_DSHOW_PROP_DEFINE_ID) 115 | V2U_DSHOW_PROP_MAP2(V2U_DSHOW_PROP_DEFINE_ID) 116 | 117 | V2U_DSHOW_PROP_COUNT /* Not a valid value! */ 118 | } V2U_DSHOW_PROP; 119 | 120 | #undef V2U_DSHOW_PROP_DEFINE_ID 121 | 122 | #endif /* _VGA2USB_V2U_DSHOW_H_ */ 123 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_util.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_util.h 22125 2013-05-11 19:41:17Z monich $ 4 | * 5 | * Copyright (C) 2003-2013 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Header file for miscellaneous utilities. 8 | * 9 | ****************************************************************************/ 10 | 11 | #ifndef _V2U_UTIL_H_ 12 | #define _V2U_UTIL_H_ 1 13 | 14 | #include "v2u_defs.h" 15 | #include 16 | 17 | #ifndef FALSE 18 | #define FALSE 0 19 | #endif 20 | 21 | #ifndef TRUE 22 | #define TRUE 1 23 | #endif 24 | 25 | #ifndef MIN 26 | # define MIN(x,y) (((x)<(y))?(x):(y)) 27 | #endif /* MIN */ 28 | 29 | #ifndef MAX 30 | # define MAX(x,y) (((x)>(y))?(x):(y)) 31 | #endif /* MAX */ 32 | 33 | #define V2U_EDID_SIZE (128) 34 | #define V2U_EEDID_SIZE (256) 35 | 36 | /* Hack for line size (aligned at 32 pixels on daVinci platform) */ 37 | #ifndef DAVINCI 38 | # ifdef __arm__ 39 | # define DAVINCI 1 40 | # else 41 | # define DAVINCI 0 42 | # endif 43 | #endif /* DAVINCI */ 44 | 45 | /* V2U_LINE_SIZE macro returns the line size in bytes */ 46 | #if DAVINCI 47 | # define V2U_LINE_SIZE_BPP(w,bpp) ((((w)+31)&(-32))*(bpp)/8) 48 | #else 49 | # define V2U_LINE_SIZE_BPP(w,bpp) ((w)*(bpp)/8) 50 | #endif /* DAVINCI */ 51 | #define V2U_LINE_SIZE(w,fmt) V2U_LINE_SIZE_BPP(w,V2UPALETTE_2_BPP(fmt)) 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif /* __cplusplus */ 56 | 57 | /** 58 | * Copies BMP row (or a part of it) that came from VGA2USB into 24-bit RGB 59 | * row in the format understood by JPEG and PNG libraries. The following image 60 | * formats are supported: 61 | * 62 | * V2U_GRABFRAME_FORMAT_Y8 63 | * V2U_GRABFRAME_FORMAT_RGB4 64 | * V2U_GRABFRAME_FORMAT_RGB8 65 | * V2U_GRABFRAME_FORMAT_RGB16 66 | * V2U_GRABFRAME_FORMAT_BGR16 67 | * V2U_GRABFRAME_FORMAT_RGB24 68 | * V2U_GRABFRAME_FORMAT_BGR24 69 | * V2U_GRABFRAME_FORMAT_ARGB32 70 | */ 71 | extern V2U_BOOL v2u_copy_line(void* dst24, const void* bmp, int fmt, int w); 72 | 73 | /** 74 | * Pixel format converters. Convert a single row from one format to another. 75 | * Parameters: 76 | * dst - points to the destination buffer that receives the requested row 77 | * in RGB24 or BGR24 format 78 | * src - points the source image 79 | * row - index of the row to transform 80 | * w - width of the row in pixels 81 | * h - height of the row in pixels 82 | * 83 | * The source image is assumed to be tightly packed, i.e. no padding between 84 | * the rows. 85 | */ 86 | void v2u_convert_yv12_to_rgb24(void* dst,const void* src,int row,int w,int h); 87 | void v2u_convert_yv12_to_bgr24(void* dst,const void* src,int row,int w,int h); 88 | void v2u_convert_i420_to_rgb24(void* dst,const void* src,int row,int w,int h); 89 | void v2u_convert_i420_to_bgr24(void* dst,const void* src,int row,int w,int h); 90 | void v2u_convert_yuy2_to_rgb24(void* dst,const void* src,int row,int w,int h); 91 | void v2u_convert_yuy2_to_bgr24(void* dst,const void* src,int row,int w,int h); 92 | void v2u_convert_2vuy_to_rgb24(void* dst,const void* src,int row,int w,int h); 93 | void v2u_convert_2vuy_to_bgr24(void* dst,const void* src,int row,int w,int h); 94 | void v2u_convert_nv12_to_rgb24(void* dst,const void* src,int row,int w,int h); 95 | void v2u_convert_nv12_to_bgr24(void* dst,const void* src,int row,int w,int h); 96 | 97 | /** 98 | * Converts a single row from the specified grab format to RGB24. Used by 99 | * v2u_write_jpeg and v2u_write_png. The following image formats are supported: 100 | * 101 | * V2U_GRABFRAME_FORMAT_Y8 102 | * V2U_GRABFRAME_FORMAT_RGB4 103 | * V2U_GRABFRAME_FORMAT_RGB8 104 | * V2U_GRABFRAME_FORMAT_RGB16 105 | * V2U_GRABFRAME_FORMAT_BGR16 106 | * V2U_GRABFRAME_FORMAT_RGB24 107 | * V2U_GRABFRAME_FORMAT_BGR24 108 | * V2U_GRABFRAME_FORMAT_ARGB32 109 | * V2U_GRABFRAME_FORMAT_YUY2 110 | * V2U_GRABFRAME_FORMAT_2VUY 111 | * V2U_GRABFRAME_FORMAT_YV12 112 | * V2U_GRABFRAME_FORMAT_I420 113 | */ 114 | extern V2U_BOOL v2u_convert_to_rgb24(void* dst, const void* scr, int fmt, 115 | int row, int w, int h); 116 | 117 | /** 118 | * Returns user-readable name for the specified device type 119 | */ 120 | extern const char* v2u_product_name(V2UProductType type); 121 | 122 | /** 123 | * Reads text EDID from the stream. The text EDID must be in the 124 | * Phoenix EDID Designer format. It looks like this: 125 | * 126 | * EDID BYTES: 127 | * 0x 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 128 | * ------------------------------------------------ 129 | * 00 | 00 FF FF FF FF FF FF 00 16 08 22 22 00 00 00 00 130 | * 10 | 08 10 01 03 EE 28 1E 78 0B 01 95 A3 57 4C 9C 25 131 | * 20 | 12 50 54 EF CF 00 81 C0 8B C0 90 40 B3 00 A9 40 132 | * 30 | D1 C0 01 01 01 01 C8 32 40 A0 60 B0 23 40 30 20 133 | * 40 | 35 00 90 2C 11 00 00 18 00 00 00 FF 00 56 33 55 134 | * 50 | 58 58 58 58 58 0A 0A 0A 0A 0A 00 00 00 FD 00 38 135 | * 60 | 55 0F 6E 10 00 0A 20 20 20 20 20 20 00 00 00 FC 136 | * 70 | 00 45 70 69 70 68 61 6E 20 44 32 55 0A 0A 00 14 137 | */ 138 | extern V2U_BOOL v2u_edid_read(FILE* in, V2U_UINT8 edid[/*V2U_EDID_SIZE*/]); 139 | 140 | /* edid buffer passed to v2u_edid_read_ext should be 256 bytes long. 141 | * Function returns EDID size (128 or 256) or zero on failure. */ 142 | extern int v2u_edid_read_ext(FILE* in, V2U_UINT8 edid[/*V2U_EEDID_SIZE*/]); 143 | 144 | /* output stream for formatted ASCII text */ 145 | typedef struct v2u_out_stream_t V2U_OUT_STREAM; 146 | 147 | /* used like fputs() */ 148 | typedef int (*V2U_TXT_STREAM_WRITER)(const char* txt, V2U_OUT_STREAM* stream); 149 | 150 | /** 151 | * Writes EDID to the stream in the text form (Phoenix EDID Designer format). 152 | */ 153 | extern V2U_BOOL v2u_edid_write_text(V2U_OUT_STREAM* stream, 154 | V2U_TXT_STREAM_WRITER writer, const V2U_UINT8 edid[/*V2U_EDID_SIZE*/]); 155 | extern V2U_BOOL v2u_edid_write_text2(V2U_OUT_STREAM* stream, 156 | V2U_TXT_STREAM_WRITER writer, const V2U_UINT8* edid, int len); 157 | 158 | /** 159 | * Writes EDID to the stream in the text form (Phoenix EDID Designer format). 160 | */ 161 | extern V2U_BOOL v2u_edid_write(FILE* out, const V2U_UINT8 edid[/*V2U_EDID_SIZE*/]); 162 | extern V2U_BOOL v2u_edid_write_ext(FILE* out, const V2U_UINT8* edid, int len); 163 | 164 | #ifdef __cplusplus 165 | } /* end of extern "C" */ 166 | #endif /* __cplusplus */ 167 | 168 | #endif /* _V2U_UTIL_H_ */ 169 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/fakelibusb_devices.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the gousb Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package gousb 16 | 17 | // fake devices connected through the fakeLibusb stack. 18 | type fakeDevice struct { 19 | devDesc *DeviceDesc 20 | strDesc map[int]string 21 | alt uint8 22 | } 23 | 24 | var fakeDevices = []fakeDevice{ 25 | // Bus 001 Device 001: ID 9999:0001 26 | // One config, one interface, one setup, 27 | // two endpoints: 0x01 OUT, 0x82 IN. 28 | { 29 | devDesc: &DeviceDesc{ 30 | Bus: 1, 31 | Address: 1, 32 | Port: 1, 33 | Spec: Version(2, 0), 34 | Device: Version(1, 0), 35 | Vendor: ID(0x9999), 36 | Product: ID(0x0001), 37 | Protocol: 255, 38 | Configs: map[int]ConfigDesc{1: { 39 | Number: 1, 40 | MaxPower: Milliamperes(100), 41 | Interfaces: []InterfaceDesc{{ 42 | Number: 0, 43 | AltSettings: []InterfaceSetting{{ 44 | Number: 0, 45 | Alternate: 0, 46 | Class: ClassVendorSpec, 47 | Endpoints: map[EndpointAddress]EndpointDesc{ 48 | 0x01: { 49 | Address: 0x01, 50 | Number: 1, 51 | Direction: EndpointDirectionOut, 52 | MaxPacketSize: 512, 53 | TransferType: TransferTypeBulk, 54 | }, 55 | 0x82: { 56 | Address: 0x82, 57 | Number: 2, 58 | Direction: EndpointDirectionIn, 59 | MaxPacketSize: 512, 60 | TransferType: TransferTypeBulk, 61 | }, 62 | }, 63 | }}, 64 | }}, 65 | }}, 66 | }, 67 | }, 68 | // Bus 001 Device 002: ID 8888:0002 69 | // One config, two interfaces. interface #0 with no endpoints, 70 | // interface #1 with two alt setups with different packet sizes for 71 | // endpoints. Two isochronous endpoints, 0x05 OUT and 0x86 OUT. 72 | { 73 | devDesc: &DeviceDesc{ 74 | Bus: 1, 75 | Address: 2, 76 | Port: 2, 77 | Spec: Version(2, 0), 78 | Device: Version(1, 3), 79 | Vendor: ID(0x8888), 80 | Product: ID(0x0002), 81 | Protocol: 255, 82 | Configs: map[int]ConfigDesc{1: { 83 | Number: 1, 84 | MaxPower: Milliamperes(100), 85 | iConfiguration: 5, 86 | Interfaces: []InterfaceDesc{{ 87 | Number: 0, 88 | AltSettings: []InterfaceSetting{{ 89 | Number: 0, 90 | Alternate: 0, 91 | Class: ClassVendorSpec, 92 | iInterface: 6, 93 | }}, 94 | }, { 95 | Number: 1, 96 | AltSettings: []InterfaceSetting{{ 97 | Number: 1, 98 | Alternate: 0, 99 | Class: ClassVendorSpec, 100 | Endpoints: map[EndpointAddress]EndpointDesc{ 101 | 0x05: { 102 | Address: 0x05, 103 | Number: 5, 104 | Direction: EndpointDirectionOut, 105 | MaxPacketSize: 3 * 1024, 106 | TransferType: TransferTypeIsochronous, 107 | UsageType: IsoUsageTypeData, 108 | }, 109 | 0x86: { 110 | Address: 0x86, 111 | Number: 6, 112 | Direction: EndpointDirectionIn, 113 | MaxPacketSize: 3 * 1024, 114 | TransferType: TransferTypeIsochronous, 115 | UsageType: IsoUsageTypeData, 116 | }, 117 | }, 118 | iInterface: 7, 119 | }, { 120 | Number: 1, 121 | Alternate: 1, 122 | Class: ClassVendorSpec, 123 | Endpoints: map[EndpointAddress]EndpointDesc{ 124 | 0x05: { 125 | Address: 0x05, 126 | Number: 5, 127 | Direction: EndpointDirectionOut, 128 | MaxPacketSize: 2 * 1024, 129 | TransferType: TransferTypeIsochronous, 130 | }, 131 | 0x86: { 132 | Address: 0x86, 133 | Number: 6, 134 | Direction: EndpointDirectionIn, 135 | MaxPacketSize: 2 * 1024, 136 | TransferType: TransferTypeIsochronous, 137 | }, 138 | }, 139 | iInterface: 8, 140 | }, { 141 | Number: 1, 142 | Alternate: 2, 143 | Class: ClassVendorSpec, 144 | Endpoints: map[EndpointAddress]EndpointDesc{ 145 | 0x05: { 146 | Address: 0x05, 147 | Number: 5, 148 | Direction: EndpointDirectionIn, 149 | MaxPacketSize: 1024, 150 | TransferType: TransferTypeIsochronous, 151 | }, 152 | 0x86: { 153 | Address: 0x86, 154 | Number: 6, 155 | Direction: EndpointDirectionIn, 156 | MaxPacketSize: 1024, 157 | TransferType: TransferTypeIsochronous, 158 | }, 159 | }, 160 | }}, 161 | }}, 162 | }}, 163 | iManufacturer: 1, 164 | iProduct: 2, 165 | iSerialNumber: 3, 166 | }, 167 | strDesc: map[int]string{ 168 | 1: "ACME Industries", 169 | 2: "Fidgety Gadget", 170 | 3: "01234567", 171 | 5: "Weird configuration", 172 | 6: "Boring setting", 173 | 7: "Fast streaming", 174 | 8: "Slower streaming", 175 | }, 176 | }, 177 | // Bus 001 Device 003: ID 9999:0002 178 | // One config, one interface, one setup, 179 | // two endpoints: 0x01 OUT, 0x81 IN. 180 | { 181 | devDesc: &DeviceDesc{ 182 | Bus: 1, 183 | Address: 3, 184 | Port: 3, 185 | Spec: Version(2, 0), 186 | Device: Version(1, 0), 187 | Vendor: ID(0x1111), 188 | Product: ID(0x1111), 189 | Protocol: 255, 190 | Configs: map[int]ConfigDesc{1: { 191 | Number: 1, 192 | MaxPower: Milliamperes(100), 193 | Interfaces: []InterfaceDesc{{ 194 | Number: 0, 195 | AltSettings: []InterfaceSetting{{ 196 | Number: 0, 197 | Alternate: 0, 198 | Class: ClassVendorSpec, 199 | Endpoints: map[EndpointAddress]EndpointDesc{ 200 | 0x01: { 201 | Address: 0x01, 202 | Number: 1, 203 | Direction: EndpointDirectionOut, 204 | MaxPacketSize: 512, 205 | TransferType: TransferTypeBulk, 206 | }, 207 | 0x81: { 208 | Address: 0x81, 209 | Number: 1, 210 | Direction: EndpointDirectionIn, 211 | MaxPacketSize: 512, 212 | TransferType: TransferTypeBulk, 213 | }, 214 | }, 215 | }}, 216 | }}, 217 | }}, 218 | }, 219 | }, 220 | } 221 | -------------------------------------------------------------------------------- /decompress-avi/wrapper.c: -------------------------------------------------------------------------------- 1 | #include "include/v2u_lib.h" 2 | #include "include/v2u_compression.h" 3 | 4 | #include 5 | #include 6 | 7 | #define N(a) (sizeof(a)/sizeof((a)[0])) 8 | 9 | 10 | /* formats */ 11 | typedef struct _V2UFormat { 12 | const char* name; 13 | V2U_UINT32 value; 14 | } V2UFormat; 15 | 16 | /* compression context */ 17 | typedef struct _V2UCompressParams { 18 | const char* fname; 19 | int count; 20 | int level; 21 | const V2UFormat* cformat; 22 | } V2UCompressParams; 23 | 24 | /* decompression context */ 25 | typedef struct _V2UDecompressParams { 26 | const char* fname; 27 | const V2UFormat* format; 28 | } V2UDecompressParams; 29 | 30 | /* compression/decompression formats */ 31 | static const V2UFormat v2u_cformats [] = { 32 | { "CRGB24", V2U_GRABFRAME_FORMAT_CRGB24 }, 33 | { "CBGR24", V2U_GRABFRAME_FORMAT_CBGR24 }, 34 | { "CYUY2", V2U_GRABFRAME_FORMAT_CYUY2 }, 35 | { "C2VUY", V2U_GRABFRAME_FORMAT_C2VUY } 36 | }; 37 | 38 | static const V2UFormat v2u_formats [] = { 39 | { "RGB24", V2U_GRABFRAME_FORMAT_RGB24 }, 40 | { "BGR24", V2U_GRABFRAME_FORMAT_BGR24 }, 41 | { "ARGB32", V2U_GRABFRAME_FORMAT_ARGB32 }, 42 | { "YUY2", V2U_GRABFRAME_FORMAT_YUY2 }, 43 | { "2VUY", V2U_GRABFRAME_FORMAT_2VUY }, 44 | { "Y8", V2U_GRABFRAME_FORMAT_Y8 }, 45 | { "YV12", V2U_GRABFRAME_FORMAT_YV12 }, 46 | { "I420", V2U_GRABFRAME_FORMAT_I420 } 47 | }; 48 | 49 | static const V2UFormat* format_by_name(const char* name, const V2UFormat* formats, int n) 50 | { 51 | int i; 52 | for (i=0; iformat) { 137 | printf("HI 8.3!\n"); 138 | palette = dp->format->value; 139 | if (!v2udec_set_palette(libctx, compressed, framelen, palette)) { 140 | printf("Incompatible decompression format\n"); 141 | result = 6; 142 | break; 143 | } 144 | } 145 | 146 | 147 | // if (!framenum) { 148 | V2U_UINT32 cpalette = v2udec_get_cpalette(libctx, compressed, framelen); 149 | const V2UFormat* src = format_by_value(cpalette, v2u_cformats, N(v2u_cformats)); 150 | const V2UFormat* dest = format_by_value(palette, v2u_formats, N(v2u_formats)); 151 | if (src && dest) { 152 | printf("Decompressing %s -> %s\n", src->name, dest->name); 153 | } 154 | // } 155 | printf("HI 9!\n"); 156 | v2udec_get_frameres(libctx, compressed, framelen, &rect); 157 | printf("HI 10!\n"); 158 | v2udec_get_videomode(libctx, compressed, framelen, &mode); 159 | printf("HI 11!\n"); 160 | if (v2udec_decompress_frame(libctx, compressed, framelen, decompressed, buflen) > 0) { 161 | printf("HI 12!\n"); 162 | 163 | /* Save decompressed frame as a bitmap file */ 164 | // FILE* out; 165 | // char bmpname[1024]; 166 | printf("Frame #%04d: timestamp=%u framesize=%d width=%d height=%d (%dx%d-%f)\n", 167 | framenum, (unsigned int)timestamp, framelen, 168 | rect.width, rect.height, 169 | mode.width, mode.height, mode.vfreq/1000.0); 170 | 171 | memcpy(deblob,decompressed,buflen); 172 | // if (dp->format) { 173 | // sprintf(bmpname,"%s-%s.%04d.bmp", dp->format->name, dp->fname, framenum); 174 | // } else { 175 | // sprintf(bmpname,"%s.%04d.bmp", dp->fname, framenum); 176 | // } 177 | // out = fopen(bmpname, "wb"); 178 | 179 | // if (out) { 180 | // v2u_write_bmp(out, rect.width, rect.height, palette, decompressed); 181 | // fclose(out); 182 | // framenum++; 183 | 184 | // /* Collect statistics */ 185 | // if (v2udec_is_keyframe(libctx, compressed, framelen)) { 186 | // KeyFramesSum += framelen; 187 | // KeyFramesCount++; 188 | // } else { 189 | // PFramesSum += framelen; 190 | // PFramesCount++; 191 | // } 192 | // } else { 193 | // printf("Failed to create file %s\n", bmpname); 194 | // result = STATUS_IOERR; 195 | // break; 196 | // } 197 | } else { 198 | printf("Frame #%04d: decoding error\n", framenum); 199 | result = 3; 200 | break; 201 | } 202 | printf("HI 30!\n"); 203 | } else { 204 | printf("File format error\n"); 205 | result = 3; 206 | break; 207 | } 208 | } 209 | printf("HI 40!\n"); 210 | v2udec_deinit_context(libctx); 211 | printf("HI 41!\n"); 212 | 213 | /* Calculating average decompressed frame sizes */ 214 | if (KeyFramesCount) { 215 | printf("Average key frame size: %d bytes\n", 216 | KeyFramesSum/KeyFramesCount); 217 | } 218 | if (PFramesCount) { 219 | printf("Average inner frame size: %d bytes\n", 220 | PFramesSum/PFramesCount); 221 | } 222 | 223 | } else { 224 | printf("Failed to allocate decompression context\n"); 225 | result = 7; 226 | } 227 | printf("HI 50!\n"); 228 | free(compressed); 229 | printf("HI 51!\n"); 230 | free(decompressed); 231 | } 232 | printf("HI 52!\n"); 233 | return result; 234 | } 235 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/usb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /* 17 | Package gousb provides an low-level interface to attached USB devices. 18 | 19 | A Short Tutorial 20 | 21 | A Context manages all resources necessary for communicating with USB 22 | devices. 23 | Through the Context users can iterate over available USB devices. 24 | 25 | The USB standard defines a mechanism of discovering USB device functionality 26 | through descriptors. After the device is attached and 27 | initialized by the host stack, it's possible to retrieve its descriptor 28 | (the device descriptor). It contains elements such as product and vendor IDs, 29 | bus number and device number (address) on the bus. 30 | 31 | In gousb, the Device struct represents a USB device. The Device struct’s Desc 32 | field contains all known information about the device. 33 | 34 | Among other information in the device descriptor is a list of configuration 35 | descriptors, accessible through Device.Desc.Configs. 36 | 37 | The USB standard allows one physical USB device to switch between different 38 | sets of behaviors, or working modes, by selecting one of the offered configs 39 | (each device has at least one). 40 | This allows the same device to sometimes present itself as e.g. a 3G modem, 41 | and sometimes as a flash drive with the drivers for that 3G modem. 42 | Configs are mutually exclusive, each device 43 | can have only one active config at a time. Switching the active config performs 44 | a light-weight device reset. Each config in the device descriptor has 45 | a unique identification number. 46 | 47 | In gousb a device config needs to be selected through Device.Config(num). 48 | It returns a Config struct that represents the device in this particular configuration. 49 | The configuration descriptor is accessible through Config.Desc. 50 | 51 | A config descriptor determines the list of available USB interfaces on the device. 52 | Each interface is a virtual device within the physical USB device and its active 53 | config. There can be many interfaces active concurrently. Interfaces are 54 | enumerated sequentially starting from zero. 55 | 56 | Additionally, each interface comes with a number of alternate settings for 57 | the interface, which are somewhat similar to device configs, but on the 58 | interface level. Each interface can have only a single alternate setting 59 | active at any time. Alternate settings are enumerated sequentially starting from 60 | zero. 61 | 62 | In gousb an interface and its alternate setting can be selected through 63 | Config.Interface(num, altNum). The Interface struct is the representation 64 | of the claimed interface with a particular alternate setting. 65 | The descriptor of the interface is available through Interface.Setting. 66 | 67 | An interface with a particular alternate setting defines up to 30 data 68 | endpoints, each identified by a unique address. The endpoint address is a combination 69 | of endpoint number (1..15) and endpoint directionality (IN/OUT). 70 | IN endpoints have addresses 0x81..0x8f, while OUT endpoints 0x01..0x0f. 71 | 72 | An endpoint can be considered similar to a UDP/IP port, 73 | except the data transfers are unidirectional. 74 | 75 | Endpoints are represented by the Endpoint struct, and all defined endpoints 76 | can be obtained through the Endpoints field of the Interface.Setting. 77 | 78 | Each endpoint descriptor (EndpointDesc) defined in the interface's endpoint 79 | map includes information about the type of the endpoint: 80 | 81 | - endpoint address 82 | 83 | - endpoint number 84 | 85 | - direction: IN (device-to-host) or OUT (host-to-device) 86 | 87 | - transfer type: USB standard defines a few distinct data transfer types: 88 | 89 | --- bulk - high throughput, but no guaranteed bandwidth and no latency guarantees, 90 | 91 | --- isochronous - medium throughput, guaranteed bandwidth, some latency guarantees, 92 | 93 | --- interrupt - low throughput, high latency guarantees. 94 | 95 | The endpoint descriptor determines the type of the transfer that will be used. 96 | 97 | - maximum packet size: maximum number of bytes that can be sent or received by the device in a single USB transaction. 98 | and a few other less frequently used pieces of endpoint information. 99 | 100 | An IN Endpoint can be opened for reading through Interface.InEndpoint(epNum), 101 | while an OUT Endpoint can be opened for writing through Interface.OutEndpoint(epNum). 102 | 103 | An InEndpoint implements the io.Reader interface, an OutEndpoint implements 104 | the io.Writer interface. Both Reads and Writes will accept larger slices 105 | of data than the endpoint's maximum packet size, the transfer will be split 106 | into smaller USB transactions as needed. But using Read/Write size equal 107 | to an integer multiple of maximum packet size helps with improving the transfer 108 | performance. 109 | 110 | Apart from 15 possible data endpoints, each USB device also has a control endpoint. 111 | The control endpoint is present regardless of the current device config, claimed 112 | interfaces and their alternate settings. It makes a lot of sense, as the control endpoint is actually used, among others, 113 | to issue commands to switch the active config or select an alternate setting for an interface. 114 | 115 | Control commands are also often used to control the behavior of the device. There is no single 116 | standard for control commands though, and many devices implement their custom control command schema. 117 | 118 | Control commands can be issued through Device.Control(). 119 | 120 | See Also 121 | 122 | For more information about USB protocol and handling USB devices, 123 | see the excellent "USB in a nutshell" guide: http://www.beyondlogic.org/usbnutshell/ 124 | 125 | */ 126 | package gousb 127 | 128 | // Context manages all resources related to USB device handling. 129 | type Context struct { 130 | ctx *libusbContext 131 | done chan struct{} 132 | libusb libusbIntf 133 | } 134 | 135 | // Debug changes the debug level. Level 0 means no debug, higher levels 136 | // will print out more debugging information. 137 | // TODO(sebek): in the next major release, replace int levels with 138 | // Go-typed constants. 139 | func (c *Context) Debug(level int) { 140 | c.libusb.setDebug(c.ctx, level) 141 | } 142 | 143 | func newContextWithImpl(impl libusbIntf) *Context { 144 | c, err := impl.init() 145 | if err != nil { 146 | panic(err) 147 | } 148 | ctx := &Context{ 149 | ctx: c, 150 | done: make(chan struct{}), 151 | libusb: impl, 152 | } 153 | go impl.handleEvents(ctx.ctx, ctx.done) 154 | return ctx 155 | } 156 | 157 | // NewContext returns a new Context instance. 158 | func NewContext() *Context { 159 | return newContextWithImpl(libusbImpl{}) 160 | } 161 | 162 | // OpenDevices calls opener with each enumerated device. 163 | // If the opener returns true, the device is opened and a Device is returned if the operation succeeds. 164 | // Every Device returned (whether an error is also returned or not) must be closed. 165 | // If there are any errors enumerating the devices, 166 | // the final one is returned along with any successfully opened devices. 167 | func (c *Context) OpenDevices(opener func(desc *DeviceDesc) bool) ([]*Device, error) { 168 | list, err := c.libusb.getDevices(c.ctx) 169 | if err != nil { 170 | return nil, err 171 | } 172 | 173 | var reterr error 174 | var ret []*Device 175 | for _, dev := range list { 176 | desc, err := c.libusb.getDeviceDesc(dev) 177 | if err != nil { 178 | c.libusb.dereference(dev) 179 | reterr = err 180 | continue 181 | } 182 | 183 | if opener(desc) { 184 | handle, err := c.libusb.open(dev) 185 | if err != nil { 186 | c.libusb.dereference(dev) 187 | reterr = err 188 | continue 189 | } 190 | ret = append(ret, &Device{handle: handle, ctx: c, Desc: desc}) 191 | } else { 192 | c.libusb.dereference(dev) 193 | } 194 | } 195 | return ret, reterr 196 | } 197 | 198 | // OpenDeviceWithVIDPID opens Device from specific VendorId and ProductId. 199 | // If none is found, it returns nil and nil error. If there are multiple devices 200 | // with the same VID/PID, it will return one of them, picked arbitrarily. 201 | // If there were any errors during device list traversal, it is possible 202 | // it will return a non-nil device and non-nil error. A Device.Close() must 203 | // be called to release the device if the returned device wasn't nil. 204 | func (c *Context) OpenDeviceWithVIDPID(vid, pid ID) (*Device, error) { 205 | var found bool 206 | devs, err := c.OpenDevices(func(desc *DeviceDesc) bool { 207 | if found { 208 | return false 209 | } 210 | if desc.Vendor == ID(vid) && desc.Product == ID(pid) { 211 | found = true 212 | return true 213 | } 214 | return false 215 | }) 216 | if len(devs) == 0 { 217 | return nil, err 218 | } 219 | return devs[0], nil 220 | } 221 | 222 | // Close releases the Context and all associated resources. 223 | func (c *Context) Close() error { 224 | var ret error 225 | c.done <- struct{}{} 226 | if c.ctx != nil { 227 | ret = c.libusb.exit(c.ctx) 228 | } 229 | c.ctx = nil 230 | return ret 231 | } 232 | -------------------------------------------------------------------------------- /driver/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "flag" 6 | "fmt" 7 | "image" 8 | "image/color" 9 | "image/jpeg" 10 | "image/png" 11 | "log" 12 | "os" 13 | "time" 14 | 15 | "github.com/google/gousb" 16 | ) 17 | 18 | var debugLogging = flag.Bool("debug", false, "Enable debug output") 19 | 20 | func main() { 21 | stage1 := flag.Bool("stage1", false, "USB mode") 22 | stage2 := flag.Bool("stage2", false, "FPGA mode and run time") 23 | resMode := flag.Int("resMode", 1, "1: 800*600, 2: 1024x768, 3: 1280x720") 24 | fps := flag.Int("fps", 2, "FPS you want to try and capture at") 25 | mjpegMode := flag.Bool("mjpeg", false, "output MJPEG so it can be processed by another program") 26 | webserver := flag.Bool("web", false, "if set, will start a webserver on 3723 with liveview and HTML5 recording") 27 | flag.Parse() 28 | 29 | ctx := gousb.NewContext() 30 | defer ctx.Close() 31 | 32 | if *debugLogging { 33 | log.Printf("Opening device...") 34 | } 35 | 36 | dev, err := ctx.OpenDeviceWithVIDPID(0x5555, 0x3382) 37 | if err != nil || dev == nil { 38 | log.Fatalf("Could not open a device: %v", err) 39 | } 40 | 41 | if *debugLogging { 42 | log.Printf("Claim default interface...") 43 | } 44 | 45 | deviceConfig, err := dev.Config(1) 46 | if err != nil { 47 | log.Printf("Failed to get config for device") 48 | return 49 | } 50 | defer dev.Close() 51 | 52 | if *debugLogging { 53 | for num, interf := range deviceConfig.Desc.Interfaces { 54 | os.Stderr.WriteString(fmt.Sprintf("\tINTERFACE #%d\n", num)) 55 | 56 | for numAlt, altset := range interf.AltSettings { 57 | os.Stderr.WriteString(fmt.Sprintf("\t\t%d - Number: %d - Alt %d\n", numAlt, altset.Number, altset.Alternate)) 58 | for numEndpoint, endpointset := range altset.Endpoints { 59 | os.Stderr.WriteString(fmt.Sprintf("\t\t\t%d - %#v\n", numEndpoint, endpointset)) 60 | } 61 | } 62 | } 63 | } 64 | 65 | if *stage1 { 66 | log.Printf("Setting the USB Controller firmware") 67 | 68 | for n, packet := range usbInit { 69 | if *debugLogging { 70 | if n%10 == 0 { 71 | thrd := len(usbInit) / 3 72 | switch n / thrd { 73 | case 0: 74 | os.Stderr.WriteString(fmt.Sprintf("U")) 75 | case 1: 76 | os.Stderr.WriteString(fmt.Sprintf("S")) 77 | case 2: 78 | os.Stderr.WriteString(fmt.Sprintf("B")) 79 | } 80 | } 81 | } 82 | 83 | _, err = dev.Control(packet.RequestType, packet.BRequest, packet.WValue, packet.WIndex, packet.Data) 84 | if err != nil { 85 | log.Printf("\nfailed to bitstream %s", err.Error()) 86 | } 87 | } 88 | 89 | log.Printf("Set the USB Controller firmware") 90 | time.Sleep(time.Second) 91 | os.Exit(0) 92 | } else if *stage2 { 93 | 94 | dev.ControlTimeout = time.Second 95 | Bench := time.Now() 96 | inBuf := make([]byte, 12) 97 | dev.Control(0xc0, 177, 0, 0, inBuf) 98 | dev.ControlTimeout = time.Hour 99 | 100 | if time.Since(Bench) > time.Second || 101 | (inBuf[0] == 0x00 && inBuf[1] == 0x00 && inBuf[2] == 0x00 && inBuf[3] == 0x00) { 102 | buf := make([]byte, 64) 103 | _, err = dev.Control(0xc0, 185, 0x0021, 0, buf) 104 | 105 | log.Printf("Setting the FPGA bitstream I think...") 106 | 107 | for n, packet := range fpgaInit { 108 | if *debugLogging { 109 | if n%60 == 0 { 110 | thrd := len(fpgaInit) / 4 111 | switch n / thrd { 112 | case 0: 113 | os.Stderr.WriteString(fmt.Sprintf("F")) 114 | case 1: 115 | os.Stderr.WriteString(fmt.Sprintf("P")) 116 | case 2: 117 | os.Stderr.WriteString(fmt.Sprintf("G")) 118 | case 3: 119 | os.Stderr.WriteString(fmt.Sprintf("A")) 120 | } 121 | } 122 | } 123 | 124 | _, err = dev.Control(packet.RequestType, packet.BRequest, packet.WValue, packet.WIndex, packet.Data) 125 | if err != nil { 126 | log.Printf("\nfailed to bitstream %s", err.Error()) 127 | } 128 | } 129 | } 130 | 131 | } else { 132 | log.Fatalf("Set a -stage1 or -stage2") 133 | } 134 | 135 | if *debugLogging { 136 | os.Stderr.WriteString(fmt.Sprintf("\r\n")) 137 | log.Printf("Activating in 2 seconds") 138 | } 139 | time.Sleep(time.Second * 1) 140 | 141 | if *debugLogging { 142 | log.Printf("Setting FPGA registers I think?...") 143 | } 144 | 145 | for n, packet := range frameSetup { 146 | if *debugLogging { 147 | if n%4 == 0 { 148 | thrd := len(frameSetup) / 4 149 | switch n / thrd { 150 | case 0: 151 | os.Stderr.WriteString(fmt.Sprintf("W")) 152 | case 1: 153 | os.Stderr.WriteString(fmt.Sprintf("O")) 154 | case 2: 155 | os.Stderr.WriteString(fmt.Sprintf("R")) 156 | case 3: 157 | os.Stderr.WriteString(fmt.Sprintf("K")) 158 | } 159 | } 160 | } 161 | 162 | _, err = dev.Control(packet.RequestType, packet.BRequest, packet.WValue, packet.WIndex, packet.Data) 163 | if err != nil { 164 | log.Printf("\nfailed to setup device %s", err.Error()) 165 | } 166 | } 167 | 168 | cfg, err := dev.Config(1) 169 | if err != nil { 170 | log.Fatalf("Kaboom, unable to grab Config(1): %s", err.Error()) 171 | } 172 | if *debugLogging { 173 | os.Stderr.WriteString(fmt.Sprintf("Config: ")) 174 | } 175 | 176 | defaultinterface, err := cfg.Interface(0, 0) 177 | if err != nil { 178 | log.Fatalf("Kaboom, unable to grab Interface(0, 0): %s", err.Error()) 179 | } 180 | if *debugLogging { 181 | os.Stderr.WriteString(fmt.Sprintf("Interface: ")) 182 | } 183 | 184 | inputTest, err := defaultinterface.InEndpoint(2) 185 | if err != nil { 186 | log.Fatalf("Kaboom, unable to grab default interface: %s", err.Error()) 187 | } 188 | if *debugLogging { 189 | os.Stderr.WriteString(fmt.Sprintf("Endpoint: ")) 190 | } 191 | 192 | inBuf := make([]byte, 12) 193 | _, err = dev.Control(0xc0, 177, 0, 0, inBuf) 194 | os.Stderr.WriteString(fmt.Sprintf("Grab In 12 Control: \n")) 195 | 196 | if *debugLogging { 197 | log.Printf("Here is a EDID blob I think? %x", inBuf) 198 | } 199 | 200 | // now to send what i think activates this 201 | 202 | frameRequest := make(chan bool) 203 | frameOutput := make(chan ReadSkipper, 1) 204 | go func() { 205 | for { 206 | <-frameRequest 207 | 208 | if *resMode == 3 { 209 | // 1280x720 210 | dev.Control(0x40, 176, 0, 0, []byte("\x06\x80\x00\x00\x08\x14\x08\xb9\xbc\xbb\x1f\x1f\x1f\x03\x05\x00\x02\xd0\x00\x01\x02\xd0\x00\xe0\x19\x01\x01\x80\x80\x05\x00\x00\x00\x00\x00\x05\x00\x02\xd0")) 211 | } else if *resMode == 2 { 212 | // 1024x768 213 | dev.Control(0x40, 176, 0, 0, []byte("\x05\x40\x00\x00\x08\x14\x08\xbb\xbc\xbb\x1f\x1f\x1f\x03\x04\x00\x03\x00\x00\x01\x03\x00\x00\xa4\x22\x01\x01\x80\x80\x05\x00\x00\x00\x00\x00\x04\x00\x03\x00")) 214 | } else { 215 | // 800x600 216 | dev.Control(0x40, 176, 0, 0, []byte("\x04\x10\x00\x00\x08\x14\x1c\x90\x91\x91\x1f\x1f\x1f\x03\x03\x20\x02\x58\x00\x01\x02\x58\x00\x7c\x19\x01\x01\x80\x80\x05\x00\x00\x00\x00\x00\x03\x20\x02\x58")) 217 | } 218 | dev.Control(0x40, 184, 0x0076, 0, []byte("")) 219 | 220 | dataBuf := make([]byte, 1280*1024*4) 221 | n, err := inputTest.Read(dataBuf) 222 | 223 | if err != nil { 224 | log.Printf("failed to read aa %s", err) 225 | // continue 226 | } 227 | 228 | if *debugLogging { 229 | f, _ := os.Create("./debug") 230 | f.Write(dataBuf[:n]) 231 | os.Stderr.WriteString(fmt.Sprintf("N=%d\n", n)) 232 | } 233 | rSk := ReadSkipper{ 234 | Data: dataBuf[:n], 235 | Bread: 4, 236 | } 237 | frameOutput <- rSk 238 | } 239 | }() 240 | 241 | if *mjpegMode { 242 | os.Stdout.WriteString("--myboundary\nContent-Type: image/jpeg\n\n") 243 | } 244 | 245 | pngPipe := make(chan []byte) 246 | if *webserver { 247 | go startWebserver(pngPipe) 248 | } 249 | 250 | go func() { 251 | for { 252 | rSk := <-frameOutput 253 | 254 | Res := GuessTheRes(len(rSk.Data)) 255 | img := image.NewNRGBA(image.Rect(0, 0, Res.X, Res.Y)) 256 | x, y := 0, 0 257 | 258 | bench := time.Now() 259 | 260 | for { 261 | 262 | RGB := rSk.ReadPixel() 263 | R, G, B := color.YCbCrToRGB(RGB[0], RGB[1], RGB[2]) 264 | img.Set(x, y, color.NRGBA{ 265 | R: B, 266 | G: G, 267 | B: R, 268 | A: 255, 269 | }) 270 | 271 | x++ 272 | if x == Res.X { 273 | x = 0 274 | y++ 275 | } 276 | if y == Res.Y { 277 | break 278 | } 279 | } 280 | 281 | if !*mjpegMode { 282 | 283 | if *webserver { 284 | var tmpBuffer bytes.Buffer 285 | err := png.Encode(&tmpBuffer, img) 286 | if err != nil { 287 | log.Printf("failed to encode PNG %s", err.Error()) 288 | continue 289 | } 290 | 291 | if *debugLogging { 292 | log.Printf("Send a buf of len %d down pngPipe", tmpBuffer.Len()) 293 | } 294 | 295 | pngPipe <- tmpBuffer.Bytes() 296 | 297 | } else { 298 | a, _ := os.Create(fmt.Sprintf("%d.png", time.Now().Unix())) 299 | png.Encode(a, img) 300 | } 301 | 302 | if *debugLogging { 303 | log.Printf("took %s to process that", time.Since(bench).String()) 304 | } 305 | 306 | continue 307 | } 308 | 309 | // MJPEG mode. 310 | // Mostly stolen from how I did it back in the days of de-ip-hdmi 311 | // https://github.com/benjojo/de-ip-hdmi/blob/master/main.go 312 | 313 | os.Stdout.WriteString("\n--myboundary\nContent-Type: image/jpeg\n\n") 314 | jpeg.Encode(os.Stdout, img, nil) 315 | 316 | if *debugLogging { 317 | log.Printf("took %s to process that", time.Since(bench).String()) 318 | } 319 | 320 | } 321 | }() 322 | 323 | for { 324 | time.Sleep(time.Second / time.Duration(*fps)) 325 | frameRequest <- true 326 | } 327 | } 328 | 329 | type usbControlPacket struct { 330 | ignore bool 331 | RequestType uint8 332 | BRequest uint8 333 | WValue uint16 334 | WIndex uint16 335 | Data []byte 336 | } 337 | 338 | type ReadSkipper struct { 339 | Data []byte 340 | Bread int 341 | } 342 | 343 | func (r *ReadSkipper) ReadPixel() [3]byte { 344 | var output [3]byte 345 | 346 | output[0] = r.readByte() 347 | output[1] = r.readByte() 348 | output[2] = r.readByte() 349 | return output 350 | } 351 | 352 | func (r *ReadSkipper) readByte() byte { 353 | r.Bread++ 354 | if r.Bread%1028 == 0 { 355 | r.Bread += 4 356 | } 357 | 358 | if r.Bread > len(r.Data)-1 { 359 | return 0x00 360 | } 361 | 362 | return r.Data[r.Bread] 363 | } 364 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | // #include 19 | import "C" 20 | import "strconv" 21 | 22 | // Class represents a USB-IF (Implementers Forum) class or subclass code. 23 | type Class uint8 24 | 25 | // Standard classes defined by USB spec, see https://www.usb.org/defined-class-codes 26 | const ( 27 | ClassPerInterface Class = 0x00 28 | ClassAudio Class = 0x01 29 | ClassComm Class = 0x02 30 | ClassHID Class = 0x03 31 | ClassPhysical Class = 0x05 32 | ClassImage Class = 0x06 33 | ClassPTP Class = ClassImage // legacy name for image 34 | ClassPrinter Class = 0x07 35 | ClassMassStorage Class = 0x08 36 | ClassHub Class = 0x09 37 | ClassData Class = 0x0a 38 | ClassSmartCard Class = 0x0b 39 | ClassContentSecurity Class = 0x0d 40 | ClassVideo Class = 0x0e 41 | ClassPersonalHealthcare Class = 0x0f 42 | ClassAudioVideo Class = 0x10 43 | ClassBillboard Class = 0x11 44 | ClassUSBTypeCBridge Class = 0x12 45 | ClassDiagnosticDevice Class = 0xdc 46 | ClassWireless Class = 0xe0 47 | ClassMiscellaneous Class = 0xef 48 | ClassApplication Class = 0xfe 49 | ClassVendorSpec Class = 0xff 50 | ) 51 | 52 | var classDescription = map[Class]string{ 53 | ClassPerInterface: "per-interface", 54 | ClassAudio: "audio", 55 | ClassComm: "communications", 56 | ClassHID: "human interface device", 57 | ClassPhysical: "physical", 58 | ClassImage: "image", 59 | ClassPrinter: "printer", 60 | ClassMassStorage: "mass storage", 61 | ClassHub: "hub", 62 | ClassData: "data", 63 | ClassSmartCard: "smart card", 64 | ClassContentSecurity: "content security", 65 | ClassVideo: "video", 66 | ClassPersonalHealthcare: "personal healthcare", 67 | ClassAudioVideo: "audio/video", 68 | ClassBillboard: "billboard", 69 | ClassUSBTypeCBridge: "USB type-C bridge", 70 | ClassDiagnosticDevice: "diagnostic device", 71 | ClassWireless: "wireless", 72 | ClassMiscellaneous: "miscellaneous", 73 | ClassApplication: "application-specific", 74 | ClassVendorSpec: "vendor-specific", 75 | } 76 | 77 | func (c Class) String() string { 78 | if d, ok := classDescription[c]; ok { 79 | return d 80 | } 81 | return strconv.Itoa(int(c)) 82 | } 83 | 84 | // Protocol is the interface class protocol, qualified by the values 85 | // of interface class and subclass. 86 | type Protocol uint8 87 | 88 | func (p Protocol) String() string { 89 | return strconv.Itoa(int(p)) 90 | } 91 | 92 | // DescriptorType identifies the type of a USB descriptor. 93 | type DescriptorType uint8 94 | 95 | // Descriptor types defined by the USB spec. 96 | const ( 97 | DescriptorTypeDevice DescriptorType = C.LIBUSB_DT_DEVICE 98 | DescriptorTypeConfig DescriptorType = C.LIBUSB_DT_CONFIG 99 | DescriptorTypeString DescriptorType = C.LIBUSB_DT_STRING 100 | DescriptorTypeInterface DescriptorType = C.LIBUSB_DT_INTERFACE 101 | DescriptorTypeEndpoint DescriptorType = C.LIBUSB_DT_ENDPOINT 102 | DescriptorTypeHID DescriptorType = C.LIBUSB_DT_HID 103 | DescriptorTypeReport DescriptorType = C.LIBUSB_DT_REPORT 104 | DescriptorTypePhysical DescriptorType = C.LIBUSB_DT_PHYSICAL 105 | DescriptorTypeHub DescriptorType = C.LIBUSB_DT_HUB 106 | ) 107 | 108 | var descriptorTypeDescription = map[DescriptorType]string{ 109 | DescriptorTypeDevice: "device", 110 | DescriptorTypeConfig: "configuration", 111 | DescriptorTypeString: "string", 112 | DescriptorTypeInterface: "interface", 113 | DescriptorTypeEndpoint: "endpoint", 114 | DescriptorTypeHID: "HID", 115 | DescriptorTypeReport: "HID report", 116 | DescriptorTypePhysical: "physical", 117 | DescriptorTypeHub: "hub", 118 | } 119 | 120 | func (dt DescriptorType) String() string { 121 | return descriptorTypeDescription[dt] 122 | } 123 | 124 | // EndpointDirection defines the direction of data flow - IN (device to host) 125 | // or OUT (host to device). 126 | type EndpointDirection bool 127 | 128 | const ( 129 | endpointNumMask = 0x0f 130 | endpointDirectionMask = 0x80 131 | // EndpointDirectionIn marks data flowing from device to host. 132 | EndpointDirectionIn EndpointDirection = true 133 | // EndpointDirectionOut marks data flowing from host to device. 134 | EndpointDirectionOut EndpointDirection = false 135 | ) 136 | 137 | var endpointDirectionDescription = map[EndpointDirection]string{ 138 | EndpointDirectionIn: "IN", 139 | EndpointDirectionOut: "OUT", 140 | } 141 | 142 | func (ed EndpointDirection) String() string { 143 | return endpointDirectionDescription[ed] 144 | } 145 | 146 | // TransferType defines the endpoint transfer type. 147 | type TransferType uint8 148 | 149 | // Transfer types defined by the USB spec. 150 | const ( 151 | TransferTypeControl TransferType = C.LIBUSB_TRANSFER_TYPE_CONTROL 152 | TransferTypeIsochronous TransferType = C.LIBUSB_TRANSFER_TYPE_ISOCHRONOUS 153 | TransferTypeBulk TransferType = C.LIBUSB_TRANSFER_TYPE_BULK 154 | TransferTypeInterrupt TransferType = C.LIBUSB_TRANSFER_TYPE_INTERRUPT 155 | transferTypeMask = 0x03 156 | ) 157 | 158 | var transferTypeDescription = map[TransferType]string{ 159 | TransferTypeControl: "control", 160 | TransferTypeIsochronous: "isochronous", 161 | TransferTypeBulk: "bulk", 162 | TransferTypeInterrupt: "interrupt", 163 | } 164 | 165 | // String returns a human-readable name of the endpoint transfer type. 166 | func (tt TransferType) String() string { 167 | return transferTypeDescription[tt] 168 | } 169 | 170 | // IsoSyncType defines the isochronous transfer synchronization type. 171 | type IsoSyncType uint8 172 | 173 | // Synchronization types defined by the USB spec. 174 | const ( 175 | IsoSyncTypeNone IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_NONE << 2 176 | IsoSyncTypeAsync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ASYNC << 2 177 | IsoSyncTypeAdaptive IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_ADAPTIVE << 2 178 | IsoSyncTypeSync IsoSyncType = C.LIBUSB_ISO_SYNC_TYPE_SYNC << 2 179 | isoSyncTypeMask = 0x0C 180 | ) 181 | 182 | var isoSyncTypeDescription = map[IsoSyncType]string{ 183 | IsoSyncTypeNone: "unsynchronized", 184 | IsoSyncTypeAsync: "asynchronous", 185 | IsoSyncTypeAdaptive: "adaptive", 186 | IsoSyncTypeSync: "synchronous", 187 | } 188 | 189 | // String returns a human-readable description of the synchronization type. 190 | func (ist IsoSyncType) String() string { 191 | return isoSyncTypeDescription[ist] 192 | } 193 | 194 | // UsageType defines the transfer usage type for isochronous and interrupt 195 | // transfers. 196 | type UsageType uint8 197 | 198 | // Usage types for iso and interrupt transfers, defined by the USB spec. 199 | const ( 200 | // Note: USB3.0 defines usage type for both isochronous and interrupt 201 | // endpoints, with the same constants representing different usage types. 202 | // UsageType constants do not correspond to bmAttribute values. 203 | UsageTypeUndefined UsageType = iota 204 | IsoUsageTypeData 205 | IsoUsageTypeFeedback 206 | IsoUsageTypeImplicit 207 | InterruptUsageTypePeriodic 208 | InterruptUsageTypeNotification 209 | usageTypeMask = 0x30 210 | ) 211 | 212 | var usageTypeDescription = map[UsageType]string{ 213 | UsageTypeUndefined: "undefined usage", 214 | IsoUsageTypeData: "data", 215 | IsoUsageTypeFeedback: "feedback", 216 | IsoUsageTypeImplicit: "implicit data", 217 | InterruptUsageTypePeriodic: "periodic", 218 | InterruptUsageTypeNotification: "notification", 219 | } 220 | 221 | func (ut UsageType) String() string { 222 | return usageTypeDescription[ut] 223 | } 224 | 225 | // Control request type bit fields as defined in the USB spec. All values are 226 | // of uint8 type. These constants can be used with Device.Control() method to 227 | // specify the type and destination of the control request, e.g. 228 | // `dev.Control(ControlOut|ControlVendor|ControlDevice, ...)`. 229 | const ( 230 | ControlIn = C.LIBUSB_ENDPOINT_IN 231 | ControlOut = C.LIBUSB_ENDPOINT_OUT 232 | 233 | // "Standard" is explicitly omitted, as functionality of standard requests 234 | // is exposed through higher level operations of gousb. 235 | ControlClass = C.LIBUSB_REQUEST_TYPE_CLASS 236 | ControlVendor = C.LIBUSB_REQUEST_TYPE_VENDOR 237 | // "Reserved" is explicitly omitted, should not be used. 238 | 239 | ControlDevice = C.LIBUSB_RECIPIENT_DEVICE 240 | ControlInterface = C.LIBUSB_RECIPIENT_INTERFACE 241 | ControlEndpoint = C.LIBUSB_RECIPIENT_ENDPOINT 242 | ControlOther = C.LIBUSB_RECIPIENT_OTHER 243 | ) 244 | 245 | // Speed identifies the speed of the device. 246 | type Speed int 247 | 248 | // Device speeds as defined in the USB spec. 249 | const ( 250 | SpeedUnknown Speed = C.LIBUSB_SPEED_UNKNOWN 251 | SpeedLow Speed = C.LIBUSB_SPEED_LOW 252 | SpeedFull Speed = C.LIBUSB_SPEED_FULL 253 | SpeedHigh Speed = C.LIBUSB_SPEED_HIGH 254 | SpeedSuper Speed = C.LIBUSB_SPEED_SUPER 255 | ) 256 | 257 | var deviceSpeedDescription = map[Speed]string{ 258 | SpeedUnknown: "unknown", 259 | SpeedLow: "low", 260 | SpeedFull: "full", 261 | SpeedHigh: "high", 262 | SpeedSuper: "super", 263 | } 264 | 265 | // String returns a human-readable name of the device speed. 266 | func (s Speed) String() string { 267 | return deviceSpeedDescription[s] 268 | } 269 | 270 | const ( 271 | selfPoweredMask = 0x40 272 | remoteWakeupMask = 0x20 273 | ) 274 | 275 | // Milliamperes is a unit of electric current consumption. 276 | type Milliamperes uint 277 | -------------------------------------------------------------------------------- /decompress-avi/include/v2u_id.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * $Id: v2u_id.h 28830 2014-11-20 21:02:03Z pzeldin $ 4 | * 5 | * Copyright (C) 2003-2014 Epiphan Systems Inc. All rights reserved. 6 | * 7 | * Defines vendor and product ids of VGA2USB hardware. Included by the 8 | * driver and by the user level code. 9 | * 10 | ****************************************************************************/ 11 | 12 | #ifndef _VGA2USB_ID_H_ 13 | #define _VGA2USB_ID_H_ 1 14 | 15 | /** 16 | * Vendor and product ids. 17 | * 18 | * NOTE: if you are adding a new product ID, don't forget to update 19 | * V2U_PRODUCT_MAP macro below. 20 | */ 21 | 22 | #define EPIPHAN_VENDORID 0x5555 23 | #define VGA2USB_VENDORID EPIPHAN_VENDORID 24 | #define VGA2USB_PRODID_VGA2USB 0x1110 25 | #define VGA2USB_PRODID_KVM2USB 0x1120 26 | #define VGA2USB_PRODID_DVI2USB 0x2222 27 | #define VGA2USB_PRODID_VGA2USB_LR 0x3340 28 | #define VGA2USB_PRODID_VGA2USB_HR 0x3332 29 | #define VGA2USB_PRODID_VGA2USB_PRO 0x3333 30 | #define VGA2USB_PRODID_VGA2USB_LR_RESPIN 0x3382 31 | #define VGA2USB_PRODID_KVM2USB_LR_RESPIN 0x3383 32 | #define VGA2USB_PRODID_VGA2USB_HR_RESPIN 0x3392 33 | #define VGA2USB_PRODID_VGA2USB_PRO_RESPIN 0x33A2 34 | #define VGA2USB_PRODID_DVI2USB_RESPIN 0x3380 35 | #define VGA2USB_PRODID_KVM2USB_LR 0x3344 36 | #define VGA2USB_PRODID_KVM2USB_PRO 0x3337 37 | #define VGA2USB_PRODID_DVI2USB_SOLO 0x3411 38 | #define VGA2USB_PRODID_DVI2USB_DUO 0x3422 39 | #define VGA2USB_PRODID_DVI2USB3 0x3500 40 | #define VGA2USB_PRODID_DVI2USB3_ET 0x3510 41 | #define VGA2USB_PRODID_SDI2USB3 0x3520 42 | #define VGA2USB_PRODID_DVI2USB3_R3 0x3501 43 | #define VGA2USB_PRODID_DVI2USB3_ET_R3 0x3511 44 | #define VGA2USB_PRODID_SDI2USB3_R3 0x3521 45 | #define VGA2USB_PRODID_VGA2FIFO 0x4000 46 | #define VGA2USB_PRODID_KVM2FIFO 0x4004 47 | #define VGA2USB_PRODID_DVI2FIFO 0x4080 48 | #define VGA2USB_PRODID_DAVINCI1 0x5000 49 | #define VGA2USB_PRODID_VGA2PCI 0x3A00 50 | #define VGA2USB_PRODID_DVI2PCI 0x3B00 51 | #define VGA2USB_PRODID_DVI2PCI_STD 0x3B10 52 | #define VGA2USB_PRODID_HDMI2PCI 0x3C00 53 | #define VGA2USB_PRODID_DVI2PCI_GEN2 0x3D00 54 | #define VGA2USB_PRODID_DVI2PCI_GII 0x3E00 55 | #define VGA2USB_PRODID_GIOCONDA 0x5100 56 | #define VGA2USB_PRODID_ORNITHOPTER 0x5200 57 | 58 | /** 59 | * Macros for detecting VGA2USB hardware 60 | */ 61 | 62 | #define VGA2USB_IS_VGA2USB(idVendor,idProduct,iProduct,iMfg) \ 63 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB && \ 64 | ((iProduct)>0 || (iMfg)>0)) 65 | 66 | #define VGA2USB_IS_KVM2USB(idVendor,idProduct,iProduct,iMfg) \ 67 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_KVM2USB && \ 68 | ((iProduct)>0 || (iMfg)>0)) 69 | 70 | #define VGA2USB_IS_DVI2USB(idVendor,idProduct,iProduct,iMfg) \ 71 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_DVI2USB && \ 72 | ((iProduct)>0 || (iMfg)>0)) 73 | 74 | #define VGA2USB_IS_VGA2USB_PRO(idVendor,idProduct,iProduct,iMfg) \ 75 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_PRO && \ 76 | ((iProduct)>0 || (iMfg)>0)) 77 | 78 | #define VGA2USB_IS_VGA2USB_HR(idVendor,idProduct,iProduct,iMfg) \ 79 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_HR && \ 80 | ((iProduct)>0 || (iMfg)>0)) 81 | 82 | #define VGA2USB_IS_VGA2USB_LR(idVendor,idProduct,iProduct,iMfg) \ 83 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_LR && \ 84 | ((iProduct)>0 || (iMfg)>0)) 85 | 86 | #define VGA2USB_IS_VGA2USB_LR_RESPIN(idVendor,idProduct,iProduct,iMfg) \ 87 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_LR_RESPIN && \ 88 | ((iProduct)>0 || (iMfg)>0)) 89 | 90 | #define VGA2USB_IS_VGA2USB_HR_RESPIN(idVendor,idProduct,iProduct,iMfg) \ 91 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_HR_RESPIN && \ 92 | ((iProduct)>0 || (iMfg)>0)) 93 | 94 | #define VGA2USB_IS_VGA2USB_PRO_RESPIN(idVendor,idProduct,iProduct,iMfg) \ 95 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_VGA2USB_PRO_RESPIN && \ 96 | ((iProduct)>0 || (iMfg)>0)) 97 | 98 | #define VGA2USB_IS_KVM2USB_LR(idVendor,idProduct,iProduct,iMfg) \ 99 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_KVM2USB_LR && \ 100 | ((iProduct)>0 || (iMfg)>0)) 101 | 102 | #define VGA2USB_IS_KVM2USB_PRO(idVendor,idProduct,iProduct,iMfg) \ 103 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_KVM2USB_PRO && \ 104 | ((iProduct)>0 || (iMfg)>0)) 105 | 106 | #define VGA2USB_IS_DVI2USB_SOLO(idVendor,idProduct,iProduct,iMfg) \ 107 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_DVI2USB_SOLO && \ 108 | ((iProduct)>0 || (iMfg)>0)) 109 | 110 | #define VGA2USB_IS_DVI2USB_DUO(idVendor,idProduct,iProduct,iMfg) \ 111 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_DVI2USB_DUO && \ 112 | ((iProduct)>0 || (iMfg)>0)) 113 | 114 | #define VGA2USB_IS_DVI2USB_RESPIN(idVendor,idProduct,iProduct,iMfg) \ 115 | ((idVendor)==VGA2USB_VENDORID &&(idProduct)==VGA2USB_PRODID_DVI2USB_RESPIN &&\ 116 | ((iProduct)>0 || (iMfg)>0)) 117 | 118 | #define VGA2USB_IS_KVM2USB_LR_RESPIN(idVendor,idProduct,iProduct,iMfg) \ 119 | ((idVendor)==VGA2USB_VENDORID && (idProduct)==VGA2USB_PRODID_KVM2USB_LR_RESPIN && \ 120 | ((iProduct)>0 || (iMfg)>0)) 121 | 122 | #define VGA2USB_IS_DVI2USB3(idVendor,idProduct,iProduct,iMfg) \ 123 | ((idVendor)==VGA2USB_VENDORID && \ 124 | ((idProduct)==VGA2USB_PRODID_DVI2USB3 || (idProduct)==VGA2USB_PRODID_DVI2USB3_R3) && \ 125 | (iProduct)==1 && (iMfg)==3) 126 | 127 | #define VGA2USB_IS_DVI2USB3_ET(idVendor,idProduct,iProduct,iMfg) \ 128 | ((idVendor)==VGA2USB_VENDORID && \ 129 | ((idProduct)==VGA2USB_PRODID_DVI2USB3_ET || (idProduct)==VGA2USB_PRODID_DVI2USB3_ET_R3) && \ 130 | (iProduct)==1 && (iMfg)==3) 131 | 132 | #define VGA2USB_IS_SDI2USB3(idVendor,idProduct,iProduct,iMfg) \ 133 | ((idVendor)==VGA2USB_VENDORID && \ 134 | ((idProduct)==VGA2USB_PRODID_SDI2USB3 || (idProduct)==VGA2USB_PRODID_SDI2USB3_R3) && \ 135 | (iProduct)==1 && (iMfg)==3) 136 | 137 | #define VGA2USB_IS_ANY(idVendor,idProduct,iProduct,iMfg) \ 138 | (VGA2USB_IS_VGA2USB(idVendor,idProduct,iProduct,iMfg) || \ 139 | VGA2USB_IS_KVM2USB(idVendor,idProduct,iProduct,iMfg) || \ 140 | VGA2USB_IS_DVI2USB(idVendor,idProduct,iProduct,iMfg) || \ 141 | VGA2USB_IS_DVI2USB_SOLO(idVendor,idProduct,iProduct,iMfg) || \ 142 | VGA2USB_IS_DVI2USB_DUO(idVendor,idProduct,iProduct,iMfg) || \ 143 | VGA2USB_IS_DVI2USB_RESPIN(idVendor,idProduct,iProduct,iMfg) || \ 144 | VGA2USB_IS_VGA2USB_PRO(idVendor,idProduct,iProduct,iMfg) || \ 145 | VGA2USB_IS_VGA2USB_HR(idVendor,idProduct,iProduct,iMfg) || \ 146 | VGA2USB_IS_VGA2USB_LR(idVendor,idProduct,iProduct,iMfg) || \ 147 | VGA2USB_IS_VGA2USB_LR_RESPIN(idVendor,idProduct,iProduct,iMfg) || \ 148 | VGA2USB_IS_VGA2USB_HR_RESPIN(idVendor,idProduct,iProduct,iMfg) || \ 149 | VGA2USB_IS_VGA2USB_PRO_RESPIN(idVendor,idProduct,iProduct,iMfg) || \ 150 | VGA2USB_IS_KVM2USB_PRO(idVendor,idProduct,iProduct,iMfg) || \ 151 | VGA2USB_IS_KVM2USB_LR(idVendor,idProduct,iProduct,iMfg) || \ 152 | VGA2USB_IS_KVM2USB_LR_RESPIN(idVendor,idProduct,iProduct,iMfg) || \ 153 | VGA2USB_IS_DVI2USB3(idVendor,idProduct,iProduct,iMfg) || \ 154 | VGA2USB_IS_DVI2USB3_ET(idVendor,idProduct,iProduct,iMfg) || \ 155 | VGA2USB_IS_SDI2USB3(idVendor,idProduct,iProduct,iMfg) \ 156 | ) 157 | 158 | 159 | /** 160 | * Windows device name format. Used by user level code on Windows to open 161 | * a handle to the VGA2USB driver. 162 | */ 163 | 164 | #define VGA2USB_WIN_DEVICE_FORMAT "EpiphanVga2usb%lu" 165 | 166 | /** 167 | * This macro helps to map VGA2USB product ids into product names 168 | */ 169 | #define V2U_PRODUCT_MAP(map) \ 170 | map( VGA2USB_PRODID_VGA2USB, V2UProductVGA2USB, "VGA2USB" )\ 171 | map( VGA2USB_PRODID_KVM2USB, V2UProductKVM2USB, "KVM2USB" )\ 172 | map( VGA2USB_PRODID_DVI2USB, V2UProductDVI2USB, "DVI2USB" )\ 173 | map( VGA2USB_PRODID_VGA2USB_LR, V2UProductVGA2USBLR, "VGA2USB LR" )\ 174 | map( VGA2USB_PRODID_VGA2USB_HR, V2UProductVGA2USBHR, "VGA2USB HR" )\ 175 | map( VGA2USB_PRODID_VGA2USB_PRO, V2UProductVGA2USBPro, "VGA2USB Pro" )\ 176 | map( VGA2USB_PRODID_VGA2USB_LR_RESPIN,V2UProductVGA2USBLRRespin,"VGA2USB LR")\ 177 | map( VGA2USB_PRODID_VGA2USB_HR_RESPIN,V2UProductVGA2USBHRRespin,"VGA2USB HR")\ 178 | map( VGA2USB_PRODID_VGA2USB_PRO_RESPIN,V2UProductVGA2USBProRespin,"VGA2USB Pro")\ 179 | map( VGA2USB_PRODID_DVI2USB_RESPIN,V2UProductDVI2USBRespin,"DVI2USB" )\ 180 | map( VGA2USB_PRODID_KVM2USB_LR, V2UProductKVM2USBLR, "KVM2USB LR" )\ 181 | map( VGA2USB_PRODID_KVM2USB_LR_RESPIN, V2UProductKVM2USBLRRespin, "KVM2USB LR")\ 182 | map( VGA2USB_PRODID_KVM2USB_PRO, V2UProductKVM2USBPro, "KVM2USB Pro" )\ 183 | map( VGA2USB_PRODID_DVI2USB_SOLO, V2UProductDVI2USBSolo, "DVI2USB Solo")\ 184 | map( VGA2USB_PRODID_DVI2USB_DUO, V2UProductDVI2USBDuo, "DVI2USB Duo" )\ 185 | map( VGA2USB_PRODID_VGA2FIFO, V2UProductVGA2FIFO, "VGA2FIFO" )\ 186 | map( VGA2USB_PRODID_KVM2FIFO, V2UProductKVM2FIFO, "KVMFIFO" )\ 187 | map( VGA2USB_PRODID_DVI2FIFO, V2UProductDVI2FIFO, "DVI2FIFO" )\ 188 | map( VGA2USB_PRODID_DAVINCI1, V2UProductDVI2Davinci1, "DVI2Davinci" )\ 189 | map( VGA2USB_PRODID_VGA2PCI, V2UProductVGA2PCI, "VGA2PCI" )\ 190 | map( VGA2USB_PRODID_GIOCONDA, V2UProductGioconda, "Gioconda" )\ 191 | map( VGA2USB_PRODID_DVI2PCI, V2UProductDVI2PCI, "DVI2PCI" )\ 192 | map( VGA2USB_PRODID_DVI2PCI_STD, V2UProductDVI2PCIStd, "DVI2PCI Std" )\ 193 | map( VGA2USB_PRODID_DVI2PCI_GEN2, V2UProductDVI2PCIGen2, "DVI2PCI Duo" )\ 194 | map( VGA2USB_PRODID_DVI2PCI_GII, V2UProductDVI2PCIGII, "DVI2PCI GII" )\ 195 | map( VGA2USB_PRODID_HDMI2PCI, V2UProductHDMI2PCI, "HDMI2PCI" )\ 196 | V2U_FX3_PRODUCT_MAP(map) 197 | #define V2U_FX3_PRODUCT_MAP(map) \ 198 | map( VGA2USB_PRODID_DVI2USB3, V2UProductDVI2USB3, "DVI2USB 3.0" )\ 199 | map( VGA2USB_PRODID_DVI2USB3_ET, V2UProductDVI2USB3ET, "DVI2USB 3.0 ET")\ 200 | map( VGA2USB_PRODID_SDI2USB3, V2UProductSDI2USB3, "SDI2USB 3.0" )\ 201 | map( VGA2USB_PRODID_DVI2USB3_R3, V2UProductDVI2USB3, "DVI2USB 3.0" )\ 202 | map( VGA2USB_PRODID_DVI2USB3_ET_R3,V2UProductDVI2USB3ET, "DVI2USB 3.0 ET")\ 203 | map( VGA2USB_PRODID_SDI2USB3_R3, V2UProductSDI2USB3, "SDI2USB 3.0" ) 204 | 205 | #endif /* _VGA2USB_ID_H_ */ 206 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/device.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Google Inc. All rights reserved. 2 | // Copyright 2016 the gousb Authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package gousb 17 | 18 | import ( 19 | "fmt" 20 | "sort" 21 | "sync" 22 | "time" 23 | ) 24 | 25 | // DeviceDesc is a representation of a USB device descriptor. 26 | type DeviceDesc struct { 27 | // Bus information 28 | Bus int // The bus on which the device was detected 29 | Address int // The address of the device on the bus 30 | Speed Speed // The negotiated operating speed for the device 31 | Port int // The usb port on which the device was detected 32 | 33 | // Version information 34 | Spec BCD // USB Specification Release Number 35 | Device BCD // The device version 36 | 37 | // Product information 38 | Vendor ID // The Vendor identifer 39 | Product ID // The Product identifier 40 | 41 | // Protocol information 42 | Class Class // The class of this device 43 | SubClass Class // The sub-class (within the class) of this device 44 | Protocol Protocol // The protocol (within the sub-class) of this device 45 | MaxControlPacketSize int // Maximum size of the control transfer 46 | 47 | // Configuration information 48 | Configs map[int]ConfigDesc 49 | 50 | iManufacturer int // The Manufacturer descriptor index 51 | iProduct int // The Product descriptor index 52 | iSerialNumber int // The SerialNumber descriptor index 53 | } 54 | 55 | // String returns a human-readable version of the device descriptor. 56 | func (d *DeviceDesc) String() string { 57 | return fmt.Sprintf("%d.%d: %s:%s (available configs: %v)", d.Bus, d.Address, d.Vendor, d.Product, d.sortedConfigIds()) 58 | } 59 | 60 | func (d *DeviceDesc) sortedConfigIds() []int { 61 | var cfgs []int 62 | for c := range d.Configs { 63 | cfgs = append(cfgs, c) 64 | } 65 | sort.Ints(cfgs) 66 | return cfgs 67 | } 68 | 69 | func (d *DeviceDesc) cfgDesc(cfgNum int) (*ConfigDesc, error) { 70 | desc, ok := d.Configs[cfgNum] 71 | if !ok { 72 | return nil, fmt.Errorf("configuration id %d not found in the descriptor of the device. Available config ids: %v", cfgNum, d.sortedConfigIds()) 73 | } 74 | return &desc, nil 75 | } 76 | 77 | // Device represents an opened USB device. 78 | // Device allows sending USB control commands through the Command() method. 79 | // For data transfers select a device configuration through a call to 80 | // Config(). 81 | // A Device must be Close()d after use. 82 | type Device struct { 83 | handle *libusbDevHandle 84 | ctx *Context 85 | 86 | // Embed the device information for easy access 87 | Desc *DeviceDesc 88 | // Timeout for control commands 89 | ControlTimeout time.Duration 90 | 91 | // Claimed config 92 | mu sync.Mutex 93 | claimed *Config 94 | 95 | // Handle AutoDetach in this library 96 | autodetach bool 97 | } 98 | 99 | // String represents a human readable representation of the device. 100 | func (d *Device) String() string { 101 | return fmt.Sprintf("vid=%s,pid=%s,bus=%d,addr=%d", d.Desc.Vendor, d.Desc.Product, d.Desc.Bus, d.Desc.Address) 102 | } 103 | 104 | // Reset performs a USB port reset to reinitialize a device. 105 | func (d *Device) Reset() error { 106 | if d.handle == nil { 107 | return fmt.Errorf("Reset() called on %s after Close", d) 108 | } 109 | d.mu.Lock() 110 | defer d.mu.Unlock() 111 | if d.claimed != nil { 112 | return fmt.Errorf("can't reset device %s while it has an active configuration %s", d, d.claimed) 113 | } 114 | return d.ctx.libusb.reset(d.handle) 115 | } 116 | 117 | // ActiveConfigNum returns the config id of the active configuration. 118 | // The value corresponds to the ConfigInfo.Config field of one of the 119 | // ConfigInfos of this Device. 120 | func (d *Device) ActiveConfigNum() (int, error) { 121 | if d.handle == nil { 122 | return 0, fmt.Errorf("ActiveConfig() called on %s after Close", d) 123 | } 124 | ret, err := d.ctx.libusb.getConfig(d.handle) 125 | return int(ret), err 126 | } 127 | 128 | // Config returns a USB device set to use a particular config. 129 | // The cfgNum provided is the config id (not the index) of the configuration to 130 | // set, which corresponds to the ConfigInfo.Config field. 131 | // USB supports only one active config per device at a time. Config claims the 132 | // device before setting the desired config and keeps it locked until Close is 133 | // called. 134 | // A claimed config needs to be Close()d after use. 135 | func (d *Device) Config(cfgNum int) (*Config, error) { 136 | if d.handle == nil { 137 | return nil, fmt.Errorf("Config(%d) called on %s after Close", cfgNum, d) 138 | } 139 | desc, err := d.Desc.cfgDesc(cfgNum) 140 | if err != nil { 141 | return nil, fmt.Errorf("device %s: %v", d, err) 142 | } 143 | cfg := &Config{ 144 | Desc: *desc, 145 | dev: d, 146 | claimed: make(map[int]bool), 147 | } 148 | 149 | if d.autodetach { 150 | for _, iface := range cfg.Desc.Interfaces { 151 | if err := d.ctx.libusb.detachKernelDriver(d.handle, uint8(iface.Number)); err != nil { 152 | return nil, fmt.Errorf("Can't detach kernel driver of the device %s and interface %d: %v", d, iface.Number, err) 153 | } 154 | } 155 | } 156 | 157 | if activeCfgNum, err := d.ActiveConfigNum(); err != nil { 158 | return nil, fmt.Errorf("failed to query active config of the device %s: %v", d, err) 159 | } else if cfgNum != activeCfgNum { 160 | if err := d.ctx.libusb.setConfig(d.handle, uint8(cfgNum)); err != nil { 161 | return nil, fmt.Errorf("failed to set active config %d for the device %s: %v", cfgNum, d, err) 162 | } 163 | } 164 | d.mu.Lock() 165 | defer d.mu.Unlock() 166 | d.claimed = cfg 167 | return cfg, nil 168 | } 169 | 170 | // DefaultInterface opens interface #0 with alternate setting #0 of the currently active 171 | // config. It's intended as a shortcut for devices that have the simplest 172 | // interface of a single config, interface and alternate setting. 173 | // The done func should be called to release the claimed interface and config. 174 | func (d *Device) DefaultInterface() (intf *Interface, done func(), err error) { 175 | cfgNum, err := d.ActiveConfigNum() 176 | if err != nil { 177 | return nil, nil, fmt.Errorf("failed to get active config number of device %s: %v", d, err) 178 | } 179 | cfg, err := d.Config(cfgNum) 180 | if err != nil { 181 | return nil, nil, fmt.Errorf("failed to claim config %d of device %s: %v", cfgNum, d, err) 182 | } 183 | i, err := cfg.Interface(0, 0) 184 | if err != nil { 185 | cfg.Close() 186 | return nil, nil, fmt.Errorf("failed to select interface #%d alternate setting %d of config %d of device %s: %v", 0, 0, cfgNum, d, err) 187 | } 188 | return i, func() { 189 | intf.Close() 190 | cfg.Close() 191 | }, nil 192 | } 193 | 194 | // Control sends a control request to the device. 195 | func (d *Device) Control(rType, request uint8, val, idx uint16, data []byte) (int, error) { 196 | if d.handle == nil { 197 | return 0, fmt.Errorf("Control() called on %s after Close", d) 198 | } 199 | return d.ctx.libusb.control(d.handle, d.ControlTimeout, rType, request, val, idx, data) 200 | } 201 | 202 | // Close closes the device. 203 | func (d *Device) Close() error { 204 | if d.handle == nil { 205 | return nil 206 | } 207 | d.mu.Lock() 208 | defer d.mu.Unlock() 209 | if d.claimed != nil { 210 | return fmt.Errorf("can't release the device %s, it has an open config %d", d, d.claimed.Desc.Number) 211 | } 212 | d.ctx.libusb.close(d.handle) 213 | d.handle = nil 214 | return nil 215 | } 216 | 217 | // GetStringDescriptor returns a device string descriptor with the given index 218 | // number. The first supported language is always used and the returned 219 | // descriptor string is converted to ASCII (non-ASCII characters are replaced 220 | // with "?"). 221 | func (d *Device) GetStringDescriptor(descIndex int) (string, error) { 222 | if d.handle == nil { 223 | return "", fmt.Errorf("GetStringDescriptor(%d) called on %s after Close", descIndex, d) 224 | } 225 | // string descriptor index value of 0 indicates no string descriptor. 226 | if descIndex == 0 { 227 | return "", nil 228 | } 229 | return d.ctx.libusb.getStringDesc(d.handle, descIndex) 230 | } 231 | 232 | // Manufacturer returns the device's manufacturer name. 233 | // GetStringDescriptor's string conversion rules apply. 234 | func (d *Device) Manufacturer() (string, error) { 235 | return d.GetStringDescriptor(d.Desc.iManufacturer) 236 | } 237 | 238 | // Product returns the device's product name. 239 | // GetStringDescriptor's string conversion rules apply. 240 | func (d *Device) Product() (string, error) { 241 | return d.GetStringDescriptor(d.Desc.iProduct) 242 | } 243 | 244 | // SerialNumber returns the device's serial number. 245 | // GetStringDescriptor's string conversion rules apply. 246 | func (d *Device) SerialNumber() (string, error) { 247 | return d.GetStringDescriptor(d.Desc.iSerialNumber) 248 | } 249 | 250 | // ConfigDescription returns the description of the selected device 251 | // configuration. GetStringDescriptor's string conversion rules apply. 252 | func (d *Device) ConfigDescription(cfg int) (string, error) { 253 | c, err := d.Desc.cfgDesc(cfg) 254 | if err != nil { 255 | return "", fmt.Errorf("%s: %v", d, err) 256 | } 257 | return d.GetStringDescriptor(c.iConfiguration) 258 | } 259 | 260 | // InterfaceDescription returns the description of the selected interface and 261 | // its alternate setting in a selected configuration. GetStringDescriptor's 262 | // string conversion rules apply. 263 | func (d *Device) InterfaceDescription(cfgNum, intfNum, altNum int) (string, error) { 264 | cfg, err := d.Desc.cfgDesc(cfgNum) 265 | if err != nil { 266 | return "", fmt.Errorf("%s: %v", d, err) 267 | } 268 | alt, err := cfg.intfDesc(intfNum, altNum) 269 | if err != nil { 270 | return "", fmt.Errorf("%s, configuration %d: %v", d, cfgNum, err) 271 | } 272 | return d.GetStringDescriptor(alt.iInterface) 273 | } 274 | 275 | // SetAutoDetach enables/disables automatic kernel driver detachment. 276 | // When autodetach is enabled gousb will automatically detach the kernel driver 277 | // on the interface and reattach it when releasing the interface. 278 | // Automatic kernel driver detachment is disabled on newly opened device handles by default. 279 | func (d *Device) SetAutoDetach(autodetach bool) error { 280 | if d.handle == nil { 281 | return fmt.Errorf("SetAutoDetach(%v) called on %s after Close", autodetach, d) 282 | } 283 | d.autodetach = autodetach 284 | var autodetachInt int 285 | if autodetach { 286 | autodetachInt = 1 287 | } 288 | return d.ctx.libusb.setAutoDetach(d.handle, autodetachInt) 289 | } 290 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/transfer_stream.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 the gousb Authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package gousb 16 | 17 | import ( 18 | "context" 19 | "io" 20 | ) 21 | 22 | type transferIntf interface { 23 | submit() error 24 | cancel() error 25 | wait(context.Context) (int, error) 26 | free() error 27 | data() []byte 28 | } 29 | 30 | type stream struct { 31 | // a fifo of USB transfers. 32 | transfers chan transferIntf 33 | // err is the first encountered error, returned to the user. 34 | err error 35 | // finished is true if transfers has been already closed. 36 | finished bool 37 | } 38 | 39 | func (s *stream) gotError(err error) { 40 | if s.err == nil { 41 | s.err = err 42 | } 43 | } 44 | 45 | func (s *stream) noMore() { 46 | if !s.finished { 47 | close(s.transfers) 48 | s.finished = true 49 | } 50 | } 51 | 52 | func (s *stream) submitAll() { 53 | count := len(s.transfers) 54 | var all []transferIntf 55 | for i := 0; i < count; i++ { 56 | all = append(all, <-s.transfers) 57 | } 58 | for _, t := range all { 59 | if err := t.submit(); err != nil { 60 | t.free() 61 | s.gotError(err) 62 | s.noMore() 63 | return 64 | } 65 | s.transfers <- t 66 | } 67 | return 68 | } 69 | 70 | func (s *stream) flushRemaining() { 71 | s.noMore() 72 | for t := range s.transfers { 73 | t.cancel() 74 | t.wait(context.Background()) 75 | t.free() 76 | } 77 | } 78 | 79 | func (s *stream) done() { 80 | if s.err == nil { 81 | close(s.transfers) 82 | } 83 | } 84 | 85 | // ReadStream is a buffer that tries to prefetch data from the IN endpoint, 86 | // reducing the latency between subsequent Read()s. 87 | // ReadStream keeps prefetching data until Close() is called or until 88 | // an error is encountered. After Close(), the buffer might still have 89 | // data left from transfers that were initiated before Close. Read()ing 90 | // from the ReadStream will keep returning available data. When no more 91 | // data is left, io.EOF is returned. 92 | type ReadStream struct { 93 | s *stream 94 | // current holds the last transfer to return. 95 | current transferIntf 96 | // total/used are the number of all/used bytes in the current transfer. 97 | total, used int 98 | } 99 | 100 | // Read reads data from the transfer stream. 101 | // The data will come from at most a single transfer, so the returned number 102 | // might be smaller than the length of p. 103 | // After a non-nil error is returned, all subsequent attempts to read will 104 | // return io.ErrClosedPipe. 105 | // Read cannot be called concurrently with other Read, ReadContext 106 | // or Close. 107 | func (r *ReadStream) Read(p []byte) (int, error) { 108 | return r.ReadContext(context.Background(), p) 109 | } 110 | 111 | // ReadContext reads data from the transfer stream. 112 | // The data will come from at most a single transfer, so the returned number 113 | // might be smaller than the length of p. 114 | // After a non-nil error is returned, all subsequent attempts to read will 115 | // return io.ErrClosedPipe. 116 | // ReadContext cannot be called concurrently with other Read, ReadContext 117 | // or Close. 118 | // The context passed controls the cancellation of this particular read 119 | // operation within the stream. The semantics is identical to 120 | // Endpoint.ReadContext. 121 | func (r *ReadStream) ReadContext(ctx context.Context, p []byte) (int, error) { 122 | if r.s.transfers == nil { 123 | return 0, io.ErrClosedPipe 124 | } 125 | if r.current == nil { 126 | t, ok := <-r.s.transfers 127 | if !ok { 128 | // no more transfers in flight 129 | r.s.transfers = nil 130 | return 0, r.s.err 131 | } 132 | n, err := t.wait(ctx) 133 | if err != nil { 134 | // wait error aborts immediately, all remaining data is invalid. 135 | t.free() 136 | r.s.flushRemaining() 137 | r.s.transfers = nil 138 | return n, err 139 | } 140 | r.current = t 141 | r.total = n 142 | r.used = 0 143 | } 144 | use := r.total - r.used 145 | if use > len(p) { 146 | use = len(p) 147 | } 148 | copy(p, r.current.data()[r.used:r.used+use]) 149 | r.used += use 150 | if r.used == r.total { 151 | if r.s.err == nil { 152 | if err := r.current.submit(); err == nil { 153 | // guaranteed to not block, len(transfers) == number of allocated transfers 154 | r.s.transfers <- r.current 155 | } else { 156 | r.s.gotError(err) 157 | r.s.noMore() 158 | } 159 | } 160 | if r.s.err != nil { 161 | r.current.free() 162 | } 163 | r.current = nil 164 | } 165 | return use, nil 166 | } 167 | 168 | // Close signals that the transfer should stop. After Close is called, 169 | // subsequent Read()s will return data from all transfers that were already 170 | // in progress before returning an io.EOF error, unless another error 171 | // was encountered earlier. 172 | // Close cannot be called concurrently with Read. 173 | func (r *ReadStream) Close() error { 174 | if r.s.transfers == nil { 175 | return nil 176 | } 177 | r.s.gotError(io.EOF) 178 | r.s.noMore() 179 | return nil 180 | } 181 | 182 | // WriteStream is a buffer that will send data asynchronously, reducing 183 | // the latency between subsequent Write()s. 184 | type WriteStream struct { 185 | s *stream 186 | total int 187 | } 188 | 189 | // Write sends the data to the endpoint. Write returning a nil error doesn't 190 | // mean that data was written to the device, only that it was written to the 191 | // buffer. Only a call to Close() that returns nil error guarantees that 192 | // all transfers have succeeded. 193 | // If the slice passed to Write does not align exactly with the transfer 194 | // buffer size (as declared in a call to NewStream), the last USB transfer 195 | // of this Write will be sent with less data than the full buffer. 196 | // After a non-nil error is returned, all subsequent attempts to write will 197 | // return io.ErrClosedPipe. 198 | // If Write encounters an error when preparing the transfer, the stream 199 | // will still try to complete any pending transfers. The total number 200 | // of bytes successfully written can be retrieved through a Written() 201 | // call after Close() has returned. 202 | // Write cannot be called concurrently with another Write, Written or Close. 203 | func (w *WriteStream) Write(p []byte) (int, error) { 204 | return w.WriteContext(context.Background(), p) 205 | } 206 | 207 | // WriteContext sends the data to the endpoint. Write returning a nil error doesn't 208 | // mean that data was written to the device, only that it was written to the 209 | // buffer. Only a call to Close() that returns nil error guarantees that 210 | // all transfers have succeeded. 211 | // If the slice passed to WriteContext does not align exactly with the transfer 212 | // buffer size (as declared in a call to NewStream), the last USB transfer 213 | // of this Write will be sent with less data than the full buffer. 214 | // After a non-nil error is returned, all subsequent attempts to write will 215 | // return io.ErrClosedPipe. 216 | // If WriteContext encounters an error when preparing the transfer, the stream 217 | // will still try to complete any pending transfers. The total number 218 | // of bytes successfully written can be retrieved through a Written() 219 | // call after Close() has returned. 220 | // WriteContext cannot be called concurrently with another Write, WriteContext, 221 | // Written, Close or CloseContext. 222 | func (w *WriteStream) WriteContext(ctx context.Context, p []byte) (int, error) { 223 | if w.s.transfers == nil || w.s.err != nil { 224 | return 0, io.ErrClosedPipe 225 | } 226 | written := 0 227 | all := len(p) 228 | for written < all { 229 | t := <-w.s.transfers 230 | n, err := t.wait(ctx) // unsubmitted transfers will return 0 bytes and no error 231 | w.total += n 232 | if err != nil { 233 | t.free() 234 | w.s.gotError(err) 235 | // This branch is used only after all the transfers were set in flight. 236 | // That means all transfers left in the queue are in flight. 237 | // They must be ignored, since this wait() failed. 238 | w.s.flushRemaining() 239 | return written, err 240 | } 241 | use := all - written 242 | if max := len(t.data()); use > max { 243 | use = max 244 | } 245 | copy(t.data(), p[written:written+use]) 246 | if err := t.submit(); err != nil { 247 | t.free() 248 | w.s.gotError(err) 249 | // Even though this submit failed, all the transfers in flight are still valid. 250 | // Don't flush remaining transfers. 251 | // We won't submit any more transfers. 252 | w.s.noMore() 253 | return written, err 254 | } 255 | written += use 256 | w.s.transfers <- t // guaranteed non blocking 257 | } 258 | return written, nil 259 | } 260 | 261 | // Close signals end of data to write. Close blocks until all transfers 262 | // that were sent are finished. The error returned by Close is the first 263 | // error encountered during writing the entire stream (if any). 264 | // Close returning nil indicates all transfers completed successfully. 265 | // After Close, the total number of bytes successfully written can be 266 | // retrieved using Written(). 267 | // Close may not be called concurrently with Write, Close or Written. 268 | func (w *WriteStream) Close() error { 269 | return w.CloseContext(context.Background()) 270 | } 271 | 272 | // Close signals end of data to write. Close blocks until all transfers 273 | // that were sent are finished. The error returned by Close is the first 274 | // error encountered during writing the entire stream (if any). 275 | // Close returning nil indicates all transfers completed successfully. 276 | // After Close, the total number of bytes successfully written can be 277 | // retrieved using Written(). 278 | // Close may not be called concurrently with Write, Close or Written. 279 | // CloseContext 280 | func (w *WriteStream) CloseContext(ctx context.Context) error { 281 | if w.s.transfers == nil { 282 | return io.ErrClosedPipe 283 | } 284 | w.s.noMore() 285 | for t := range w.s.transfers { 286 | n, err := t.wait(ctx) 287 | w.total += n 288 | t.free() 289 | if err != nil { 290 | w.s.gotError(err) 291 | w.s.flushRemaining() 292 | } 293 | t.free() 294 | } 295 | w.s.transfers = nil 296 | return w.s.err 297 | } 298 | 299 | // Written returns the number of bytes successfully written by the stream. 300 | // Written may be called only after Close() or CloseContext() 301 | // has been called and returned. 302 | func (w *WriteStream) Written() int { 303 | return w.total 304 | } 305 | 306 | func newStream(tt []transferIntf) *stream { 307 | s := &stream{ 308 | transfers: make(chan transferIntf, len(tt)), 309 | } 310 | for _, t := range tt { 311 | s.transfers <- t 312 | } 313 | return s 314 | } 315 | -------------------------------------------------------------------------------- /vendor/github.com/google/gousb/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/websocket/websocket.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package websocket implements a client and server for the WebSocket protocol 6 | // as specified in RFC 6455. 7 | // 8 | // This package currently lacks some features found in alternative 9 | // and more actively maintained WebSocket packages: 10 | // 11 | // https://godoc.org/github.com/gorilla/websocket 12 | // https://godoc.org/nhooyr.io/websocket 13 | package websocket // import "golang.org/x/net/websocket" 14 | 15 | import ( 16 | "bufio" 17 | "crypto/tls" 18 | "encoding/json" 19 | "errors" 20 | "io" 21 | "io/ioutil" 22 | "net" 23 | "net/http" 24 | "net/url" 25 | "sync" 26 | "time" 27 | ) 28 | 29 | const ( 30 | ProtocolVersionHybi13 = 13 31 | ProtocolVersionHybi = ProtocolVersionHybi13 32 | SupportedProtocolVersion = "13" 33 | 34 | ContinuationFrame = 0 35 | TextFrame = 1 36 | BinaryFrame = 2 37 | CloseFrame = 8 38 | PingFrame = 9 39 | PongFrame = 10 40 | UnknownFrame = 255 41 | 42 | DefaultMaxPayloadBytes = 32 << 20 // 32MB 43 | ) 44 | 45 | // ProtocolError represents WebSocket protocol errors. 46 | type ProtocolError struct { 47 | ErrorString string 48 | } 49 | 50 | func (err *ProtocolError) Error() string { return err.ErrorString } 51 | 52 | var ( 53 | ErrBadProtocolVersion = &ProtocolError{"bad protocol version"} 54 | ErrBadScheme = &ProtocolError{"bad scheme"} 55 | ErrBadStatus = &ProtocolError{"bad status"} 56 | ErrBadUpgrade = &ProtocolError{"missing or bad upgrade"} 57 | ErrBadWebSocketOrigin = &ProtocolError{"missing or bad WebSocket-Origin"} 58 | ErrBadWebSocketLocation = &ProtocolError{"missing or bad WebSocket-Location"} 59 | ErrBadWebSocketProtocol = &ProtocolError{"missing or bad WebSocket-Protocol"} 60 | ErrBadWebSocketVersion = &ProtocolError{"missing or bad WebSocket Version"} 61 | ErrChallengeResponse = &ProtocolError{"mismatch challenge/response"} 62 | ErrBadFrame = &ProtocolError{"bad frame"} 63 | ErrBadFrameBoundary = &ProtocolError{"not on frame boundary"} 64 | ErrNotWebSocket = &ProtocolError{"not websocket protocol"} 65 | ErrBadRequestMethod = &ProtocolError{"bad method"} 66 | ErrNotSupported = &ProtocolError{"not supported"} 67 | ) 68 | 69 | // ErrFrameTooLarge is returned by Codec's Receive method if payload size 70 | // exceeds limit set by Conn.MaxPayloadBytes 71 | var ErrFrameTooLarge = errors.New("websocket: frame payload size exceeds limit") 72 | 73 | // Addr is an implementation of net.Addr for WebSocket. 74 | type Addr struct { 75 | *url.URL 76 | } 77 | 78 | // Network returns the network type for a WebSocket, "websocket". 79 | func (addr *Addr) Network() string { return "websocket" } 80 | 81 | // Config is a WebSocket configuration 82 | type Config struct { 83 | // A WebSocket server address. 84 | Location *url.URL 85 | 86 | // A Websocket client origin. 87 | Origin *url.URL 88 | 89 | // WebSocket subprotocols. 90 | Protocol []string 91 | 92 | // WebSocket protocol version. 93 | Version int 94 | 95 | // TLS config for secure WebSocket (wss). 96 | TlsConfig *tls.Config 97 | 98 | // Additional header fields to be sent in WebSocket opening handshake. 99 | Header http.Header 100 | 101 | // Dialer used when opening websocket connections. 102 | Dialer *net.Dialer 103 | 104 | handshakeData map[string]string 105 | } 106 | 107 | // serverHandshaker is an interface to handle WebSocket server side handshake. 108 | type serverHandshaker interface { 109 | // ReadHandshake reads handshake request message from client. 110 | // Returns http response code and error if any. 111 | ReadHandshake(buf *bufio.Reader, req *http.Request) (code int, err error) 112 | 113 | // AcceptHandshake accepts the client handshake request and sends 114 | // handshake response back to client. 115 | AcceptHandshake(buf *bufio.Writer) (err error) 116 | 117 | // NewServerConn creates a new WebSocket connection. 118 | NewServerConn(buf *bufio.ReadWriter, rwc io.ReadWriteCloser, request *http.Request) (conn *Conn) 119 | } 120 | 121 | // frameReader is an interface to read a WebSocket frame. 122 | type frameReader interface { 123 | // Reader is to read payload of the frame. 124 | io.Reader 125 | 126 | // PayloadType returns payload type. 127 | PayloadType() byte 128 | 129 | // HeaderReader returns a reader to read header of the frame. 130 | HeaderReader() io.Reader 131 | 132 | // TrailerReader returns a reader to read trailer of the frame. 133 | // If it returns nil, there is no trailer in the frame. 134 | TrailerReader() io.Reader 135 | 136 | // Len returns total length of the frame, including header and trailer. 137 | Len() int 138 | } 139 | 140 | // frameReaderFactory is an interface to creates new frame reader. 141 | type frameReaderFactory interface { 142 | NewFrameReader() (r frameReader, err error) 143 | } 144 | 145 | // frameWriter is an interface to write a WebSocket frame. 146 | type frameWriter interface { 147 | // Writer is to write payload of the frame. 148 | io.WriteCloser 149 | } 150 | 151 | // frameWriterFactory is an interface to create new frame writer. 152 | type frameWriterFactory interface { 153 | NewFrameWriter(payloadType byte) (w frameWriter, err error) 154 | } 155 | 156 | type frameHandler interface { 157 | HandleFrame(frame frameReader) (r frameReader, err error) 158 | WriteClose(status int) (err error) 159 | } 160 | 161 | // Conn represents a WebSocket connection. 162 | // 163 | // Multiple goroutines may invoke methods on a Conn simultaneously. 164 | type Conn struct { 165 | config *Config 166 | request *http.Request 167 | 168 | buf *bufio.ReadWriter 169 | rwc io.ReadWriteCloser 170 | 171 | rio sync.Mutex 172 | frameReaderFactory 173 | frameReader 174 | 175 | wio sync.Mutex 176 | frameWriterFactory 177 | 178 | frameHandler 179 | PayloadType byte 180 | defaultCloseStatus int 181 | 182 | // MaxPayloadBytes limits the size of frame payload received over Conn 183 | // by Codec's Receive method. If zero, DefaultMaxPayloadBytes is used. 184 | MaxPayloadBytes int 185 | } 186 | 187 | // Read implements the io.Reader interface: 188 | // it reads data of a frame from the WebSocket connection. 189 | // if msg is not large enough for the frame data, it fills the msg and next Read 190 | // will read the rest of the frame data. 191 | // it reads Text frame or Binary frame. 192 | func (ws *Conn) Read(msg []byte) (n int, err error) { 193 | ws.rio.Lock() 194 | defer ws.rio.Unlock() 195 | again: 196 | if ws.frameReader == nil { 197 | frame, err := ws.frameReaderFactory.NewFrameReader() 198 | if err != nil { 199 | return 0, err 200 | } 201 | ws.frameReader, err = ws.frameHandler.HandleFrame(frame) 202 | if err != nil { 203 | return 0, err 204 | } 205 | if ws.frameReader == nil { 206 | goto again 207 | } 208 | } 209 | n, err = ws.frameReader.Read(msg) 210 | if err == io.EOF { 211 | if trailer := ws.frameReader.TrailerReader(); trailer != nil { 212 | io.Copy(ioutil.Discard, trailer) 213 | } 214 | ws.frameReader = nil 215 | goto again 216 | } 217 | return n, err 218 | } 219 | 220 | // Write implements the io.Writer interface: 221 | // it writes data as a frame to the WebSocket connection. 222 | func (ws *Conn) Write(msg []byte) (n int, err error) { 223 | ws.wio.Lock() 224 | defer ws.wio.Unlock() 225 | w, err := ws.frameWriterFactory.NewFrameWriter(ws.PayloadType) 226 | if err != nil { 227 | return 0, err 228 | } 229 | n, err = w.Write(msg) 230 | w.Close() 231 | return n, err 232 | } 233 | 234 | // Close implements the io.Closer interface. 235 | func (ws *Conn) Close() error { 236 | err := ws.frameHandler.WriteClose(ws.defaultCloseStatus) 237 | err1 := ws.rwc.Close() 238 | if err != nil { 239 | return err 240 | } 241 | return err1 242 | } 243 | 244 | // IsClientConn reports whether ws is a client-side connection. 245 | func (ws *Conn) IsClientConn() bool { return ws.request == nil } 246 | 247 | // IsServerConn reports whether ws is a server-side connection. 248 | func (ws *Conn) IsServerConn() bool { return ws.request != nil } 249 | 250 | // LocalAddr returns the WebSocket Origin for the connection for client, or 251 | // the WebSocket location for server. 252 | func (ws *Conn) LocalAddr() net.Addr { 253 | if ws.IsClientConn() { 254 | return &Addr{ws.config.Origin} 255 | } 256 | return &Addr{ws.config.Location} 257 | } 258 | 259 | // RemoteAddr returns the WebSocket location for the connection for client, or 260 | // the Websocket Origin for server. 261 | func (ws *Conn) RemoteAddr() net.Addr { 262 | if ws.IsClientConn() { 263 | return &Addr{ws.config.Location} 264 | } 265 | return &Addr{ws.config.Origin} 266 | } 267 | 268 | var errSetDeadline = errors.New("websocket: cannot set deadline: not using a net.Conn") 269 | 270 | // SetDeadline sets the connection's network read & write deadlines. 271 | func (ws *Conn) SetDeadline(t time.Time) error { 272 | if conn, ok := ws.rwc.(net.Conn); ok { 273 | return conn.SetDeadline(t) 274 | } 275 | return errSetDeadline 276 | } 277 | 278 | // SetReadDeadline sets the connection's network read deadline. 279 | func (ws *Conn) SetReadDeadline(t time.Time) error { 280 | if conn, ok := ws.rwc.(net.Conn); ok { 281 | return conn.SetReadDeadline(t) 282 | } 283 | return errSetDeadline 284 | } 285 | 286 | // SetWriteDeadline sets the connection's network write deadline. 287 | func (ws *Conn) SetWriteDeadline(t time.Time) error { 288 | if conn, ok := ws.rwc.(net.Conn); ok { 289 | return conn.SetWriteDeadline(t) 290 | } 291 | return errSetDeadline 292 | } 293 | 294 | // Config returns the WebSocket config. 295 | func (ws *Conn) Config() *Config { return ws.config } 296 | 297 | // Request returns the http request upgraded to the WebSocket. 298 | // It is nil for client side. 299 | func (ws *Conn) Request() *http.Request { return ws.request } 300 | 301 | // Codec represents a symmetric pair of functions that implement a codec. 302 | type Codec struct { 303 | Marshal func(v interface{}) (data []byte, payloadType byte, err error) 304 | Unmarshal func(data []byte, payloadType byte, v interface{}) (err error) 305 | } 306 | 307 | // Send sends v marshaled by cd.Marshal as single frame to ws. 308 | func (cd Codec) Send(ws *Conn, v interface{}) (err error) { 309 | data, payloadType, err := cd.Marshal(v) 310 | if err != nil { 311 | return err 312 | } 313 | ws.wio.Lock() 314 | defer ws.wio.Unlock() 315 | w, err := ws.frameWriterFactory.NewFrameWriter(payloadType) 316 | if err != nil { 317 | return err 318 | } 319 | _, err = w.Write(data) 320 | w.Close() 321 | return err 322 | } 323 | 324 | // Receive receives single frame from ws, unmarshaled by cd.Unmarshal and stores 325 | // in v. The whole frame payload is read to an in-memory buffer; max size of 326 | // payload is defined by ws.MaxPayloadBytes. If frame payload size exceeds 327 | // limit, ErrFrameTooLarge is returned; in this case frame is not read off wire 328 | // completely. The next call to Receive would read and discard leftover data of 329 | // previous oversized frame before processing next frame. 330 | func (cd Codec) Receive(ws *Conn, v interface{}) (err error) { 331 | ws.rio.Lock() 332 | defer ws.rio.Unlock() 333 | if ws.frameReader != nil { 334 | _, err = io.Copy(ioutil.Discard, ws.frameReader) 335 | if err != nil { 336 | return err 337 | } 338 | ws.frameReader = nil 339 | } 340 | again: 341 | frame, err := ws.frameReaderFactory.NewFrameReader() 342 | if err != nil { 343 | return err 344 | } 345 | frame, err = ws.frameHandler.HandleFrame(frame) 346 | if err != nil { 347 | return err 348 | } 349 | if frame == nil { 350 | goto again 351 | } 352 | maxPayloadBytes := ws.MaxPayloadBytes 353 | if maxPayloadBytes == 0 { 354 | maxPayloadBytes = DefaultMaxPayloadBytes 355 | } 356 | if hf, ok := frame.(*hybiFrameReader); ok && hf.header.Length > int64(maxPayloadBytes) { 357 | // payload size exceeds limit, no need to call Unmarshal 358 | // 359 | // set frameReader to current oversized frame so that 360 | // the next call to this function can drain leftover 361 | // data before processing the next frame 362 | ws.frameReader = frame 363 | return ErrFrameTooLarge 364 | } 365 | payloadType := frame.PayloadType() 366 | data, err := ioutil.ReadAll(frame) 367 | if err != nil { 368 | return err 369 | } 370 | return cd.Unmarshal(data, payloadType, v) 371 | } 372 | 373 | func marshal(v interface{}) (msg []byte, payloadType byte, err error) { 374 | switch data := v.(type) { 375 | case string: 376 | return []byte(data), TextFrame, nil 377 | case []byte: 378 | return data, BinaryFrame, nil 379 | } 380 | return nil, UnknownFrame, ErrNotSupported 381 | } 382 | 383 | func unmarshal(msg []byte, payloadType byte, v interface{}) (err error) { 384 | switch data := v.(type) { 385 | case *string: 386 | *data = string(msg) 387 | return nil 388 | case *[]byte: 389 | *data = msg 390 | return nil 391 | } 392 | return ErrNotSupported 393 | } 394 | 395 | /* 396 | Message is a codec to send/receive text/binary data in a frame on WebSocket connection. 397 | To send/receive text frame, use string type. 398 | To send/receive binary frame, use []byte type. 399 | 400 | Trivial usage: 401 | 402 | import "websocket" 403 | 404 | // receive text frame 405 | var message string 406 | websocket.Message.Receive(ws, &message) 407 | 408 | // send text frame 409 | message = "hello" 410 | websocket.Message.Send(ws, message) 411 | 412 | // receive binary frame 413 | var data []byte 414 | websocket.Message.Receive(ws, &data) 415 | 416 | // send binary frame 417 | data = []byte{0, 1, 2} 418 | websocket.Message.Send(ws, data) 419 | 420 | */ 421 | var Message = Codec{marshal, unmarshal} 422 | 423 | func jsonMarshal(v interface{}) (msg []byte, payloadType byte, err error) { 424 | msg, err = json.Marshal(v) 425 | return msg, TextFrame, err 426 | } 427 | 428 | func jsonUnmarshal(msg []byte, payloadType byte, v interface{}) (err error) { 429 | return json.Unmarshal(msg, v) 430 | } 431 | 432 | /* 433 | JSON is a codec to send/receive JSON data in a frame from a WebSocket connection. 434 | 435 | Trivial usage: 436 | 437 | import "websocket" 438 | 439 | type T struct { 440 | Msg string 441 | Count int 442 | } 443 | 444 | // receive JSON type T 445 | var data T 446 | websocket.JSON.Receive(ws, &data) 447 | 448 | // send JSON type T 449 | websocket.JSON.Send(ws, data) 450 | */ 451 | var JSON = Codec{jsonMarshal, jsonUnmarshal} 452 | --------------------------------------------------------------------------------