LibMedia+LibWeb: Prefer MatroskaDemuxer for media playback

MatroskaDemuxer supports multiple streams already, and gives us a bit
more control over seeking.
This commit is contained in:
Zaggy1024 2025-09-27 15:11:06 -05:00 committed by Jelle Raaijmakers
parent 0ff330c906
commit dfe59b8a4f
3 changed files with 10 additions and 4 deletions

View File

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibMedia/Containers/Matroska/MatroskaDemuxer.h>
#include <LibMedia/FFmpeg/FFmpegDemuxer.h>
#include <LibMedia/MutexedDemuxer.h>
#include <LibMedia/Providers/AudioDataProvider.h>
@ -16,9 +17,14 @@
namespace Media {
DecoderErrorOr<NonnullRefPtr<PlaybackManager>> PlaybackManager::try_create(NonnullOwnPtr<SeekableStream>&& stream)
DecoderErrorOr<NonnullRefPtr<PlaybackManager>> PlaybackManager::try_create(ReadonlyBytes data)
{
auto inner_demuxer = DECODER_TRY_ALLOC(FFmpeg::FFmpegDemuxer::create(move(stream)));
auto inner_demuxer = TRY([&] -> DecoderErrorOr<NonnullRefPtr<Demuxer>> {
auto matroska_result = Matroska::MatroskaDemuxer::from_data(data);
if (!matroska_result.is_error())
return matroska_result.release_value();
return DECODER_TRY_ALLOC(FFmpeg::FFmpegDemuxer::create(make<FixedMemoryStream>(data)));
}());
auto demuxer = DECODER_TRY_ALLOC(try_make_ref_counted<MutexedDemuxer>(inner_demuxer));
// Create the weak wrapper.

View File

@ -36,7 +36,7 @@ public:
using AudioTracks = Vector<Track, EXPECTED_AUDIO_TRACK_COUNT>;
static DecoderErrorOr<NonnullRefPtr<PlaybackManager>> try_create(NonnullOwnPtr<SeekableStream>&& stream);
static DecoderErrorOr<NonnullRefPtr<PlaybackManager>> try_create(ReadonlyBytes data);
~PlaybackManager();
AK::Duration current_time() const;

View File

@ -1173,7 +1173,7 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::process_media_data(Function<void(Str
{
auto& realm = this->realm();
auto playback_manager_result = Media::PlaybackManager::try_create(make<FixedMemoryStream>(m_media_data.bytes()));
auto playback_manager_result = Media::PlaybackManager::try_create(m_media_data.bytes());
// -> If the media data cannot be fetched at all, due to network errors, causing the user agent to give up trying to fetch the resource
// -> If the media data can be fetched but is found by inspection to be in an unsupported format, or can otherwise not be rendered at all