Skip to content

Commit a643261

Browse files
committed
AudioMixerにMediaProcessorトレイトの実装を追加(process_outputは未実装)
1 parent 090cb8f commit a643261

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/mixer_audio.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,68 @@ impl AudioMixer {
397397
}
398398
*/
399399
}
400+
401+
impl MediaProcessor for AudioMixer {
402+
fn spec(&self) -> MediaProcessorSpec {
403+
MediaProcessorSpec {
404+
input_stream_ids: self.input_streams.keys().copied().collect(),
405+
output_stream_ids: vec![self.output_stream_id],
406+
stats: ProcessorStats::AudioMixer(self.stats.clone()),
407+
}
408+
}
409+
410+
fn process_input(&mut self, input: MediaProcessorInput) -> orfail::Result<()> {
411+
let input_stream = self
412+
.input_streams
413+
.iter_mut()
414+
.find_map(|(&id, v)| (id == input.stream_id).then_some(v))
415+
.or_fail()?;
416+
if let Some(sample) = input.sample {
417+
let data = sample.expect_audio_data().or_fail()?;
418+
419+
if input_stream.start_timestamp.is_none() {
420+
// 合成開始時刻の判断用に最初のタイムスタンプを覚えておく
421+
//
422+
// なお開始時刻に達した後は、データのタイムスタンプにギャップがあったとしても
423+
// 連続しているものとして扱う。
424+
//
425+
// これは Chrome を含む多くのブラウザがこの挙動なのと、
426+
// ギャップ部分のハンドリングは Sora 側の責務であるため。
427+
// 下手に Hisui 側でハンドリングしてしまうと、ギャップが
428+
// 極端に大きいためにあえて Sora がそのまま放置した区間を
429+
// 埋めようとしてディスクやメモリを食いつぶしてしまう恐れがある。
430+
input_stream.start_timestamp = Some(data.timestamp);
431+
}
432+
433+
// サンプルキューに要素を追加する
434+
//
435+
// 想定外の入力が来ていないかを念のためにチェックする
436+
// (format と stereo については stereo_samples() の中でチェックしている)
437+
(data.sample_rate == SAMPLE_RATE).or_fail()?;
438+
input_stream
439+
.sample_queue
440+
.extend(data.stereo_samples().or_fail()?);
441+
} else {
442+
input_stream.eos = true;
443+
}
444+
Ok(())
445+
}
446+
447+
fn process_output(&mut self) -> orfail::Result<MediaProcessorOutput> {
448+
/*
449+
if let Some(data) = self.encoded.pop_front() {
450+
Ok(MediaProcessorOutput::Processed {
451+
stream_id: self.output_stream_id,
452+
sample: MediaSample::audio_data(data),
453+
})
454+
} else if self.eos {
455+
Ok(MediaProcessorOutput::Finished)
456+
} else {
457+
Ok(MediaProcessorOutput::Pending {
458+
awaiting_stream_id: self.input_stream_id,
459+
})
460+
}
461+
*/
462+
todo!()
463+
}
464+
}

0 commit comments

Comments
 (0)