Changeset 157055 in webkit


Ignore:
Timestamp:
Oct 7, 2013, 1:04:46 PM (12 years ago)
Author:
dino@apple.com
Message:

[Mac] Drawing video into canvas doesn't work on the first attempt
https://bugs.webkit.org/show_bug.cgi?id=122404

Patch by Jer Noble <jer.noble@apple.com> on 2013-10-07
Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-canvas-drawing.html

If creating and painting from an AVPlayerItemVideoOutput fails, fall back
to the (much slower) AVAssetImageGenerator path. Make sure to revert to the
AVPlayerItemVideoOutput path when that object begins to have available
images, however.

To do so, remove the "MAC_OS_X_VERSION_MIN_REQUIRED < 1080" check around
the AVAssetImageGenerator code, and allow both the image generator and video
output to exist simultaneously.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::MediaPlayerPrivateAVFoundationObjC::hasContextRenderer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyContextVideoRenderer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::destroyImageGenerator):
(WebCore::MediaPlayerPrivateAVFoundationObjC::paintCurrentFrameInContext):
(WebCore::MediaPlayerPrivateAVFoundationObjC::videoOutputHasAvailableFrame):
(WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput):

LayoutTests:

  • media/video-canvas-drawing-expected.png: Added.
  • media/video-canvas-drawing-expected.txt: Added.
  • media/video-canvas-drawing.html: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r157053 r157055  
     12013-10-07  Jer Noble  <jer.noble@apple.com>
     2
     3        [Mac] Drawing video into canvas doesn't work on the first attempt
     4        https://bugs.webkit.org/show_bug.cgi?id=122404
     5
     6        Reviewed by Eric Carlson.
     7
     8        * media/video-canvas-drawing-expected.png: Added.
     9        * media/video-canvas-drawing-expected.txt: Added.
     10        * media/video-canvas-drawing.html: Added.
     11
    1122013-10-07  Tim Horton  <timothy_horton@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r157054 r157055  
     12013-10-07  Jer Noble  <jer.noble@apple.com>
     2
     3        [Mac] Drawing video into canvas doesn't work on the first attempt
     4        https://bugs.webkit.org/show_bug.cgi?id=122404
     5
     6        Reviewed by Eric Carlson.
     7
     8        Test: media/video-canvas-drawing.html
     9
     10        If creating and painting from an AVPlayerItemVideoOutput fails, fall back
     11        to the (much slower) AVAssetImageGenerator path. Make sure to revert to the
     12        AVPlayerItemVideoOutput path when that object begins to have available
     13        images, however.
     14
     15        To do so, remove the "__MAC_OS_X_VERSION_MIN_REQUIRED < 1080" check around
     16        the AVAssetImageGenerator code, and allow both the image generator and video
     17        output to exist simultaneously.
     18
     19        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
     20        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     21        (WebCore::MediaPlayerPrivateAVFoundationObjC::hasContextRenderer):
     22        (WebCore::MediaPlayerPrivateAVFoundationObjC::destroyContextVideoRenderer):
     23        (WebCore::MediaPlayerPrivateAVFoundationObjC::destroyImageGenerator):
     24        (WebCore::MediaPlayerPrivateAVFoundationObjC::paintCurrentFrameInContext):
     25        (WebCore::MediaPlayerPrivateAVFoundationObjC::videoOutputHasAvailableFrame):
     26        (WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput):
     27
    1282013-10-07  Jer Noble  <jer.noble@apple.com>
    229
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h

    r157044 r157055  
    155155    virtual bool hasSingleSecurityOrigin() const;
    156156   
    157 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    158157    void createImageGenerator();
    159158    void destroyImageGenerator();
    160159    RetainPtr<CGImageRef> createImageForTimeInRect(float, const IntRect&);
    161160    void paintWithImageGenerator(GraphicsContext*, const IntRect&);
    162 #else
     161
     162#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    163163    void createVideoOutput();
    164164    void destroyVideoOutput();
    165165    RetainPtr<CVPixelBufferRef> createPixelBuffer();
     166    bool videoOutputHasAvailableFrame();
    166167    void paintWithVideoOutput(GraphicsContext*, const IntRect&);
    167168#endif
     
    202203    bool m_haveCheckedPlayability;
    203204
    204 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    205205    RetainPtr<AVAssetImageGenerator> m_imageGenerator;
    206 #else
     206#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    207207    RetainPtr<AVPlayerItemVideoOutput> m_videoOutput;
    208208    RetainPtr<CVPixelBufferRef> m_lastImage;
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r156726 r157055  
    313313{
    314314#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    315     return m_videoOutput;
    316 #else
     315    if (m_videoOutput)
     316        return true;
     317#endif
    317318    return m_imageGenerator;
    318 #endif
    319319}
    320320
     
    328328}
    329329
    330 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    331330void MediaPlayerPrivateAVFoundationObjC::createImageGenerator()
    332331{
     
    345344    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::createImageGenerator(%p) - returning %p", this, m_imageGenerator.get());
    346345}
    347 #endif
    348346
    349347void MediaPlayerPrivateAVFoundationObjC::destroyContextVideoRenderer()
     
    351349#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    352350    destroyVideoOutput();
    353 #else
     351#endif
    354352    destroyImageGenerator();
    355 #endif
    356 }
    357 
    358 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
     353}
     354
    359355void MediaPlayerPrivateAVFoundationObjC::destroyImageGenerator()
    360356{
     
    366362    m_imageGenerator = 0;
    367363}
    368 #endif
    369364
    370365void MediaPlayerPrivateAVFoundationObjC::createVideoLayer()
     
    803798
    804799#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    805     paintWithVideoOutput(context, rect);
    806 #else
    807     paintWithImageGenerator(context, rect);
    808 #endif
     800    if (videoOutputHasAvailableFrame())
     801        paintWithVideoOutput(context, rect);
     802    else
     803#endif
     804        paintWithImageGenerator(context, rect);
    809805
    810806    END_BLOCK_OBJC_EXCEPTIONS;
     
    826822}
    827823
    828 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    829824void MediaPlayerPrivateAVFoundationObjC::paintWithImageGenerator(GraphicsContext* context, const IntRect& rect)
    830825{
     
    840835    }
    841836}
    842 #endif
    843837
    844838static HashSet<String> mimeTypeCache()
     
    858852}
    859853
    860 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
    861854RetainPtr<CGImageRef> MediaPlayerPrivateAVFoundationObjC::createImageForTimeInRect(float time, const IntRect& rect)
    862855{
     
    879872    return image;
    880873}
    881 #endif
    882874
    883875void MediaPlayerPrivateAVFoundationObjC::getSupportedTypes(HashSet<String>& supportedTypes)
     
    12601252}
    12611253
     1254bool MediaPlayerPrivateAVFoundationObjC::videoOutputHasAvailableFrame()
     1255{
     1256    if (!m_avPlayerItem)
     1257        return false;
     1258
     1259    if (m_lastImage)
     1260        return true;
     1261
     1262    if (!m_videoOutput)
     1263        createVideoOutput();
     1264
     1265    return [m_videoOutput hasNewPixelBufferForItemTime:[m_avPlayerItem currentTime]];
     1266}
     1267
    12621268void MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput(GraphicsContext* context, const IntRect& rect)
    12631269{
     
    12821288        CGRect imageRect = CGRectMake(0, 0, CVPixelBufferGetWidth(m_lastImage.get()), CVPixelBufferGetHeight(m_lastImage.get()));
    12831289        [ciContext drawImage:image.get() inRect:outputRect fromRect:imageRect];
     1290
     1291        // If we have created an AVAssetImageGenerator in the past due to m_videoOutput not having an available
     1292        // video frame, destroy it now that it is no longer needed.
     1293        if (m_imageGenerator)
     1294            destroyImageGenerator();
    12841295    }
    12851296}
Note: See TracChangeset for help on using the changeset viewer.