Skip to content

Commit e7aa39c

Browse files
author
Daniel Paulus
authored
add pairing check, remove irritating libusb error, change av stream has started-log message to: PING received (#91)
* Add check to make sure the device is paired before trying to start the AV stream. * remove irritating error messages handle_events: error: libusb: interrupted [code -10] that are actually not an error * change log.Info("AudioVideo-Stream has started") to log.Info("PING received")
1 parent 77ca679 commit e7aa39c

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/danielpaulus/quicktime_video_hack
33
go 1.16
44

55
require (
6+
github.com/danielpaulus/go-ios v1.0.13
67
github.com/danielpaulus/gst v0.0.0-20200201205042-e6d2974fceb8
78
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
89
github.com/google/gousb v2.1.0+incompatible

go.sum

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
2+
github.com/danielpaulus/go-ios v1.0.12 h1:B0pirHZibKBanZgxZGrOwoejLlEb9zgtde7eHORxLVA=
3+
github.com/danielpaulus/go-ios v1.0.12/go.mod h1:k+X7QB2ffFOhTkly/nNwvV1VIysif1MWS1s8GgYXpU4=
4+
github.com/danielpaulus/go-ios v1.0.13 h1:MFc/QOcNXRY2vv/KRijES/sI0+aHTXfzgEeK6qsZOOU=
5+
github.com/danielpaulus/go-ios v1.0.13/go.mod h1:k+X7QB2ffFOhTkly/nNwvV1VIysif1MWS1s8GgYXpU4=
16
github.com/danielpaulus/gst v0.0.0-20200201205042-e6d2974fceb8 h1:+XiTgRoo1bCA3paC4e/0WYWI7+J2O7hR/IYuSikANMw=
27
github.com/danielpaulus/gst v0.0.0-20200201205042-e6d2974fceb8/go.mod h1:JbhjLST5AaUXpKQK65g9144BK8QHftbpuFoYuhDuONw=
38
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -7,13 +12,18 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh
712
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
813
github.com/google/gousb v2.1.0+incompatible h1:ApzMDjF3FeO219QwWybJxYfFhXQzPLOEy0o+w9k5DNI=
914
github.com/google/gousb v2.1.0+incompatible/go.mod h1:Tl4HdAs1ThE3gECkNwz+1MWicX6FXddhJEw7L8jRDiI=
15+
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
16+
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
17+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
1018
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
1119
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
20+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
1221
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1322
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
1423
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1524
github.com/lijo-jose/glib v0.0.0-20191012030101-93ee72d7d646 h1:7I8sylThkL59rDoHMANuIxtB490DvrLAIZosNY9fDMM=
1625
github.com/lijo-jose/glib v0.0.0-20191012030101-93ee72d7d646/go.mod h1:wzypjnJX+g/LKnKDVvJni/u0gNlQestTwv6Kt/Qf3fk=
26+
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40/go.mod h1:vy1vK6wD6j7xX6O6hXe621WabdtNkou2h7uRtTfRMyg=
1727
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
1828
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
1929
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -27,10 +37,15 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
2737
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
2838
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
2939
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
40+
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3041
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
3142
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3243
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
44+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3345
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
3446
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
47+
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
3548
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
3649
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
50+
howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5 h1:AQkaJpH+/FmqRjmXZPELom5zIERYZfwTjnHpfoVMQEc=
51+
howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=

main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import (
44
"bufio"
55
"encoding/json"
66
"fmt"
7+
stdlog "log"
78
"os"
89
"os/signal"
10+
"strings"
911
"time"
1012

13+
"github.com/danielpaulus/go-ios/ios"
1114
"github.com/danielpaulus/quicktime_video_hack/screencapture"
1215
"github.com/danielpaulus/quicktime_video_hack/screencapture/coremedia"
1316
"github.com/danielpaulus/quicktime_video_hack/screencapture/diagnostics"
@@ -66,6 +69,7 @@ The commands work as following:
6669
log.Info("Set Debug mode")
6770
log.SetLevel(log.DebugLevel)
6871
}
72+
stdlog.SetOutput(new(LogrusWriter))
6973
shouldPrintVersionNoDashes, _ := arguments.Bool("version")
7074
shouldPrintVersion, _ := arguments.Bool("--version")
7175
if shouldPrintVersionNoDashes || shouldPrintVersion {
@@ -84,6 +88,7 @@ The commands work as following:
8488
if err != nil {
8589
printErrJSON(err, "no device found to use")
8690
}
91+
checkDeviceIsPaired(device)
8792

8893
activateCommand, _ := arguments.Bool("activate")
8994
if activateCommand {
@@ -416,6 +421,20 @@ func waitForSigInt(stopSignalChannel chan interface{}) {
416421
}()
417422
}
418423

424+
func checkDeviceIsPaired(device screencapture.IosDevice) {
425+
dev, err := ios.GetDevice(screencapture.Correct24CharacterSerial(device.SerialNumber))
426+
if err != nil {
427+
printErrJSON(err, "device not found, is it still connected?")
428+
os.Exit(1)
429+
}
430+
allValues, err := ios.GetValuesPlist(dev)
431+
if err != nil {
432+
printErrJSON(err, "failed getting deviceinfo, you need to pair the device before running qvh")
433+
os.Exit(1)
434+
}
435+
log.Infof("found %s %s for udid %s", allValues["DeviceName"], allValues["ProductVersion"], dev.Properties.SerialNumber)
436+
}
437+
419438
func printErrJSON(err error, msg string) {
420439
printJSON(map[string]interface{}{
421440
"original_error": err.Error(),
@@ -429,3 +448,18 @@ func printJSON(output map[string]interface{}) {
429448
}
430449
println(string(text))
431450
}
451+
452+
//this is to ban these irritating "2021/04/29 14:27:59 handle_events: error: libusb: interrupted [code -10]" libusb messages
453+
type LogrusWriter int
454+
455+
const interruptedError = "interrupted [code -10]"
456+
457+
func (LogrusWriter) Write(data []byte) (int, error) {
458+
logmessage := string(data)
459+
if strings.Contains(logmessage, interruptedError) {
460+
log.Tracef("gousb_logs:%s", logmessage)
461+
return len(data), nil
462+
}
463+
log.Infof("gousb_logs:%s", logmessage)
464+
return len(data), nil
465+
}

screencapture/discovery.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (d *IosDevice) DetailsMap() map[string]interface{} {
229229
return map[string]interface{}{
230230
"deviceName": d.ProductName,
231231
"usb_device_info": d.UsbInfo,
232-
"udid": correct24CharacterSerial(d.SerialNumber),
232+
"udid": Correct24CharacterSerial(d.SerialNumber),
233233
"screen_mirroring_enabled": d.IsActivated(),
234234
}
235235
}
@@ -238,7 +238,7 @@ func (d *IosDevice) DetailsMap() map[string]interface{} {
238238
//There is an exception, some devices like the Xr and Xs have a 24 character USB serial. Usbmux, Xcode etc.
239239
//however insert a dash after the 8th character in this case. To be compatible with other MacOS X and iOS tools,
240240
//we insert the dash here as well.
241-
func correct24CharacterSerial(usbSerial string) string {
241+
func Correct24CharacterSerial(usbSerial string) string {
242242
usbSerial = strings.Trim(usbSerial, "\x00")
243243
if len(usbSerial) == 24 {
244244
return fmt.Sprintf("%s-%s", usbSerial[0:8], usbSerial[8:])

screencapture/messageprocessor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewMessageProcessorWithClockBuilder(usbWriter UsbWriter, stopSignal chan in
5959
func (mp *MessageProcessor) ReceiveData(data []byte) {
6060
switch binary.LittleEndian.Uint32(data) {
6161
case packet.PingPacketMagic:
62-
log.Info("AudioVideo-Stream has started")
62+
log.Info("PING received")
6363
mp.usbWriter.WriteDataToUsb(packet.NewPingPacketAsBytes())
6464
return
6565
case packet.SyncPacketMagic:

0 commit comments

Comments
 (0)