mirror of
https://github.com/kerberos-io/agent.git
synced 2026-08-23 15:08:32 +00:00
Merge pull request #312 from kerberos-io/fix/moq-double-pts-insertion
fix/moq-double-pts-insertion
This commit is contained in:
@@ -59,6 +59,16 @@ func BroadcastPath(prefix string, deviceKey string) string {
|
|||||||
return prefix + "/" + strings.Trim(deviceKey, "/") + "/live.hang"
|
return prefix + "/" + strings.Trim(deviceKey, "/") + "/live.hang"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimestampUs converts the capture presentation timestamp from milliseconds.
|
||||||
|
// CompositionTime must not be added: it is already represented in the PTS and
|
||||||
|
// is only used by muxers to derive DTS for streams containing B-frames.
|
||||||
|
func TimestampUs(presentationTimeMs int64) uint64 {
|
||||||
|
if presentationTimeMs < 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return uint64(presentationTimeMs) * 1000
|
||||||
|
}
|
||||||
|
|
||||||
func hasAnnexBStartCode(payload []byte) bool {
|
func hasAnnexBStartCode(payload []byte) bool {
|
||||||
return len(payload) >= 4 && payload[0] == 0 && payload[1] == 0 &&
|
return len(payload) >= 4 && payload[0] == 0 && payload[1] == 0 &&
|
||||||
((payload[2] == 0 && payload[3] == 1) || payload[2] == 1)
|
((payload[2] == 0 && payload[3] == 1) || payload[2] == 1)
|
||||||
|
|||||||
@@ -72,3 +72,12 @@ func TestBroadcastPath(t *testing.T) {
|
|||||||
t.Fatalf("BroadcastPath() default = %q", got)
|
t.Fatalf("BroadcastPath() default = %q", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTimestampUs(t *testing.T) {
|
||||||
|
if got := TimestampUs(1234); got != 1_234_000 {
|
||||||
|
t.Fatalf("TimestampUs() = %d, want 1234000", got)
|
||||||
|
}
|
||||||
|
if got := TimestampUs(-1); got != 0 {
|
||||||
|
t.Fatalf("TimestampUs() negative = %d, want 0", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -152,17 +152,13 @@ func publishLiveStreamMoQ(ctx context.Context, config liveMoQConfig) error {
|
|||||||
writing = true
|
writing = true
|
||||||
log.Log.Info("cloud.publishLiveStreamMoQ(): first H.264 keyframe received; broadcast is live")
|
log.Log.Info("cloud.publishLiveStreamMoQ(): first H.264 keyframe received; broadcast is live")
|
||||||
}
|
}
|
||||||
presentationTimeMs := packet.Time + packet.CompositionTime
|
|
||||||
if presentationTimeMs < 0 {
|
|
||||||
presentationTimeMs = 0
|
|
||||||
}
|
|
||||||
payload, err := livemoq.NormalizeH264AccessUnit(packet.Data)
|
payload, err := livemoq.NormalizeH264AccessUnit(packet.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("normalize H.264 access unit: %w", err)
|
return fmt.Errorf("normalize H.264 access unit: %w", err)
|
||||||
}
|
}
|
||||||
frame := moq.Frame{
|
frame := moq.Frame{
|
||||||
Payload: payload,
|
Payload: payload,
|
||||||
TimestampUs: uint64(presentationTimeMs) * 1000,
|
TimestampUs: livemoq.TimestampUs(packet.Time),
|
||||||
}
|
}
|
||||||
if err := stream.WriteFrame(frame); err != nil {
|
if err := stream.WriteFrame(frame); err != nil {
|
||||||
return fmt.Errorf("write H.264 access unit: %w", err)
|
return fmt.Errorf("write H.264 access unit: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user