Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ $ curl -XPUT 10.0.0.1:7912/minicap
$ curl -XPUT 10.0.0.1:7912/minitouch
```

## 修改 minicap 虚拟分辨率

可以指定 max 参数修改虚拟屏幕最大像素,未指定时在 800 和 1280 间切换;q 参数可以指定质量

```bash
# no parameter
$ curl -XPUT 10.0.0.1:7912/info/revise

# add parameter
$ curl -XPUT 10.0.0.1:7912/info/revise?max=720&q=80
```

## 视频录制(不推荐用)
开始录制

Expand Down
68 changes: 68 additions & 0 deletions httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,74 @@ func (server *Server) initHTTPServer() {
// fmt.Fprintf(w, "rotation change to %d", deviceRotation)
})

m.HandleFunc("/info/revise", func(w http.ResponseWriter, r *http.Request) {
apkServiceTimer.Reset(apkServiceTimeout)
max := r.URL.Query().Get("max")
q := r.URL.Query().Get("q")
if max == "" {
if displayMaxWidthHeight == 800 {
displayMaxWidthHeight = 1280
} else {
displayMaxWidthHeight = 800
}
} else {
maxWidthHeight, err := strconv.Atoi(max)
if err == nil && maxWidthHeight > 0 {
displayMaxWidthHeight = maxWidthHeight
} else {
renderJSON(w, map[string]string{
"maxWidthHeight": "maxWidthHeight error",
})
return
}
}
if q != "" {
qua, err := strconv.Atoi(q)
if err == nil {
if qua >= 0 && qua <= 100 {
quality = qua
} else {
quality = 80
}
} else {
renderJSON(w, map[string]string{
"quality": "quality error",
})
return
}
}
// copy form codeskyblue
// Kill not controled minicap
killed := false
procWalk(func(proc procfs.Proc) {
executable, _ := proc.Executable()
if filepath.Base(executable) != "minicap" {
return
}
stat, err := proc.NewStat()
if err != nil || stat.PPID != 1 { // only not controled minicap need killed
return
}
if p, err := os.FindProcess(proc.PID); err == nil {
log.Println("Kill", executable)
p.Kill()
killed = true
}
})
if killed {
service.Start("minicap")
}
updateMinicapRotation(deviceRotation)

// APK Service will send rotation to atx-agent when rotation changes
runShellTimeout(5*time.Second, "am", "startservice", "--user", "0", "-n", "com.github.uiautomator/.Service")
renderJSON(w, map[string]int{
"maxWidthHeight": displayMaxWidthHeight,
"quality": quality,
})
// fmt.Fprintf(w, "rotation change to %d", deviceRotation)
})

/*
# URLRules:
# URLPath ends with / means directory, eg: $DEVICE_URL/upload/sdcard/
Expand Down
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,23 @@ type MinicapInfo struct {
var (
deviceRotation int
displayMaxWidthHeight = 800
quality = 80
)

func updateMinicapRotation(rotation int) {
devInfo := getDeviceInfo()
width, height := devInfo.Display.Width, devInfo.Display.Height
if width >= height {
if displayMaxWidthHeight > width {
displayMaxWidthHeight = 800
}
} else {
if displayMaxWidthHeight > height {
displayMaxWidthHeight = 800
}
}
service.UpdateArgs("minicap", "/data/local/tmp/minicap", "-S", "-P",
fmt.Sprintf("%dx%d@%dx%d/%d", width, height, displayMaxWidthHeight, displayMaxWidthHeight, rotation))
fmt.Sprintf("%dx%d@%dx%d/%d", width, height, displayMaxWidthHeight, displayMaxWidthHeight, rotation), "-Q", strconv.Itoa(quality))
}

func checkUiautomatorInstalled() (ok bool) {
Expand Down Expand Up @@ -222,6 +232,7 @@ func Screenshot(filename string, thumbnailSize string) (err error) {
"LD_LIBRARY_PATH=/data/local/tmp",
"/data/local/tmp/minicap",
"-P", fmt.Sprintf("%dx%d@%s/%d", f.Width, f.Height, thumbnailSize, f.Rotation),
"-Q", "100",
"-s", ">"+filename); err != nil {
return
}
Expand Down Expand Up @@ -540,7 +551,7 @@ func main() {
service.Add("minicap", cmdctrl.CommandInfo{
Environ: []string{"LD_LIBRARY_PATH=/data/local/tmp"},
Args: []string{"/data/local/tmp/minicap", "-S", "-P",
fmt.Sprintf("%dx%d@%dx%d/0", width, height, displayMaxWidthHeight, displayMaxWidthHeight)},
fmt.Sprintf("%dx%d@%dx%d/0", width, height, displayMaxWidthHeight, displayMaxWidthHeight), "-Q", strconv.Itoa(quality)},
})
service.Add("minitouch", cmdctrl.CommandInfo{
Args: []string{"/data/local/tmp/minitouch"},
Expand Down