Skip to content

Commit c383795

Browse files
author
Datanoise
committed
refactor: update components to use new reusable I/O abstractions
- Update transcode.go to use new StreamReader from io.go - Update webrtc.go to use new StreamReader from io.go - Update server/handlers_stream.go to use FindNextPageBoundary from ogg.go - Maintain all existing functionality with cleaner architecture
1 parent 09f0e44 commit c383795

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

relay/transcode.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,7 @@ func (tm *TranscoderManager) performTranscode(ctx context.Context, inst *Transco
135135
offset, signal := input.Subscribe(id, 32*1024)
136136
defer input.Unsubscribe(id)
137137

138-
reader := &StreamReader{
139-
Stream: input,
140-
Offset: offset,
141-
Signal: signal,
142-
Ctx: ctx,
143-
ID: id,
144-
}
138+
reader := NewStreamReader(input.Buffer, offset, signal, ctx, id).WithOggSync(input)
145139

146140
// 3. Decode
147141
decoder, err := mp3.NewDecoder(reader)

relay/webrtc.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,11 @@ func (wm *WebRTCManager) streamToTrack(pc *webrtc.PeerConnection, track *webrtc.
248248
}
249249

250250
if !foundSync {
251-
logrus.Errorf("WebRTC: Could not find Ogg sync in first 512KB for %s. Is it an Opus stream?", stream.MountName)
251+
logrus.WithField("mount", stream.MountName).Error("WebRTC: Could not find Ogg sync in first 512KB. Is it an Opus stream?")
252252
return
253253
}
254254

255-
reader := &StreamReader{
256-
Stream: stream,
257-
Offset: offset,
258-
Signal: signal,
259-
Ctx: ctx,
260-
ID: id,
261-
}
255+
reader := NewStreamReader(stream.Buffer, offset, signal, ctx, id).WithOggSync(stream)
262256

263257
// We wrap the reader to prepend the OggHead if available.
264258
// This ensures NewOpusReader always sees the ID/Tag headers.

server/handlers_stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func (s *Server) serveStreamData(w http.ResponseWriter, r *http.Request, stream
327327

328328
n, next, skipped := stream.Buffer.ReadAt(offset, buf[:readLimit])
329329
if skipped && stream.IsOggStream {
330-
offset = stream.Buffer.FindNextPageBoundary(next)
330+
offset = relay.FindNextPageBoundary(stream.Buffer.Data, stream.Buffer.Size, stream.Buffer.Head, next)
331331
continue
332332
}
333333
if n == 0 {

0 commit comments

Comments
 (0)