Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/danielpaulus/go-ios v1.0.13
github.com/danielpaulus/gst v0.0.0-20200201205042-e6d2974fceb8
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/google/gousb v2.1.0+incompatible
github.com/google/gousb v1.1.0
github.com/lijo-jose/glib v0.0.0-20191012030101-93ee72d7d646
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/google/gousb v1.1.0 h1:s/970WE1z968MC+dtWbuxDHCcx9kwANQo6UcZtfTfx0=
github.com/google/gousb v1.1.0/go.mod h1:Tl4HdAs1ThE3gECkNwz+1MWicX6FXddhJEw7L8jRDiI=
github.com/google/gousb v2.1.0+incompatible h1:ApzMDjF3FeO219QwWybJxYfFhXQzPLOEy0o+w9k5DNI=
github.com/google/gousb v2.1.0+incompatible/go.mod h1:Tl4HdAs1ThE3gECkNwz+1MWicX6FXddhJEw7L8jRDiI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
Expand Down
115 changes: 15 additions & 100 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package main

import (
"bufio"
"encoding/json"
"fmt"
stdlog "log"
"os"
"os/signal"
"strings"
"time"

Expand All @@ -27,11 +25,12 @@ func main() {
Usage:
qvh devices [-v]
qvh activate [--udid=<udid>] [-v]
qvh record <h264file> <wavfile> [--udid=<udid>] [-v]
qvh record [--udid=<udid>] [-v]
qvh audio <outfile> (--mp3 | --ogg | --wav) [--udid=<udid>] [-v]
qvh gstreamer [--pipeline=<pipeline>] [--examples] [--udid=<udid>] [-v]
qvh diagnostics <outfile> [--dump=<dumpfile>] [--udid=<udid>]
qvh --version | version
qvh test


Options:
Expand Down Expand Up @@ -88,13 +87,14 @@ The commands work as following:
if err != nil {
printErrJSON(err, "no device found to use")
}
checkDeviceIsPaired(device)
//checkDeviceIsPaired(device)

activateCommand, _ := arguments.Bool("activate")
if activateCommand {
activate(device)
return
}

audioCommand, _ := arguments.Bool("audio")
if audioCommand {
outfile, err := arguments.String("<outfile>")
Expand Down Expand Up @@ -143,17 +143,8 @@ The commands work as following:

recordCommand, _ := arguments.Bool("record")
if recordCommand {
h264FilePath, err := arguments.String("<h264file>")
if err != nil {
printErrJSON(err, "Missing <h264file> parameter. Please specify a valid path like '/home/me/out.h264'")
return
}
waveFilePath, err := arguments.String("<wavfile>")
if err != nil {
printErrJSON(err, "Missing <wavfile> parameter. Please specify a valid path like '/home/me/out.raw'")
return
}
record(h264FilePath, waveFilePath, device)

record("", "", device)
}
gstreamerCommand, _ := arguments.Bool("gstreamer")
if gstreamerCommand {
Expand Down Expand Up @@ -226,7 +217,7 @@ func recordAudioGst(outfile string, device screencapture.IosDevice, audiotype st
printErrJSON(err, "Failed creating custom pipeline")
return
}
startWithConsumer(gStreamer, device, true)
screencapture.StartWithConsumer(gStreamer, device, true)
}

func runDiagnostics(outfile string, dump bool, dumpFile string, device screencapture.IosDevice) {
Expand All @@ -238,10 +229,10 @@ func runDiagnostics(outfile string, dump bool, dumpFile string, device screencap
defer metricsFile.Close()
consumer := diagnostics.NewDiagnosticsConsumer(metricsFile, time.Second*10)
if dump {
startWithConsumerDump(consumer, device, dumpFile)
screencapture.StartWithConsumerDump(consumer, device, dumpFile)
return
}
startWithConsumer(consumer, device, false)
screencapture.StartWithConsumer(consumer, device, false)
}

func recordAudioWav(outfile string, device screencapture.IosDevice) {
Expand All @@ -268,7 +259,7 @@ func recordAudioWav(outfile string, device screencapture.IosDevice) {
}

}()
startWithConsumer(wavFileWriter, device, true)
screencapture.StartWithConsumer(wavFileWriter, device, true)
}

func startGStreamerWithCustomPipeline(device screencapture.IosDevice, pipelineString string) {
Expand All @@ -278,13 +269,13 @@ func startGStreamerWithCustomPipeline(device screencapture.IosDevice, pipelineSt
printErrJSON(err, "Failed creating custom pipeline")
return
}
startWithConsumer(gStreamer, device, false)
screencapture.StartWithConsumer(gStreamer, device, false)
}

func startGStreamer(device screencapture.IosDevice) {
log.Debug("Starting Gstreamer")
gStreamer := gstadapter.New()
startWithConsumer(gStreamer, device, false)
screencapture.StartWithConsumer(gStreamer, device, false)
}

// Just dump a list of what was discovered to the console
Expand Down Expand Up @@ -321,19 +312,8 @@ func activate(device screencapture.IosDevice) {
func record(h264FilePath string, wavFilePath string, device screencapture.IosDevice) {
log.Debugf("Writing video output to:'%s' and audio to: %s", h264FilePath, wavFilePath)

h264File, err := os.Create(h264FilePath)
if err != nil {
log.Debugf("Error creating h264File:%s", err)
log.Errorf("Could not open h264File '%s'", h264FilePath)
}
wavFile, err := os.Create(wavFilePath)
if err != nil {
log.Debugf("Error creating wav file:%s", err)
log.Errorf("Could not open wav file '%s'", wavFilePath)
}

writer := coremedia.NewAVFileWriter(bufio.NewWriter(h264File), bufio.NewWriter(wavFile))

/*
defer func() {
stat, err := wavFile.Stat()
if err != nil {
Expand All @@ -352,73 +332,8 @@ func record(h264FilePath string, wavFilePath string, device screencapture.IosDev
log.Fatalf("Error closing h264File '%s'. %s", h264FilePath, err.Error())
}

}()
startWithConsumer(writer, device, false)
}

func startWithConsumer(consumer screencapture.CmSampleBufConsumer, device screencapture.IosDevice, audioOnly bool) {
var err error
device, err = screencapture.EnableQTConfig(device)
if err != nil {
printErrJSON(err, "Error enabling QT config")
return
}

adapter := screencapture.UsbAdapter{}
stopSignal := make(chan interface{})
waitForSigInt(stopSignal)

mp := screencapture.NewMessageProcessor(&adapter, stopSignal, consumer, audioOnly)

err = adapter.StartReading(device, &mp, stopSignal)
consumer.Stop()
if err != nil {
printErrJSON(err, "failed connecting to usb")
}
}

func startWithConsumerDump(consumer screencapture.CmSampleBufConsumer, device screencapture.IosDevice, dumpPath string) {
var err error
device, err = screencapture.EnableQTConfig(device)
if err != nil {
printErrJSON(err, "Error enabling QT config")
return
}

inboundMessagesFile, err := os.Create("inbound-" + dumpPath)
if err != nil {
log.Fatalf("Could not open file: %v", err)
}
defer inboundMessagesFile.Close()
outboundMessagesFile, err := os.Create("outbound-" + dumpPath)
if err != nil {
log.Fatalf("Could not open file: %v", err)
}
defer outboundMessagesFile.Close()
log.Debug("Start dumping all binary transfer")
adapter := screencapture.UsbAdapter{Dump: true, DumpInWriter: inboundMessagesFile, DumpOutWriter: outboundMessagesFile}
stopSignal := make(chan interface{})
waitForSigInt(stopSignal)

mp := screencapture.NewMessageProcessor(&adapter, stopSignal, consumer, false)

err = adapter.StartReading(device, &mp, stopSignal)
consumer.Stop()
if err != nil {
printErrJSON(err, "failed connecting to usb")
}
}

func waitForSigInt(stopSignalChannel chan interface{}) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
log.Debugf("Signal received: %s", sig)
var stopSignal interface{}
stopSignalChannel <- stopSignal
}
}()
}()*/
screencapture.StartWithConsumer(nil, device, false)
}

func checkDeviceIsPaired(device screencapture.IosDevice) {
Expand Down
12 changes: 7 additions & 5 deletions screencapture/gstadapter/gst_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package gstadapter
import (
"encoding/binary"
"fmt"
"os"
"runtime"

"github.com/danielpaulus/gst"
"github.com/danielpaulus/quicktime_video_hack/screencapture/coremedia"
"github.com/lijo-jose/glib"
log "github.com/sirupsen/logrus"
"os"
"runtime"
)

//GstAdapter contains the AppSrc for accessing Gstreamer.
Expand All @@ -36,11 +35,12 @@ func New() *GstAdapter {
audioAppSrc := setUpAudioPipelineBase(pl)
setupLivePlayAudio(pl)

pl.SetState(gst.STATE_PLAYING)
runGlibMainLoop()
pl.SetState(gst.STATE_PLAYING)


log.Info("Gstreamer is running!")
gsta := GstAdapter{videoAppSrc: videoAppSrc, audioAppSrc: audioAppSrc, firstAudioSample: true}
gsta := GstAdapter{videoAppSrc: videoAppSrc, audioAppSrc: audioAppSrc, firstAudioSample: true, pipeline: pl}

return &gsta
}
Expand Down Expand Up @@ -220,6 +220,8 @@ func checkElem(e *gst.Element, name string) {

//Consume will transfer AV data into a Gstreamer AppSrc
func (gsta *GstAdapter) Consume(buf coremedia.CMSampleBuffer) error {
s, _, _:=gsta.pipeline.GetState(200)
log.Info(s.String())
if buf.MediaType == coremedia.MediaTypeSound {
if gsta.firstAudioSample {
gsta.firstAudioSample = false
Expand Down
6 changes: 6 additions & 0 deletions screencapture/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ type UsbDataReceiver interface {
type UsbWriter interface {
WriteDataToUsb(data []byte)
}

//UsbWriter can be used to send data to a USB Endpoint
type UsbWriterNew interface {
WriteDataToUsb(data []byte) error
ReadFrame() ([]byte, error)
}
2 changes: 1 addition & 1 deletion screencapture/messageprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (mp *MessageProcessor) handleSyncPacket(data []byte) {
}
log.Debugf("Rcv:%s", ogPacket.String())

replyBytes := ogPacket.NewReply()
replyBytes := ogPacket.NewReply(0)
log.Debugf("Send OG-REPLY {correlation:%x}", ogPacket.CorrelationID)
mp.usbWriter.WriteDataToUsb(replyBytes)
case packet.CWPA:
Expand Down
6 changes: 3 additions & 3 deletions screencapture/messageprocessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func TestMessageProcessorRespondsCorrectlyToSyncMessages(t *testing.T) {
description: "Expect correct reply for cwpa",
},
{
receivedData: loadFromFile("og-request")[4:],
expectedReply: [][]byte{loadFromFile("og-reply")},
description: "Expect correct reply for og",
receivedData: loadFromFile("gocmd-request")[4:],
expectedReply: [][]byte{loadFromFile("gocmd-reply")},
description: "Expect correct reply for gocmd",
},
{
receivedData: loadFromFile("stop-request")[4:],
Expand Down
4 changes: 2 additions & 2 deletions screencapture/packet/sync_og.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func NewSyncOgPacketFromBytes(data []byte) (SyncOgPacket, error) {
}

//NewReply returns a []byte containing the default reply for a SyncOgPacket
func (sp SyncOgPacket) NewReply() []byte {
func (sp SyncOgPacket) NewReply(response uint64) []byte {
responseBytes := make([]byte, 24)
binary.LittleEndian.PutUint32(responseBytes, 24)
binary.LittleEndian.PutUint32(responseBytes[4:], ReplyPacketMagic)
binary.LittleEndian.PutUint64(responseBytes[8:], sp.CorrelationID)
binary.LittleEndian.PutUint64(responseBytes[16:], 0)
binary.LittleEndian.PutUint64(responseBytes[16:], response)

return responseBytes

Expand Down
Loading