Skip to content

Commit fad26ea

Browse files
danielPaulusMesmerdanielpaulus
danielPaulusMesmer
andauthored
Fix#51 (#60)
* add pipeline nil check to linux adapter * log more detailed errors * clean up adapter * fix string format booleans Co-authored-by: Daniel Paulus <[email protected]>
1 parent c2b77dd commit fad26ea

File tree

5 files changed

+46
-200
lines changed

5 files changed

+46
-200
lines changed

screencapture/discovery.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,21 @@ func isMuxConfig(confDesc gousb.ConfigDesc) bool {
205205
}
206206

207207
func findInterfaceForSubclass(confDesc gousb.ConfigDesc, subClass gousb.Class) (bool, int) {
208-
for i := range confDesc.Interfaces {
208+
for _, iface := range confDesc.Interfaces {
209209
//usually the interfaces we care about have only one altsetting
210-
isVendorClass := confDesc.Interfaces[i].AltSettings[0].Class == gousb.ClassVendorSpec
211-
isCorrectSubClass := confDesc.Interfaces[i].AltSettings[0].SubClass == subClass
210+
211+
for _, alt := range iface.AltSettings {
212+
isVendorClass := alt.Class == gousb.ClassVendorSpec
213+
isCorrectSubClass := alt.SubClass == subClass
214+
log.Debugf("found: %t", isCorrectSubClass && isVendorClass)
215+
216+
}
217+
isVendorClass := iface.AltSettings[0].Class == gousb.ClassVendorSpec
218+
isCorrectSubClass := iface.AltSettings[0].SubClass == subClass
219+
220+
log.Debugf("iface:%v altsettings:%d isvendor:%t isub:%t", iface, len(iface.AltSettings), isVendorClass, isCorrectSubClass)
212221
if isVendorClass && isCorrectSubClass {
213-
return true, confDesc.Interfaces[i].Number
222+
return true, iface.Number
214223
}
215224
}
216225
return false, -1

screencapture/frameextractor.go

-86
This file was deleted.

screencapture/frameextractor_test.go

-96
This file was deleted.

screencapture/gstadapter/gst_adapter_linux.go

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func (gsta GstAdapter) Stop() {
9898
log.Warn("Failed sending EOS signal for video app source")
9999
}
100100

101+
if gsta.pipeline == nil {
102+
return
103+
}
101104
bus := gsta.pipeline.GetBus()
102105

103106
//I hope those are 60 seconds

screencapture/usbadapter.go

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package screencapture
22

33
import (
4+
"encoding/binary"
45
"errors"
6+
"fmt"
7+
"io"
58

69
"github.com/google/gousb"
710
log "github.com/sirupsen/logrus"
@@ -35,15 +38,13 @@ func (usa *UsbAdapter) StartReading(device IosDevice, receiver UsbDataReceiver,
3538
}
3639
confignum, _ := usbDevice.ActiveConfigNum()
3740

38-
log.Debugf("Config is active: %d", confignum)
41+
log.Debugf("Config is active: %d, QT config is: %d", confignum, device.QTConfigIndex)
3942

40-
config, err := usbDevice.Config(confignum)
43+
config, err := usbDevice.Config(device.QTConfigIndex)
4144
if err != nil {
4245
return errors.New("Could not retrieve config")
4346
}
4447

45-
sendQTConfigControlRequest(usbDevice)
46-
4748
log.Debugf("QT Config is active: %s", config.String())
4849

4950
val, err := usbDevice.Control(0x02, 0x01, 0, 0x86, make([]byte, 0))
@@ -94,22 +95,27 @@ func (usa *UsbAdapter) StartReading(device IosDevice, receiver UsbDataReceiver,
9495
return err
9596
}
9697
log.Debug("Endpoint claimed")
97-
log.Infof("Device '%s' USB connection ready", device.SerialNumber)
98+
log.Infof("Device '%s' USB connection ready, waiting for ping..", device.SerialNumber)
9899
go func() {
99-
100-
frameExtractor := NewLengthFieldBasedFrameExtractor()
101100
for {
102-
buffer := make([]byte, 65536)
101+
buffer := make([]byte, 4)
103102

104-
n, err := stream.Read(buffer)
103+
n, err := io.ReadFull(stream, buffer)
105104
if err != nil {
106-
log.Error("couldn't read bytes", err)
105+
log.Errorf("Failed reading 4bytes length with err:%s only received: %d", err, n)
107106
return
108107
}
109-
frame, isCompleteFrame := frameExtractor.ExtractFrame(buffer[:n])
110-
if isCompleteFrame {
111-
receiver.ReceiveData(frame)
108+
//the 4 bytes header are included in the length, so we need to subtract them
109+
//here to know how long the payload will be
110+
length := binary.LittleEndian.Uint32(buffer) - 4
111+
dataBuffer := make([]byte, length)
112+
113+
n, err = io.ReadFull(stream, dataBuffer)
114+
if err != nil {
115+
log.Errorf("Failed reading payload with err:%s only received: %d/%d bytes", err, n, length)
116+
return
112117
}
118+
receiver.ReceiveData(dataBuffer)
113119
}
114120
}()
115121

@@ -125,6 +131,11 @@ func (usa *UsbAdapter) StartReading(device IosDevice, receiver UsbDataReceiver,
125131
iface.Close()
126132

127133
sendQTDisableConfigControlRequest(usbDevice)
134+
log.Debug("Resetting device config")
135+
_, err = usbDevice.Config(device.UsbMuxConfigIndex)
136+
if err != nil {
137+
log.Warn(err)
138+
}
128139

129140
return nil
130141
}
@@ -148,6 +159,11 @@ func grabInBulk(setting gousb.InterfaceSetting) (int, error) {
148159
}
149160

150161
func grabQuickTimeInterface(config *gousb.Config) (*gousb.Interface, error) {
151-
_, ifaceIndex := findInterfaceForSubclass(config.Desc, QuicktimeSubclass)
162+
log.Debug("Looking for quicktime interface..")
163+
found, ifaceIndex := findInterfaceForSubclass(config.Desc, QuicktimeSubclass)
164+
if !found {
165+
return nil, fmt.Errorf("did not find interface %v", config)
166+
}
167+
log.Debugf("Found Quicktimeinterface: %d", ifaceIndex)
152168
return config.Interface(ifaceIndex, 0)
153169
}

0 commit comments

Comments
 (0)