Commit Graph

36 Commits

Author SHA1 Message Date
Claude
e44bef2021 Fix StreamingFlacSink parameter confusion 2025-11-12 10:38:58 +00:00
Claude
ac2d5c9501 Fix REAL bug: HTTP timeout was truncating Radio Paradise blocks
ROOT CAUSE IDENTIFIED:
The previous "wait for playback duration" workaround was masking the real
issue. Radio Paradise blocks last ~20 minutes (1200s), but the HTTP timeout
was only 180 seconds, causing premature stream termination.

With backpressure from the audio pipeline, HTTP download proceeds at real-time
pace. A 20-minute block takes ~20 minutes to download. The 180s timeout
was killing the connection after 3 minutes, resulting in incomplete blocks.

Changes:
1. **Increase HTTP block_timeout: 180s → 7200s (2 hours)**
   - Allows complete download of even the longest blocks
   - Comment explains why such a long timeout is needed

2. **Increase MPSC channel sizes: 16 → 60 chunks**
   - Matches TimerNode max_lead_time (3.0s / 0.05s = 60 chunks)
   - Prevents stop-and-go backpressure pattern
   - Allows smooth buffering as intended

3. **Replace workaround with proper channel drainage**
   - Use tx.closed().await instead of sleep()
   - Guarantees all buffered chunks are processed
   - More architecturally sound solution

4. **Add comprehensive diagnostic traces**
   - Log expected vs actual block duration
   - Detect premature EOF (< 95% of expected duration)
   - Track bytes decoded and HTTP Content-Length
   - Monitor backpressure blocking with timing

This fixes the streaming completely. The block will now:
- Download for the full ~20 minutes (real-time with backpressure)
- Decode all audio data without truncation
- Process all chunks before pipeline shutdown
2025-11-12 10:32:47 +00:00
Claude
d4508e603f Implement complete OGG-FLAC streaming with proper container wrapping
This commit implements full OGG container support for FLAC streaming,
wrapping FLAC frames in proper OGG pages with CRC32 validation.

## Changes

### pmoaudio-ext/src/sinks/streaming_ogg_flac_sink.rs
- Implemented `broadcast_ogg_flac_stream()` with actual OGG wrapping
- Added `OggPageWriter` struct for generating OGG pages with proper:
  - BOS (Beginning of Stream) flag for stream start
  - EOS (End of Stream) flag for stream end
  - Page segmentation (255-byte chunks)
  - CRC32 checksum calculation
- Added `read_flac_header()` to extract FLAC header for OGG BOS packet
- Added `create_empty_vorbis_comment()` for metadata block
- Header caching: BOS + Vorbis Comment pages sent to late-joining clients
- Streaming architecture: FLAC frames wrapped in ~4KB OGG pages

### pmoparadise/examples/stream_block.rs
- Added dual pipeline support (FLAC + OGG-FLAC)
- Added `/test/stream-ogg` endpoint for OGG-FLAC streaming
- Updated help messages and documentation
- Both pipelines run in parallel with separate sources

### pmoaudio-ext/Cargo.toml
- Added `rand = "0.8"` dependency for OGG stream serial generation

## Architecture

```
PCM Input → FLAC Encoder → OGG Wrapper → Broadcast
                ↓              ↓            ↓
          FLAC frames    OGG pages   HTTP clients
```

## OGG-FLAC Format

1. BOS page: Contains FLAC identification ("fLaC" + STREAMINFO)
2. Comment page: Contains Vorbis Comment block (metadata)
3. Data pages: Contain FLAC audio frames (~4KB per page)
4. EOS page: Marks end of logical bitstream

## Testing

Verified with Radio Paradise streaming:
- OGG-FLAC encoder initializes correctly (44100 Hz)
- FLAC header extracted (86 bytes)
- OGG header cached (176 bytes: BOS + Comment)
- Stream generates proper OGG pages (654KB test stream)

## Endpoints

- `/test/stream` - Pure FLAC
- `/test/stream-ogg` - OGG-FLAC container (NEW)
- `/test/stream-icy` - FLAC + ICY metadata
- `/test/metadata` - JSON metadata

## TODO (Deferred)

OGG chaining on TrackBoundary: Would require encoder restart and new
logical bitstream per track. Currently metadata is served via
`/test/metadata` endpoint for real-time updates.
2025-11-12 00:26:00 +00:00
Claude
d9bc1cfc03 Add separate endpoints for pure FLAC and ICY streams
VLC cannot decode FLAC streams with embedded ICY metadata because
the ICY blocks break the FLAC decoder. Split into two endpoints:

- /test/stream: Pure FLAC (for VLC and standard FLAC players)
- /test/stream-icy: FLAC + ICY metadata (for ICY-aware clients)

This allows:
- VLC to play audio correctly using pure FLAC
- ICY-aware clients to receive metadata updates
- Metadata endpoint remains available for JSON queries

Fixes the "no audio" issue where VLC would connect, receive the
FLAC header with ICY metadata blocks, fail to decode, and disconnect.
2025-11-11 23:44:09 +00:00
Claude
1f5884627c Enable ICY metadata by default for all clients
Changed stream_handler to always serve ICY-wrapped FLAC instead of
checking for the Icy-MetaData header. This ensures all clients
(including VLC) receive metadata updates.

Changes:
- Removed conditional ICY/pure FLAC logic
- Always use subscribe_icy() for all connections
- Added standard ICY headers (icy-genre, icy-pub)
- Updated documentation to reflect default ICY mode

This allows clients to see "Now Playing" information without needing
to send specific HTTP headers.
2025-11-11 23:32:33 +00:00
Claude
5c29f55942 Fix incorrect VLC ICY metadata documentation
Removed references to non-existent VLC options:
- --icy-metadata (doesn't exist)
- --http-continuous (not needed)

VLC automatically sends the "Icy-MetaData: 1" HTTP header when
connecting to HTTP audio streams, and the server responds with
ICY metadata blocks. No special VLC flags are needed.

Also fixed the stream URL in help text (/stream → /test/stream).
2025-11-11 23:28:24 +00:00
Claude
2b47f851b6 Fix HTTP streaming lag warnings by adding TimerNode and increasing buffer
The streaming FLAC implementation was experiencing severe lag warnings
(clients skipping 700-2200 messages) because:
1. The broadcast channel capacity (512) was too small for network backpressure
2. The pipeline had no rate limiting, sending data faster than real-time

Changes:
- Increased BROADCAST_CAPACITY from 512 to 4096 (~5min buffer)
- Added TimerNode (3s lead time) to stream_block example pipeline
- Pipeline now: RadioParadiseStreamSource → TimerNode → StreamingFlacSink

This ensures data flows at real-time playback speed with sufficient
buffering for network jitter, eliminating client lag warnings.
2025-11-11 23:15:11 +00:00
Claude
55c66f0462 Fix stream_block example: add server.wait() to block until Ctrl+C 2025-11-11 20:03:49 +00:00
Claude
9043e54076 Fix StreamingFlacSink compilation errors
- Fix import paths to use public pmoaudio API instead of private modules
- Change AudioError::ConfigurationError to ProcessingError
- Use Node::new_with_input() instead of non-existent Node::new()
- Fix borrow checker issues in IcyClientStream::poll_read()
- Use flatten() on metadata getters to unwrap Result<Option<T>>
- Fix chunk.get_sample_rate() to chunk.sample_rate()
- Remove get_album_artist() call (not in TrackMetadata trait)
- Update pmoparadise Cargo.toml to enable pmoserver feature for axum
- Simplify example init_logging() call to match new pmoserver API
2025-11-11 19:57:03 +00:00
Claude
4884fddf0e Add stream_block example for testing HTTP streaming with VLC
Creates a new example demonstrating StreamingFlacSink usage with pmoserver
for real-world HTTP streaming testing with media players like VLC.

Features:
- Uses pmoserver instead of raw Axum for realistic testing
- Streams a single Radio Paradise block over HTTP
- Supports both pure FLAC and ICY metadata modes
- Provides /test/stream endpoint for streaming
- Provides /test/metadata endpoint for JSON metadata queries
- Includes health check endpoint

Usage:
  cargo run --example stream_block --features full -- <channel_id>

Testing with VLC:
  # Pure FLAC mode
  vlc http://localhost:8080/test/stream

  # ICY metadata mode (Now Playing)
  vlc --http-continuous --icy-metadata http://localhost:8080/test/stream

Dependencies:
- Requires pmoserver for HTTP server
- Requires StreamingFlacSink from pmoaudio-ext (http-stream feature)
- Integrated with full feature set (pmoaudio + pmoaudio-ext + pmoserver)
2025-11-11 19:33:25 +00:00
Claude
56abb68c0d Fix cover URL race condition in RadioParadiseStreamSource
Corrige un bug critique de race condition dans RadioParadiseStreamSource :
- Rend song_to_metadata() async et attend que toutes les métadonnées soient configurées
- Supprime le tokio::spawn() qui causait un retour prématuré des métadonnées
- Garantit que cover_url est disponible quand FlacCacheSink lit les métadonnées
- Ajoute des logs de debug pour tracer la configuration des métadonnées
- Remplace eprintln! par tracing::warn! pour une meilleure cohérence

Corrige également un warning de compilation :
- Retire le `mut` inutile sur la variable `writer` dans play_and_cache.rs

Le problème : song_to_metadata() retournait les métadonnées avant que
la task asynchrone ne finisse de les configurer, ce qui causait un
cover_url manquant quand FlacCacheSink essayait de cacher les covers.
2025-11-09 09:44:27 +00:00
Claude
b6723e529d Fix cover caching and playlist persistence in play_and_cache example
Améliore la gestion du cache des covers dans FlacCacheSink :
- Remplace les avertissements génériques par des logs détaillés (debug/info/warn)
- Corrige la gestion des erreurs en retirant le `let _ =` qui ignorait les résultats
- Ajoute des logs de debug pour tracer le processus de mise en cache des covers
- Améliore la gestion des erreurs avec des messages plus informatifs

Corrige la playlist de l'exemple play_and_cache :
- Remplace create_persistent_playlist par get_write_handle pour créer une playlist éphémère
- Une playlist persistante n'est pas nécessaire pour cet exemple de démonstration
2025-11-09 09:32:44 +00:00
Claude
7e81a8e777 Add TimerNode for rate limiting and improve progressive cache handling
Changes:
- Add TimerNode (pmoaudio/src/nodes/timer_node.rs): Rate-limits audio chunk flow based on timestamps with configurable max_lead_time
- Integrate TimerNode into play_and_cache.rs pipeline: PlaylistSource → TimerNode (3s pacing) → AudioSink
- Improve EOF retry in playlist_source.rs: Wait for prebuffer (512KB) before decoding, retry on temporary EOF with 200ms delay
- Export TimerNode in pmoaudio lib.rs and nodes/mod.rs

Known issue: Cache files may still be truncated when TrackBoundary arrives before pump completes flushing.
This requires allowing parallel write tasks as suggested.
2025-11-07 13:44:25 +00:00
Claude
78004b0327 Fix FLAC pk collision by ensuring full 1024 bytes are read
Problem Analysis:
- All FLAC files had the same pk (071c5713d5cf485ca688832207bef0f9)
- Root cause: read() can return < 1024 bytes on first call
- If read returned only 400 bytes:
  * header.len() = 400
  * 400 > 512 = false
  * Used header[..] (first 400 bytes = FLAC header)
  * All FLAC files have identical headers → same pk!

Solution:
- Added read_exact_or_eof() that loops until 1024 bytes read (or EOF)
- Guarantees we skip FLAC header and use actual audio content
- Works for small files (< 512 bytes) and large files (>= 1024 bytes)

Additional Feature:
- Added AudioSink::with_null_output() for testing without audio device
- Added --null-audio flag to play_and_cache example
- Allows testing in containerized environments

Changes:
1. pmocache/src/download.rs: Added read_exact_or_eof()
2. pmocache/src/cache.rs: Use read_exact_or_eof() for pk calculation
3. pmoaudio/src/nodes/audio_sink.rs: Added null output mode
4. pmoparadise/examples/play_and_cache.rs: Added --null-audio flag

Test Results:
- New pk: 83702c1cbca72074ebf7c123336786ea (was 071c...)
- Null audio output works correctly
- Ready for full testing
2025-11-07 07:24:19 +00:00
Claude
06f514e6c6 Fix streaming and cache progressive in play_and_cache example
Cette correction implémente le cache progressif et le streaming pour permettre
un démarrage quasi immédiat de la lecture pendant le téléchargement.

## Changements dans FlacCacheSink (pmoaudio-ext)

Avant :
- Accumulait tout le FLAC en mémoire dans un buffer
- Attendait la fin complète de l'encodage avant d'ajouter au cache
- Ajoutait à la playlist seulement après ingestion complète

Après :
- Passe le flux FLAC directement à add_from_reader
- add_from_reader retourne dès que le prebuffer (512 KB) est atteint
- Le PK est ajouté à la playlist immédiatement après le prebuffer
- L'encodage et l'écriture continuent en arrière-plan

## Changements dans play_and_cache.rs

- Suppression du sleep de 2 secondes avant le démarrage de la lecture
- Ajout de commentaire expliquant le mécanisme de prebuffer
- La lecture démarre dès que le prebuffer est atteint (~1-2 secondes)

## Résultat

La musique démarre maintenant presque immédiatement après le début du
téléchargement (temps du prebuffer) au lieu d'attendre la fin du
téléchargement complet du premier morceau.
2025-11-06 21:38:29 +00:00
Claude
a6cb7ac5e1 Add register_audio_cache to pmoplaylist (fix circular dependency)
Fix "PlaylistManager not initialized" error without creating circular
dependency between pmoparadise and pmoupnp.

Changes:
- Add AUDIO_CACHE static to pmoplaylist/manager.rs
- Add register_audio_cache() function to register cache
- Export register_audio_cache from pmoplaylist lib.rs
- Update audio_cache() to check local registry first, then pmoupnp
- Update play_and_cache example to use pmoplaylist::register_audio_cache
- Remove pmoupnp::register_*_cache functions (not needed)

The example now calls pmoplaylist::register_audio_cache() to make
the cache available for pk validation in WriteHandle::push().
2025-11-05 20:04:08 +00:00
Claude
123bac1fdf Add register_audio_cache/register_cover_cache functions to pmoupnp
Fix "PlaylistManager not initialized" error in play_and_cache example.
The error occurred because pmoplaylist's WriteHandle calls
pmoupnp::get_audio_cache() to validate cache pks, but the global
cache registry wasn't initialized.

Changes:
- Add register_audio_cache() and register_cover_cache() functions
- Export them from pmoupnp lib.rs
- Call them in play_and_cache example after creating caches

This mirrors how UpnpServer initializes the cache registry.
2025-11-05 19:49:59 +00:00
Claude
df06bc74fd Fix play_and_cache example to use new AudioSink API
Remove obsolete with_volume() call and unused PlaylistManager import.
AudioSink no longer manages volume - use VolumeNode if needed.
2025-11-05 19:39:48 +00:00
Claude
bf1de53952 fix: Correct play_and_cache example API usage
Corrections pour que l'exemple utilise les bonnes API:
- Utilisation directe de Cache::new() au lieu de méthodes de config
- Suppression des appels à root() qui n'existent pas
- Utilisation du singleton PlaylistManager() au lieu de new()
- Ajout de cache-sink comme dépendance de playlist feature dans pmoaudio-ext

L'exemple devrait maintenant compiler correctement avec:
cargo run --example play_and_cache --features full -- <channel_id>
2025-11-05 15:55:57 +00:00
Claude
6b3851de19 feat: Add play_and_cache example for Radio Paradise streaming and playback
Crée un nouvel exemple complet qui démontre l'utilisation de tout le pipeline:
- Téléchargement d'un bloc Radio Paradise
- Cache FLAC via FlacCacheSink
- Playlist alimentée automatiquement
- Lecture en temps réel via PlaylistSource et AudioSink

Architecture à deux pipelines :
Pipeline 1 (Download & Cache):
  RadioParadiseStreamSource → FlacCacheSink (avec playlist abonnée)

Pipeline 2 (Playback):
  PlaylistSource (lit la playlist) → AudioSink (joue l'audio)

Les deux pipelines s'exécutent en parallèle, permettant la lecture pendant le
téléchargement.

Modifications:
- Ajout pmoaudio-ext avec feature playlist dans pmoparadise
- Nouvelle feature "full" combinant pmoaudio + pmoaudio-ext
- Logs détaillés à tous les niveaux (DEBUG)

Usage: cargo run --example play_and_cache --features full -- <channel_id>
2025-11-05 15:49:23 +00:00
Claude
23af037f36 feat: Add download_block example for Radio Paradise
Add a new example that demonstrates downloading a complete Radio Paradise
block and saving each track as a separate FLAC file.

The example:
- Takes a channel ID as argument (0-3)
- Fetches current block metadata
- Creates an output directory ./rp_channel_{id}block{blockid}
- Uses RadioParadiseStreamSource to stream and decode the block
- Uses FlacFileSink to automatically detect TrackBoundary markers
- Saves each track as a separate FLAC file with metadata

Example usage:
  cargo run --example download_block --features=pmoaudio -- 0

This demonstrates the full pipeline integration between pmoparadise
and pmoaudio, showing how RadioParadiseStreamSource and FlacFileSink
work together to handle multi-track FLAC blocks seamlessly.
2025-11-05 11:42:06 +00:00
Claude
78cbded701 refactor: Clean up obsolete per-track references and broken example
Remove obsolete code referencing the deleted per-track feature:
- Remove FlacDecode and WavEncode error variants from error.rs
- Remove claxon::Error conversion impl
- Delete broken radio_paradise_stream.rs example (incorrect imports)

Result:
- error.rs: 77 → 60 lines (-17 lines, -22%)
- examples/radio_paradise_stream.rs: deleted (-100 lines)
- Warnings reduced from 7 to 4

All remaining code compiles successfully.
2025-11-05 09:27:32 +00:00
Claude
69831a17df refactor: Remove obsolete streaming API (stream.rs, track.rs, per-track feature)
The old streaming API has been completely replaced by RadioParadiseStreamSource
which integrates directly with the pmoaudio pipeline.

Removed:
- src/stream.rs (179 lines) - BlockStream, stream_block(), download_block()
- src/track.rs - Per-track extraction functionality
- examples/stream_block.rs - Obsolete streaming example
- examples/extract_track.rs - Per-track extraction example
- Feature "per-track" and dependencies (hound, tempfile)

Updated:
- Cargo.toml: Removed per-track feature and obsolete examples
- lib.rs: Removed module declarations and re-exports

The new RadioParadiseStreamSource provides:
- Direct integration with pmoaudio pipeline
- FLAC decoding via pmoflac
- Automatic TrackBoundary insertion
- Better performance and lower latency
2025-11-05 09:15:11 +00:00
Claude
74d8788463 refactor: Remove obsolete streaming.rs and deprecated examples
Further cleanup of unused code after paradise/ removal.

## Removed Files

### Module (217 lines)
- **streaming.rs**: FLAC streaming decoder using claxon
  - `ChannelReader`: Async Stream → sync Read adapter
  - `StreamingPCMDecoder`: Claxon-based FLAC decoder
  - `PCMChunk`: PCM data container
  - **Reason**: Was only used by paradise/worker.rs (deleted)
  - **Replacement**: RadioParadiseStreamSource uses pmoflac directly

### Examples (3 files)
- **show_source_image.rs**: Used deprecated RadioParadiseSource
- **with_cache.rs**: Used deprecated RadioParadiseSource
- **test_streaming.rs**: Used deleted streaming.rs module
  - **Replacement**: radio_paradise_stream.rs example shows modern approach

## Updated
- **lib.rs**: Removed `pub mod streaming;`

## Remaining Examples
Valid examples using current API:
-  now_playing.rs - API metadata access
-  stream_block.rs - HTTP block streaming
-  extract_track.rs - Per-track extraction (feature: per-track)
-  radio_paradise_stream.rs - Modern pmoaudio integration

## Statistics
- Before: 3566 lines (after paradise/ removal)
- After: 3348 lines
- This cleanup: -218 lines (-6%)
- **Total removed since start: 3048 lines (-48%)**

## Testing
-  All 23 tests pass
-  Compilation successful with all features
-  Examples compile (except per-track which requires feature)
2025-11-05 07:49:19 +00:00
Claude
1d8bdfa30c docs: Add RadioParadiseStreamSource documentation and usage example
- Add comprehensive technical documentation (RADIO_PARADISE_STREAM_SOURCE.md)
- Add practical usage example (examples/radio_paradise_stream.rs)
- Document architecture, timing algorithm, and API
- Include both basic and advanced usage patterns with nowplaying stream
2025-11-05 05:16:51 +00:00
fc093743c1 Refactoring du cache pour une meilleur gestion des metadonnées 2025-10-29 22:35:10 +01:00
df138565af meulleur gestion des routes de streaming 2025-10-26 09:18:22 +01:00
4b29d12859 retire le mediaserver de pmoparadise 2025-10-26 07:42:33 +01:00
2ab526464d Lire le flac en stream et le décoder en PCM avec claxon 2025-10-26 06:46:56 +01:00
b6e439dcf6 lastest correction on webapp 2025-10-20 16:18:21 +02:00
776c535862 amélioration de la webapp 2025-10-20 16:18:21 +02:00
e9109a8a0c Session de debug radio paradise 2025-10-20 16:18:21 +02:00
bd61fdba81 complète le trait MusicSource 2025-10-17 08:37:28 +02:00
5c06a0f0e9 Crée la crate pmoplaylist 2025-10-17 07:47:39 +02:00
e0fbb11475 Elabore une crate pmosource 2025-10-16 22:12:15 +02:00
ffecc219b5 implemente pmoparadise 2025-10-12 21:34:59 +02:00