fix(whip): wire teardown hook in NewWHIPHandler constructor (mirrors WHEP NewHandler pattern)
This commit is contained in:
parent
1be78a8185
commit
7f545962f6
1 changed files with 13 additions and 2 deletions
|
|
@ -36,6 +36,10 @@ type WHIPHandler struct {
|
||||||
// NewWHIPHandler wraps the subsystem in an Echo-compatible WHIP handler.
|
// NewWHIPHandler wraps the subsystem in an Echo-compatible WHIP handler.
|
||||||
// maxPublishers caps concurrent ingest sessions across all streams;
|
// maxPublishers caps concurrent ingest sessions across all streams;
|
||||||
// pass 0 to default to 64.
|
// pass 0 to default to 64.
|
||||||
|
//
|
||||||
|
// The constructor registers a teardown hook on the Subsystem so that
|
||||||
|
// when a process stops, any active WHIP publisher is closed automatically
|
||||||
|
// (mirroring the pattern used by the WHEP NewHandler).
|
||||||
func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler {
|
func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler {
|
||||||
total := int64(maxPublishers)
|
total := int64(maxPublishers)
|
||||||
if total <= 0 {
|
if total <= 0 {
|
||||||
|
|
@ -47,6 +51,12 @@ func NewWHIPHandler(s *Subsystem, maxPublishers int) *WHIPHandler {
|
||||||
ingestStream: make(map[string]string),
|
ingestStream: make(map[string]string),
|
||||||
maxCapTotal: total,
|
maxCapTotal: total,
|
||||||
}
|
}
|
||||||
|
// Wire the WHIP teardown hook so onWHIPProcessStop notifies us
|
||||||
|
// before releasing the port allocation — same pattern as WHEP's
|
||||||
|
// NewHandler → s.SetTeardownHook(h.tearDownStreamPeers).
|
||||||
|
if s != nil {
|
||||||
|
s.SetWHIPTeardownHook(h.tearDownStreamIngests)
|
||||||
|
}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,8 +323,9 @@ func (h *WHIPHandler) awaitIngestClose(resource string, peer *corewebrtc.IngestP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tearDownStreamIngests is called by the Subsystem's onWHIPProcessStop
|
// tearDownStreamIngests is called by the Subsystem's SetWHIPTeardownHook
|
||||||
// hook to close any active publisher when the FFmpeg process stops.
|
// to close any active publisher when the FFmpeg process stops.
|
||||||
|
// Not exported — registered internally via NewWHIPHandler.
|
||||||
func (h *WHIPHandler) tearDownStreamIngests(streamID string) {
|
func (h *WHIPHandler) tearDownStreamIngests(streamID string) {
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
bucket := h.ingestByStream[streamID]
|
bucket := h.ingestByStream[streamID]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue