[MSE][Mac] Crash when removing MediaSource from HTMLMediaElement.
https://bugs.webkit.org/show_bug.cgi?id=125269

Reviewed by Sam Weinig.

Fixes the media/media-source/media-source-fastseek.html test when run with MallocScribble enabled.

It's possible for a SourceBufferPrivateAVFObjC to outlive its MediaSourcePrivateAVFObjC, so
make sure to clear the pointer from the former to the latter when the latter is destroyed.
That means we now have to check to see if the pointer to the latter is still valid at every
call site.

As a drive-by fix, rename m_parent to m_mediaSource to more accurately reflect what the pointer
points to.

* platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
(WebCore::MediaSourcePrivateAVFObjC::~MediaSourcePrivateAVFObjC): Clear the SourceBuffer's backpointer.
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
(WebCore::SourceBufferPrivateAVFObjC::clearMediaSource):
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC): Rename m_parent -> m_mediaSource.
(WebCore::SourceBufferPrivateAVFObjC::append): Check m_mediaSource before calling.
(WebCore::SourceBufferPrivateAVFObjC::removedFromMediaSource): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::readyState): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::setReadyState): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::trackDidChangeEnabled): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::flushAndEnqueueNonDisplayingSamples): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::enqueueSample): Ditto.
(WebCore::SourceBufferPrivateAVFObjC::setActive): Ditto.
* platform/mock/mediasource/MockMediaSourcePrivate.cpp:
(WebCore::MockMediaSourcePrivate::~MockMediaSourcePrivate): Clear the SourceBuffer's backpointer.
* platform/mock/mediasource/MockSourceBufferPrivate.cpp:
(WebCore::MockSourceBufferPrivate::MockSourceBufferPrivate): Rename m_parent -> m_mediaSource.
(WebCore::MockSourceBufferPrivate::removedFromMediaSource): Check m_mediaSource before calling.
(WebCore::MockSourceBufferPrivate::readyState): Ditto.
(WebCore::MockSourceBufferPrivate::setReadyState): Ditto.
(WebCore::MockSourceBufferPrivate::setActive): Ditto.
* platform/mock/mediasource/MockSourceBufferPrivate.h:
(WebCore::MockSourceBufferPrivate::clearMediaSource):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@160281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[MSE] Bring end-of-stream algorithm section up to current spec.
https://bugs.webkit.org/show_bug.cgi?id=125270

Reviewed by Darin Adler.

Source/WebCore:

Test: media/media-source/media-source-end-of-stream.html

Separate the "endOfStream()" method from the "end of stream algorithm".

* Modules/mediasource/MediaSource.cpp:
(WebCore::SourceBufferIsUpdating): Added predicate function.
(WebCore::MediaSource::endOfStream): Call streamEndedWithError().
(WebCore::MediaSource::streamEndedWithError): Added.
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::appendBufferTimerFired): Call streamEndedWithError().
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Ditto.
* Modules/mediasource/SourceBuffer.h:
* html/HTMLMediaElement.cpp:
(HTMLMediaElement::mediaLoadingFailedFatally): Renamed from mediaEngineError.
(HTMLMediaElement::mediaLoadingFailed): Call renamed method.
* html/HTMLMediaElement.h:
* platform/graphics/avfoundation/objc/MediaSourcePrivateAVFObjC.mm:
(WebCore::MediaSourcePrivateAVFObjC::markEndOfStream): Set load state to Loaded.
* platform/mock/mediasource/MockMediaPlayerMediaSource.cpp:
(WebCore::MockMediaPlayerMediaSource::setNetworkState): Simple setter.
* platform/mock/mediasource/MockMediaPlayerMediaSource.h:
* platform/mock/mediasource/MockMediaSourcePrivate.cpp:
(WebCore::MockMediaSourcePrivate::MockMediaSourcePrivate): Set the intitial duration to NaN.
(WebCore::MockMediaSourcePrivate::markEndOfStream): Set load state to Loaded.

LayoutTests:

* media/media-source/media-source-end-of-stream-expected.txt: Added.
* media/media-source/media-source-end-of-stream.html: Added.

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