feat(audio): format detection and HTTP codec negotiation#25
Conversation
Implement Phase 1 roadmap item for sniffing audio containers (WAV, MP3, Ogg, FLAC) from magic bytes and MP3 sync, mapping Content-Type to the same codes, and rejecting obvious non-audio document responses when no audio signature is present. Host (oxide-browser): - Add audio_format module with sniffing, MIME helpers, AUDIO_HTTP_ACCEPT, and unit tests. - Register api_audio_detect_format, api_audio_play_with_format, api_audio_channel_play_with_format, api_audio_last_url_content_type. - Extend api_audio_play_url with Accept header, Content-Type capture, MIME vs sniff warnings, and fast-fail (-4) for document-like bodies. - Add HostState::last_audio_url_content_type and audio_try_play hint helper with mismatch warnings. SDK (oxide-sdk): - Add AudioFormat enum and wrappers for detect, play with hint, channel play with hint, and last URL Content-Type string. ROADMAP: mark Audio format detection and codec negotiation as shipped. Made-with: Cursor
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis change implements audio format detection and codec negotiation for the oxide-browser audio subsystem. A new audio_format module provides container signature sniffing and MIME-type parsing to identify audio formats. New host APIs enable SDK guests to detect formats from byte buffers, retrieve last-fetched Content-Type headers, and play audio with format hints. The host now validates that fetched audio URLs return actual audio content rather than error pages. Changes
Sequence DiagramsequenceDiagram
participant Guest as Guest (SDK)
participant Host as Host (Browser)
participant Network as Network (HTTP)
Guest->>Host: audio_play_url(url)
Host->>Network: Fetch audio data
Network-->>Host: Response + Content-Type header
Host->>Host: Store Content-Type<br/>(last_audio_url_content_type)
Host->>Host: Sniff format from bytes<br/>(magic signatures)
Host->>Host: Validate not HTML/error<br/>(MIME checks)
alt Format valid & signature found
Host->>Host: Play audio data
Host-->>Guest: Success
else Non-audio document or no signature
Host-->>Guest: Return -4 (error)
end
Guest->>Host: audio_play_with_format(data, format_hint)
Host->>Host: Sniff format from bytes
alt Hint matches sniffed format
Host->>Host: Play audio on channel 0
Host-->>Guest: Success
else Hint mismatch
Host->>Host: Log warning, play anyway
Host-->>Guest: Success
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Implement Phase 1 roadmap item for sniffing audio containers (WAV, MP3, Ogg, FLAC) from magic bytes and MP3 sync, mapping Content-Type to the same codes, and rejecting obvious non-audio document responses when no audio signature is present.
Host (oxide-browser):
SDK (oxide-sdk):
ROADMAP: mark Audio format detection and codec negotiation as shipped.
Made-with: Cursor
Summary by CodeRabbit
Release Notes