Skip to content

Commit d27a07d

Browse files
ronevenRon Evendanielpaulus
authored
Added a QVH deactivation command that can be used in case device is not recognized by usbmuxd after recording (#87)
Co-authored-by: Ron Even <[email protected]> Co-authored-by: danielpaulus <[email protected]>
1 parent e7aa39c commit d27a07d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func main() {
2727
Usage:
2828
qvh devices [-v]
2929
qvh activate [--udid=<udid>] [-v]
30+
qvh deactivate [--udid=<udid>] [-v]
3031
qvh record <h264file> <wavfile> [--udid=<udid>] [-v]
3132
qvh audio <outfile> (--mp3 | --ogg | --wav) [--udid=<udid>] [-v]
3233
qvh gstreamer [--pipeline=<pipeline>] [--examples] [--udid=<udid>] [-v]
@@ -45,6 +46,8 @@ The commands work as following:
4546
4647
activate enables the video streaming config for the device specified by --udid
4748
49+
deactivate disables the video streaming config for the device specified by --udid (in case it is stuck on streaming config)
50+
4851
record will start video&audio recording. Video will be saved in a raw h264 file playable by VLC.
4952
Audio will be saved in a uncompressed wav file. Run like: "qvh record /home/yourname/out.h264 /home/yourname/out.wav"
5053
@@ -95,6 +98,13 @@ The commands work as following:
9598
activate(device)
9699
return
97100
}
101+
102+
deactivateCommand, _ := arguments.Bool("deactivate")
103+
if deactivateCommand {
104+
deactivate(device)
105+
return
106+
}
107+
98108
audioCommand, _ := arguments.Bool("audio")
99109
if audioCommand {
100110
outfile, err := arguments.String("<outfile>")
@@ -318,6 +328,20 @@ func activate(device screencapture.IosDevice) {
318328
})
319329
}
320330

331+
func deactivate(device screencapture.IosDevice) {
332+
log.Debugf("Disabling device: %v", device)
333+
var err error
334+
device, err = screencapture.DisableQTConfig(device)
335+
if err != nil {
336+
printErrJSON(err, "Error disabling QT config")
337+
return
338+
}
339+
340+
printJSON(map[string]interface{}{
341+
"device_activated": device.DetailsMap(),
342+
})
343+
}
344+
321345
func record(h264FilePath string, wavFilePath string, device screencapture.IosDevice) {
322346
log.Debugf("Writing video output to:'%s' and audio to: %s", h264FilePath, wavFilePath)
323347

screencapture/activator.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,37 @@ func EnableQTConfig(device IosDevice) (IosDevice, error) {
5353
return device, err
5454
}
5555

56+
func DisableQTConfig(device IosDevice) (IosDevice, error) {
57+
usbSerial := device.SerialNumber
58+
ctx := gousb.NewContext()
59+
usbDevice, err := OpenDevice(ctx, device)
60+
if err != nil {
61+
return IosDevice{}, err
62+
}
63+
if !isValidIosDeviceWithActiveQTConfig(usbDevice.Desc) {
64+
log.Debugf("Skipping %s because it is already deactivated", usbSerial)
65+
return device, nil
66+
}
67+
68+
confignum, _ := usbDevice.ActiveConfigNum()
69+
log.Debugf("Config is active: %d, QT config is: %d", confignum, device.QTConfigIndex)
70+
71+
for i := 0; i < 20; i++{
72+
sendQTDisableConfigControlRequest(usbDevice)
73+
log.Debugf("Resetting device config (#%d)", i + 1)
74+
_, err := usbDevice.Config(device.UsbMuxConfigIndex)
75+
if err != nil {
76+
log.Warn(err)
77+
}
78+
}
79+
80+
confignum, _ = usbDevice.ActiveConfigNum()
81+
log.Debugf("Config is active: %d, QT config is: %d", confignum, device.QTConfigIndex)
82+
83+
84+
return device, err
85+
}
86+
5687
func sendQTConfigControlRequest(device *gousb.Device) {
5788
response := make([]byte, 0)
5889
val, err := device.Control(0x40, 0x52, 0x00, 0x02, response)

0 commit comments

Comments
 (0)