Update rtmp server

This commit is contained in:
Ingo Oppermann
2025-08-06 15:59:25 +02:00
parent e633aa78e9
commit c960227f1b
6 changed files with 36 additions and 16 deletions

2
go.mod
View File

@@ -12,7 +12,7 @@ require (
github.com/atrox/haikunatorgo/v2 v2.0.1
github.com/caddyserver/certmagic v0.23.0
github.com/datarhei/gosrt v0.9.0
github.com/datarhei/joy4 v0.0.0-20240603190808-b1407345907e
github.com/datarhei/joy4 v0.0.0-20250806135534-393d6bb11439
github.com/dolthub/swiss v0.2.1
github.com/fujiwara/shapeio v1.0.0
github.com/go-playground/validator/v10 v10.27.0

4
go.sum
View File

@@ -50,8 +50,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/datarhei/gosrt v0.9.0 h1:FW8A+F8tBiv7eIa57EBHjtTJKFX+OjvLogF/tFXoOiA=
github.com/datarhei/gosrt v0.9.0/go.mod h1:rqTRK8sDZdN2YBgp1EEICSV4297mQk0oglwvpXhaWdk=
github.com/datarhei/joy4 v0.0.0-20240603190808-b1407345907e h1:Qc/0D4xvXrazFkoi/4UGqO15yQ1JN5I8h7RwdzCLgTY=
github.com/datarhei/joy4 v0.0.0-20240603190808-b1407345907e/go.mod h1:Jcw/6jZDQQmPx8A7INEkXmuEF7E9jjBbSTfVSLwmiQw=
github.com/datarhei/joy4 v0.0.0-20250806135534-393d6bb11439 h1:8HMGWtglP1I23Qd4PLLeDthkLY2Ye67ePW5zY61v+Hs=
github.com/datarhei/joy4 v0.0.0-20250806135534-393d6bb11439/go.mod h1:Jcw/6jZDQQmPx8A7INEkXmuEF7E9jjBbSTfVSLwmiQw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@@ -46,7 +46,6 @@ func (self *Queue) SetMaxGopCount(n int) {
self.lock.Lock()
self.maxgopcount = n
self.lock.Unlock()
return
}
func (self *Queue) WriteHeader(streams []av.CodecData) error {
@@ -85,17 +84,34 @@ func (self *Queue) WritePacket(pkt av.Packet) (err error) {
self.lock.Lock()
self.buf.Push(pkt)
if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame {
self.curgopcount++
}
for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 {
pkt := self.buf.Pop()
if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame {
self.curgopcount--
if self.videoidx == -1 { // audio only stream
if pkt.IsKeyFrame {
self.curgopcount++
}
if self.curgopcount < self.maxgopcount {
break
for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 {
pkt := self.buf.Pop()
if pkt.IsKeyFrame {
self.curgopcount--
}
if self.curgopcount < self.maxgopcount {
break
}
}
} else { // video only or video+audio stream
if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame {
self.curgopcount++
}
for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 {
pkt := self.buf.Pop()
if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame {
self.curgopcount--
}
if self.curgopcount < self.maxgopcount {
break
}
}
}

View File

@@ -3,11 +3,12 @@ package aac
import (
"bufio"
"fmt"
"io"
"time"
"github.com/datarhei/joy4/av"
"github.com/datarhei/joy4/av/avutil"
"github.com/datarhei/joy4/codec/aacparser"
"io"
"time"
)
type Muxer struct {

View File

@@ -279,15 +279,18 @@ func (prober *Prober) TagToPacket(tag flvio.Tag, timestamp int32) (pkt av.Packet
case flvio.AAC_RAW:
ok = true
pkt.Data = tag.Data
pkt.IsKeyFrame = true
}
case flvio.SOUND_SPEEX:
ok = true
pkt.Data = tag.Data
pkt.IsKeyFrame = true
case flvio.SOUND_NELLYMOSER:
ok = true
pkt.Data = tag.Data
pkt.IsKeyFrame = true
}
}

2
vendor/modules.txt vendored
View File

@@ -78,7 +78,7 @@ github.com/datarhei/gosrt/crypto
github.com/datarhei/gosrt/net
github.com/datarhei/gosrt/packet
github.com/datarhei/gosrt/rand
# github.com/datarhei/joy4 v0.0.0-20240603190808-b1407345907e
# github.com/datarhei/joy4 v0.0.0-20250806135534-393d6bb11439
## explicit; go 1.14
github.com/datarhei/joy4/av
github.com/datarhei/joy4/av/avutil