[MSE] Implement a maximum buffer size for SourceBuffer
https://bugs.webkit.org/show_bug.cgi?id=135614

Reviewed by Jer Noble.

Implement the MSE coded frame eviction algorithm: when new buffers are appended attempt
to keep the amount of data buffered below a maximum size (which is determined by the media
session manager) by freeing coded frames as follows:
    1 - Free frames in 30 second chunks from 0 to 30 seconds before the current time.
    2 - If there are time ranges after the range with the current time, free frames in
        30 second chunks from duration back to the beginning of the time range after
        current time.

For now we DO NOT throw a QUOTA_EXCEEDED_ERR when we are not able to free up enough
space to remain below the prescribed quota, because some big name, widely deployed, 
code bases ignore the error and continue appending data as though the failed append
succeeded, leading to a corrupted bitstream and failure to play.

* Modules/mediasource/SampleMap.cpp:
(WebCore::SampleMap::addSample): Drive-by performance optimization: sample->presentationTime()
    is used more than once, stash it in a local variable.
(WebCore::SampleMap::removeSample): Ditto.

* Modules/mediasource/SourceBuffer.cpp:
(WebCore::logRanges): Debug-only function to log TimeRanges.
(WebCore::SourceBuffer::SourceBuffer):
(WebCore::SourceBuffer::remove): Optimize logging. Buffer full and coded frame eviction logic
    is in SourceBuffer instead of SourceBufferPrivate.
(WebCore::SourceBuffer::appendBufferInternal): Ditto.
(WebCore::SourceBuffer::sourceBufferPrivateAppendComplete): Set m_bufferFull when more data
    has been buffered than allowed.
(WebCore::removeSamplesFromTrackBuffer): Add logging.
(WebCore::SourceBuffer::removeCodedFrames): Improve logging. Avoid debug build assert when
    current time is after last enqueued presentation time.
(WebCore::SourceBuffer::evictCodedFrames): The coded frame eviction algorithm.
(WebCore::SourceBuffer::maximumBufferSize): Return the maximum amount of data that can 
    be buffered.
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Improve logging. Don't attempt
    to create a PlatformTimeRanges with inverted start and end to avoid an assert in debug.
(WebCore::SourceBuffer::hasAudio): New, return true if there are any audio tracks.
(WebCore::SourceBuffer::hasVideo): New, return true if there are any video tracks.
(WebCore::SourceBuffer::sourceBufferPrivateHasAudio): Call hasAudio.
(WebCore::SourceBuffer::sourceBufferPrivateHasVideo): Call hasVideo.
(WebCore::SourceBuffer::hasCurrentTime): Return true if currentTime is greater than duration.
(WebCore::SourceBuffer::hasFutureTime): Ditto.
(WebCore::SourceBuffer::extraMemoryCost): Return the amount of data buffered: the size of
    the input buffer plus the size of all track samples.
(WebCore::SourceBuffer::reportExtraMemoryCost): Move buffered size calculation to extraMemoryCost.
(WebCore::SourceBuffer::document): Document accessor.
* Modules/mediasource/SourceBuffer.h: Drive-by size optimization by moving all bool member
    variables to the end of class.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::refreshCachedTime): Drive-by removal of overly chatty logging.
(WebCore::HTMLMediaElement::maximumSourceBufferSize): New, maximum source buffer size.
* html/HTMLMediaElement.h:

* html/HTMLMediaSession.cpp:
(WebCore::HTMLMediaSession::maximumMediaSourceBufferSize): New, get maximum source buffer 
    size from settings, return full amount for an SourceBuffer with video and audio, return 5%
    of the maximum for an audio-only SourceBuffer.
* html/HTMLMediaSession.h:

* page/Settings.in: Add maximumSourceBufferSize. Default value is enough for approximately
    five minutes of 1080p video and stereo audio.

* platform/graphics/PlatformTimeRanges.cpp:
(WebCore::PlatformTimeRanges::totalDuration): Drive-by optimization.
(WebCore::PlatformTimeRanges::dump): New, allow a PlatformTimeRanges to be printed.
* platform/graphics/PlatformTimeRanges.h:

* platform/graphics/SourceBufferPrivate.h: Delete evictCodedFrames and isFull, that logic
    is not in SourceBuffer.
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::processCodedFrame): Drive-by logging fix.
(WebCore::SourceBufferPrivateAVFObjC::evictCodedFrames): Deleted.
(WebCore::SourceBufferPrivateAVFObjC::isFull): Deleted.

* platform/mock/mediasource/MockSourceBufferPrivate.cpp:
(WebCore::MockSourceBufferPrivate::evictCodedFrames): Deleted.
(WebCore::MockSourceBufferPrivate::isFull): Deleted.
* platform/mock/mediasource/MockSourceBufferPrivate.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@172657 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS] Teach postprocess-headers.sh to remove code guarded by ENABLE_IOS_GESTURE_EVENTS
and ENABLE_TOUCH_EVENTS if applicable
https://bugs.webkit.org/show_bug.cgi?id=135993

Reviewed by Andy Estes.

Add support infrastructure to remove code from public and private API headers that is
guarded by macro define ENABLE_{IOS_GESTURE, TOUCH}_EVENTS when these features are disabled.

We aren't using this functionality yet, but we will soon.

* postprocess-headers.sh:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@172658 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Fix gliding in AxisScrollSnapAnimator for Mac
https://bugs.webkit.org/show_bug.cgi?id=135971

Patch by Wenson Hsieh <wenson_hsieh@apple.com> on 2014-08-15
Reviewed by Dean Jackson.

Previously, momentum events that are handled immediately after finishing a glide animation cause a second, extremely
slow glide animation to trigger. To fix this, I added a new state DestinationReached. During this state, additional
momentum events that are handled after the glide animation completes will not fill up the momentum window and trigger
a second glide event.

* platform/mac/AxisScrollSnapAnimator.h:
* platform/mac/AxisScrollSnapAnimator.mm:
(WebCore::AxisScrollSnapAnimator::AxisScrollSnapAnimator):
(WebCore::AxisScrollSnapAnimator::handleWheelEvent):
(WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate):
(WebCore::AxisScrollSnapAnimator::endScrollSnapAnimation):
(WebCore::AxisScrollSnapAnimator::computeGlideDelta):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@172659 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Improve page to process relationship tracking
https://bugs.webkit.org/show_bug.cgi?id=135996
<rdar://problem/16991213>

Reviewed by Sam Weinig.

* UIProcess/VisitedLinkProvider.cpp:
(WebKit::VisitedLinkProvider::removeAll):
(WebKit::VisitedLinkProvider::pendingVisitedLinksTimerFired):
(WebKit::VisitedLinkProvider::sendTable):
Added assertions for m_processes only having valid entries.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reattachToWebProcess): When attaching to a new process,
tell the old process that the page is not longer associated with it, avoiding
a potential stale pointer.
If re-attached to an existing process, make sure that we perform all the same
registrations as after having launched a new process. This substantially improves
the behavior when the number of open tabs is over process limit.
(WebKit::WebPageProxy::reattachToWebProcessWithItem): Added ASSERT(!isValid())
to avoid confusion. All other calls to reattachToWebProcess() have this as a
runtime check, but reattachToWebProcessWithItem() is only called for valid pages.
(WebKit::WebPageProxy::terminateProcess): Added an assertion with a FIXME for
something that will need to be fixed another day.

* UIProcess/WebPageProxy.h: Removed an unimplemented function.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::addExistingWebPage): Added assertions for page map sanity.
(WebKit::WebProcessProxy::removeWebPage): Added a check for page state being Terminated
already. This avoids an assertion failure that happened under the new call to
removeWebPage() in reattachToWebProcess(), as we are now calling it for terminated
processes that are not in WebContext::m_processes any more.
(WebKit::WebProcessProxy::didFinishLaunching): Added an assertion that page agrees
about using this process.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@172660 268f45cc-cd09-0410-ab3c-d52691b4dbfc