mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-23 20:09:49 -08:00
do not include recorder and HLS muxer in sent bytes (#4380) (#5039)
Some checks are pending
code_lint / go (push) Waiting to run
code_lint / go_mod (push) Waiting to run
code_lint / docs (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
Some checks are pending
code_lint / go (push) Waiting to run
code_lint / go_mod (push) Waiting to run
code_lint / docs (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
in API (/paths/list, /paths/get) and metrics (paths_bytes_sent), the amount of sent bytes was increased even in case of writes to the recorder and HLS muxer, which are not generating network traffic. This fixes the issue.
This commit is contained in:
parent
ada39d22cd
commit
cd80814009
28 changed files with 615 additions and 656 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/bluenviron/gortmplib"
|
||||
"github.com/bluenviron/gortmplib/pkg/message"
|
||||
"github.com/bluenviron/gortsplib/v5/pkg/description"
|
||||
"github.com/bluenviron/gortsplib/v5/pkg/format"
|
||||
"github.com/bluenviron/mediacommon/v2/pkg/codecs/ac3"
|
||||
"github.com/bluenviron/mediacommon/v2/pkg/codecs/h264"
|
||||
|
|
@ -37,8 +38,8 @@ func timestampToDuration(t int64, clockRate int) time.Duration {
|
|||
|
||||
// FromStream maps a MediaMTX stream to a RTMP stream.
|
||||
func FromStream(
|
||||
str *stream.Stream,
|
||||
reader stream.Reader,
|
||||
desc *description.Session,
|
||||
r *stream.Reader,
|
||||
conn *gortmplib.ServerConn,
|
||||
nconn net.Conn,
|
||||
writeTimeout time.Duration,
|
||||
|
|
@ -46,13 +47,12 @@ func FromStream(
|
|||
var tracks []format.Format
|
||||
var w *gortmplib.Writer
|
||||
|
||||
for _, media := range str.Desc.Medias {
|
||||
for _, media := range desc.Medias {
|
||||
for _, forma := range media.Formats {
|
||||
switch forma := forma.(type) {
|
||||
case *format.AV1:
|
||||
if slices.Contains(conn.FourCcList, interface{}(fourCCToString(message.FourCCAV1))) {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -74,8 +74,7 @@ func FromStream(
|
|||
|
||||
case *format.VP9:
|
||||
if slices.Contains(conn.FourCcList, interface{}(fourCCToString(message.FourCCVP9))) {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -99,8 +98,7 @@ func FromStream(
|
|||
if slices.Contains(conn.FourCcList, interface{}(fourCCToString(message.FourCCHEVC))) {
|
||||
var videoDTSExtractor *h265.DTSExtractor
|
||||
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -137,8 +135,7 @@ func FromStream(
|
|||
case *format.H264:
|
||||
var videoDTSExtractor *h264.DTSExtractor
|
||||
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -191,8 +188,7 @@ func FromStream(
|
|||
|
||||
case *format.Opus:
|
||||
if slices.Contains(conn.FourCcList, interface{}(fourCCToString(message.FourCCOpus))) {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -225,8 +221,7 @@ func FromStream(
|
|||
}
|
||||
|
||||
case *format.MPEG4Audio:
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -257,8 +252,7 @@ func FromStream(
|
|||
|
||||
case *format.MPEG4AudioLATM:
|
||||
if !forma.CPresent {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -289,8 +283,7 @@ func FromStream(
|
|||
case *format.MPEG1Audio:
|
||||
// TODO: check sample rate and layer,
|
||||
// unfortunately they are not available at this stage.
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -325,8 +318,7 @@ func FromStream(
|
|||
|
||||
case *format.AC3:
|
||||
if slices.Contains(conn.FourCcList, interface{}(fourCCToString(message.FourCCAC3))) {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -353,8 +345,7 @@ func FromStream(
|
|||
|
||||
case *format.G711:
|
||||
if forma.SampleRate == 8000 {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -381,8 +372,7 @@ func FromStream(
|
|||
forma.SampleRate == 11025 ||
|
||||
forma.SampleRate == 22050 ||
|
||||
forma.SampleRate == 44100) {
|
||||
str.AddReader(
|
||||
reader,
|
||||
r.OnData(
|
||||
media,
|
||||
forma,
|
||||
func(u unit.Unit) error {
|
||||
|
|
@ -420,10 +410,10 @@ func FromStream(
|
|||
}
|
||||
|
||||
n := 1
|
||||
for _, media := range str.Desc.Medias {
|
||||
for _, media := range desc.Medias {
|
||||
for _, forma := range media.Formats {
|
||||
if !slices.Contains(tracks, forma) {
|
||||
reader.Log(logger.Warn, "skipping track %d (%s)", n, forma.Codec())
|
||||
r.Parent.Log(logger.Warn, "skipping track %d (%s)", n, forma.Codec())
|
||||
}
|
||||
n++
|
||||
}
|
||||
|
|
|
|||
|
|
@ -409,13 +409,13 @@ func TestFromStream(t *testing.T) {
|
|||
err = conn.Accept()
|
||||
require.NoError(t, err)
|
||||
|
||||
reader := test.NilLogger
|
||||
r := &stream.Reader{Parent: test.NilLogger}
|
||||
|
||||
err = FromStream(strm, reader, conn, nconn, 10*time.Second)
|
||||
err = FromStream(strm.Desc, r, conn, nconn, 10*time.Second)
|
||||
require.NoError(t, err)
|
||||
defer strm.RemoveReader(reader)
|
||||
|
||||
strm.StartReader(reader)
|
||||
strm.AddReader(r)
|
||||
defer strm.RemoveReader(r)
|
||||
|
||||
switch ca {
|
||||
case "h264 + aac":
|
||||
|
|
@ -675,56 +675,44 @@ func TestFromStream(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFromStreamNoSupportedCodecs(t *testing.T) {
|
||||
strm := &stream.Stream{
|
||||
WriteQueueSize: 512,
|
||||
RTPMaxPayloadSize: 1450,
|
||||
Desc: &description.Session{Medias: []*description.Media{{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.VP8{}},
|
||||
}}},
|
||||
GenerateRTPPackets: true,
|
||||
Parent: test.NilLogger,
|
||||
desc := &description.Session{Medias: []*description.Media{{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.VP8{}},
|
||||
}}}
|
||||
|
||||
r := &stream.Reader{
|
||||
Parent: test.Logger(func(logger.Level, string, ...interface{}) {
|
||||
t.Error("should not happen")
|
||||
}),
|
||||
}
|
||||
err := strm.Initialize()
|
||||
require.NoError(t, err)
|
||||
|
||||
l := test.Logger(func(logger.Level, string, ...interface{}) {
|
||||
t.Error("should not happen")
|
||||
})
|
||||
|
||||
err = FromStream(strm, l, nil, nil, 0)
|
||||
err := FromStream(desc, r, nil, nil, 0)
|
||||
require.Equal(t, errNoSupportedCodecsFrom, err)
|
||||
}
|
||||
|
||||
func TestFromStreamSkipUnsupportedTracks(t *testing.T) {
|
||||
strm := &stream.Stream{
|
||||
WriteQueueSize: 512,
|
||||
RTPMaxPayloadSize: 1450,
|
||||
Desc: &description.Session{Medias: []*description.Media{
|
||||
{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.VP8{}},
|
||||
},
|
||||
{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.H264{}},
|
||||
},
|
||||
}},
|
||||
GenerateRTPPackets: true,
|
||||
Parent: test.NilLogger,
|
||||
}
|
||||
err := strm.Initialize()
|
||||
require.NoError(t, err)
|
||||
desc := &description.Session{Medias: []*description.Media{
|
||||
{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.VP8{}},
|
||||
},
|
||||
{
|
||||
Type: description.MediaTypeVideo,
|
||||
Formats: []format.Format{&format.H264{}},
|
||||
},
|
||||
}}
|
||||
|
||||
n := 0
|
||||
|
||||
l := test.Logger(func(l logger.Level, format string, args ...interface{}) {
|
||||
require.Equal(t, logger.Warn, l)
|
||||
if n == 0 {
|
||||
require.Equal(t, "skipping track 1 (VP8)", fmt.Sprintf(format, args...))
|
||||
}
|
||||
n++
|
||||
})
|
||||
r := &stream.Reader{
|
||||
Parent: test.Logger(func(l logger.Level, format string, args ...interface{}) {
|
||||
require.Equal(t, logger.Warn, l)
|
||||
if n == 0 {
|
||||
require.Equal(t, "skipping track 1 (VP8)", fmt.Sprintf(format, args...))
|
||||
}
|
||||
n++
|
||||
}),
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:9121")
|
||||
require.NoError(t, err)
|
||||
|
|
@ -754,9 +742,8 @@ func TestFromStreamSkipUnsupportedTracks(t *testing.T) {
|
|||
err = conn.Accept()
|
||||
require.NoError(t, err)
|
||||
|
||||
err = FromStream(strm, l, conn, nil, 0)
|
||||
err = FromStream(desc, r, conn, nil, 0)
|
||||
require.NoError(t, err)
|
||||
defer strm.RemoveReader(l)
|
||||
|
||||
require.Equal(t, 1, n)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue