debug needed
This commit is contained in:
parent
4c80f8a25e
commit
bd0812cc42
@ -73,6 +73,7 @@ func (w *WavFIFODriver) Properties() []prop.Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *WavFIFODriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
func (w *WavFIFODriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
||||||
|
logrus.Debugf("wave header: %v", w.waveHeader)
|
||||||
offset := FmtHeaderOffset + FmtHeaderIDSize + FmtHeaderChunkSizeSize + int64(w.waveHeader.Size) + DataChunkIDSize + DataChunkSizeSize
|
offset := FmtHeaderOffset + FmtHeaderIDSize + FmtHeaderChunkSizeSize + int64(w.waveHeader.Size) + DataChunkIDSize + DataChunkSizeSize
|
||||||
if _, err := w.f.Seek(
|
if _, err := w.f.Seek(
|
||||||
offset,
|
offset,
|
||||||
@ -105,6 +106,7 @@ func (w *WavFIFODriver) AudioRecord(p prop.Media) (audio.Reader, error) {
|
|||||||
case <-w.closed:
|
case <-w.closed:
|
||||||
return nil, func() {}, io.EOF
|
return nil, func() {}, io.EOF
|
||||||
case pcmData, ok := <-pcm:
|
case pcmData, ok := <-pcm:
|
||||||
|
logrus.Debug("got %d bytes pcm data", len(pcmData))
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, func() {}, io.ErrClosedPipe
|
return nil, func() {}, io.ErrClosedPipe
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"github.com/pion/mediadevices"
|
"github.com/pion/mediadevices"
|
||||||
"github.com/pion/mediadevices/pkg/codec/opus"
|
"github.com/pion/mediadevices/pkg/codec/opus"
|
||||||
"github.com/pion/mediadevices/pkg/codec/x264"
|
"github.com/pion/mediadevices/pkg/codec/x264"
|
||||||
"github.com/pion/mediadevices/pkg/prop"
|
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -56,8 +55,10 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
|
|||||||
|
|
||||||
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
|
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
|
||||||
Video: func(mtc *mediadevices.MediaTrackConstraints) {
|
Video: func(mtc *mediadevices.MediaTrackConstraints) {
|
||||||
mtc.Height = prop.IntExact(c.option.Video.Height)
|
/*
|
||||||
mtc.Width = prop.IntExact(c.option.Video.Width)
|
mtc.Height = prop.IntExact(c.option.Video.Height)
|
||||||
|
mtc.Width = prop.IntExact(c.option.Video.Width)
|
||||||
|
*/
|
||||||
},
|
},
|
||||||
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
|
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
|
||||||
Codec: codecSelector,
|
Codec: codecSelector,
|
||||||
|
@ -31,8 +31,6 @@ func ExampleOptions() *Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Options) MakeFIFO() error {
|
func (o *Options) MakeFIFO() error {
|
||||||
if err := os.Remove(o.AudioPipe); err != nil {
|
os.Remove(o.AudioPipe)
|
||||||
return err
|
return syscall.Mkfifo(o.AudioPipe, 0600)
|
||||||
}
|
|
||||||
return syscall.Mkfifo(o.AudioDevice, 0600)
|
|
||||||
}
|
}
|
||||||
|
@ -91,19 +91,6 @@ func (s *Server) startCapture(qemu *qemu.Domain) {
|
|||||||
if err := s.options.MakeFIFO(); err != nil {
|
if err := s.options.MakeFIFO(); err != nil {
|
||||||
logrus.Fatal("failed to make pipe file: ", err)
|
logrus.Fatal("failed to make pipe file: ", err)
|
||||||
}
|
}
|
||||||
if _, err := qemu.Run(qmp.Command{
|
|
||||||
Execute: "human-monitor-command",
|
|
||||||
Args: map[string]string{
|
|
||||||
"command-line": fmt.Sprintf(
|
|
||||||
"wavcapture %s %s",
|
|
||||||
s.options.AudioPipe,
|
|
||||||
s.options.AudioDevice,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
}); err != nil {
|
|
||||||
logrus.Fatal("run audio command failed: ", err)
|
|
||||||
}
|
|
||||||
logrus.Debug("audio capture set")
|
|
||||||
|
|
||||||
if err := driver.GetManager().Register(
|
if err := driver.GetManager().Register(
|
||||||
audiodriver.New(s.options.AudioPipe),
|
audiodriver.New(s.options.AudioPipe),
|
||||||
@ -126,6 +113,19 @@ func (s *Server) startCapture(qemu *qemu.Domain) {
|
|||||||
logrus.Fatal("video initialize failed: ", err)
|
logrus.Fatal("video initialize failed: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := qemu.Run(qmp.Command{
|
||||||
|
Execute: "human-monitor-command",
|
||||||
|
Args: map[string]string{
|
||||||
|
"command-line": fmt.Sprintf(
|
||||||
|
"wavcapture %s %s",
|
||||||
|
s.options.AudioPipe,
|
||||||
|
s.options.AudioDevice,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}); err != nil {
|
||||||
|
logrus.Fatal("run audio command failed: ", err)
|
||||||
|
}
|
||||||
|
logrus.Debug("audio capture set")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(o *Options) {
|
func Setup(o *Options) {
|
||||||
|
@ -25,7 +25,7 @@ func (s *Server) getInstruction(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) exchangeSDP(c *gin.Context) {
|
func (s *Server) exchangeSDP(c *gin.Context) {
|
||||||
var offer *webrtc.SessionDescription
|
offer := &webrtc.SessionDescription{}
|
||||||
if err := c.BindJSON(offer); err != nil {
|
if err := c.BindJSON(offer); err != nil {
|
||||||
c.JSON(http.StatusBadRequest, Response{
|
c.JSON(http.StatusBadRequest, Response{
|
||||||
Succeed: false,
|
Succeed: false,
|
||||||
|
@ -1,12 +1,30 @@
|
|||||||
package webserver
|
package webserver
|
||||||
|
|
||||||
import "github.com/gin-contrib/static"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
func (s *Server) setupRoute() {
|
func (s *Server) setupRoute() {
|
||||||
s.webServer.
|
apiHandler := gin.New()
|
||||||
Use(static.Serve("/", newFS())).
|
groupV1 := apiHandler.Group("/api/v1")
|
||||||
POST("/api/v1/sdp", s.exchangeSDP).
|
{
|
||||||
GET("/api/v1/instruction", s.getInstruction).
|
groupV1.
|
||||||
GET("/api/v1/iceserver/url", s.getICEConfig).
|
POST("/sdp", s.exchangeSDP).
|
||||||
GET("/api/v1/name", s.getName)
|
GET("/instruction", s.getInstruction).
|
||||||
|
GET("/iceserver/url", s.getICEConfig).
|
||||||
|
GET("/name", s.getName)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.webServer.Use(func(ctx *gin.Context) {
|
||||||
|
path := ctx.Request.RequestURI
|
||||||
|
logrus.Debug(path)
|
||||||
|
if strings.HasPrefix(path, "/api") {
|
||||||
|
apiHandler.HandleContext(ctx)
|
||||||
|
} else {
|
||||||
|
staticFileHandler()(ctx)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -5,33 +5,33 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate cp -r ../../web/dist ./
|
//go:generate cp -r ../../web/dist ./
|
||||||
//go:embed dist
|
//go:embed dist
|
||||||
var staticFiles embed.FS
|
var staticFiles embed.FS
|
||||||
|
|
||||||
type ginFS struct {
|
func staticFileHandler() gin.HandlerFunc {
|
||||||
fs http.FileSystem
|
sf, err := fs.Sub(staticFiles, "dist")
|
||||||
}
|
if err != nil {
|
||||||
|
logrus.Fatal("compile error: ", err)
|
||||||
func newFS() *ginFS {
|
|
||||||
f, _ := fs.Sub(staticFiles, "dist")
|
|
||||||
return &ginFS{
|
|
||||||
fs: http.FS(f),
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ginFS) Exists(prefix string, filepath string) bool {
|
fs := http.FileServer(http.FS(sf))
|
||||||
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
|
|
||||||
if _, err := s.fs.Open(p); err != nil {
|
return func(ctx *gin.Context) {
|
||||||
return false
|
defer ctx.Abort()
|
||||||
|
filename := strings.TrimLeft(ctx.Request.RequestURI, "/")
|
||||||
|
|
||||||
|
logrus.Debug("static file: ", filename)
|
||||||
|
|
||||||
|
if filename == "" {
|
||||||
|
filename = "index.html"
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ginFS) Open(name string) (http.File, error) {
|
fs.ServeHTTP(ctx.Writer, ctx.Request)
|
||||||
return s.fs.Open(name)
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user