Skip to main content

Module segment_cache

Module segment_cache 

Source
Expand description

Segment-aware cache optimized for media streaming (HLS/DASH segments).

Media streaming protocols like HLS and DASH split content into short segments — individually addressable byte ranges that are requested sequentially per stream. A general-purpose cache is sub-optimal for this workload because:

  • Segments from the same stream must be evicted together or in sequence- order; random-key eviction damages buffering performance.
  • Played (consumed) segments are rarely re-requested and can be evicted early to free room for upcoming segments.
  • Clients typically need lookahead prefetch hints so the application layer can start fetching segments before they are requested.

SegmentCache addresses all of these requirements with a byte-budget and per-stream sequence ordering.

§Example

use oximedia_cache::segment_cache::{
    MediaSegment, SegmentCache, SegmentCacheConfig, SegmentRef,
};

let config = SegmentCacheConfig {
    max_segments: 128,
    max_bytes: 64 * 1024 * 1024,
    prefetch_ahead: 3,
    evict_played: true,
};
let mut cache = SegmentCache::new(config);

let seg = MediaSegment {
    segment_id: "stream1-0000".to_string(),
    stream_id:  "stream1".to_string(),
    sequence:   0,
    duration_secs: 6.0,
    data:       vec![0u8; 1024],
    content_type: "video/mp2t".to_string(),
};
cache.insert(seg).expect("insert");

let r = SegmentRef { stream_id: "stream1".to_string(), sequence: 0 };
assert!(cache.get(&r).is_some());

Structs§

MediaSegment
A single media segment as stored in the cache.
SegmentCache
Segment-aware cache for HLS/DASH media segments.
SegmentCacheConfig
Configuration for SegmentCache.
SegmentCacheStats
Snapshot of SegmentCache statistics.
SegmentRef
Lightweight reference used as a cache look-up key.

Enums§

SegmentCacheError
Errors that can occur during segment cache operations.