Skip to content

Commit 235db39

Browse files
author
Datanoise
committed
fix: use OutputMount as unique key for transcoder management to prevent instance conflicts
1 parent 3c70866 commit 235db39

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

relay/transcode.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type TranscoderInstance struct {
3030
}
3131

3232
type TranscoderManager struct {
33-
instances map[string]*TranscoderInstance // key is Name
33+
instances map[string]*TranscoderInstance // key is OutputMount
3434
mu sync.RWMutex
3535
relay *Relay
3636
}
@@ -46,7 +46,7 @@ func (tm *TranscoderManager) StartTranscoder(cfg *config.TranscoderConfig) {
4646
tm.mu.Lock()
4747
defer tm.mu.Unlock()
4848

49-
if inst, ok := tm.instances[cfg.Name]; ok {
49+
if inst, ok := tm.instances[cfg.OutputMount]; ok {
5050
inst.Stop()
5151
}
5252

@@ -57,17 +57,17 @@ func (tm *TranscoderManager) StartTranscoder(cfg *config.TranscoderConfig) {
5757
active: true,
5858
StartTime: time.Now(),
5959
}
60-
tm.instances[cfg.Name] = inst
60+
tm.instances[cfg.OutputMount] = inst
6161

6262
go tm.runTranscoder(ctx, inst)
6363
}
6464

65-
func (tm *TranscoderManager) StopTranscoder(name string) {
65+
func (tm *TranscoderManager) StopTranscoder(outputMount string) {
6666
tm.mu.Lock()
6767
defer tm.mu.Unlock()
68-
if inst, ok := tm.instances[name]; ok {
68+
if inst, ok := tm.instances[outputMount]; ok {
6969
inst.Stop()
70-
delete(tm.instances, name)
70+
delete(tm.instances, outputMount)
7171
}
7272
}
7373

@@ -299,10 +299,10 @@ func (w *streamWriter) Write(p []byte) (n int, err error) {
299299
return len(p), nil
300300
}
301301

302-
func (tm *TranscoderManager) GetInstance(name string) *TranscoderInstance {
302+
func (tm *TranscoderManager) GetInstance(outputMount string) *TranscoderInstance {
303303
tm.mu.RLock()
304304
defer tm.mu.RUnlock()
305-
return tm.instances[name]
305+
return tm.instances[outputMount]
306306
}
307307

308308
type TranscoderStats struct {

server/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ func (s *Server) handleToggleTranscoder(w http.ResponseWriter, r *http.Request)
19971997
if tc.Enabled {
19981998
s.TranscoderM.StartTranscoder(tc)
19991999
} else {
2000-
s.TranscoderM.StopTranscoder(tc.Name)
2000+
s.TranscoderM.StopTranscoder(tc.OutputMount)
20012001
}
20022002
break
20032003
}
@@ -2016,11 +2016,12 @@ func (s *Server) handleDeleteTranscoder(w http.ResponseWriter, r *http.Request)
20162016
for _, tc := range s.Config.Transcoders {
20172017
if tc.Name != name {
20182018
newTCs = append(newTCs, tc)
2019+
} else {
2020+
s.TranscoderM.StopTranscoder(tc.OutputMount)
20192021
}
20202022
}
20212023
s.Config.Transcoders = newTCs
20222024
s.Config.SaveConfig()
2023-
s.ReloadConfig(s.Config)
20242025
http.Redirect(w, r, "/admin#tab-transcoding", http.StatusSeeOther)
20252026
}
20262027

@@ -2032,7 +2033,7 @@ func (s *Server) handleTranscoderStats(w http.ResponseWriter, r *http.Request) {
20322033

20332034
var stats []relay.TranscoderStats
20342035
for _, tc := range s.Config.Transcoders {
2035-
inst := s.TranscoderM.GetInstance(tc.Name)
2036+
inst := s.TranscoderM.GetInstance(tc.OutputMount)
20362037
uptime := "OFF"
20372038
var frames, bytes int64
20382039
active := false

0 commit comments

Comments
 (0)