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