Commit 8a6b8df
Datanoise
relay: fix stale-burst replay and false Ogg page alignment
Several related bugs in the audio path together caused two user-visible
symptoms: new listeners hearing old audio when the source was idle, and
glitched / shuffled audio on otherwise-healthy streams.
- Stream.Subscribe was bursting from Buffer.Head minus burst-size
unconditionally, so when a producer had been silent for a while a
new listener received seconds of stale buffered audio. Add a
FreshHead watermark plus a LastDataReceived > 2s freshness gate,
and have all producer entry points (icecast SOURCE, relay pull,
WebRTC source, transcoder, AutoDJ MP3/Opus encoders) call a new
Stream.BeginSession() that advances FreshHead and wipes stale Ogg
state at the start of each session.
- Stream.Broadcast tracked any byte sequence matching 'OggS' as a
page boundary, including false positives inside Opus packet
payloads. Validate the Ogg version byte (must be 0) before
recording an offset; same validation in the new
CircularBuffer.AlignToOggPage replacing the unsafe free function
in relay/ogg.go.
- Transcoder restarts re-initialised the Opus encoder with a fresh
serial number but left the old PageOffsets / OggHead behind, so
listeners could be aligned to bytes from a previous Ogg serial.
BeginSession now resets that state.
- OggHead / OggHeaderOffset and Buffer.Head / Buffer.Data were read
and written without locking from multiple goroutines. Add
Stream.SetOggHead / GetOggHead (defensive copy under lock) and
CircularBuffer.SnapshotHead / AlignToOggPage (under the buffer's
own lock) and route all callers through them.
- Subscribe's page-alignment fallback initialised bestAlign to
LastPageOffset and could end up walking the listener backwards
past the requested start. Search for the smallest tracked offset
>= start and otherwise fall back to Head (never backwards).1 parent db4fd8f commit 8a6b8df
8 files changed
Lines changed: 242 additions & 85 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | | - | |
116 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
| |||
146 | 152 | | |
147 | 153 | | |
148 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
149 | 207 | | |
150 | 208 | | |
151 | 209 | | |
| |||
188 | 246 | | |
189 | 247 | | |
190 | 248 | | |
191 | | - | |
192 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
193 | 260 | | |
194 | | - | |
195 | | - | |
| 261 | + | |
| 262 | + | |
196 | 263 | | |
197 | 264 | | |
198 | 265 | | |
| |||
265 | 332 | | |
266 | 333 | | |
267 | 334 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
271 | 348 | | |
272 | 349 | | |
273 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
274 | 355 | | |
275 | | - | |
276 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
277 | 359 | | |
278 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
279 | 364 | | |
280 | 365 | | |
281 | 366 | | |
282 | 367 | | |
283 | | - | |
284 | | - | |
| 368 | + | |
| 369 | + | |
285 | 370 | | |
286 | 371 | | |
287 | 372 | | |
288 | | - | |
289 | 373 | | |
290 | 374 | | |
291 | 375 | | |
292 | 376 | | |
293 | | - | |
294 | | - | |
295 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
296 | 382 | | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
301 | 387 | | |
302 | 388 | | |
303 | | - | |
304 | | - | |
305 | | - | |
| 389 | + | |
306 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
307 | 395 | | |
308 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
309 | 400 | | |
310 | 401 | | |
311 | 402 | | |
312 | 403 | | |
313 | | - | |
314 | | - | |
| 404 | + | |
| 405 | + | |
315 | 406 | | |
316 | 407 | | |
317 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
172 | 175 | | |
173 | 176 | | |
174 | 177 | | |
| |||
233 | 236 | | |
234 | 237 | | |
235 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
236 | 244 | | |
237 | 245 | | |
238 | 246 | | |
| |||
254 | 262 | | |
255 | 263 | | |
256 | 264 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
260 | 268 | | |
261 | 269 | | |
262 | 270 | | |
| |||
0 commit comments