/*
 * Copyright (C) 2011-2026 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#pragma once

#if ENABLE(VIDEO) && USE(AVFOUNDATION)

#include <CoreMedia/CMTime.h>
#include <WebCore/MediaPlayerPrivateAVFoundation.h>
#include <WebCore/SharedBuffer.h>
#include <WebCore/VideoFrameMetadata.h>
#include <wtf/Forward.h>
#include <wtf/MainThreadDispatcher.h>
#include <wtf/Observer.h>
#include <wtf/RobinHoodHashMap.h>
#include <wtf/WorkQueue.h>

OBJC_CLASS AVAssetImageGenerator;
OBJC_CLASS AVAssetTrack;
OBJC_CLASS AVAssetResourceLoadingRequest;
OBJC_CLASS AVMediaSelectionGroup;
OBJC_CLASS AVOutputContext;
OBJC_CLASS AVPlayerItem;
OBJC_CLASS AVPlayerItemLegibleOutput;
OBJC_CLASS AVPlayerItemMetadataCollector;
OBJC_CLASS AVPlayerItemMetadataOutput;
OBJC_CLASS AVPlayerItemVideoOutput;
OBJC_CLASS AVPlayerLayer;
OBJC_CLASS AVURLAsset;
OBJC_CLASS NSArray;
OBJC_CLASS NSMutableDictionary;
OBJC_CLASS WebCoreAVFLoaderDelegate;
OBJC_CLASS WebCoreAVFMovieObserver;

typedef struct CGImage *CGImageRef;
typedef struct CF_BRIDGED_TYPE(id) __CVBuffer *CVPixelBufferRef;
typedef struct OpaqueFigVideoTarget *FigVideoTargetRef;
typedef NSString *AVMediaCharacteristic;
typedef double NSTimeInterval;

namespace WebCore {

class AudioSourceProviderAVFObjC;
class AudioTrackPrivateAVFObjC;
class CDMInstanceFairPlayStreamingAVFObjC;
class CDMSessionAVFoundationObjC;
class ImageRotationSessionVT;
class InbandChapterTrackPrivateAVFObjC;
class InbandMetadataTextTrackPrivateAVF;
class MediaPlaybackTarget;
class MediaSelectionGroupAVFObjC;
class PixelBufferConformerCV;
class QueuedVideoOutput;
class VideoLayerManagerObjC;
class VideoTrackPrivateAVFObjC;
class WebCoreAVFResourceLoader;

class WEBCORE_EXPORT MediaPlayerPrivateAVFoundationObjC final : public MediaPlayerPrivateAVFoundation {
public:
    explicit MediaPlayerPrivateAVFoundationObjC(MediaPlayer&);
    virtual ~MediaPlayerPrivateAVFoundationObjC();

    static void registerMediaEngine(MediaEngineRegistrar);

    void setAsset(RetainPtr<id>&&);
    void didEnd(double) final;
    void metadataLoaded() final;

    void processCue(NSArray *, NSArray *, const MediaTime&);
    void flushCues();

    bool shouldWaitForLoadingOfResource(AVAssetResourceLoadingRequest *);
    void didCancelLoadingRequest(AVAssetResourceLoadingRequest *);
    void didStopLoadingRequest(AVAssetResourceLoadingRequest *);

#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
    RetainPtr<AVAssetResourceLoadingRequest> takeRequestForKeyURI(const String&);
    void setShouldContinueAfterKeyNeeded(bool) final;
#endif

    void playerItemStatusDidChange(int);
    void NODELETE playbackLikelyToKeepUpWillChange();
    void playbackLikelyToKeepUpDidChange(bool);
    void NODELETE playbackBufferEmptyWillChange();
    void playbackBufferEmptyDidChange(bool);
    void NODELETE playbackBufferFullWillChange();
    void playbackBufferFullDidChange(bool);
    void loadedTimeRangesDidChange(RetainPtr<NSArray>&&);
    void seekableTimeRangesDidChange(RetainPtr<NSArray>&&, NSTimeInterval, NSTimeInterval);
    void tracksDidChange(const RetainPtr<NSArray>&);
    void hasEnabledAudioDidChange(bool);
    void hasEnabledVideoDidChange(bool);
    void presentationSizeDidChange(FloatSize);
    void durationDidChange(const MediaTime&);
    void rateDidChange(double);
    void timeControlStatusDidChange(int);
    void metadataGroupDidArrive(const RetainPtr<NSArray>&, const MediaTime&);
    void metadataDidArrive(const RetainPtr<NSArray>&, const MediaTime&);
    void firstFrameAvailableDidChange(bool);
    void trackEnabledDidChange(bool);
    void NODELETE canPlayFastReverseDidChange(bool);
    void NODELETE canPlayFastForwardDidChange(bool);

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    void playbackTargetIsWirelessDidChange();
#endif

    void outputObscuredDueToInsufficientExternalProtectionChanged(bool);

    MediaTime currentTime() const final;
    void outputMediaDataWillChange();
    void processChapterTracks();

    Ref<WebCoreAVFResourceLoader> ensureAVFResourceLoader(AVAssetResourceLoadingRequest *);

    bool isAudible() const { return m_isAudible; }

private:
#if ENABLE(ENCRYPTED_MEDIA)
    void cdmInstanceAttached(CDMInstance&) final;
    void cdmInstanceDetached(CDMInstance&) final;
    void attemptToDecryptWithInstance(CDMInstance&) final;
    void setWaitingForKey(bool);
    bool waitingForKey() const final { return m_waitingForKey; }
#endif

    // engine support
    class Factory;
    static bool isAvailable();
    static void getSupportedTypes(HashSet<String>& types);
    static MediaPlayer::SupportsType supportsTypeAndCodecs(const MediaEngineSupportParameters&);
    static bool supportsKeySystem(const String& keySystem, const String& mimeType);
    static HashSet<SecurityOriginData> originsInMediaCache(const String&);
    static void clearMediaCache(const String&, WallTime modifiedSince);
    static void clearMediaCacheForOrigins(const String&, const HashSet<SecurityOriginData>&);

    void setBufferingPolicy(MediaPlayer::BufferingPolicy) final;

    void tracksChanged() final;

    void cancelLoad() final;

    void notifyTrackModeChanged() final;
    void synchronizeTextTrackState() final;

    bool timeIsProgressing() const final { return effectiveRate(); }
    void platformPageIsVisibleChanged(bool) final;
    void platformViewportVisibilityChanged(ViewportVisibility) final;

    void platformPlay() final;
    void platformPause() final;
    bool platformPaused() const final;
    void setVolumeLocked(bool) final;
    void setVolume(float) final;
    void setMuted(bool) final;
    void paint(GraphicsContext&, const FloatRect&) final;
    void paintCurrentFrameInContext(GraphicsContext&, const FloatRect&) final;
    PlatformLayer* platformLayer() const final;
#if ENABLE(VIDEO_PRESENTATION_MODE)
    RetainPtr<PlatformLayer> createVideoFullscreenLayer() final;
    void setVideoFullscreenLayer(PlatformLayer*, Function<void()>&& completionHandler) final;
    void updateVideoFullscreenInlineImage() final;
    void setVideoFullscreenFrame(const FloatRect&) final;
    void setVideoFullscreenGravity(MediaPlayer::VideoGravity) final;
    void setVideoFullscreenMode(MediaPlayer::VideoFullscreenMode) final;
    void videoFullscreenStandbyChanged() final;
#endif
    void setPlayerRate(double, std::optional<MonotonicTime>&& = std::nullopt);

#if PLATFORM(IOS_FAMILY)
    NSArray *timedMetadata() const final;
    String accessLog() const final;
    String errorLog() const final;
    void sceneIdentifierDidChange() final;
#endif

    bool supportsAcceleratedRendering() const final { return true; }
    MediaTime mediaTimeForTimeValue(const MediaTime&) const final;

    void createAVPlayer() final;
    void createAVPlayerItem() final;
    void createAVPlayerLayer();
    void createAVAssetForURL(const URL&) final;
    void createAVAssetForURL(const URL&, RetainPtr<NSMutableDictionary>);
    MediaPlayerPrivateAVFoundation::ItemStatus playerItemStatus() const final;
    MediaPlayerPrivateAVFoundation::AssetStatus assetStatus() const final;
    long assetErrorCode() const final;

    double seekableTimeRangesLastModifiedTime() const final;
    double liveUpdateInterval() const final;

    void checkPlayability();
    void setRateDouble(double) final;
    double rate() const final;
    double effectiveRate() const final;
    void setPreservesPitch(bool) final;
    void setPitchCorrectionAlgorithm(MediaPlayer::PitchCorrectionAlgorithm) final;
    void seekToTargetInternal(const SeekTarget&) final;
    unsigned long long totalBytes() const final;
    const PlatformTimeRanges& platformBufferedTimeRanges() const final;
    MediaTime platformMinTimeSeekable() const final;
    MediaTime platformMaxTimeSeekable() const final;
    MediaTime platformDuration() const final;
    MediaTime platformMaxTimeLoaded() const final;
    void beginLoadingMetadata() final;
    void sizeChanged() final;
    void resolvedURLChanged() final;

    bool isHLS() const final { return m_cachedAssetIsHLS.value_or(false); }

    bool hasAvailableVideoFrame() const final;

    void createContextVideoRenderer() final;
    void destroyContextVideoRenderer() final;

    void createVideoLayer() final;
    void destroyVideoLayer() final;

    bool hasContextRenderer() const final;
    bool hasLayerRenderer() const final;


    enum class ShouldAnimate : bool { No, Yes };
    void updateVideoLayerGravity() final { updateVideoLayerGravity(ShouldAnimate::No); }
    void updateVideoLayerGravity(ShouldAnimate);

    void updateIsAudible() final;

    bool didPassCORSAccessCheck() const final;
    std::optional<bool> isCrossOrigin(const SecurityOrigin&) const final;

    MediaTime getStartDate() const final;

    void setTextTrackRepresentation(TextTrackRepresentation*) final;
    void syncTextTrackBounds() final;

    void setAVPlayerItem(AVPlayerItem *);

#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
    AudioSourceProvider* audioSourceProvider() final;
#endif

    void createImageGenerator();
    void destroyImageGenerator();
    RetainPtr<CGImageRef> createImageForTimeInRect(float, const FloatRect&);

    using UpdateCompletion = CompletionHandler<void()>;
    void updateLastImage(NOESCAPE UpdateCompletion&&);

    void createVideoOutput();
    void destroyVideoOutput();
    bool updateLastPixelBuffer();
    bool videoOutputHasAvailableFrame();
    void paintWithVideoOutput(GraphicsContext&, const FloatRect&);
    RefPtr<VideoFrame> videoFrameForCurrentTime() final;
    RefPtr<NativeImage> nativeImageForCurrentTime() final;
    DestinationColorSpace colorSpace() final;

    enum class UpdateResult { Succeeded, Failed, TimedOut, ObjectDestroyed };
    UpdateResult waitForVideoOutputMediaDataWillChange();

#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
    void keyAdded() final;
    RefPtr<LegacyCDMSession> createSession(const String& keySystem, LegacyCDMSessionClient&) final;
#endif

    String languageOfPrimaryAudioTrack() const final;

    void processMediaSelectionOptions();
    bool hasLoadedMediaSelectionGroups();

    AVMediaSelectionGroup *safeMediaSelectionGroupForLegibleMedia();
    AVMediaSelectionGroup *safeMediaSelectionGroupForAudibleMedia();
    AVMediaSelectionGroup *safeMediaSelectionGroupForVisualMedia();

    AVAssetTrack* firstEnabledAudibleTrack() const;
    AVAssetTrack* firstEnabledVisibleTrack() const;
    AVAssetTrack* firstEnabledTrack(AVMediaCharacteristic) const;

#if ENABLE(DATACUE_VALUE)
    void processMetadataTrack();
#endif

    void setCurrentTextTrack(InbandTextTrackPrivateAVF*) final;
    ThreadSafeWeakPtr<InbandTextTrackPrivateAVF> currentTextTrack() const final { return m_currentTextTrack; }

    void updateAudioTracks();
    void updateVideoTracks();

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    bool hasVideo() const final;
    bool hasAudio() const final;
    bool isCurrentPlaybackTargetWireless() const final;
    String wirelessPlaybackTargetName() const final;
    MediaPlayer::WirelessPlaybackTargetType wirelessPlaybackTargetType() const final;
    bool wirelessVideoPlaybackDisabled() const final;
    void setWirelessVideoPlaybackDisabled(bool) final;
    OptionSet<MediaPlaybackTargetType> supportedPlaybackTargetTypes() const final;
    static OptionSet<MediaPlaybackTargetType> playbackTargetTypes();
    void updateDisableExternalPlayback();
#endif

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    void setWirelessPlaybackTarget(Ref<MediaPlaybackTarget>&&) final;
    void setShouldPlayToPlaybackTarget(bool) final;
#endif

    double maxFastForwardRate() const final { return m_cachedCanPlayFastForward ? std::numeric_limits<double>::infinity() : 2.0; }
    double minFastReverseRate() const final { return m_cachedCanPlayFastReverse ? -std::numeric_limits<double>::infinity() : 0.0; }

    Vector<String> preferredAudioCharacteristics() const;

    void setShouldDisableSleep(bool) final;
    void updateRotationSession();

    std::optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics() final;
    Ref<VideoPlaybackQualityMetricsPromise> asyncVideoPlaybackQualityMetrics() final;

#if !RELEASE_LOG_DISABLED
    ASCIILiteral logClassName() const final { return "MediaPlayerPrivateAVFoundationObjC"_s; }
#endif

    AVPlayer *objCAVFoundationAVPlayer() const final { return m_avPlayer.get(); }

    bool performTaskAtTime(Function<void(const MediaTime&)>&&, const MediaTime&) final;
    void setShouldObserveTimeControlStatus(bool);

    void setPreferredDynamicRangeMode(DynamicRangeMode) final;
    void setPlatformDynamicRangeLimit(PlatformDynamicRangeLimit) final;

    void audioOutputDeviceChanged() final;

    void currentTimeDidChange(MediaTime&&) const;
    bool setCurrentTimeDidChangeCallback(MediaPlayer::CurrentTimeDidChangeCallback&&) final;

    bool currentTimeIsBuffered() const;

    bool supportsPlayAtHostTime() const final { return true; }
    bool supportsPauseAtHostTime() const final { return true; }
    bool playAtHostTime(const MonotonicTime&) final;
    bool pauseAtHostTime(const MonotonicTime&) final;
    bool haveBeenAskedToPaint() const { return m_haveBeenAskedToPaint; }

    void startVideoFrameMetadataGathering() final;
    void stopVideoFrameMetadataGathering() final;
    std::optional<VideoFrameMetadata> videoFrameMetadata() final { return std::exchange(m_videoFrameMetadata, { }); }
    void setResourceOwner(const ProcessIdentity& resourceOwner) final { m_resourceOwner = resourceOwner; }

    void checkNewVideoFrameMetadata();

    void setShouldDisableHDR(bool) final;

    std::optional<bool> allTracksArePlayable() const;
    bool containsDisabledTracks() const;
    bool trackIsPlayable(AVAssetTrack*) const;

    std::optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics(AVPlayerLayer*) const;

    void setVideoTarget(const PlatformVideoTarget&) final;

#if HAVE(SPATIAL_TRACKING_LABEL)
    String defaultSpatialTrackingLabel() const;
    void setDefaultSpatialTrackingLabel(const String&) final;

    String spatialTrackingLabel() const;
    void setSpatialTrackingLabel(const String&) final;

    void updateSpatialTrackingLabel();
#endif

    void isInFullscreenOrPictureInPictureChanged(bool) final;

#if ENABLE(LINEAR_MEDIA_PLAYER)
    bool supportsLinearMediaPlayer() const final { return true; }
#endif


    void forEachResourceLoader(Function<void(WebCoreAVFResourceLoader&)>&&) const;
    void addResourceLoader(AVAssetResourceLoadingRequest *, Ref<WebCoreAVFResourceLoader>&&);
    RefPtr<WebCoreAVFResourceLoader> getResourceLoader(AVAssetResourceLoadingRequest *) const;
    RefPtr<WebCoreAVFResourceLoader> takeResourceLoader(AVAssetResourceLoadingRequest *);

#if HAVE(AVPLAYER_PARTICIPATESINAUDIOSESSION)
    void setParticipatesInAudioSession(bool);
#endif

    void updateLayerAttachment();
    bool shouldAttachLayerToPlayer();

#if PLATFORM(MAC)
    void screenReservedChanged(bool) final;
#endif

    RetainPtr<AVURLAsset> m_avAsset;
    RetainPtr<AVPlayer> m_avPlayer;
    RetainPtr<AVPlayerItem> m_avPlayerItem;
    RetainPtr<AVPlayerLayer> m_videoLayer WTF_GUARDED_BY_CAPABILITY(mainThread);
    const UniqueRef<VideoLayerManagerObjC> m_videoLayerManager;
    MediaPlayer::VideoGravity m_videoFullscreenGravity { MediaPlayer::VideoGravity::ResizeAspect };
    const RetainPtr<WebCoreAVFMovieObserver> m_objcObserver;
    RetainPtr<id> m_timeObserver;
    mutable String m_languageOfPrimaryAudioTrack;
    bool m_videoFrameHasDrawn { false };
    bool m_haveCheckedPlayability { false };
    bool m_createAssetPending { false };

#if ENABLE(LINEAR_MEDIA_PLAYER)
    RetainPtr<FigVideoTargetRef> m_videoTarget;
#endif

#if ENABLE(WEB_AUDIO) && USE(MEDIATOOLBOX)
    RefPtr<AudioSourceProviderAVFObjC> m_provider;
#endif

    RetainPtr<AVAssetImageGenerator> m_imageGenerator;
    RefPtr<QueuedVideoOutput> m_videoOutput;
    RetainPtr<CVPixelBufferRef> m_lastPixelBuffer;
    RefPtr<NativeImage> m_lastImage;
    std::unique_ptr<ImageRotationSessionVT> m_imageRotationSession;
    std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer;

    friend class WebCoreAVFResourceLoader;
    mutable Lock m_resourceLoaderMapLock;
    HashMap<RetainPtr<AVAssetResourceLoadingRequest>, Ref<WebCoreAVFResourceLoader>> m_resourceLoaderMap;
    const RetainPtr<WebCoreAVFLoaderDelegate> m_loaderDelegate;
    MemoryCompactRobinHoodHashMap<String, RetainPtr<AVAssetResourceLoadingRequest>> m_keyURIToRequestMap;

    RetainPtr<AVPlayerItemLegibleOutput> m_legibleOutput;

    Vector<Ref<AudioTrackPrivateAVFObjC>> m_audioTracks;
    Vector<Ref<VideoTrackPrivateAVFObjC>> m_videoTracks;
    RefPtr<MediaSelectionGroupAVFObjC> m_audibleGroup;
    RefPtr<MediaSelectionGroupAVFObjC> m_visualGroup;

    ThreadSafeWeakPtr<InbandTextTrackPrivateAVF> m_currentTextTrack;

#if ENABLE(DATACUE_VALUE)
    RefPtr<InbandMetadataTextTrackPrivateAVF> m_metadataTrack;
#endif

    MemoryCompactRobinHoodHashMap<String, Ref<InbandChapterTrackPrivateAVFObjC>> m_chapterTracks;

#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    RefPtr<MediaPlaybackTarget> m_playbackTarget;
#if PLATFORM(MAC)
    RetainPtr<AVOutputContext> m_outputContext;
#endif
#endif

#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
    WeakPtr<CDMSessionAVFoundationObjC> m_session;
    bool m_shouldContinueAfterKeyNeeded { false };
#endif

#if ENABLE(ENCRYPTED_MEDIA)
    bool m_waitingForKey { false };
#endif

#if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
    RefPtr<CDMInstanceFairPlayStreamingAVFObjC> m_cdmInstance;
#endif

    RetainPtr<AVPlayerItemMetadataCollector> m_metadataCollector;
    RetainPtr<AVPlayerItemMetadataOutput> m_metadataOutput;
    RetainPtr<id> m_currentTimeObserver;

    mutable RetainPtr<NSArray> m_cachedSeekableRanges;
    RetainPtr<NSArray> m_cachedTracks;
    RetainPtr<NSArray> m_currentMetaData;
    FloatSize m_cachedPresentationSize;
    mutable MediaPlayer::CurrentTimeDidChangeCallback m_currentTimeDidChangeCallback;
    mutable MediaTime m_cachedCurrentTime { -1, 1, 0 };
    mutable MediaTime m_lastPeriodicObserverMediaTime;
    mutable Markable<WallTime> m_wallClockAtCachedCurrentTime;
    mutable int m_timeControlStatusAtCachedCurrentTime { 0 };
    mutable double m_requestedRateAtCachedCurrentTime { 0 };
    RefPtr<SharedBuffer> m_keyID;
    double m_cachedRate { 0 };
    bool m_requestedPlaying { false };
    double m_requestedRate { 1.0 };
    double m_volume { 1 };
    int m_cachedTimeControlStatus { 0 };
    mutable long long m_cachedTotalBytes { 0 };
    unsigned m_pendingStatusChanges { 0 };
    int m_cachedItemStatus;
    int m_runLoopNestingLevel { 0 };
    MediaPlayer::BufferingPolicy m_bufferingPolicy { MediaPlayer::BufferingPolicy::Default };
    bool m_cachedLikelyToKeepUp { false };
    bool m_cachedBufferEmpty { false };
    bool m_cachedBufferFull { false };
    bool m_cachedHasEnabledAudio { false };
    bool m_cachedHasEnabledVideo { false };
    bool m_cachedIsReadyForDisplay { false };
    bool m_haveBeenAskedToCreateLayer { false };
    bool m_cachedCanPlayFastForward { false };
    bool m_cachedCanPlayFastReverse { false };
    mutable bool m_cachedAssetIsLoaded { false };
    mutable std::optional<bool> m_cachedAssetIsPlayable;
    mutable std::optional<bool> m_cachedTracksArePlayable;
    mutable std::optional<bool> m_cachedAssetIsHLS;
    bool m_volumeLocked { false };
    bool m_muted { false };
    bool m_preservesPitch { true };
    bool m_shouldObserveTimeControlStatus { false };
    bool m_isInFullscreenOrPictureInPicture { false };
    bool m_automaticallyWaitsToMinimizeStalling { false };
#if ENABLE(WIRELESS_PLAYBACK_TARGET)
    mutable bool m_allowsWirelessVideoPlayback { true };
    bool m_shouldPlayToPlaybackTarget { false };
#endif
    bool m_waitForVideoOutputMediaDataWillChangeTimedOut { false };
    bool m_haveBeenAskedToPaint { false };
    uint64_t m_sampleCount { 0 };
    RetainPtr<id> m_videoFrameMetadataGatheringObserver;
    bool m_isGatheringVideoFrameMetadata { false };
    bool m_isAudible { false };
    bool m_isVideoPlayer { false };
    std::optional<VideoFrameMetadata> m_videoFrameMetadata;
    mutable std::optional<NSTimeInterval> m_cachedSeekableTimeRangesLastModifiedTime;
    mutable std::optional<NSTimeInterval> m_cachedLiveUpdateInterval;
    RefPtr<Observer<void()>> m_currentImageChangedObserver;
    RefPtr<Observer<void()>> m_waitForVideoOutputMediaDataWillChangeObserver;
    ProcessIdentity m_resourceOwner;
    PlatformTimeRanges m_buffered;
    TrackID m_currentTextTrackID { 0 };
    const Ref<PlatformMediaResourceLoader> m_mediaResourceLoader;
    const Ref<GuaranteedSerialFunctionDispatcher> m_targetDispatcher;
#if HAVE(SPATIAL_TRACKING_LABEL)
    String m_defaultSpatialTrackingLabel;
    String m_spatialTrackingLabel;
#endif
#if !RELEASE_LOG_DISABLED
    uint64_t m_childIdentifierSeed { 0 };
#endif
};

}

SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::MediaPlayerPrivateAVFoundationObjC)
static bool isType(const WebCore::MediaPlayerPrivateInterface& player) { return player.mediaPlayerType() == WebCore::MediaPlayerType::AVFObjC; }
SPECIALIZE_TYPE_TRAITS_END()

#endif
