Skip to content

Commit

Permalink
Detect resolution change and reinit hw session (#2884)
Browse files Browse the repository at this point in the history
* Detect resolution change and reinit hw session

* Add log for requesting HW Session Reinit
  • Loading branch information
leszko authored Oct 10, 2023
1 parent 45a03e7 commit 75259e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ func processSegment(ctx context.Context, cxn *rtmpConnection, seg *stream.HLSSeg
}

clog.V(common.DEBUG).Infof(ctx, "Processing segment dur=%v bytes=%v", seg.Duration, len(seg.Data))
if segPar != nil && segPar.ForceSessionReinit {
clog.V(common.DEBUG).Infof(ctx, "Requesting HW Session Reinitialization for seg.SeqNo=%v", seg.SeqNo)
}
if monitor.Enabled {
monitor.SegmentEmerged(ctx, nonce, seg.SeqNo, len(BroadcastJobVideoProfiles), seg.Duration)
}
Expand Down
12 changes: 12 additions & 0 deletions server/mediaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type rtmpConnection struct {
lastUsed time.Time
sourceBytes uint64
transcodedBytes uint64
mu sync.Mutex
mediaFormat ffmpeg.MediaFormatInfo
}

func (s *LivepeerServer) getActiveRtmpConnectionUnsafe(mid core.ManifestID) (*rtmpConnection, bool) {
Expand Down Expand Up @@ -1012,6 +1014,16 @@ func (s *LivepeerServer) HandlePush(w http.ResponseWriter, r *http.Request) {
}
}()

// Reinitialize HW Session if video segment resolution has changed
cxn.mu.Lock()
if cxn.mediaFormat == (ffmpeg.MediaFormatInfo{}) {
cxn.mediaFormat = mediaFormat
} else if cxn.mediaFormat != mediaFormat {
cxn.mediaFormat = mediaFormat
segPar.ForceSessionReinit = true
}
cxn.mu.Unlock()

// Do the transcoding!
urls, err := processSegment(ctx, cxn, seg, &segPar)
if err != nil {
Expand Down

0 comments on commit 75259e3

Please sign in to comment.