BIG rewrite stream info

This commit is contained in:
Alex X
2024-06-15 16:46:03 +03:00
parent ecfe802065
commit 96504e2fb0
88 changed files with 1043 additions and 854 deletions
+14 -10
View File
@@ -13,7 +13,7 @@ import (
)
type Producer struct {
core.SuperProducer
core.Connection
rd *core.ReadBuffer
}
@@ -28,26 +28,35 @@ func Open(r io.Reader) (*Producer, error) {
buf = annexb.EncodeToAVCC(buf, false) // won't break original buffer
var codec *core.Codec
var format string
switch {
case h264.NALUType(buf) == h264.NALUTypeSPS:
codec = h264.AVCCToCodec(buf)
format = "h264"
case h265.NALUType(buf) == h265.NALUTypeVPS:
codec = h265.AVCCToCodec(buf)
format = "hevc"
default:
return nil, errors.New("bitstream: unsupported header: " + hex.EncodeToString(buf[:8]))
}
prod := &Producer{rd: rd}
prod.Type = "Bitstream producer"
prod.Medias = []*core.Media{
medias := []*core.Media{
{
Kind: core.KindVideo,
Direction: core.DirectionRecvonly,
Codecs: []*core.Codec{codec},
},
}
return prod, nil
return &Producer{
Connection: core.Connection{
ID: core.NewID(),
FormatName: format,
Medias: medias,
Transport: r,
},
rd: rd,
}, nil
}
func (c *Producer) Start() error {
@@ -84,8 +93,3 @@ func (c *Producer) Start() error {
}
}
}
func (c *Producer) Stop() error {
_ = c.SuperProducer.Close()
return c.rd.Close()
}
+20 -19
View File
@@ -12,26 +12,32 @@ import (
)
type Keyframe struct {
core.SuperConsumer
core.Connection
wr *core.WriteBuffer
}
// Deprecated: should be rewritten
func NewKeyframe() *Keyframe {
return &Keyframe{
core.SuperConsumer{
Medias: []*core.Media{
{
Kind: core.KindVideo,
Direction: core.DirectionSendonly,
Codecs: []*core.Codec{
{Name: core.CodecJPEG},
{Name: core.CodecH264},
{Name: core.CodecH265},
},
},
medias := []*core.Media{
{
Kind: core.KindVideo,
Direction: core.DirectionSendonly,
Codecs: []*core.Codec{
{Name: core.CodecJPEG},
{Name: core.CodecH264},
{Name: core.CodecH265},
},
},
core.NewWriteBuffer(nil),
}
wr := core.NewWriteBuffer(nil)
return &Keyframe{
Connection: core.Connection{
ID: core.NewID(),
FormatName: "keyframe",
Medias: medias,
Transport: wr,
},
wr: wr,
}
}
@@ -98,8 +104,3 @@ func (k *Keyframe) CodecName() string {
func (k *Keyframe) WriteTo(wr io.Writer) (int64, error) {
return k.wr.WriteTo(wr)
}
func (k *Keyframe) Stop() error {
_ = k.SuperConsumer.Close()
return k.wr.Close()
}
+11 -10
View File
@@ -9,14 +9,12 @@ import (
)
type Producer struct {
core.SuperProducer
core.Connection
rd *core.ReadBuffer
}
func Open(rd io.Reader) (*Producer, error) {
prod := &Producer{rd: core.NewReadBuffer(rd)}
prod.Type = "MJPEG producer"
prod.Medias = []*core.Media{
medias := []*core.Media{
{
Kind: core.KindVideo,
Direction: core.DirectionRecvonly,
@@ -29,7 +27,15 @@ func Open(rd io.Reader) (*Producer, error) {
},
},
}
return prod, nil
return &Producer{
Connection: core.Connection{
ID: core.NewID(),
FormatName: "mjpeg",
Medias: medias,
Transport: rd,
},
rd: core.NewReadBuffer(rd),
}, nil
}
func (c *Producer) Start() error {
@@ -70,8 +76,3 @@ func (c *Producer) Start() error {
buf = buf[i:]
}
}
func (c *Producer) Stop() error {
_ = c.SuperProducer.Close()
return c.rd.Close()
}
+18 -16
View File
@@ -13,7 +13,7 @@ import (
"github.com/AlexxIT/go2rtc/pkg/magic/bitstream"
"github.com/AlexxIT/go2rtc/pkg/magic/mjpeg"
"github.com/AlexxIT/go2rtc/pkg/mpegts"
"github.com/AlexxIT/go2rtc/pkg/multipart"
"github.com/AlexxIT/go2rtc/pkg/mpjpeg"
"github.com/AlexxIT/go2rtc/pkg/wav"
"github.com/AlexxIT/go2rtc/pkg/y4m"
)
@@ -26,29 +26,31 @@ func Open(r io.Reader) (core.Producer, error) {
return nil, err
}
switch {
case string(b) == annexb.StartCode:
switch string(b) {
case annexb.StartCode:
return bitstream.Open(rd)
case string(b) == wav.FourCC:
case wav.FourCC:
return wav.Open(rd)
case string(b) == y4m.FourCC:
case y4m.FourCC:
return y4m.Open(rd)
}
case bytes.HasPrefix(b, []byte{0xFF, 0xD8}):
return mjpeg.Open(rd)
case bytes.HasPrefix(b, []byte(flv.Signature)):
switch string(b[:3]) {
case flv.Signature:
return flv.Open(rd)
}
case bytes.HasPrefix(b, []byte("--")):
return multipart.Open(rd)
case b[0] == 0xFF && (b[1] == 0xF1 || b[1] == 0xF9):
switch string(b[:2]) {
case "\xFF\xD8":
return mjpeg.Open(rd)
case "\xFF\xF1", "\xFF\xF9":
return aac.Open(rd)
case "--":
return mpjpeg.Open(rd)
}
case b[0] == mpegts.SyncByte:
switch b[0] {
case mpegts.SyncByte:
return mpegts.Open(rd)
}