LibWeb: Set decoder error when decoding fails

This commit is contained in:
MINAqwq 2024-04-11 23:08:46 +02:00 committed by Tim Flynn
parent 2f10243fa2
commit 7c54a32870
Notes: sideshowbarker 2024-07-17 00:53:02 +09:00
3 changed files with 15 additions and 1 deletions

View file

@ -37,6 +37,10 @@ AudioTrack::AudioTrack(JS::Realm& realm, JS::NonnullGCPtr<HTMLMediaElement> medi
auto playback_position = static_cast<double>(position.to_milliseconds()) / 1000.0;
m_media_element->set_current_playback_position(playback_position);
};
m_audio_plugin->on_decoder_error = [this](String error_message) {
m_media_element->set_decoder_error(error_message).release_value_but_fixme_should_propagate_errors();
};
}
AudioTrack::~AudioTrack()

View file

@ -35,6 +35,7 @@ public:
virtual Duration duration() = 0;
Function<void(Duration)> on_playback_position_updated;
Function<void(String)> on_decoder_error;
protected:
AudioCodecPlugin();

View file

@ -43,8 +43,17 @@ ErrorOr<NonnullOwnPtr<AudioCodecPluginAgnostic>> AudioCodecPluginAgnostic::creat
Audio::OutputState::Suspended, loader->sample_rate(), /* channels = */ 2, latency_ms,
[&plugin = *plugin, loader](Bytes buffer, Audio::PcmSampleFormat format, size_t sample_count) -> ReadonlyBytes {
VERIFY(format == Audio::PcmSampleFormat::Float32);
auto samples = loader->get_more_samples(sample_count).release_value_but_fixme_should_propagate_errors();
auto samples_result = loader->get_more_samples(sample_count);
if (samples_result.is_error()) {
plugin.on_decoder_error(MUST(String::formatted("Decoding failure: {}", samples_result.error())));
return buffer.trim(0);
}
auto samples = samples_result.release_value();
VERIFY(samples.size() <= sample_count);
FixedMemoryStream writing_stream { buffer };
for (auto& sample : samples) {