Skip to content

Commit

Permalink
fix a/v sync
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jul 30, 2023
1 parent 5f8da0e commit 3db6c80
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 61 deletions.
30 changes: 15 additions & 15 deletions internal/core/hls_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ func (m *hlsMuxer) createVideoTrack(stream *stream.Stream) (*media.Media, *gohls
videoMedia := stream.Medias().FindFormat(&videoFormatH265)

if videoFormatH265 != nil {
videoStartPTSFilled := false
var videoStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration

Check warning on line 344 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L343-L344

Added lines #L343 - L344 were not covered by tests

stream.AddReader(m, videoMedia, videoFormatH265, func(unit formatprocessor.Unit) {

Check warning on line 346 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L346

Added line #L346 was not covered by tests
m.ringBuffer.Push(func() error {
Expand All @@ -351,12 +351,12 @@ func (m *hlsMuxer) createVideoTrack(stream *stream.Stream) (*media.Media, *gohls
return nil
}

if !videoStartPTSFilled {
videoStartPTSFilled = true
videoStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS

Check warning on line 356 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L354-L356

Added lines #L354 - L356 were not covered by tests
}
pts := tunit.PTS - videoStartPTS

pts := tunit.PTS - startPTS

Check warning on line 359 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L359

Added line #L359 was not covered by tests
err := m.muxer.WriteH26x(tunit.NTP, pts, tunit.AU)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
Expand All @@ -381,8 +381,8 @@ func (m *hlsMuxer) createVideoTrack(stream *stream.Stream) (*media.Media, *gohls
videoMedia = stream.Medias().FindFormat(&videoFormatH264)

if videoFormatH264 != nil {
videoStartPTSFilled := false
var videoStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration

stream.AddReader(m, videoMedia, videoFormatH264, func(unit formatprocessor.Unit) {
m.ringBuffer.Push(func() error {
Expand All @@ -392,12 +392,12 @@ func (m *hlsMuxer) createVideoTrack(stream *stream.Stream) (*media.Media, *gohls
return nil
}

if !videoStartPTSFilled {
videoStartPTSFilled = true
videoStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS
}
pts := tunit.PTS - videoStartPTS

pts := tunit.PTS - startPTS
err := m.muxer.WriteH26x(tunit.NTP, pts, tunit.AU)
if err != nil {
return fmt.Errorf("muxer error: %v", err)
Expand Down Expand Up @@ -440,8 +440,8 @@ func (m *hlsMuxer) createAudioTrack(stream *stream.Stream) (*media.Media, *gohls
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
}
pts := tunit.PTS - audioStartPTS

pts := tunit.PTS - audioStartPTS

Check warning on line 444 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L444

Added line #L444 was not covered by tests
err := m.muxer.WriteMPEG4Audio(
tunit.NTP,
pts,
Expand Down Expand Up @@ -483,8 +483,8 @@ func (m *hlsMuxer) createAudioTrack(stream *stream.Stream) (*media.Media, *gohls
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
}
pts := tunit.PTS - audioStartPTS

pts := tunit.PTS - audioStartPTS

Check warning on line 487 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L487

Added line #L487 was not covered by tests
err := m.muxer.WriteMPEG4Audio(
tunit.NTP,
pts,
Expand Down Expand Up @@ -519,8 +519,8 @@ func (m *hlsMuxer) createAudioTrack(stream *stream.Stream) (*media.Media, *gohls
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
}
pts := tunit.PTS - audioStartPTS

pts := tunit.PTS - audioStartPTS

Check warning on line 523 in internal/core/hls_muxer.go

View check run for this annotation

Codecov / codecov/patch

internal/core/hls_muxer.go#L523

Added line #L523 was not covered by tests
err := m.muxer.WriteOpus(
tunit.NTP,
pts,
Expand Down
48 changes: 24 additions & 24 deletions internal/core/rtmp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ func (c *rtmpConn) setupVideo(
videoMedia := stream.Medias().FindFormat(&videoFormatH264)

if videoFormatH264 != nil {
videoStartPTSFilled := false
var videoStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration
var videoDTSExtractor *h264.DTSExtractor

stream.AddReader(c, videoMedia, videoFormatH264, func(unit formatprocessor.Unit) {
Expand All @@ -342,11 +342,11 @@ func (c *rtmpConn) setupVideo(
return nil
}

if !videoStartPTSFilled {
videoStartPTSFilled = true
videoStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS
}
pts := tunit.PTS - videoStartPTS
pts := tunit.PTS - startPTS

idrPresent := false
nonIDRPresent := false
Expand Down Expand Up @@ -420,8 +420,8 @@ func (c *rtmpConn) setupAudio(
audioMedia := stream.Medias().FindFormat(&audioFormatMPEG4Generic)

if audioMedia != nil {
audioStartPTSFilled := false
var audioStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration

stream.AddReader(c, audioMedia, audioFormatMPEG4Generic, func(unit formatprocessor.Unit) {
ringBuffer.Push(func() error {
Expand All @@ -431,11 +431,11 @@ func (c *rtmpConn) setupAudio(
return nil
}

if !audioStartPTSFilled {
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS

Check warning on line 436 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L434-L436

Added lines #L434 - L436 were not covered by tests
}
pts := tunit.PTS - audioStartPTS
pts := tunit.PTS - startPTS

Check warning on line 438 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L438

Added line #L438 was not covered by tests

if videoFormat != nil {
if !*videoFirstIDRFound {
Expand Down Expand Up @@ -474,8 +474,8 @@ func (c *rtmpConn) setupAudio(
audioFormatMPEG4AudioLATM.Config != nil &&
len(audioFormatMPEG4AudioLATM.Config.Programs) == 1 &&
len(audioFormatMPEG4AudioLATM.Config.Programs[0].Layers) == 1 {
audioStartPTSFilled := false
var audioStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration

Check warning on line 478 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L477-L478

Added lines #L477 - L478 were not covered by tests

stream.AddReader(c, audioMedia, audioFormatMPEG4AudioLATM, func(unit formatprocessor.Unit) {

Check warning on line 480 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L480

Added line #L480 was not covered by tests
ringBuffer.Push(func() error {
Expand All @@ -485,11 +485,11 @@ func (c *rtmpConn) setupAudio(
return nil
}

if !audioStartPTSFilled {
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS

Check warning on line 490 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L488-L490

Added lines #L488 - L490 were not covered by tests
}
pts := tunit.PTS - audioStartPTS
pts := tunit.PTS - startPTS

Check warning on line 492 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L492

Added line #L492 was not covered by tests

if videoFormat != nil {
if !*videoFirstIDRFound {
Expand All @@ -514,18 +514,18 @@ func (c *rtmpConn) setupAudio(
audioMedia = stream.Medias().FindFormat(&audioFormatMPEG2)

Check warning on line 514 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L514

Added line #L514 was not covered by tests

if audioMedia != nil {
audioStartPTSFilled := false
var audioStartPTS time.Duration
startPTSFilled := false
var startPTS time.Duration

Check warning on line 518 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L517-L518

Added lines #L517 - L518 were not covered by tests

stream.AddReader(c, audioMedia, audioFormatMPEG2, func(unit formatprocessor.Unit) {

Check warning on line 520 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L520

Added line #L520 was not covered by tests
ringBuffer.Push(func() error {
tunit := unit.(*formatprocessor.UnitMPEG2Audio)

if !audioStartPTSFilled {
audioStartPTSFilled = true
audioStartPTS = tunit.PTS
if !startPTSFilled {
startPTSFilled = true
startPTS = tunit.PTS

Check warning on line 526 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L524-L526

Added lines #L524 - L526 were not covered by tests
}
pts := tunit.PTS - audioStartPTS
pts := tunit.PTS - startPTS

Check warning on line 528 in internal/core/rtmp_conn.go

View check run for this annotation

Codecov / codecov/patch

internal/core/rtmp_conn.go#L528

Added line #L528 was not covered by tests

if videoFormat != nil {
if !*videoFirstIDRFound {
Expand Down
Loading

0 comments on commit 3db6c80

Please sign in to comment.