std::vector<WebMediaPlayer::TrackId> SourceBuffer::initializationSegmentReceived(const std::vector<MediaTrackInfo>& newTracks)
{
    WTF_LOG(Media, "SourceBuffer::initializationSegmentReceived %p tracks=%zu", this, newTracks.size());
    ASSERT(m_source);
    ASSERT(m_source->mediaElement());
    ASSERT(m_updating);

    // TODO(servolk): Implement proper 'initialization segment received' algorithm according to MSE spec:
    // https://w3c.github.io/media-source/#sourcebuffer-init-segment-received
    std::vector<WebMediaPlayer::TrackId> result;
    for (const auto& trackInfo : newTracks) {
        const auto& trackType = std::get<0>(trackInfo);
        const auto& id = std::get<1>(trackInfo);
        const auto& kind = std::get<2>(trackInfo);
        const auto& label = std::get<3>(trackInfo);
        const auto& language = std::get<4>(trackInfo);

        if (!RuntimeEnabledFeatures::audioVideoTracksEnabled()) {
            static WebMediaPlayer::TrackId nextTrackId = 0;
            result.push_back(++nextTrackId);
            continue;
        }

        const TrackBase* trackBase = nullptr;
        if (trackType == WebMediaPlayer::AudioTrack) {
            AudioTrack* audioTrack = nullptr;
            if (!m_firstInitializationSegmentReceived) {
                audioTrack = AudioTrack::create(id, kind, label, language, false);
                audioTracks().add(audioTrack);
                m_source->mediaElement()->audioTracks().add(audioTrack);
            } else {
                audioTrack = findExistingTrackById(audioTracks(), id);
                ASSERT(audioTrack);
            }
            trackBase = audioTrack;
            result.push_back(audioTrack->trackId());
        } else if (trackType == WebMediaPlayer::VideoTrack) {
            VideoTrack* videoTrack = nullptr;
            if (!m_firstInitializationSegmentReceived) {
                videoTrack = VideoTrack::create(id, kind, label, language, false);
                videoTracks().add(videoTrack);
                m_source->mediaElement()->videoTracks().add(videoTrack);
            } else {
                videoTrack = findExistingTrackById(videoTracks(), id);
                ASSERT(videoTrack);
            }
            trackBase = videoTrack;
            result.push_back(videoTrack->trackId());
        } else {
            NOTREACHED();
        }
        (void)trackBase;
#if !LOG_DISABLED
        const char* logActionStr = m_firstInitializationSegmentReceived ? "using existing" : "added";
        const char* logTrackTypeStr = (trackType == WebMediaPlayer::AudioTrack) ? "audio" : "video";
        WTF_LOG(Media, "Tracks (sb=%p): %s %sTrack %p trackId=%d id=%s label=%s lang=%s", this, logActionStr, logTrackTypeStr, trackBase, trackBase->trackId(), trackBase->id().utf8().data(), trackBase->label().utf8().data(), trackBase->language().utf8().data());
#endif
    }

    if (!m_firstInitializationSegmentReceived) {
        // 5. If active track flag equals true, then run the following steps:
        // 5.1. Add this SourceBuffer to activeSourceBuffers.
        // 5.2. Queue a task to fire a simple event named addsourcebuffer at
        // activesourcebuffers.
        m_source->setSourceBufferActive(this);

        // 6. Set first initialization segment received flag to true.
        m_firstInitializationSegmentReceived = true;
    }

    return result;
}