-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix blocking sync callbacks for qtbox + new 3rdparty/mpv example
- Loading branch information
Showing
7 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//source: https://github.com/mpv-player/mpv-examples/tree/master/libmpv/qml | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/therecipe/qt/core" | ||
"github.com/therecipe/qt/gui" | ||
"github.com/therecipe/qt/quick" | ||
|
||
"github.com/therecipe/qt/internal/examples/3rdparty/mpv" | ||
) | ||
|
||
func main() { | ||
gui.NewQGuiApplication(len(os.Args), os.Args) | ||
|
||
mpv.InitMpv() | ||
|
||
view := quick.NewQQuickView(nil) | ||
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView) | ||
view.SetSource(core.NewQUrl3("qrc:/qml/main.qml", 0)) //qrc:/mpvtest/main.qml should work as well, since init.go is not patching out the embedding | ||
view.Show() | ||
|
||
gui.QGuiApplication_Exec() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import QtQuick 2.0 | ||
import QtQuick.Controls 1.0 | ||
|
||
import mpvtest 1.0 | ||
|
||
Item { | ||
width: 1280 | ||
height: 720 | ||
|
||
MpvObject { | ||
id: renderer | ||
anchors.fill: parent | ||
|
||
MouseArea { | ||
anchors.fill: parent | ||
onClicked: renderer.command(["loadfile", "test.mkv"]) | ||
} | ||
} | ||
|
||
Rectangle { | ||
id: labelFrame | ||
anchors.margins: -50 | ||
radius: 5 | ||
color: "white" | ||
border.color: "black" | ||
opacity: 0.8 | ||
anchors.fill: box | ||
} | ||
|
||
Row { | ||
id: box | ||
anchors.bottom: renderer.bottom | ||
anchors.left: renderer.left | ||
anchors.right: renderer.right | ||
anchors.margins: 100 | ||
|
||
Text { | ||
anchors.margins: 10 | ||
wrapMode: Text.WordWrap | ||
text: "QtQuick and mpv are both rendering stuff.\n | ||
Click to load test.mkv" | ||
} | ||
|
||
// Don't take these controls too seriously. They're for testing. | ||
Column { | ||
CheckBox { | ||
id: checkbox | ||
anchors.margins: 10 | ||
// Heavily filtered means good, right? | ||
text: "Make video look like on a Smart TV" | ||
onClicked: { | ||
if (checkbox.checked) { | ||
renderer.setProperty("sharpen", 5.0) | ||
} else { | ||
renderer.setProperty("sharpen", 0) | ||
} | ||
} | ||
} | ||
Slider { | ||
id: slider | ||
anchors.margins: 10 | ||
anchors.left: checkbox.left | ||
anchors.right: checkbox.right | ||
minimumValue: -100 | ||
maximumValue: 100 | ||
value: 0 | ||
onValueChanged: renderer.setProperty("gamma", slider.value | 0) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strconv" | ||
) | ||
|
||
func main() { | ||
if _, ok := os.LookupEnv("QT_PKG_CONFIG"); !ok { | ||
println("please export QT_PKG_CONFIG") | ||
os.Exit(1) | ||
} | ||
|
||
pwd, pwdErr := os.Getwd() | ||
if pwdErr != nil { | ||
println("failed to get PWD", pwdErr.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
if _, err := os.Stat("mpv-examples"); err == nil { | ||
println("mpv-examples already cloned") | ||
} else { | ||
if out, err := exec.Command("git", "clone", "--depth=1", "https://github.com/mpv-player/mpv-examples.git").CombinedOutput(); err != nil { | ||
println("failed to clone mpv-examples", err.Error()) | ||
println(string(out)) | ||
os.Exit(1) | ||
} | ||
println("cloned mpv-examples") | ||
} | ||
|
||
//patch *.pro to build a static lib | ||
exec.Command("bash", "-c", fmt.Sprintf("echo \"TEMPLATE = lib\" >> %v", filepath.Join(pwd, "mpv-examples", "libmpv", "qml", "mpvtest.pro"))).CombinedOutput() | ||
exec.Command("bash", "-c", fmt.Sprintf("echo \"CONFIG += staticlib\" >> %v", filepath.Join(pwd, "mpv-examples", "libmpv", "qml", "mpvtest.pro"))).CombinedOutput() | ||
|
||
//patch main.cpp | ||
exec.Command("bash", "-c", fmt.Sprintf("head -n -17 %[1]v > %[2]v && mv %[2]v %[1]v", filepath.Join(pwd, "mpv-examples", "libmpv", "qml", "main.cpp"), filepath.Join(pwd, "mpv-examples", "libmpv", "qml", "copy_main.cpp"))).CombinedOutput() | ||
exec.Command("bash", "-c", fmt.Sprintf("echo 'extern \"C\" void initMpv() { std::setlocale(LC_NUMERIC, \"C\"); qmlRegisterType<MpvObject>(\"mpvtest\", 1, 0, \"MpvObject\"); }' >> %[1]v", filepath.Join(pwd, "mpv-examples", "libmpv", "qml", "main.cpp"))).CombinedOutput() | ||
|
||
//only tested on arch, since the libmpv version is quite old on ubuntu 16.04 and 18.04 | ||
for _, target := range []string{runtime.GOOS} { | ||
|
||
qCmd := exec.Command("qmake", "mpvtest.pro") | ||
qCmd.Dir = filepath.Join(pwd, "mpv-examples", "libmpv", "qml") | ||
if out, err := qCmd.CombinedOutput(); err != nil { | ||
println("failed to generate makefile for", target, err.Error()) | ||
println(string(out)) | ||
os.Exit(1) | ||
} | ||
println("generated makefile for", target) | ||
|
||
iCmd := exec.Command("make", "-j", strconv.Itoa(runtime.NumCPU())) | ||
iCmd.Dir = filepath.Join(pwd, "mpv-examples", "libmpv", "qml") | ||
if out, err := iCmd.CombinedOutput(); err != nil { | ||
println("failed to make mpv-examples for", target) | ||
println(string(out)) | ||
os.Exit(1) | ||
} | ||
println("built mpv-examples for", target) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package mpv | ||
|
||
/* | ||
#cgo pkg-config: mpv | ||
#cgo linux,amd64 LDFLAGS: -L ${SRCDIR}/mpv-examples/libmpv/qml -lmpvtest | ||
void initMpv(); | ||
*/ | ||
import "C" | ||
import ( | ||
"github.com/therecipe/qt/core" | ||
_ "github.com/therecipe/qt/quick" | ||
) | ||
|
||
type stub struct{ core.QObject } //TODO: needed for linking at the moment | ||
|
||
func InitMpv() { | ||
C.initMpv() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters