mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-27 10:00:24 +00:00
LibWeb: Set decoder error when decoding fails
This commit is contained in:
parent
2f10243fa2
commit
7c54a32870
Notes:
sideshowbarker
2024-07-17 00:53:02 +09:00
Author: https://github.com/MINAqwq Commit: https://github.com/SerenityOS/serenity/commit/7c54a32870 Pull-request: https://github.com/SerenityOS/serenity/pull/23936 Reviewed-by: https://github.com/Zaggy1024 Reviewed-by: https://github.com/trflynn89
3 changed files with 15 additions and 1 deletions
|
@ -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()
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
virtual Duration duration() = 0;
|
||||
|
||||
Function<void(Duration)> on_playback_position_updated;
|
||||
Function<void(String)> on_decoder_error;
|
||||
|
||||
protected:
|
||||
AudioCodecPlugin();
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue