Repository: LadybirdBrowser/ladybird
File: Libraries/LibMedia/PlaybackManager.cpp (C++)

Code before:
        playback_manager->m_audio_tracks.extend(move(audio_tracks));
        playback_manager->m_audio_track_datas.extend(move(audio_track_datas));
        playback_manager->m_preferred_video_track = preferred_video_track;
        playback_manager->m_preferred_audio_track = preferred_audio_track;
        playback_manager->m_duration = move(duration);

        playback_manager->set_up_error_handlers();

        if (!playback_manager->m_audio_tracks.is_empty()) {
            playback_manager->m_audio_sink = MUST(AudioMixingSink::try_create());
        }

        if (auto audio_sink = playback_manager->m_audio_sink) {
            VERIFY(playback_manager->current_time().is_zero());
            playback_manager->m_time_provider = make_ref_counted<WrapperTimeProvider<AudioMixingSink>>(*audio_sink);
        }

        if (playback_manager->on_track_added) {
            for (auto const& audio_track : playback_manager->m_audio_tracks)
                playback_manager->on_track_added(TrackType::Audio, audio_track);
            for (auto const& video_track : playback_manager->m_video_tracks)
                playback_manager->on_track_added(TrackType::Video, video_track);
        }

        if (playback_manager->on_metadata_parsed)
            playback_manager->on_metadata_parsed(playback_manager->m_duration);
    });

    return {};
}

NonnullRefPtr<PlaybackManager> PlaybackManager::create()
{
    auto playback_manager = adopt_ref(*new (nothrow) PlaybackManager());
    playback_manager->m_handler = make<PausedStateHandler>(*playback_manager);
    return playback_manager;
}

PlaybackManager::PlaybackManager()
    : m_weak_wrapper(make_ref_counted<WeakPlaybackManager>())
    , m_time_provider(make_ref_counted<GenericTimeProvider>())
{
    m_weak_wrapper->m_manager = this;
}

PlaybackManager::~PlaybackManager()
{
    m_weak_wrapper->revoke();
}

void PlaybackManager::add_media_source(ReadonlyBytes media_data)

Review comment (suggestion):
I think it makes sense to have `on_metadata_parsed` take no parameters, since the metadata should never change while running synchronously on the main thread, and it can be accessible through getters.

Code after:
        playback_manager->m_audio_tracks.extend(move(audio_tracks));
        playback_manager->m_audio_track_datas.extend(move(audio_track_datas));
        playback_manager->m_preferred_video_track = preferred_video_track;
        playback_manager->m_preferred_audio_track = preferred_audio_track;
        playback_manager->m_duration = move(duration);

        playback_manager->set_up_error_handlers();

        if (!playback_manager->m_audio_tracks.is_empty()) {
            playback_manager->m_audio_sink = MUST(AudioMixingSink::try_create());
        }

        if (auto audio_sink = playback_manager->m_audio_sink) {
            VERIFY(playback_manager->current_time().is_zero());
            playback_manager->m_time_provider = make_ref_counted<WrapperTimeProvider<AudioMixingSink>>(*audio_sink);
        }

        if (playback_manager->on_track_added) {
            for (auto const& audio_track : playback_manager->m_audio_tracks)
                playback_manager->on_track_added(TrackType::Audio, audio_track);
            for (auto const& video_track : playback_manager->m_video_tracks)
                playback_manager->on_track_added(TrackType::Video, video_track);
        }

        if (playback_manager->on_metadata_parsed)
            playback_manager->on_metadata_parsed();
    });

    return {};
}

NonnullRefPtr<PlaybackManager> PlaybackManager::create()
{
    auto playback_manager = adopt_ref(*new (nothrow) PlaybackManager());
    playback_manager->m_handler = make<PausedStateHandler>(*playback_manager);
    return playback_manager;
}

PlaybackManager::PlaybackManager()
    : m_weak_wrapper(make_ref_counted<WeakPlaybackManager>())
    , m_time_provider(make_ref_counted<GenericTimeProvider>())
{
    m_weak_wrapper->m_manager = this;
}

PlaybackManager::~PlaybackManager()
{
    m_weak_wrapper->revoke();
}

void PlaybackManager::add_media_source(ReadonlyBytes media_data)