2011-05-05 Eric Carlson <eric.carlson@apple.com>
authorEric Carlson <eric.carlson@apple.com>
Thu, 5 May 2011 18:17:23 +0000 (18:17 +0000)
committerAdemar de Souza Reis Jr <ademar.reis@openbossa.org>
Fri, 3 Jun 2011 20:36:45 +0000 (17:36 -0300)
commitdf47be25abb20f21305ec0ff5dfe724e20007b05
tree6d93143887e76cb085bcf109b6a3a2d3b1a0605f
parent2e981d382127127856ecdd06e086dbb42ae1e52e
2011-05-05  Eric Carlson  <eric.carlson@apple.com>

        Reviewed by Adam Roben.

        The preload attribute of the video tag is not completely implemented
        https://bugs.webkit.org/show_bug.cgi?id=43673
        <rdar://problem/9369746>

        This change implements "preload=metadata" for the AVFoundation backend.
        Tested manually with manual-tests/media-elements/video-preload.html.

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_havePreparedToPlay.
        (WebCore::HTMLMediaElement::prepareForLoad): Ditto.
        (WebCore::HTMLMediaElement::prepareToPlay): New, tell player to prepare to play.
        (WebCore::HTMLMediaElement::seek): Call prepareToPlay when preload is less than 'auto'
            because we need to have media data loaded to seek.
        (WebCore::HTMLMediaElement::updatePlayState): Call prepareToPlay.
        * html/HTMLMediaElement.h:

        * manual-tests/media-elements/video-preload.html: Make changing urls work.

        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
        (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation):  Remove
            m_videoFrameHasDrawn and m_delayingLoad as they are no longer used.
        (WebCore::MediaPlayerPrivateAVFoundation::resumeLoad): Removed.
        (WebCore::MediaPlayerPrivateAVFoundation::load): Don't initialize m_videoFrameHasDrawn.
            Move all preload logic to setPreload, call it from here.
        (WebCore::MediaPlayerPrivateAVFoundation::prepareToPlay): Move all preload logic to
            setPreload, call it.
        (WebCore::MediaPlayerPrivateAVFoundation::duration): Don't cache duration = 0, it is
            unlikely to be correct and isn't worth caching. Use invalidTime() function.
        (WebCore::MediaPlayerPrivateAVFoundation::seeking): Use invalidTime() function.
        (WebCore::MediaPlayerPrivateAVFoundation::setNaturalSize): Add logging.
        (WebCore::MediaPlayerPrivateAVFoundation::updateStates): Update for name change AVAssetStatus
            to AssetStatus. Always create a AVPlayerItem for live streams because they can't be inspected
            without one. Set networkState to 'idle' when the playback buffer is full because that is
            a signal that AVFoundation won't do any more IO. Set readyState to 'HAVE_CURRENT_DATA'
            when the first frame is available.
        (WebCore::MediaPlayerPrivateAVFoundation::metadataLoaded): Call tracksChanged so we cache
            width, height, hasVideo, etc.
        (WebCore::MediaPlayerPrivateAVFoundation::loadedTimeRangesChanged): Use invalidTime() function.
        (WebCore::MediaPlayerPrivateAVFoundation::timeChanged): Ditto.
        (WebCore::MediaPlayerPrivateAVFoundation::seekCompleted): Ditto.
        (WebCore::MediaPlayerPrivateAVFoundation::repaint): Don't set m_videoFrameHasDrawn, it is done
            in derived classes.
        (WebCore::MediaPlayerPrivateAVFoundation::setPreload): Centralize all logic about when to create
            AVAsset and AVPlayerItem here.
        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:

        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.h:
        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm:
        (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
            m_videoFrameHasDrawn.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::hasAvailableVideoFrame): New, renamed from
            videoLayerIsReadyToDisplay. Return true if we have a layer with frames available or
            if we have painted a frame to the context.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL): New, create the AVAsset
            if necessary.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForCacheResource): Ditto.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer): Restructure logic.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem): New, create AVPlayerItem.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Correct logging.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::playerItemStatus): Return "buffer full" when
            the buffer is full.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::platformDuration): Get the duration from the
            AVAsset when we haven't allocated the AVPlayerItem yet so that we can return duration
            when we only have metadata.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus): Update for name change.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::paint): Set m_videoFrameHasDrawn.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Get attributes from AVAsset
            when when we haven't allocated the AVPlayerItem yet so that we can report attributes
            when we only have metadata.
        (WebCore::MediaPlayerPrivateAVFoundationObjC::sizeChanged): Guard against being called before
            we have allocated the AVPlayerItem.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@85865 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/manual-tests/media-elements/video-preload.html
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm