Changeset 167776 in webkit


Ignore:
Timestamp:
Apr 24, 2014 2:46:19 PM (10 years ago)
Author:
eric.carlson@apple.com
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 Brent Fulgham.

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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167773 r167776  
     12014-04-24  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] don't ask for AVAssetTrack properties before they are available
     4        https://bugs.webkit.org/show_bug.cgi?id=131902
     5        <rdar://problem/16505076>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        No new tests, the behavior this changes can not be tested with a layout test.
     10
     11        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
     12        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     13        (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
     14            m_cachedTotalBytes.
     15        (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Don't report that
     16            metadata has been loaded until the track properties we need have been loaded too.
     17        (WebCore::MediaPlayerPrivateAVFoundationObjC::totalBytes): Cache totalBytes instead
     18            of recalculating it every time.
     19        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Invalidate cached
     20            total bytes.
     21        (WebCore::assetTrackMetadataKeyNames): Array of AVAssetTrack properties we use.
     22
    1232014-04-24  Myles C. Maxfield  <mmaxfield@apple.com>
    224
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r167734 r167776  
    323323    double m_cachedDuration;
    324324    double m_cachedRate;
     325    mutable long long m_cachedTotalBytes;
    325326    unsigned m_pendingStatusChanges;
    326327    int m_cachedItemStatus;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r167734 r167776  
    295295static NSArray *assetMetadataKeyNames();
    296296static NSArray *itemKVOProperties();
     297static NSArray* assetTrackMetadataKeyNames();
    297298
    298299#if !LOG_DISABLED
     
    366367    , m_cachedDuration(MediaPlayer::invalidTime())
    367368    , m_cachedRate(0)
     369    , m_cachedTotalBytes(0)
    368370    , m_pendingStatusChanges(0)
    369371    , m_cachedItemStatus(MediaPlayerAVPlayerItemStatusDoesNotExist)
     
    785787{
    786788    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata(%p) - requesting metadata loading", this);
    787     [m_avAsset.get() loadValuesAsynchronouslyForKeys:[assetMetadataKeyNames() retain] completionHandler:^{
    788         [m_objcObserver.get() metadataLoaded];
     789
     790    dispatch_group_t metadataLoadingGroup = dispatch_group_create();
     791    dispatch_group_enter(metadataLoadingGroup);
     792    auto weakThis = createWeakPtr();
     793    [m_avAsset.get() loadValuesAsynchronouslyForKeys:assetMetadataKeyNames() completionHandler:^{
     794
     795        callOnMainThread([weakThis, metadataLoadingGroup] {
     796            if (weakThis && [weakThis->m_avAsset.get() statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
     797                for (AVAssetTrack *track in [weakThis->m_avAsset.get() tracks]) {
     798                    dispatch_group_enter(metadataLoadingGroup);
     799                    [track loadValuesAsynchronouslyForKeys:assetTrackMetadataKeyNames() completionHandler:^{
     800                        dispatch_group_leave(metadataLoadingGroup);
     801                    }];
     802                }
     803            }
     804            dispatch_group_leave(metadataLoadingGroup);
     805        });
    789806    }];
     807
     808    dispatch_group_notify(metadataLoadingGroup, dispatch_get_main_queue(), ^{
     809        callOnMainThread([weakThis] {
     810            if (weakThis)
     811                [weakThis->m_objcObserver.get() metadataLoaded];
     812        });
     813
     814        dispatch_release(metadataLoadingGroup);
     815    });
    790816}
    791817
     
    11321158        return 0;
    11331159
    1134     long long totalMediaSize = 0;
     1160    if (m_cachedTotalBytes)
     1161        return m_cachedTotalBytes;
     1162
    11351163    for (AVPlayerItemTrack *thisTrack in m_cachedTracks.get())
    1136         totalMediaSize += [[thisTrack assetTrack] totalSampleDataLength];
    1137 
    1138     return totalMediaSize;
     1164        m_cachedTotalBytes += [[thisTrack assetTrack] totalSampleDataLength];
     1165
     1166    return m_cachedTotalBytes;
    11391167}
    11401168
     
    23622390{
    23632391    m_cachedTracks = tracks;
     2392    m_cachedTotalBytes = 0;
    23642393
    23652394    tracksChanged();
     
    24402469                nil];
    24412470    }
     2471    return keys;
     2472}
     2473
     2474NSArray* assetTrackMetadataKeyNames()
     2475{
     2476    static NSArray* keys = [[NSArray alloc] initWithObjects:@"totalSampleDataLength", @"mediaType", nil];
     2477
    24422478    return keys;
    24432479}
Note: See TracChangeset for help on using the changeset viewer.