Skip to content

Commit

Permalink
check track muted once playing (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 authored Sep 19, 2023
1 parent 03611df commit 589f449
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pkg/pipeline/source/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (s *SDKSource) onTrackSubscribed(track *webrtc.TrackRemote, pub *lksdk.Remo
}
s.AudioTranscoding = true

writer, err := s.createWriter(track, rp, ts)
writer, err := s.createWriter(track, pub, rp, ts)
if err != nil {
onSubscribeErr = err
return
Expand All @@ -360,7 +360,7 @@ func (s *SDKSource) onTrackSubscribed(track *webrtc.TrackRemote, pub *lksdk.Remo
s.VideoTranscoding = true
}

writer, err := s.createWriter(track, rp, ts)
writer, err := s.createWriter(track, pub, rp, ts)
if err != nil {
onSubscribeErr = err
return
Expand Down Expand Up @@ -417,6 +417,7 @@ func (s *SDKSource) onTrackSubscribed(track *webrtc.TrackRemote, pub *lksdk.Remo

func (s *SDKSource) createWriter(
track *webrtc.TrackRemote,
pub lksdk.TrackPublication,
rp *lksdk.RemoteParticipant,
ts *config.TrackSource,
) (*sdk.AppWriter, error) {
Expand All @@ -435,7 +436,7 @@ func (s *SDKSource) createWriter(
}

ts.AppSrc = app.SrcFromElement(src)
writer, err := sdk.NewAppWriter(track, rp, ts, s.sync, s.callbacks, logFilename)
writer, err := sdk.NewAppWriter(track, pub, rp, ts, s.sync, s.callbacks, logFilename)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -505,6 +506,7 @@ func (s *SDKSource) onTrackFinished(trackID string) {

func (s *SDKSource) onParticipantDisconnected(rp *lksdk.RemoteParticipant) {
if rp.Identity() == s.Identity {
logger.Debugw("Participant disconnected")
s.onDisconnected()
}
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/pipeline/source/sdk/appwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
type AppWriter struct {
logger logger.Logger
logFile *os.File
pub lksdk.TrackPublication
track *webrtc.TrackRemote
codec types.MimeType
src *app.Source
Expand Down Expand Up @@ -83,6 +84,7 @@ type AppWriter struct {

func NewAppWriter(
track *webrtc.TrackRemote,
pub lksdk.TrackPublication,
rp *lksdk.RemoteParticipant,
ts *config.TrackSource,
sync *synchronizer.Synchronizer,
Expand All @@ -92,6 +94,7 @@ func NewAppWriter(
w := &AppWriter{
logger: logger.GetLogger().WithValues("trackID", track.ID(), "kind", track.Kind().String()),
track: track,
pub: pub,
codec: ts.MimeType,
src: ts.AppSrc,
callbacks: callbacks,
Expand Down Expand Up @@ -154,10 +157,18 @@ func (w *AppWriter) TrackID() string {
}

func (w *AppWriter) Play() {
w.playing.Break()
w.playing.Once(func() {
if w.pub.IsMuted() {
w.SetTrackMuted(true)
}
})
}

func (w *AppWriter) SetTrackMuted(muted bool) {
if !w.playing.IsBroken() {
return
}

w.muted.Store(muted)
if muted {
w.logger.Debugw("track muted", "timestamp", time.Since(w.startTime).Seconds())
Expand Down
1 change: 0 additions & 1 deletion test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func (r *Runner) publishSampleToRoom(t *testing.T, codec types.MimeType, withMut
if withMuting {
go func() {
muted := false
time.Sleep(time.Second * 15)
for {
select {
case <-done:
Expand Down

0 comments on commit 589f449

Please sign in to comment.