Changeset 85518 in webkit
- Timestamp:
- May 2, 2011 2:04:42 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r85515 r85518 1 2011-05-02 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r85483. 4 http://trac.webkit.org/changeset/85483 5 https://bugs.webkit.org/show_bug.cgi?id=59958 6 7 Causes media test failures. (Requested by eric_carlson on 8 #webkit). 9 10 * html/HTMLMediaElement.cpp: 11 (WebCore::HTMLMediaElement::HTMLMediaElement): 12 (WebCore::HTMLMediaElement::prepareForLoad): 13 (WebCore::HTMLMediaElement::seek): 14 (WebCore::HTMLMediaElement::updatePlayState): 15 * html/HTMLMediaElement.h: 16 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp: 17 (WebCore::MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation): 18 (WebCore::MediaPlayerPrivateAVFoundation::resumeLoad): 19 (WebCore::MediaPlayerPrivateAVFoundation::load): 20 (WebCore::MediaPlayerPrivateAVFoundation::prepareToPlay): 21 (WebCore::MediaPlayerPrivateAVFoundation::paint): 22 (WebCore::MediaPlayerPrivateAVFoundation::duration): 23 (WebCore::MediaPlayerPrivateAVFoundation::seeking): 24 (WebCore::MediaPlayerPrivateAVFoundation::updateStates): 25 (WebCore::MediaPlayerPrivateAVFoundation::hasAvailableVideoFrame): 26 (WebCore::MediaPlayerPrivateAVFoundation::metadataLoaded): 27 (WebCore::MediaPlayerPrivateAVFoundation::loadedTimeRangesChanged): 28 (WebCore::MediaPlayerPrivateAVFoundation::timeChanged): 29 (WebCore::MediaPlayerPrivateAVFoundation::seekCompleted): 30 (WebCore::MediaPlayerPrivateAVFoundation::repaint): 31 (WebCore::MediaPlayerPrivateAVFoundation::setPreload): 32 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h: 33 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.h: 34 * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm: 35 (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): 36 (WebCore::MediaPlayerPrivateAVFoundationObjC::videoLayerIsReadyToDisplay): 37 (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerForURL): 38 (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerForCacheResource): 39 (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer): 40 (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): 41 (WebCore::MediaPlayerPrivateAVFoundationObjC::playerItemStatus): 42 (WebCore::MediaPlayerPrivateAVFoundationObjC::platformDuration): 43 (WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus): 44 (WebCore::MediaPlayerPrivateAVFoundationObjC::paint): 45 (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): 46 (WebCore::MediaPlayerPrivateAVFoundationObjC::sizeChanged): 47 1 48 2011-05-02 Adam Barth <abarth@webkit.org> 2 49 -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r85488 r85518 172 172 , m_loadInitiatedByUserGesture(false) 173 173 , m_completelyLoaded(false) 174 , m_havePreparedToPlay(false)175 174 { 176 175 LOG(Media, "HTMLMediaElement::HTMLMediaElement"); … … 519 518 m_haveFiredLoadedData = false; 520 519 m_completelyLoaded = false; 521 m_havePreparedToPlay = false;522 520 m_displayMode = Unknown; 523 521 … … 1085 1083 return m_player ? m_player->supportsSave() : false; 1086 1084 } 1087 1088 void HTMLMediaElement::prepareToPlay() 1089 { 1090 if (m_havePreparedToPlay) 1091 return; 1092 m_havePreparedToPlay = true; 1093 m_player->prepareToPlay(); 1094 } 1095 1085 1096 1086 void HTMLMediaElement::seek(float time, ExceptionCode& ec) 1097 1087 { … … 1105 1095 return; 1106 1096 } 1107 1108 // If the media engine has been told to postpone loading data, let it go ahead now.1109 if (m_preload < MediaPlayer::Auto && m_readyState < HAVE_FUTURE_DATA)1110 prepareToPlay();1111 1097 1112 1098 // Get the current time before setting m_seeking, m_lastSeekTime is returned once it is set. … … 2211 2197 2212 2198 if (couldPlayIfEnoughData()) 2213 prepareToPlay();2199 m_player->prepareToPlay(); 2214 2200 2215 2201 if (hasMediaControls()) -
trunk/Source/WebCore/html/HTMLMediaElement.h
r85483 r85518 287 287 void cancelPendingEventsAndCallbacks(); 288 288 void waitForSourceChange(); 289 void prepareToPlay();290 289 291 290 enum InvalidSourceAction { DoNothing, Complain }; … … 419 418 bool m_loadInitiatedByUserGesture : 1; 420 419 bool m_completelyLoaded : 1; 421 bool m_havePreparedToPlay : 1;422 420 }; 423 421 -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp
r85483 r85518 31 31 32 32 #include "ApplicationCacheHost.h" 33 #include "ApplicationCacheResource.h"34 33 #include "DocumentLoader.h" 35 34 #include "FrameView.h" … … 47 46 namespace WebCore { 48 47 48 static const float invalidTime = -1.0f; 49 49 50 MediaPlayerPrivateAVFoundation::MediaPlayerPrivateAVFoundation(MediaPlayer* player) 50 51 : m_player(player) 51 52 , m_queuedNotifications() 52 53 , m_queueMutex() 54 , m_mainThreadCallPending(false) 53 55 , m_networkState(MediaPlayer::Empty) 54 56 , m_readyState(MediaPlayer::HaveNothing) … … 57 59 , m_cachedMaxTimeLoaded(0) 58 60 , m_cachedMaxTimeSeekable(0) 59 , m_cachedDuration(invalidTime ())60 , m_reportedDuration(invalidTime ())61 , m_seekTo(invalidTime ())61 , m_cachedDuration(invalidTime) 62 , m_reportedDuration(invalidTime) 63 , m_seekTo(invalidTime) 62 64 , m_requestedRate(1) 63 , m_delayCallbacks( 0)64 , m_ mainThreadCallPending(false)65 , m_delayCallbacks(false) 66 , m_havePreparedToPlay(false) 65 67 , m_assetIsPlayable(false) 66 68 , m_visible(false) 69 , m_videoFrameHasDrawn(false) 67 70 , m_loadingMetadata(false) 71 , m_delayingLoad(false) 68 72 , m_isAllowedToRender(false) 69 73 , m_cachedHasAudio(false) … … 164 168 } 165 169 170 void MediaPlayerPrivateAVFoundation::resumeLoad() 171 { 172 LOG(Media, "MediaPlayerPrivateAVFoundation::resumeLoad(%p)", this); 173 174 ASSERT(m_delayingLoad); 175 m_delayingLoad = false; 176 177 if (m_assetURL.length()) 178 prepareToPlay(); 179 } 180 166 181 void MediaPlayerPrivateAVFoundation::load(const String& url) 167 182 { … … 177 192 } 178 193 194 m_videoFrameHasDrawn = false; 179 195 m_assetURL = url; 180 196 … … 183 199 return; 184 200 185 setPreload(m_preload); 201 if (m_preload == MediaPlayer::None) { 202 LOG(Media, "MediaPlayerPrivateAVFoundation::load(%p) - preload==none so returning", this); 203 m_delayingLoad = true; 204 return; 205 } 206 207 prepareToPlay(); 186 208 } 187 209 … … 211 233 LOG(Media, "MediaPlayerPrivateAVFoundation::prepareToPlay(%p)", this); 212 234 213 setPreload(MediaPlayer::Auto); 235 m_preload = MediaPlayer::Auto; 236 if (m_havePreparedToPlay) 237 return; 238 m_havePreparedToPlay = true; 239 240 m_delayingLoad = false; 241 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 242 Frame* frame = m_player->frameView() ? m_player->frameView()->frame() : 0; 243 ApplicationCacheHost* cacheHost = frame ? frame->loader()->documentLoader()->applicationCacheHost() : 0; 244 ApplicationCacheResource* resource = 0; 245 if (cacheHost && cacheHost->shouldLoadResourceFromApplicationCache(ResourceRequest(m_assetURL), resource) && resource) 246 createAVPlayerForCacheResource(resource); 247 else 248 #endif 249 createAVPlayerForURL(m_assetURL); 250 checkPlayability(); 214 251 } 215 252 … … 233 270 } 234 271 272 void MediaPlayerPrivateAVFoundation::paint(GraphicsContext*, const IntRect&) 273 { 274 // This is the base class, only need to remember that a frame has been drawn. 275 m_videoFrameHasDrawn = true; 276 } 277 235 278 float MediaPlayerPrivateAVFoundation::duration() const 236 279 { 237 if (m_cachedDuration != invalidTime())238 return m_cachedDuration;239 240 280 if (!metaDataAvailable()) 241 281 return 0; 242 282 243 float duration = platformDuration(); 244 if (!duration || duration == invalidTime()) 245 return 0; 246 247 m_cachedDuration = duration; 248 LOG(Media, "MediaPlayerPrivateAVFMac::duration(%p) - caching %f", this, m_cachedDuration); 283 if (m_cachedDuration == invalidTime) { 284 m_cachedDuration = platformDuration(); 285 LOG(Media, "MediaPlayerPrivateAVFMac::duration(%p) - caching %f", this, m_cachedDuration); 286 } 287 249 288 return m_cachedDuration; 250 289 } … … 288 327 return false; 289 328 290 return m_seekTo != invalidTime ();329 return m_seekTo != invalidTime; 291 330 } 292 331 … … 394 433 else { 395 434 // -loadValuesAsynchronouslyForKeys:completionHandler: has invoked its handler; test status of keys and determine state. 396 A ssetStatus avAssetStatus = assetStatus();435 AVAssetStatus avAssetStatus = assetStatus(); 397 436 ItemStatus itemStatus = playerItemStatus(); 398 437 … … 400 439 if (m_readyState < MediaPlayer::HaveMetadata && avAssetStatus > MediaPlayerAVAssetStatusLoading) { 401 440 if (m_assetIsPlayable) { 402 if (itemStatus <= MediaPlayerAVPlayerItemStatusUnknown) {441 if (itemStatus == MediaPlayerAVPlayerItemStatusUnknown) { 403 442 if (avAssetStatus == MediaPlayerAVAssetStatusFailed || m_preload > MediaPlayer::MetaData) { 404 443 // We may have a playable asset that doesn't support inspection prior to playback; go ahead … … 407 446 m_networkState = MediaPlayer::Loading; 408 447 prepareToPlay(); 409 } else { 410 // The asset is playable, but we don't want to load media data yet so don't allocate 411 // the player item. Even though we don't want to play yet, allocate a player so 412 // we can create a layer as soon as possible. 413 createAVPlayer(); 448 } else 414 449 m_networkState = MediaPlayer::Idle; 415 }416 450 } 417 m_readyState = MediaPlayer::HaveMetadata; 451 if (avAssetStatus == MediaPlayerAVAssetStatusLoaded) 452 m_readyState = MediaPlayer::HaveMetadata; 418 453 } else { 419 454 // FIX ME: fetch the error associated with the @"playable" key to distinguish between format … … 429 464 float maxLoaded = maxTimeLoaded(); 430 465 switch (itemStatus) { 431 case MediaPlayerAVPlayerItemStatusDoesNotExist:432 466 case MediaPlayerAVPlayerItemStatusUnknown: 433 467 break; … … 438 472 m_readyState = MediaPlayer::HaveEnoughData; 439 473 break; 440 474 case MediaPlayerAVPlayerItemStatusReadyToPlay: 441 475 case MediaPlayerAVPlayerItemStatusPlaybackBufferFull: 442 m_networkState = MediaPlayer::Idle;443 444 case MediaPlayerAVPlayerItemStatusReadyToPlay:445 476 // If the readyState is already HaveEnoughData, don't go lower because of this state change. 446 477 if (m_readyState == MediaPlayer::HaveEnoughData) … … 455 486 } 456 487 457 if (itemStatus != MediaPlayerAVPlayerItemStatusPlaybackBufferFull && itemStatus>= MediaPlayerAVPlayerItemStatusReadyToPlay)488 if (itemStatus >= MediaPlayerAVPlayerItemStatusReadyToPlay) 458 489 m_networkState = (maxLoaded == duration()) ? MediaPlayer::Loaded : MediaPlayer::Loading; 459 490 } … … 465 496 466 497 if (!m_haveReportedFirstVideoFrame && m_cachedHasVideo && hasAvailableVideoFrame()) { 467 if (m_readyState < MediaPlayer::HaveCurrentData)468 m_readyState = MediaPlayer::HaveCurrentData;469 498 m_haveReportedFirstVideoFrame = true; 470 499 m_player->firstVideoFrameAvailable(); … … 502 531 } 503 532 533 bool MediaPlayerPrivateAVFoundation::hasAvailableVideoFrame() const 534 { 535 if (currentRenderingMode() == MediaRenderingToLayer) 536 return videoLayerIsReadyToDisplay(); 537 538 // When using the software renderer we hope someone will signal that a frame is available so we might as well 539 // wait until we know that a frame has been drawn. 540 return m_videoFrameHasDrawn; 541 } 542 504 543 void MediaPlayerPrivateAVFoundation::acceleratedRenderingStateChanged() 505 544 { … … 511 550 { 512 551 m_loadingMetadata = false; 513 tracksChanged();514 552 updateStates(); 515 553 } … … 538 576 float dur = duration(); 539 577 if (dur != m_reportedDuration) { 540 if (m_reportedDuration != invalidTime ())578 if (m_reportedDuration != invalidTime) 541 579 m_player->durationChanged(); 542 580 m_reportedDuration = dur; … … 553 591 LOG(Media, "MediaPlayerPrivateAVFoundation::timeChanged(%p) - time = %f", this, time); 554 592 555 if (m_seekTo == invalidTime ())593 if (m_seekTo == invalidTime) 556 594 return; 557 595 … … 563 601 float currentRate = rate(); 564 602 if ((currentRate > 0 && time >= m_seekTo) || (currentRate < 0 && time <= m_seekTo) || (abs(m_seekTo - time) <= smallSeekDelta)) { 565 m_seekTo = invalidTime ();603 m_seekTo = invalidTime; 566 604 updateStates(); 567 605 m_player->timeChanged(); … … 574 612 575 613 if (finished) 576 m_seekTo = invalidTime ();614 m_seekTo = invalidTime; 577 615 } 578 616 … … 591 629 void MediaPlayerPrivateAVFoundation::repaint() 592 630 { 631 m_videoFrameHasDrawn = true; 593 632 m_player->repaint(); 594 633 } … … 608 647 { 609 648 m_preload = preload; 610 if (!m_assetURL.length()) 611 return; 612 613 if (m_preload >= MediaPlayer::MetaData && assetStatus() == MediaPlayerAVAssetStatusDoesNotExist) { 614 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 615 Frame* frame = m_player->frameView() ? m_player->frameView()->frame() : 0; 616 ApplicationCacheHost* cacheHost = frame ? frame->loader()->documentLoader()->applicationCacheHost() : 0; 617 ApplicationCacheResource* resource; 618 if (cacheHost && cacheHost->shouldLoadResourceFromApplicationCache(ResourceRequest(m_assetURL), resource) && resource) { 619 // AVFoundation can't open arbitrary data pointers, so if this ApplicationCacheResource doesn't 620 // have a valid local path, just open the resource's original URL. 621 if (resource->path().isEmpty()) 622 createAVAssetForURL(resource->url()); 623 else 624 createAVAssetForCacheResource(resource); 625 } else 626 #endif 627 createAVAssetForURL(m_assetURL); 628 629 checkPlayability(); 630 } 631 632 if (m_preload == MediaPlayer::Auto && playerItemStatus() == MediaPlayerAVPlayerItemStatusDoesNotExist) 633 createAVPlayerItem(); 649 if (m_delayingLoad && m_preload != MediaPlayer::None) 650 resumeLoad(); 634 651 } 635 652 -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
r85483 r85518 143 143 virtual unsigned bytesLoaded() const; 144 144 virtual void setSize(const IntSize&); 145 virtual void paint(GraphicsContext*, const IntRect&) = 0;145 virtual void paint(GraphicsContext*, const IntRect&); 146 146 virtual void paintCurrentFrameInContext(GraphicsContext*, const IntRect&) = 0; 147 147 virtual void setPreload(MediaPlayer::Preload); 148 virtual bool hasAvailableVideoFrame() const; 148 149 #if USE(ACCELERATED_COMPOSITING) 149 150 virtual PlatformLayer* platformLayer() const { return 0; } … … 159 160 160 161 // Required interfaces for concrete derived classes. 161 virtual void createAVAssetForURL(const String&) = 0; 162 virtual void createAVPlayer() = 0; 163 virtual void createAVPlayerItem() = 0; 162 virtual void createAVPlayerForURL(const String& url) = 0; 164 163 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 165 virtual void createAV AssetForCacheResource(ApplicationCacheResource*) = 0;164 virtual void createAVPlayerForCacheResource(ApplicationCacheResource*) = 0; 166 165 #endif 167 166 168 167 enum ItemStatus { 169 MediaPlayerAVPlayerItemStatusDoesNotExist,170 168 MediaPlayerAVPlayerItemStatusUnknown, 171 169 MediaPlayerAVPlayerItemStatusFailed, … … 177 175 virtual ItemStatus playerItemStatus() const = 0; 178 176 179 enum AssetStatus { 180 MediaPlayerAVAssetStatusDoesNotExist, 177 enum AVAssetStatus { 181 178 MediaPlayerAVAssetStatusUnknown, 182 179 MediaPlayerAVAssetStatusLoading, … … 186 183 MediaPlayerAVAssetStatusPlayable, 187 184 }; 188 virtual A ssetStatus assetStatus() const = 0;185 virtual AVAssetStatus assetStatus() const = 0; 189 186 190 187 virtual void platformSetVisible(bool) = 0; … … 210 207 virtual void createVideoLayer() = 0; 211 208 virtual void destroyVideoLayer() = 0; 212 213 virtual bool hasAvailableVideoFrame() const = 0; 209 virtual bool videoLayerIsReadyToDisplay() const = 0; 214 210 215 211 virtual bool hasContextRenderer() const = 0; … … 217 213 218 214 protected: 215 void resumeLoad(); 219 216 void updateStates(); 220 217 … … 240 237 241 238 static void mainThreadCallback(void*); 242 243 float invalidTime() const { return -1.0f; }244 239 245 240 private: 241 246 242 MediaPlayer* m_player; 247 243 248 244 Vector<Notification> m_queuedNotifications; 249 245 Mutex m_queueMutex; 246 bool m_mainThreadCallPending; 250 247 251 248 mutable RefPtr<TimeRanges> m_cachedLoadedTimeRanges; … … 267 264 float m_requestedRate; 268 265 int m_delayCallbacks; 269 bool m_ mainThreadCallPending;266 bool m_havePreparedToPlay; 270 267 bool m_assetIsPlayable; 271 268 bool m_visible; 269 bool m_videoFrameHasDrawn; 272 270 bool m_loadingMetadata; 271 bool m_delayingLoad; 273 272 bool m_isAllowedToRender; 274 273 bool m_cachedHasAudio; -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.h
r85483 r85518 87 87 88 88 virtual void createAVPlayer(); 89 virtual void createAVPlayerItem(); 90 virtual void createAVAssetForURL(const String& url); 89 virtual void createAVPlayerForURL(const String& url); 91 90 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 92 virtual void createAV AssetForCacheResource(ApplicationCacheResource*);91 virtual void createAVPlayerForCacheResource(ApplicationCacheResource*); 93 92 #endif 94 93 virtual MediaPlayerPrivateAVFoundation::ItemStatus playerItemStatus() const; 95 virtual MediaPlayerPrivateAVFoundation::A ssetStatus assetStatus() const;94 virtual MediaPlayerPrivateAVFoundation::AVAssetStatus assetStatus() const; 96 95 97 96 virtual void checkPlayability(); … … 107 106 virtual void sizeChanged(); 108 107 109 virtual bool hasAvailableVideoFrame() const;110 111 108 virtual void createContextVideoRenderer(); 112 109 virtual void destroyContextVideoRenderer(); … … 114 111 virtual void createVideoLayer(); 115 112 virtual void destroyVideoLayer(); 113 virtual bool videoLayerIsReadyToDisplay() const; 116 114 117 115 virtual bool hasContextRenderer() const; … … 128 126 RetainPtr<AVAssetImageGenerator> m_imageGenerator; 129 127 id m_timeObserver; 130 bool m_videoFrameHasDrawn;131 128 }; 132 129 -
trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm
r85483 r85518 139 139 , m_objcObserver(AdoptNS, [[WebCoreAVFMovieObserver alloc] initWithCallback:this]) 140 140 , m_timeObserver(0) 141 , m_videoFrameHasDrawn(false)142 141 { 143 142 } … … 236 235 } 237 236 238 bool MediaPlayerPrivateAVFoundationObjC::hasAvailableVideoFrame() const 239 { 240 return (m_videoFrameHasDrawn || (m_videoLayer && [m_videoLayer.get() isReadyForDisplay])); 241 } 242 243 void MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL(const String& url) 244 { 245 if (m_avAsset) 246 return; 247 237 bool MediaPlayerPrivateAVFoundationObjC::videoLayerIsReadyToDisplay() const 238 { 239 return (m_videoLayer && [m_videoLayer.get() isReadyForDisplay]); 240 } 241 242 void MediaPlayerPrivateAVFoundationObjC::createAVPlayerForURL(const String& url) 243 { 248 244 setDelayCallbacks(true); 249 NSURL *cocoaURL = KURL(ParsedURLString, url); 250 m_avAsset.adoptNS([[AVURLAsset alloc] initWithURL:cocoaURL options:nil]); 251 setDelayCallbacks(false); 245 246 if (!m_avAsset) { 247 NSURL *cocoaURL = KURL(ParsedURLString, url); 248 m_avAsset.adoptNS([[AVURLAsset alloc] initWithURL:cocoaURL options:nil]); 249 } 250 251 createAVPlayer(); 252 252 } 253 253 254 254 #if ENABLE(OFFLINE_WEB_APPLICATIONS) 255 void MediaPlayerPrivateAVFoundationObjC::createAVAssetForCacheResource(ApplicationCacheResource* resource) 256 { 257 if (m_avAsset) 258 return; 259 260 // AVFoundation can't open arbitrary data pointers. 261 ASSERT(!resource->path().isEmpty()); 255 void MediaPlayerPrivateAVFoundationObjC::createAVPlayerForCacheResource(ApplicationCacheResource* resource) 256 { 257 // AVFoundation can't open arbitrary data pointers, so if this ApplicationCacheResource doesn't 258 // have a valid local path, just open the resource's original URL. 259 if (resource->path().isEmpty()) { 260 createAVPlayerForURL(resource->url()); 261 return; 262 } 262 263 263 264 setDelayCallbacks(true); 264 265 265 NSURL* localURL = [NSURL fileURLWithPath:resource->path()]; 266 m_avAsset.adoptNS([[AVURLAsset alloc] initWithURL:localURL options:nil]); 267 268 setDelayCallbacks(false); 266 if (!m_avAsset) { 267 NSURL* localURL = [NSURL fileURLWithPath:resource->path()]; 268 m_avAsset.adoptNS([[AVURLAsset alloc] initWithURL:localURL options:nil]); 269 } 270 271 createAVPlayer(); 269 272 } 270 273 #endif … … 272 275 void MediaPlayerPrivateAVFoundationObjC::createAVPlayer() 273 276 { 274 if (m_avPlayer) 275 return; 276 277 setDelayCallbacks(true); 278 279 m_avPlayer.adoptNS([[AVPlayer alloc] init]); 280 [m_avPlayer.get() addObserver:m_objcObserver.get() forKeyPath:@"rate" options:nil context:(void *)MediaPlayerAVFoundationObservationContextPlayer]; 281 282 // Add a time observer, ask to be called infrequently because we don't really want periodic callbacks but 283 // our observer will also be called whenever a seek happens. 284 const double veryLongInterval = 60*60*60*24*30; 285 WebCoreAVFMovieObserver *observer = m_objcObserver.get(); 286 m_timeObserver = [m_avPlayer.get() addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(veryLongInterval, 10) queue:nil usingBlock:^(CMTime time){ 287 [observer timeChanged:CMTimeGetSeconds(time)]; 288 }]; 289 290 setDelayCallbacks(false); 291 } 292 293 void MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem() 294 { 295 if (m_avPlayerItem) 296 return; 297 298 setDelayCallbacks(true); 299 300 // Create the player item so we can media data. 301 m_avPlayerItem.adoptNS([[AVPlayerItem alloc] initWithAsset:m_avAsset.get()]); 302 303 [[NSNotificationCenter defaultCenter] addObserver:m_objcObserver.get()selector:@selector(didEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:m_avPlayerItem.get()]; 304 305 for (NSString *keyName in itemKVOProperties()) 306 [m_avPlayerItem.get() addObserver:m_objcObserver.get() forKeyPath:keyName options:nil context:(void *)MediaPlayerAVFoundationObservationContextPlayerItem]; 307 308 [m_avPlayer.get() replaceCurrentItemWithPlayerItem:m_avPlayerItem.get()]; 277 if (!m_avPlayer) { 278 m_avPlayer.adoptNS([[AVPlayer alloc] init]); 279 280 [m_avPlayer.get() addObserver:m_objcObserver.get() forKeyPath:@"rate" options:nil context:(void *)MediaPlayerAVFoundationObservationContextPlayer]; 281 282 // Add a time observer, ask to be called infrequently because we don't really want periodic callbacks but 283 // our observer will also be called whenever a seek happens. 284 const double veryLongInterval = 60*60*60*24*30; 285 WebCoreAVFMovieObserver *observer = m_objcObserver.get(); 286 m_timeObserver = [m_avPlayer.get() addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(veryLongInterval, 10) queue:nil usingBlock:^(CMTime time){ 287 [observer timeChanged:CMTimeGetSeconds(time)]; 288 }]; 289 } 290 291 if (!m_avPlayerItem) { 292 // Create the player item so we can media data. 293 m_avPlayerItem.adoptNS([[AVPlayerItem alloc] initWithAsset:m_avAsset.get()]); 294 295 [[NSNotificationCenter defaultCenter] addObserver:m_objcObserver.get()selector:@selector(didEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:m_avPlayerItem.get()]; 296 297 for (NSString *keyName in itemKVOProperties()) 298 [m_avPlayerItem.get() addObserver:m_objcObserver.get() forKeyPath:keyName options:nil context:(void *)MediaPlayerAVFoundationObservationContextPlayerItem]; 299 300 [m_avPlayer.get() replaceCurrentItemWithPlayerItem:m_avPlayerItem.get()]; 301 } 309 302 310 303 setDelayCallbacks(false); … … 322 315 void MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata() 323 316 { 324 LOG(Media, "MediaPlayerPrivateAVFoundationObjC:: beginLoadingMetadata(%p) - requesting metadata loading", this);317 LOG(Media, "MediaPlayerPrivateAVFoundationObjC::playabilityKnown(%p) - requesting metadata loading", this); 325 318 [m_avAsset.get() loadValuesAsynchronouslyForKeys:[assetMetadataKeyNames() retain] completionHandler:^{ 326 319 [m_objcObserver.get() metadataLoaded]; … … 331 324 { 332 325 if (!m_avPlayerItem) 333 return MediaPlayerPrivateAVFoundation::MediaPlayerAVPlayerItemStatus DoesNotExist;326 return MediaPlayerPrivateAVFoundation::MediaPlayerAVPlayerItemStatusUnknown; 334 327 335 328 AVPlayerItemStatus status = [m_avPlayerItem.get() status]; … … 340 333 if ([m_avPlayerItem.get() isPlaybackLikelyToKeepUp]) 341 334 return MediaPlayerPrivateAVFoundation::MediaPlayerAVPlayerItemStatusPlaybackLikelyToKeepUp; 342 if ( [m_avPlayerItem.get() isPlaybackBufferFull])335 if (buffered()->contain(duration())) 343 336 return MediaPlayerPrivateAVFoundation::MediaPlayerAVPlayerItemStatusPlaybackBufferFull; 344 if ( [m_avPlayerItem.get() isPlaybackBufferEmpty])337 if (buffered()->contain(currentTime())) 345 338 return MediaPlayerPrivateAVFoundation::MediaPlayerAVPlayerItemStatusPlaybackBufferEmpty; 346 339 … … 393 386 float MediaPlayerPrivateAVFoundationObjC::platformDuration() const 394 387 { 395 if (!metaDataAvailable() )396 return invalidTime();388 if (!metaDataAvailable() || !m_avPlayerItem) 389 return 0; 397 390 398 CMTime cmDuration; 399 400 // Check the avitem if we have one, some assets never report duration. 401 if (m_avPlayerItem) 402 cmDuration = [m_avPlayerItem.get() duration]; 403 else 404 cmDuration= [m_avAsset.get() duration]; 405 391 float duration; 392 CMTime cmDuration = [m_avPlayerItem.get() duration]; 406 393 if (CMTIME_IS_NUMERIC(cmDuration)) 407 return narrowPrecisionToFloat(CMTimeGetSeconds(cmDuration)); 408 409 if (CMTIME_IS_INDEFINITE(cmDuration)) 410 return numeric_limits<float>::infinity(); 411 412 LOG(Media, "MediaPlayerPrivateAVFoundationObjC::duration(%p) - invalid duration, returning -1", this); 413 return invalidTime(); 394 duration = narrowPrecisionToFloat(CMTimeGetSeconds(cmDuration)); 395 else if (CMTIME_IS_INDEFINITE(cmDuration)) 396 duration = numeric_limits<float>::infinity(); 397 else { 398 LOG(Media, "MediaPlayerPrivateAVFoundationObjC::duration(%p) - invalid duration, returning 0", this); 399 return 0; 400 } 401 402 return duration; 414 403 } 415 404 … … 547 536 } 548 537 549 MediaPlayerPrivateAVFoundation::A ssetStatus MediaPlayerPrivateAVFoundationObjC::assetStatus() const538 MediaPlayerPrivateAVFoundation::AVAssetStatus MediaPlayerPrivateAVFoundationObjC::assetStatus() const 550 539 { 551 540 if (!m_avAsset) 552 return MediaPlayerAVAssetStatus DoesNotExist;541 return MediaPlayerAVAssetStatusUnknown; 553 542 554 543 for (NSString *keyName in assetMetadataKeyNames()) { … … 599 588 setDelayCallbacks(false); 600 589 601 m_videoFrameHasDrawn = true;590 MediaPlayerPrivateAVFoundation::paint(context, rect); 602 591 } 603 592 … … 674 663 void MediaPlayerPrivateAVFoundationObjC::tracksChanged() 675 664 { 676 if (!m_avAsset)677 return;678 679 665 // This is called whenever the tracks collection changes so cache hasVideo and hasAudio since we are 680 666 // asked about those fairly fequently. 681 if (!m_avPlayerItem) { 682 // We don't have a player item yet, so check with the asset because some assets support inspection 683 // prior to becoming ready to play. 684 setHasVideo([[m_avAsset.get() tracksWithMediaCharacteristic:AVMediaCharacteristicVisual] count]); 685 setHasAudio([[m_avAsset.get() tracksWithMediaCharacteristic:AVMediaCharacteristicAudible] count]); 686 setHasClosedCaptions([[m_avAsset.get() tracksWithMediaType:AVMediaTypeClosedCaption] count]); 687 } else { 688 bool hasVideo = false; 689 bool hasAudio = false; 690 bool hasCaptions = false; 691 NSArray *tracks = [m_avPlayerItem.get() tracks]; 692 for (AVPlayerItemTrack *track in tracks) { 693 if ([track isEnabled]) { 694 AVAssetTrack *assetTrack = [track assetTrack]; 695 if ([[assetTrack mediaType] isEqualToString:AVMediaTypeVideo]) 696 hasVideo = true; 697 else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeAudio]) 698 hasAudio = true; 699 else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeClosedCaption]) 700 hasCaptions = true; 701 } 667 bool hasVideo = false; 668 bool hasAudio = false; 669 bool hasCaptions = false; 670 NSArray *tracks = [m_avPlayerItem.get() tracks]; 671 for (AVPlayerItemTrack *track in tracks) { 672 if ([track isEnabled]) { 673 AVAssetTrack *assetTrack = [track assetTrack]; 674 if ([[assetTrack mediaType] isEqualToString:AVMediaTypeVideo]) 675 hasVideo = true; 676 else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeAudio]) 677 hasAudio = true; 678 else if ([[assetTrack mediaType] isEqualToString:AVMediaTypeClosedCaption]) 679 hasCaptions = true; 702 680 } 703 setHasVideo(hasVideo);704 setHasAudio(hasAudio);705 setHasClosedCaptions(hasCaptions);706 }681 } 682 setHasVideo(hasVideo); 683 setHasAudio(hasAudio); 684 setHasClosedCaptions(hasCaptions); 707 685 708 686 sizeChanged(); … … 711 689 void MediaPlayerPrivateAVFoundationObjC::sizeChanged() 712 690 { 713 if (!m_avAsset)714 return;715 716 691 NSArray *tracks = [m_avAsset.get() tracks]; 717 692 718 693 // Some assets don't report track properties until they are completely ready to play, but we 719 694 // want to report a size as early as possible so use presentationSize when an asset has no tracks. 720 if ( m_avPlayerItem &&![tracks count]) {695 if (![tracks count]) { 721 696 setNaturalSize(IntSize([m_avPlayerItem.get() presentationSize])); 722 697 return;
Note: See TracChangeset
for help on using the changeset viewer.