Changeset 167658 in webkit


Ignore:
Timestamp:
Apr 22, 2014 7:06:36 AM (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 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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167654 r167658  
     12014-04-22  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 Jer Noble.
     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-22  Peter Molnar  <pmolnar.u-szeged@partner.samsung.com>
    224
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r167632 r167658  
    321321    double m_cachedDuration;
    322322    double m_cachedRate;
     323    mutable long long m_cachedTotalBytes;
    323324    unsigned m_pendingStatusChanges;
    324325    int m_cachedItemStatus;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r167632 r167658  
    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)
     
    784786{
    785787    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata(%p) - requesting metadata loading", this);
     788    dispatch_group_t metadataLoadingGroup = dispatch_group_create();
     789    dispatch_group_enter(metadataLoadingGroup);
    786790    [m_avAsset.get() loadValuesAsynchronouslyForKeys:[assetMetadataKeyNames() retain] completionHandler:^{
     791        if ([m_avAsset.get() statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
     792            for (AVAssetTrack *track in [m_avAsset.get() tracks]) {
     793                dispatch_group_enter(metadataLoadingGroup);
     794                [track loadValuesAsynchronouslyForKeys:[assetTrackMetadataKeyNames() retain] completionHandler:^{
     795                    dispatch_group_leave(metadataLoadingGroup);
     796                }];
     797            }
     798        }
     799        dispatch_group_leave(metadataLoadingGroup);
     800    }];
     801    dispatch_group_notify(metadataLoadingGroup, dispatch_get_main_queue(), ^{
    787802        [m_objcObserver.get() metadataLoaded];
    788     }];
     803    });
     804    dispatch_release(metadataLoadingGroup);
    789805}
    790806
     
    11311147        return 0;
    11321148
    1133     long long totalMediaSize = 0;
     1149    if (m_cachedTotalBytes)
     1150        return m_cachedTotalBytes;
     1151
    11341152    for (AVPlayerItemTrack *thisTrack in m_cachedTracks.get())
    1135         totalMediaSize += [[thisTrack assetTrack] totalSampleDataLength];
    1136 
    1137     return totalMediaSize;
     1153        m_cachedTotalBytes += [[thisTrack assetTrack] totalSampleDataLength];
     1154
     1155    return m_cachedTotalBytes;
    11381156}
    11391157
     
    23442362{
    23452363    m_cachedTracks = tracks;
     2364    m_cachedTotalBytes = 0;
    23462365
    23472366    tracksChanged();
     
    24222441                nil];
    24232442    }
     2443    return keys;
     2444}
     2445
     2446NSArray* assetTrackMetadataKeyNames()
     2447{
     2448    static NSArray* keys;
     2449    if (!keys)
     2450        keys = @[@"totalSampleDataLength", @"mediaType"];
     2451
    24242452    return keys;
    24252453}
Note: See TracChangeset for help on using the changeset viewer.