mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibMedia/Audio: Use duration in the container if stream doesn't have one
This commit is contained in:
parent
b789ba5e5f
commit
4df2de2f20
Notes:
github-actions[bot]
2025-03-13 18:34:50 +00:00
Author: https://github.com/Lubrsi
Commit: 4df2de2f20
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3892
Reviewed-by: https://github.com/ADKaster
1 changed files with 14 additions and 3 deletions
|
@ -90,9 +90,20 @@ ErrorOr<void> FFmpegLoaderPlugin::initialize()
|
|||
|
||||
// This is an initial estimate of the total number of samples in the stream.
|
||||
// During decoding, we might need to increase the number as more frames come in.
|
||||
double duration_in_seconds = static_cast<double>(m_audio_stream->duration) * time_base();
|
||||
if (duration_in_seconds < 0)
|
||||
auto duration_in_seconds = TRY([this] -> ErrorOr<double> {
|
||||
if (m_audio_stream->duration >= 0) {
|
||||
auto time_base = av_q2d(m_audio_stream->time_base);
|
||||
return static_cast<double>(m_audio_stream->duration) * time_base;
|
||||
}
|
||||
|
||||
// If the stream doesn't specify the duration, fallback to what the container says the duration is.
|
||||
// If the container doesn't know the duration, then we're out of luck. Return an error.
|
||||
if (m_format_context->duration < 0)
|
||||
return Error::from_string_literal("Negative stream duration");
|
||||
|
||||
return static_cast<double>(m_format_context->duration) / AV_TIME_BASE;
|
||||
}());
|
||||
|
||||
m_total_samples = AK::round_to<decltype(m_total_samples)>(sample_rate() * duration_in_seconds);
|
||||
|
||||
// Allocate packet (logical chunk of data) and frame (video / audio frame) buffers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue