Commit fe4e265
committed
fix(transcode): idle-gate encode loop + dedupe input/format/bitrate
Two CPU-side improvements on top of v2.2.1:
1. EncodeMP3 / EncodeOpus skip the encode + broadcast call when the
output mount has zero listeners. The decoder still drains so the
upstream input buffer doesn t overrun us, but the dominant work
(LAME / Opus encode + Broadcast write-lock + listener-signal
fan-out) is gated behind ListenersCount() > 0. Empty mounts now
cost only the decoder + a cheap atomic load per frame.
2. EnsureAutoMP3Transcoders dedupes against any existing transcoder
that produces the same input + format + bitrate, not only against
matching output-mount names. A manual entry like
/dnb -> /dnb-128 (mp3 128)
and an auto-spawn
/dnb -> /dnb-mp3-128 (mp3 128)
now collapse to one (the manual wins). The new snapshotInstances
helper covers the case where a manual transcoder is added at
runtime via the admin API after the auto twin already started.
Also lifts the streamWriter struct out of the per-frame loop in
EncodeMP3 — the struct is stateless across calls, so allocating
38 of them per second per transcoder was just GC pressure.
Empirically (10 transcoders, 3 source mounts):
v2.2.1 ~50 % CPU
+ remove 2 duplicate manual transcoders (config-side) ~22 %
+ idle-gate ~17 %
Total drop from the v2.2.0-era baseline: ~83 %.1 parent 73d4066 commit fe4e265
1 file changed
Lines changed: 70 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
375 | 380 | | |
376 | 381 | | |
377 | 382 | | |
| |||
382 | 387 | | |
383 | 388 | | |
384 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
385 | 400 | | |
386 | 401 | | |
387 | 402 | | |
388 | 403 | | |
389 | 404 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | 405 | | |
395 | 406 | | |
396 | 407 | | |
| |||
482 | 493 | | |
483 | 494 | | |
484 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
485 | 503 | | |
486 | 504 | | |
487 | 505 | | |
| |||
535 | 553 | | |
536 | 554 | | |
537 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
538 | 570 | | |
539 | 571 | | |
540 | 572 | | |
| |||
612 | 644 | | |
613 | 645 | | |
614 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
615 | 653 | | |
616 | 654 | | |
617 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
618 | 665 | | |
619 | 666 | | |
620 | 667 | | |
621 | 668 | | |
622 | 669 | | |
623 | 670 | | |
624 | 671 | | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
625 | 690 | | |
626 | 691 | | |
627 | 692 | | |
| |||
0 commit comments