Skip to main content

SourceBufferCore

Struct SourceBufferCore 

Source
pub struct SourceBufferCore {
Show 13 fields pub id: usize, pub mime_type: String, pub updating: bool, pub buffered: TimeRanges, pub mode: String, pub timestamp_offset: f64, pub append_window_start: f64, pub append_window_end: f64, pub samples: Vec<FragSample>, pub demux: Fmp4Demuxer, pub owner: usize, pub evicted_until_sec: f64, pub runtime: u64,
}
Expand description

個別トラックの SourceBuffer データ。 【2026-10-17】従来はバイト列を貯めて「100KB = 1 秒」と見なした buffered を返す仮実装だった。 fMP4 を Fmp4Demuxer で解析し、取り出したサンプルの表示時刻から buffered を作る。

Fields§

§id: usize§mime_type: String§updating: bool§buffered: TimeRanges§mode: String

"segments"(既定)または "sequence"。

§timestamp_offset: f64

セグメント内のタイムスタンプに加算するオフセット(秒)。

§append_window_start: f64

取り込む表示時刻の下限(秒、既定 0.0)。

§append_window_end: f64

取り込む表示時刻の上限(秒、既定 +∞)。

§samples: Vec<FragSample>

解析済みのサンプル(復号順。トラック情報は demux.tracks)。

§demux: Fmp4Demuxer§owner: usize

所属する MediaSource の番号(JS 側の _ms_id。0 は未所属)。

§evicted_until_sec: f64

evict_before で破棄した範囲の終わり(秒)。ここより前へのシークはデータの入れ直しを待つ。

§runtime: u64

作った JS の実行環境の番号(JsRuntime::runtime_id。0 は不明)。 【2026-11-17】その実行環境が捨てられた(ページ遷移・タブやウィンドウを閉じた・アプリを止めた)ときに この SourceBuffer も捨てる(TODO R2 (c) ②。remove_buffers_of_runtime)。

Implementations§

Source§

impl SourceBufferCore

Source

pub fn new(id: usize, mime_type: &str) -> Self

Source

pub fn set_mode(&mut self, mode: &str) -> Result<(), MseError>

Source

pub fn set_timestamp_offset(&mut self, offset: f64) -> Result<(), MseError>

Source

pub fn set_append_window_start(&mut self, start: f64) -> Result<(), MseError>

Source

pub fn set_append_window_end(&mut self, end: f64) -> Result<(), MseError>

Source

pub fn change_type(&mut self, mime_type: &str) -> Result<(), MseError>

changeType(type): 同一 SourceBuffer 上で後続セグメントの MIME タイプ・コーデックを切り替える。

Source

pub fn video_dimensions(&self) -> Option<(u32, u32)>

初期化セグメント(moov)から得られた映像トラックの (width, height)。

Source

pub fn append_buffer(&mut self, chunk: &[u8]) -> Result<(), MseError>

チャンクの追記(appendBuffer)。初期化セグメントもメディアセグメントも、任意の区切りで渡せる。

Source

fn update_buffered(&mut self)

buffered(秒): 最初のトラック(映像があれば映像)のサンプルの表示区間を併合したもの。

Source

pub fn remove_range(&mut self, start: f64, end: f64)

remove(start, end): 表示時刻が [start, end) 秒のサンプルを捨てる。

Source

pub fn total_samples_bytes(&self) -> usize

現在バッファ内に保持されている全サンプルの合計バイト数。

Source

pub fn evict_before( &mut self, current_time_sec: f64, keep_behind_sec: f64, ) -> usize

current_time - keep_behind_sec より前の古いサンプルをパージ(エビクション)してメモリを解放する。 破棄されたサンプルの件数を返す。

映像は GOP の途中で切らない: 閾値以前で最後のキーフレームより前だけを消す(残りの先頭が 参照先の無いフレームになり、そこへシークすると画が壊れるため)。手前にキーフレームが 無ければその映像トラックは消さない。

Source

pub fn seek_needs_refetch(&self, target: f64) -> bool

時刻 target へのシークが、evict_before で破棄した範囲に落ちていて、再生を始められる サンプル(映像はキーフレーム)がまだ無いか。真なら JS がデータを入れ直すまで待つ。

Source

pub fn find_next_sync_pts_after_gap( &self, current_time: f64, max_gap_sec: f64, ) -> Option<f64>

パケットロスや不連続チャンク到着によって生じた未バッファの PTS ギャップ(current_time が どの buffered 区間にも属さず、かつ後方に次の buffered 区間が存在する場合)を検出し、 次の利用可能なキーフレーム(または区間先頭)の表示時刻(秒)へジャンプすべき復帰先を返す。 ギャップ内でない場合や、max_gap_sec を超える大規模シーク待ちの場合は None を返す。

Source

pub fn abort(&mut self)

バッファのクリア(abort / remove)

Source

pub fn clear(&mut self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.