Rewrite magic client
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/AlexxIT/go2rtc/internal/streams"
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/AlexxIT/go2rtc/pkg/flv"
|
||||
"github.com/AlexxIT/go2rtc/pkg/magic"
|
||||
"github.com/AlexxIT/go2rtc/pkg/mjpeg"
|
||||
"github.com/AlexxIT/go2rtc/pkg/multipart"
|
||||
@@ -52,14 +51,6 @@ func handleHTTP(url string) (core.Producer, error) {
|
||||
case "multipart/x-mixed-replace":
|
||||
return multipart.NewClient(res)
|
||||
|
||||
case "video/x-flv":
|
||||
client, err := flv.Open(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.URL = url
|
||||
return client, nil
|
||||
|
||||
default: // "video/mpeg":
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -13,6 +13,8 @@ import (
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
const Signature = "FLV"
|
||||
|
||||
type Client struct {
|
||||
URL string
|
||||
|
||||
@@ -178,7 +180,7 @@ func (c *Client) readHeader() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if string(b[:3]) != "FLV" {
|
||||
if string(b[:3]) != Signature {
|
||||
return errors.New("flv: wrong header")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,19 +7,14 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/AlexxIT/go2rtc/pkg/flv"
|
||||
"github.com/AlexxIT/go2rtc/pkg/h264/annexb"
|
||||
"github.com/AlexxIT/go2rtc/pkg/magic/bitstream"
|
||||
"github.com/AlexxIT/go2rtc/pkg/magic/mjpeg"
|
||||
"github.com/AlexxIT/go2rtc/pkg/mpegts"
|
||||
)
|
||||
|
||||
// Client - can read unknown bytestream and autodetect format
|
||||
type Client struct {
|
||||
rd *core.ReadSeeker
|
||||
prod core.Producer
|
||||
}
|
||||
|
||||
func Open(r io.Reader) (*Client, error) {
|
||||
func Open(r io.Reader) (core.Producer, error) {
|
||||
rd := core.NewReadSeeker(r)
|
||||
|
||||
b, err := rd.Peek(4)
|
||||
@@ -28,18 +23,14 @@ func Open(r io.Reader) (*Client, error) {
|
||||
}
|
||||
|
||||
switch {
|
||||
case bytes.HasPrefix(b, []byte(annexb.StartCode)) || bytes.HasPrefix(b, []byte{0, 0, 1}):
|
||||
var prod core.Producer
|
||||
if prod, err = bitstream.Open(rd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{rd: rd, prod: prod}, nil
|
||||
case bytes.HasPrefix(b, []byte(annexb.StartCode)):
|
||||
return bitstream.Open(rd)
|
||||
|
||||
case bytes.HasPrefix(b, []byte{0xFF, 0xD8}):
|
||||
return &Client{rd: rd, prod: mjpeg.NewClient(rd)}, nil
|
||||
return mjpeg.NewClient(rd), nil
|
||||
|
||||
case bytes.HasPrefix(b, []byte{'F', 'L', 'V'}):
|
||||
break // TODO
|
||||
case bytes.HasPrefix(b, []byte(flv.Signature)):
|
||||
return flv.Open(rd)
|
||||
|
||||
case b[0] == mpegts.SyncByte:
|
||||
break // TODO
|
||||
@@ -1,27 +0,0 @@
|
||||
package magic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
)
|
||||
|
||||
func (c *Client) GetMedias() []*core.Media {
|
||||
return c.prod.GetMedias()
|
||||
}
|
||||
|
||||
func (c *Client) GetTrack(media *core.Media, codec *core.Codec) (*core.Receiver, error) {
|
||||
return c.prod.GetTrack(media, codec)
|
||||
}
|
||||
|
||||
func (c *Client) Start() error {
|
||||
return c.prod.Start()
|
||||
}
|
||||
|
||||
func (c *Client) Stop() (err error) {
|
||||
return c.prod.Stop()
|
||||
}
|
||||
|
||||
func (c *Client) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(c.prod)
|
||||
}
|
||||
Reference in New Issue
Block a user