Title: [167658] trunk/Source/WebCore
- Revision
- 167658
- Author
- eric.carl...@apple.com
- Date
- 2014-04-22 07:06:36 -0700 (Tue, 22 Apr 2014)
Log Message
[Mac] don't ask for AVAssetTrack properties before they are available
https://bugs.webkit.org/show_bug.cgi?id=131902
<rdar://problem/16505076>
Reviewed by Jer Noble.
No new tests, the behavior this changes can not be tested with a layout test.
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
m_cachedTotalBytes.
(WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Don't report that
metadata has been loaded until the track properties we need have been loaded too.
(WebCore::MediaPlayerPrivateAVFoundationObjC::totalBytes): Cache totalBytes instead
of recalculating it every time.
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Invalidate cached
total bytes.
(WebCore::assetTrackMetadataKeyNames): Array of AVAssetTrack properties we use.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (167657 => 167658)
--- trunk/Source/WebCore/ChangeLog 2014-04-22 13:39:49 UTC (rev 167657)
+++ trunk/Source/WebCore/ChangeLog 2014-04-22 14:06:36 UTC (rev 167658)
@@ -1,3 +1,25 @@
+2014-04-22 Eric Carlson <eric.carl...@apple.com>
+
+ [Mac] don't ask for AVAssetTrack properties before they are available
+ https://bugs.webkit.org/show_bug.cgi?id=131902
+ <rdar://problem/16505076>
+
+ Reviewed by Jer Noble.
+
+ No new tests, the behavior this changes can not be tested with a layout test.
+
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
+ m_cachedTotalBytes.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Don't report that
+ metadata has been loaded until the track properties we need have been loaded too.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::totalBytes): Cache totalBytes instead
+ of recalculating it every time.
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Invalidate cached
+ total bytes.
+ (WebCore::assetTrackMetadataKeyNames): Array of AVAssetTrack properties we use.
+
2014-04-22 Peter Molnar <pmolnar.u-sze...@partner.samsung.com>
Buildfix after r167650 broke non-Cocoa builds
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (167657 => 167658)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-04-22 13:39:49 UTC (rev 167657)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-04-22 14:06:36 UTC (rev 167658)
@@ -320,6 +320,7 @@
FloatSize m_cachedPresentationSize;
double m_cachedDuration;
double m_cachedRate;
+ mutable long long m_cachedTotalBytes;
unsigned m_pendingStatusChanges;
int m_cachedItemStatus;
bool m_cachedLikelyToKeepUp;
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (167657 => 167658)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-04-22 13:39:49 UTC (rev 167657)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-04-22 14:06:36 UTC (rev 167658)
@@ -294,6 +294,7 @@
static NSArray *assetMetadataKeyNames();
static NSArray *itemKVOProperties();
+static NSArray* assetTrackMetadataKeyNames();
#if !LOG_DISABLED
static const char *boolString(bool val)
@@ -365,6 +366,7 @@
, m_currentTextTrack(0)
, m_cachedDuration(MediaPlayer::invalidTime())
, m_cachedRate(0)
+ , m_cachedTotalBytes(0)
, m_pendingStatusChanges(0)
, m_cachedItemStatus(MediaPlayerAVPlayerItemStatusDoesNotExist)
, m_cachedLikelyToKeepUp(false)
@@ -783,9 +785,23 @@
void MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata()
{
LOG(Media, "MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata(%p) - requesting metadata loading", this);
+ dispatch_group_t metadataLoadingGroup = dispatch_group_create();
+ dispatch_group_enter(metadataLoadingGroup);
[m_avAsset.get() loadValuesAsynchronouslyForKeys:[assetMetadataKeyNames() retain] completionHandler:^{
+ if ([m_avAsset.get() statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
+ for (AVAssetTrack *track in [m_avAsset.get() tracks]) {
+ dispatch_group_enter(metadataLoadingGroup);
+ [track loadValuesAsynchronouslyForKeys:[assetTrackMetadataKeyNames() retain] completionHandler:^{
+ dispatch_group_leave(metadataLoadingGroup);
+ }];
+ }
+ }
+ dispatch_group_leave(metadataLoadingGroup);
+ }];
+ dispatch_group_notify(metadataLoadingGroup, dispatch_get_main_queue(), ^{
[m_objcObserver.get() metadataLoaded];
- }];
+ });
+ dispatch_release(metadataLoadingGroup);
}
MediaPlayerPrivateAVFoundation::ItemStatus MediaPlayerPrivateAVFoundationObjC::playerItemStatus() const
@@ -1130,11 +1146,13 @@
if (!metaDataAvailable())
return 0;
- long long totalMediaSize = 0;
+ if (m_cachedTotalBytes)
+ return m_cachedTotalBytes;
+
for (AVPlayerItemTrack *thisTrack in m_cachedTracks.get())
- totalMediaSize += [[thisTrack assetTrack] totalSampleDataLength];
+ m_cachedTotalBytes += [[thisTrack assetTrack] totalSampleDataLength];
- return totalMediaSize;
+ return m_cachedTotalBytes;
}
void MediaPlayerPrivateAVFoundationObjC::setAsset(id asset)
@@ -2343,6 +2361,7 @@
void MediaPlayerPrivateAVFoundationObjC::tracksDidChange(RetainPtr<NSArray> tracks)
{
m_cachedTracks = tracks;
+ m_cachedTotalBytes = 0;
tracksChanged();
updateStates();
@@ -2424,6 +2443,15 @@
return keys;
}
+NSArray* assetTrackMetadataKeyNames()
+{
+ static NSArray* keys;
+ if (!keys)
+ keys = @[@"totalSampleDataLength", @"mediaType"];
+
+ return keys;
+}
+
} // namespace WebCore
@implementation WebCoreAVFMovieObserver
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes