Add support incoming H264 bitstream #745
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AlexxIT/go2rtc/internal/api"
|
||||||
"github.com/AlexxIT/go2rtc/internal/streams"
|
"github.com/AlexxIT/go2rtc/internal/streams"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/hls"
|
"github.com/AlexxIT/go2rtc/pkg/hls"
|
||||||
@@ -22,6 +23,8 @@ func Init() {
|
|||||||
streams.HandleFunc("httpx", handleHTTP)
|
streams.HandleFunc("httpx", handleHTTP)
|
||||||
|
|
||||||
streams.HandleFunc("tcp", handleTCP)
|
streams.HandleFunc("tcp", handleTCP)
|
||||||
|
|
||||||
|
api.HandleFunc("api/stream", apiStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleHTTP(rawURL string) (core.Producer, error) {
|
func handleHTTP(rawURL string) (core.Producer, error) {
|
||||||
@@ -89,3 +92,26 @@ func handleTCP(rawURL string) (core.Producer, error) {
|
|||||||
|
|
||||||
return magic.Open(conn)
|
return magic.Open(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiStream(w http.ResponseWriter, r *http.Request) {
|
||||||
|
dst := r.URL.Query().Get("dst")
|
||||||
|
stream := streams.Get(dst)
|
||||||
|
if stream == nil {
|
||||||
|
http.Error(w, api.StreamNotFound, http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := magic.Open(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.AddProducer(client)
|
||||||
|
defer stream.RemoveProducer(client)
|
||||||
|
|
||||||
|
if err = client.Start(); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ func (c *Producer) Start() error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(c.Receivers) > 0 {
|
||||||
pkt := &rtp.Packet{
|
pkt := &rtp.Packet{
|
||||||
Header: rtp.Header{Timestamp: core.Now90000()},
|
Header: rtp.Header{Timestamp: core.Now90000()},
|
||||||
Payload: annexb.EncodeToAVCC(buf[:i], true),
|
Payload: annexb.EncodeToAVCC(buf[:i], true),
|
||||||
@@ -77,6 +78,7 @@ func (c *Producer) Start() error {
|
|||||||
c.Receivers[0].WriteRTP(pkt)
|
c.Receivers[0].WriteRTP(pkt)
|
||||||
|
|
||||||
//log.Printf("[AVC] %v, len: %d", h264.Types(pkt.Payload), len(pkt.Payload))
|
//log.Printf("[AVC] %v, len: %d", h264.Types(pkt.Payload), len(pkt.Payload))
|
||||||
|
}
|
||||||
|
|
||||||
buf = buf[i:]
|
buf = buf[i:]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user