@@ -12,9 +12,7 @@ import (
1212func CreateNewWHEP (
1313 whepSessionID string ,
1414 audioTrack * codecs.TrackMultiCodec ,
15- audioLayer string ,
1615 videoTrack * codecs.TrackMultiCodec ,
17- videoLayer string ,
1816 peerConnection * webrtc.PeerConnection ,
1917 pliSender func (),
2018) (w * WHEPSession ) {
@@ -31,10 +29,8 @@ func CreateNewWHEP(
3129 videoBitrateWindowStart : time .Now (),
3230 }
3331
34- log .Println ("WHEPSession.CreateNewWHEP.AudioLayer" , audioLayer )
35- log .Println ("WHEPSession.CreateNewWHEP.VideoLayer" , videoLayer )
36- w .AudioLayerCurrent .Store (audioLayer )
37- w .VideoLayerCurrent .Store (videoLayer )
32+ w .AudioLayerCurrent .Store ("" )
33+ w .VideoLayerCurrent .Store ("" )
3834 w .IsWaitingForKeyframe .Store (true )
3935 w .IsSessionClosed .Store (false )
4036 return w
@@ -106,15 +102,15 @@ func (w *WHEPSession) GetWHEPSessionStatus() (state SessionState) {
106102 return
107103}
108104
109- // Finds the corresponding WHIP session to the WHEP session id and sets the requested audio layer
105+ // Sets the requested audio layer for this WHEP session.
110106func (w * WHEPSession ) SetAudioLayer (encodingID string ) {
111107 log .Println ("Setting Audio Layer" )
112108 w .AudioLayerCurrent .Store (encodingID )
113109 w .IsWaitingForKeyframe .Store (true )
114110 w .SendPLI ()
115111}
116112
117- // Finds the corresponding WHIP session to the WHEP session id and sets the requested video layer
113+ // Sets the requested video layer for this WHEP session.
118114func (w * WHEPSession ) SetVideoLayer (encodingID string ) {
119115 log .Println ("Setting Video Layer" )
120116 w .VideoLayerCurrent .Store (encodingID )
@@ -127,10 +123,9 @@ func (w *WHEPSession) SendPLI() {
127123 return
128124 }
129125
130- if w .pliSender != nil {
131- w .pliSender ()
132- }
126+ w .pliSender ()
133127}
128+
134129func (w * WHEPSession ) updateVideoBitrateLocked (now time.Time ) {
135130 if w .videoBitrateWindowStart .IsZero () {
136131 w .videoBitrateWindowStart = now
@@ -151,3 +146,30 @@ func (w *WHEPSession) updateVideoBitrateLocked(now time.Time) {
151146 w .videoBitrateWindowStart = now
152147 w .videoBitrateWindowBytes = w .VideoBytesWritten
153148}
149+
150+ func (w * WHEPSession ) GetAudioLayerOrDefault (defaultLayer string ) string {
151+ w .AudioLock .Lock ()
152+ defer w .AudioLock .Unlock ()
153+
154+ currentLayer , _ := w .AudioLayerCurrent .Load ().(string )
155+ if currentLayer != "" {
156+ return currentLayer
157+ }
158+
159+ w .AudioLayerCurrent .Store (defaultLayer )
160+ return defaultLayer
161+ }
162+
163+ func (w * WHEPSession ) GetVideoLayerOrDefault (defaultLayer string ) string {
164+ w .VideoLock .Lock ()
165+ defer w .VideoLock .Unlock ()
166+
167+ currentLayer , _ := w .VideoLayerCurrent .Load ().(string )
168+ if currentLayer != "" {
169+ return currentLayer
170+ }
171+
172+ w .VideoLayerCurrent .Store (defaultLayer )
173+ w .IsWaitingForKeyframe .Store (true )
174+ return defaultLayer
175+ }
0 commit comments