BIG rewrite stream info
This commit is contained in:
+7
-9
@@ -9,14 +9,17 @@ import (
|
||||
)
|
||||
|
||||
type Consumer struct {
|
||||
core.SuperConsumer
|
||||
core.Connection
|
||||
wr *core.WriteBuffer
|
||||
}
|
||||
|
||||
func NewConsumer() *Consumer {
|
||||
wr := core.NewWriteBuffer(nil)
|
||||
return &Consumer{
|
||||
core.SuperConsumer{
|
||||
Type: "YUV4MPEG2 passive consumer",
|
||||
core.Connection{
|
||||
ID: core.NewID(),
|
||||
Transport: wr,
|
||||
FormatName: "yuv4mpegpipe",
|
||||
Medias: []*core.Media{
|
||||
{
|
||||
Kind: core.KindVideo,
|
||||
@@ -27,7 +30,7 @@ func NewConsumer() *Consumer {
|
||||
},
|
||||
},
|
||||
},
|
||||
core.NewWriteBuffer(nil),
|
||||
wr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +63,3 @@ func (c *Consumer) AddTrack(media *core.Media, _ *core.Codec, track *core.Receiv
|
||||
func (c *Consumer) WriteTo(wr io.Writer) (int64, error) {
|
||||
return c.wr.WriteTo(wr)
|
||||
}
|
||||
|
||||
func (c *Consumer) Stop() error {
|
||||
_ = c.SuperConsumer.Close()
|
||||
return c.wr.Close()
|
||||
}
|
||||
|
||||
+14
-41
@@ -2,7 +2,6 @@ package y4m
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
@@ -19,41 +18,13 @@ func Open(r io.Reader) (*Producer, error) {
|
||||
|
||||
b = b[:len(b)-1] // remove \n
|
||||
|
||||
sdp := string(b)
|
||||
var fmtp string
|
||||
|
||||
for b != nil {
|
||||
// YUV4MPEG2 W1280 H720 F24:1 Ip A1:1 C420mpeg2 XYSCSS=420MPEG2
|
||||
// https://manned.org/yuv4mpeg.5
|
||||
// https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/yuv4mpegenc.c
|
||||
key := b[0]
|
||||
var value string
|
||||
if i := bytes.IndexByte(b, ' '); i > 0 {
|
||||
value = string(b[1:i])
|
||||
b = b[i+1:]
|
||||
} else {
|
||||
value = string(b[1:])
|
||||
b = nil
|
||||
}
|
||||
|
||||
switch key {
|
||||
case 'W':
|
||||
fmtp = "width=" + value
|
||||
case 'H':
|
||||
fmtp += ";height=" + value
|
||||
case 'C':
|
||||
fmtp += ";colorspace=" + value
|
||||
}
|
||||
}
|
||||
fmtp := ParseHeader(b)
|
||||
|
||||
if GetSize(fmtp) == 0 {
|
||||
return nil, errors.New("y4m: unsupported format: " + sdp)
|
||||
return nil, errors.New("y4m: unsupported format: " + string(b))
|
||||
}
|
||||
|
||||
prod := &Producer{rd: rd, cl: r.(io.Closer)}
|
||||
prod.Type = "YUV4MPEG2 producer"
|
||||
prod.SDP = sdp
|
||||
prod.Medias = []*core.Media{
|
||||
medias := []*core.Media{
|
||||
{
|
||||
Kind: core.KindVideo,
|
||||
Direction: core.DirectionRecvonly,
|
||||
@@ -67,14 +38,21 @@ func Open(r io.Reader) (*Producer, error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return prod, nil
|
||||
return &Producer{
|
||||
Connection: core.Connection{
|
||||
ID: core.NewID(),
|
||||
FormatName: "yuv4mpegpipe",
|
||||
Medias: medias,
|
||||
SDP: string(b),
|
||||
Transport: r,
|
||||
},
|
||||
rd: rd,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Producer struct {
|
||||
core.SuperProducer
|
||||
core.Connection
|
||||
rd *bufio.Reader
|
||||
cl io.Closer
|
||||
}
|
||||
|
||||
func (c *Producer) Start() error {
|
||||
@@ -103,8 +81,3 @@ func (c *Producer) Start() error {
|
||||
c.Receivers[0].WriteRTP(pkt)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Producer) Stop() error {
|
||||
_ = c.SuperProducer.Close()
|
||||
return c.cl.Close()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package y4m
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
@@ -10,6 +11,34 @@ const FourCC = "YUV4"
|
||||
|
||||
const frameHdr = "FRAME\n"
|
||||
|
||||
func ParseHeader(b []byte) (fmtp string) {
|
||||
for b != nil {
|
||||
// YUV4MPEG2 W1280 H720 F24:1 Ip A1:1 C420mpeg2 XYSCSS=420MPEG2
|
||||
// https://manned.org/yuv4mpeg.5
|
||||
// https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/yuv4mpegenc.c
|
||||
key := b[0]
|
||||
|
||||
var value string
|
||||
if i := bytes.IndexByte(b, ' '); i > 0 {
|
||||
value = string(b[1:i])
|
||||
b = b[i+1:]
|
||||
} else {
|
||||
value = string(b[1:])
|
||||
b = nil
|
||||
}
|
||||
|
||||
switch key {
|
||||
case 'W':
|
||||
fmtp = "width=" + value
|
||||
case 'H':
|
||||
fmtp += ";height=" + value
|
||||
case 'C':
|
||||
fmtp += ";colorspace=" + value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetSize(fmtp string) int {
|
||||
w := core.Atoi(core.Between(fmtp, "width=", ";"))
|
||||
h := core.Atoi(core.Between(fmtp, "height=", ";"))
|
||||
|
||||
Reference in New Issue
Block a user