[Win] Update Media Player logic for new Legible Output API
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jul 2015 01:11:12 +0000 (01:11 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Jul 2015 01:11:12 +0000 (01:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146922
<rdar://problem/20542574>

Reviewed by Eric Carlson.

* AVFoundationSupport.py: Check for updated AVFCF feature.
* platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
(WebCore::InbandTextTrackPrivateAVF::processNativeSamples): Update to call the
new 'readNativeSampleBuffer' method.
(WebCore::InbandTextTrackPrivateAVF::readNativeSampleBuffer): Added. This is a no-op
on Windows if it has the new AVCF API. Otherwise, it contains the same implementation
that has always been used in 'processNativeSamples'.
* platform/graphics/avfoundation/InbandTextTrackPrivateAVF.h:
* platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.cpp:
(WebCore::InbandTextTrackPrivateAVCF::readNativeSampleBuffer): Added. Use the new
Legible Output API instead of the old CoreMedia solution if it is available.
* platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.h:
(WebCore::InbandTextTrackPrivateAVCF::mediaSelectionOption):
* platform/graphics/avfoundation/cf/InbandTextTrackPrivateLegacyAVCF.cpp:
(WebCore::InbandTextTrackPrivateLegacyAVCF::readNativeSampleBuffer): Add a stub implementation.
* platform/graphics/avfoundation/cf/InbandTextTrackPrivateLegacyAVCF.h:
* platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
(WebCore::AVFWrapper::createPlayerItem): Use the new Legible Output API if it is available.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186798 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/AVFoundationSupport.py
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp
Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.h
Source/WebCore/platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.cpp
Source/WebCore/platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.h
Source/WebCore/platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp

index 62170f3..7a42187 100644 (file)
@@ -57,3 +57,7 @@ if lookFor("/include/QuartzCore/CACFLayer.h"):
     regexp = re.compile("CACFLayerSetContentsScale")
     if fileContains("/include/QuartzCore/CACFLayer.h", regexp):
         print "#define HAVE_CACFLAYER_SETCONTENTSSCALE 1"
     regexp = re.compile("CACFLayerSetContentsScale")
     if fileContains("/include/QuartzCore/CACFLayer.h", regexp):
         print "#define HAVE_CACFLAYER_SETCONTENTSSCALE 1"
+if lookFor("/include/AVFoundationCF/AVCFPlayerItemLegibleOutput.h"):
+    regexp = re.compile("kAVCFPlayerItemLegibleOutput_CallbacksVersion_2")
+    if fileContains("/include/AVFoundationCF/AVCFPlayerItemLegibleOutput.h", regexp):
+        print "#define HAVE_AVCFPLAYERITEM_CALLBACK_VERSION_2 1"
index 9802f46..aabeeb8 100644 (file)
@@ -1,3 +1,30 @@
+2015-07-13  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Update Media Player logic for new Legible Output API
+        https://bugs.webkit.org/show_bug.cgi?id=146922
+        <rdar://problem/20542574>
+
+        Reviewed by Eric Carlson.
+
+        * AVFoundationSupport.py: Check for updated AVFCF feature.
+        * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
+        (WebCore::InbandTextTrackPrivateAVF::processNativeSamples): Update to call the
+        new 'readNativeSampleBuffer' method.
+        (WebCore::InbandTextTrackPrivateAVF::readNativeSampleBuffer): Added. This is a no-op
+        on Windows if it has the new AVCF API. Otherwise, it contains the same implementation
+        that has always been used in 'processNativeSamples'.
+        * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.h:
+        * platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.cpp:
+        (WebCore::InbandTextTrackPrivateAVCF::readNativeSampleBuffer): Added. Use the new
+        Legible Output API instead of the old CoreMedia solution if it is available.
+        * platform/graphics/avfoundation/cf/InbandTextTrackPrivateAVCF.h:
+        (WebCore::InbandTextTrackPrivateAVCF::mediaSelectionOption):
+        * platform/graphics/avfoundation/cf/InbandTextTrackPrivateLegacyAVCF.cpp:
+        (WebCore::InbandTextTrackPrivateLegacyAVCF::readNativeSampleBuffer): Add a stub implementation.
+        * platform/graphics/avfoundation/cf/InbandTextTrackPrivateLegacyAVCF.h:
+        * platform/graphics/avfoundation/cf/MediaPlayerPrivateAVFoundationCF.cpp:
+        (WebCore::AVFWrapper::createPlayerItem): Use the new Legible Output API if it is available.
+
 2015-07-13  Matt Rajca  <mrajca@apple.com>
 
         Media Session: add plumbing for delivering start/end-of-interruption events
 2015-07-13  Matt Rajca  <mrajca@apple.com>
 
         Media Session: add plumbing for delivering start/end-of-interruption events
index 59a02b0..b9b9231 100644 (file)
@@ -489,29 +489,11 @@ void InbandTextTrackPrivateAVF::processNativeSamples(CFArrayRef nativeSamples, c
     LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples - %li sample buffers at time %.2f\n", count, presentationTime.toDouble());
 
     for (CFIndex i = 0; i < count; i++) {
     LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples - %li sample buffers at time %.2f\n", count, presentationTime.toDouble());
 
     for (CFIndex i = 0; i < count; i++) {
-
-        CMSampleBufferRef sampleBuffer = (CMSampleBufferRef)CFArrayGetValueAtIndex(nativeSamples, i);
-        if (!sampleBuffer)
-            continue;
-
-        CMSampleTimingInfo timingInfo;
-        OSStatus status = CMSampleBufferGetSampleTimingInfo(sampleBuffer, i, &timingInfo);
-        if (status) {
-            LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples(%p) - CMSampleBufferGetSampleTimingInfo returned error %x for sample %li", this, static_cast<int>(status), i);
+        RefPtr<ArrayBuffer> buffer;
+        MediaTime duration;
+        CMFormatDescriptionRef formatDescription;
+        if (!readNativeSampleBuffer(nativeSamples, i, buffer, duration, formatDescription))
             continue;
             continue;
-        }
-
-        CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
-        size_t bufferLength = CMBlockBufferGetDataLength(blockBuffer);
-        if (bufferLength < ISOBox::boxHeaderSize()) {
-            LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples(%p) - ERROR: CMSampleBuffer size length unexpectedly small (%zu)!!", this, bufferLength);
-            continue;
-        }
-
-        m_sampleInputBuffer.resize(m_sampleInputBuffer.size() + bufferLength);
-        CMBlockBufferCopyDataBytes(blockBuffer, 0, bufferLength, m_sampleInputBuffer.data() + m_sampleInputBuffer.size() - bufferLength);
-
-        RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(m_sampleInputBuffer.data(), m_sampleInputBuffer.size());
 
         String type = ISOBox::peekType(buffer.get());
         size_t boxLength = ISOBox::peekLength(buffer.get());
 
         String type = ISOBox::peekType(buffer.get());
         size_t boxLength = ISOBox::peekLength(buffer.get());
@@ -523,7 +505,7 @@ void InbandTextTrackPrivateAVF::processNativeSamples(CFArrayRef nativeSamples, c
         LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples(%p) - chunk type = '%s', size = %zu", this, type.utf8().data(), boxLength);
 
         if (type == ISOWebVTTCue::boxType()) {
         LOG(Media, "InbandTextTrackPrivateAVF::processNativeSamples(%p) - chunk type = '%s', size = %zu", this, type.utf8().data(), boxLength);
 
         if (type == ISOWebVTTCue::boxType()) {
-            ISOWebVTTCue cueData = ISOWebVTTCue(presentationTime, toMediaTime(timingInfo.duration), buffer.get());
+            ISOWebVTTCue cueData = ISOWebVTTCue(presentationTime, duration, buffer.get());
             LOG(Media, "    sample presentation time = %.2f, duration = %.2f", cueData.presentationTime().toDouble(), cueData.duration().toDouble());
             LOG(Media, "    id = \"%s\", settings = \"%s\", cue text = \"%s\"", cueData.id().utf8().data(), cueData.settings().utf8().data(), cueData.cueText().utf8().data());
             LOG(Media, "    sourceID = \"%s\", originalStartTime = \"%s\"", cueData.sourceID().utf8().data(), cueData.originalStartTime().utf8().data());
             LOG(Media, "    sample presentation time = %.2f, duration = %.2f", cueData.presentationTime().toDouble(), cueData.duration().toDouble());
             LOG(Media, "    id = \"%s\", settings = \"%s\", cue text = \"%s\"", cueData.id().utf8().data(), cueData.settings().utf8().data(), cueData.cueText().utf8().data());
             LOG(Media, "    sourceID = \"%s\", originalStartTime = \"%s\"", cueData.sourceID().utf8().data(), cueData.originalStartTime().utf8().data());
@@ -535,7 +517,6 @@ void InbandTextTrackPrivateAVF::processNativeSamples(CFArrayRef nativeSamples, c
             if (m_haveReportedVTTHeader)
                 break;
 
             if (m_haveReportedVTTHeader)
                 break;
 
-            CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
             if (!formatDescription)
                 break;
 
             if (!formatDescription)
                 break;
 
@@ -570,6 +551,42 @@ void InbandTextTrackPrivateAVF::processNativeSamples(CFArrayRef nativeSamples, c
     }
 }
 
     }
 }
 
+bool InbandTextTrackPrivateAVF::readNativeSampleBuffer(CFArrayRef nativeSamples, CFIndex index, RefPtr<ArrayBuffer>& buffer, MediaTime& duration, CMFormatDescriptionRef& formatDescription)
+{
+#if OS(WINDOWS) && HAVE(AVCFPLAYERITEM_CALLBACK_VERSION_2)
+    return false;
+#else
+    CMSampleBufferRef const sampleBuffer = reinterpret_cast<CMSampleBufferRef>(const_cast<void*>(CFArrayGetValueAtIndex(nativeSamples, index)));
+    if (!sampleBuffer)
+        return false;
+
+    CMSampleTimingInfo timingInfo;
+    OSStatus status = CMSampleBufferGetSampleTimingInfo(sampleBuffer, index, &timingInfo);
+    if (status) {
+        LOG(Media, "InbandTextTrackPrivateAVF::readNativeSampleBuffer(%p) - CMSampleBufferGetSampleTimingInfo returned error %x for sample %li", this, static_cast<int>(status), index);
+        return false;
+    }
+
+    duration = toMediaTime(timingInfo.duration);
+
+    CMBlockBufferRef blockBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
+    size_t bufferLength = CMBlockBufferGetDataLength(blockBuffer);
+    if (bufferLength < ISOBox::boxHeaderSize()) {
+        LOG(Media, "InbandTextTrackPrivateAVF::readNativeSampleBuffer(%p) - ERROR: CMSampleBuffer size length unexpectedly small (%zu)!!", this, bufferLength);
+        return false;
+    }
+
+    m_sampleInputBuffer.resize(m_sampleInputBuffer.size() + bufferLength);
+    CMBlockBufferCopyDataBytes(blockBuffer, 0, bufferLength, m_sampleInputBuffer.data() + m_sampleInputBuffer.size() - bufferLength);
+
+    buffer = ArrayBuffer::create(m_sampleInputBuffer.data(), m_sampleInputBuffer.size());
+
+    formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
+
+    return true;
+#endif
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(VIDEO) && (USE(AVFOUNDATION) || PLATFORM(IOS))
 } // namespace WebCore
 
 #endif // ENABLE(VIDEO) && (USE(AVFOUNDATION) || PLATFORM(IOS))
index 15f10f5..4a8ee90 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 2012-2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "InbandTextTrackPrivateClient.h"
 #include <wtf/text/StringBuilder.h>
 
 #include "InbandTextTrackPrivateClient.h"
 #include <wtf/text/StringBuilder.h>
 
+typedef const struct opaqueCMFormatDescription* CMFormatDescriptionRef;
+
+namespace JSC {
+class ArrayBuffer;
+}
+
 namespace WebCore {
 
 class AVFInbandTrackParent {
 namespace WebCore {
 
 class AVFInbandTrackParent {
@@ -70,6 +76,8 @@ public:
     virtual Category textTrackCategory() const = 0;
     
     virtual MediaTime startTimeVariance() const override { return MediaTime(1, 4); }
     virtual Category textTrackCategory() const = 0;
     
     virtual MediaTime startTimeVariance() const override { return MediaTime(1, 4); }
+
+    virtual bool readNativeSampleBuffer(CFArrayRef nativeSamples, CFIndex, RefPtr<JSC::ArrayBuffer>&, MediaTime&, CMFormatDescriptionRef&);
     
 protected:
     InbandTextTrackPrivateAVF(AVFInbandTrackParent*, CueFormat);
     
 protected:
     InbandTextTrackPrivateAVF(AVFInbandTrackParent*, CueFormat);
index e6ca444..f7cb476 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include "InbandTextTrackPrivateAVCF.h"
 
 #include "FloatConversion.h"
 #include "InbandTextTrackPrivateAVCF.h"
 
 #include "FloatConversion.h"
+#include "ISOVTTCue.h"
 #include "InbandTextTrackPrivate.h"
 #include "InbandTextTrackPrivateAVF.h"
 #include "Logging.h"
 #include "InbandTextTrackPrivate.h"
 #include "InbandTextTrackPrivateAVF.h"
 #include "Logging.h"
+#include "MediaTimeAVFoundation.h"
 #include "SoftLinking.h"
 #include "SoftLinking.h"
+#include <JavaScriptCore/ArrayBuffer.h>
 
 #include <AVFoundationCF/AVCFPlayerItemLegibleOutput.h>
 #include <AVFoundationCF/AVFoundationCF.h>
 
 #include <AVFoundationCF/AVCFPlayerItemLegibleOutput.h>
 #include <AVFoundationCF/AVFoundationCF.h>
@@ -184,6 +187,29 @@ bool InbandTextTrackPrivateAVCF::isDefault() const
     return false;
 }
 
     return false;
 }
 
+bool InbandTextTrackPrivateAVCF::readNativeSampleBuffer(CFArrayRef nativeSamples, CFIndex index, RefPtr<ArrayBuffer>& buffer, MediaTime& duration, CMFormatDescriptionRef& formatDescription)
+{
+    const AVCFPlayerItemLegibleOutputSample* sampleBuffer = reinterpret_cast<const AVCFPlayerItemLegibleOutputSample*>(CFArrayGetValueAtIndex(nativeSamples, index));
+    if (!sampleBuffer)
+        return false;
+
+    duration = toMediaTime(sampleBuffer->duration);
+    formatDescription = sampleBuffer->formatDescription;
+
+    size_t bufferLength = CFDataGetLength(sampleBuffer->buffer);
+    if (bufferLength < ISOBox::boxHeaderSize()) {
+        LOG(Media, "InbandTextTrackPrivateLegacyAVCF::readNativeSampleBuffer(%p) - ERROR: CFBuffer size length unexpectedly small (%zu)!!", this, bufferLength);
+        return false;
+    }
+
+    m_sampleInputBuffer.resize(m_sampleInputBuffer.size() + bufferLength);
+    CFDataGetBytes(sampleBuffer->buffer, CFRangeMake(0, bufferLength), reinterpret_cast<UInt8*>(m_sampleInputBuffer.data()) + m_sampleInputBuffer.size() - bufferLength);
+
+    buffer = ArrayBuffer::create(m_sampleInputBuffer.data(), m_sampleInputBuffer.size());
+
+    return true;
+}
+
 } // namespace WebCore
 
 #endif
 } // namespace WebCore
 
 #endif
index 88f732a..fd12486 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -55,7 +55,8 @@ public:
 
     virtual void disconnect() override;
 
 
     virtual void disconnect() override;
 
-    virtual Category textTrackCategory() const override { return InBand; }
+    Category textTrackCategory() const override { return InBand; }
+    bool readNativeSampleBuffer(CFArrayRef nativeSamples, CFIndex, RefPtr<JSC::ArrayBuffer>&, MediaTime&, CMFormatDescriptionRef&) override;
 
     AVCFMediaSelectionOptionRef mediaSelectionOption() const { return m_mediaSelectionOption.get(); }
 
 
     AVCFMediaSelectionOptionRef mediaSelectionOption() const { return m_mediaSelectionOption.get(); }
 
index e3bc495..a426281 100644 (file)
@@ -1616,7 +1616,11 @@ void AVFWrapper::createPlayerItem()
     AVCFPlayerItemOutputSetSuppressPlayerRendering(m_legibleOutput.get(), TRUE);
 
     AVCFPlayerItemLegibleOutputCallbacks callbackInfo;
     AVCFPlayerItemOutputSetSuppressPlayerRendering(m_legibleOutput.get(), TRUE);
 
     AVCFPlayerItemLegibleOutputCallbacks callbackInfo;
+#if HAVE(AVCFPLAYERITEM_CALLBACK_VERSION_2)
+    callbackInfo.version = kAVCFPlayerItemLegibleOutput_CallbacksVersion_2;
+#else
     callbackInfo.version = kAVCFPlayerItemLegibleOutput_CallbacksVersion_1;
     callbackInfo.version = kAVCFPlayerItemLegibleOutput_CallbacksVersion_1;
+#endif
     ASSERT(callbackContext());
     callbackInfo.context = callbackContext();
     callbackInfo.legibleOutputCallback = AVFWrapper::legibleOutputCallback;
     ASSERT(callbackContext());
     callbackInfo.context = callbackContext();
     callbackInfo.legibleOutputCallback = AVFWrapper::legibleOutputCallback;