Title: [276828] trunk/Source/WebCore
Revision
276828
Author
[email protected]
Date
2021-04-29 19:04:29 -0700 (Thu, 29 Apr 2021)

Log Message

Adopt AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification
https://bugs.webkit.org/show_bug.cgi?id=225170
Source/WebCore:

rdar://77086915

Reviewed by Eric Carlson.

When the AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification is received, the SourceBuffer will now
re-enqueue all audio frames from currentTime.
The handling of AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification is currently broken in AVFoundation.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: Add missing #include
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(-[WebAVSampleBufferErrorListener beginObservingRenderer:]): Add listener
(-[WebAVSampleBufferErrorListener stopObservingRenderer:]): Remove listener
(-[WebAVSampleBufferErrorListener audioRendererWasAutomaticallyFlushed:]):
(WebCore::SourceBufferPrivateAVFObjC::rendererWasAutomaticallyFlushed):

Source/WebCore/PAL:

Reviewed by Eric Carlson.

* pal/cocoa/AVFoundationSoftLink.h: Add AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification and its related key
* pal/cocoa/AVFoundationSoftLink.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276827 => 276828)


--- trunk/Source/WebCore/ChangeLog	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/ChangeLog	2021-04-30 02:04:29 UTC (rev 276828)
@@ -1,4 +1,24 @@
 2021-04-29  Jean-Yves Avenard  <[email protected]>
+
+        Adopt AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification
+        https://bugs.webkit.org/show_bug.cgi?id=225170
+        rdar://77086915
+
+        Reviewed by Eric Carlson.
+
+        When the AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification is received, the SourceBuffer will now
+        re-enqueue all audio frames from currentTime.
+        The handling of AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification is currently broken in AVFoundation.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: Add missing #include
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (-[WebAVSampleBufferErrorListener beginObservingRenderer:]): Add listener
+        (-[WebAVSampleBufferErrorListener stopObservingRenderer:]): Remove listener
+        (-[WebAVSampleBufferErrorListener audioRendererWasAutomaticallyFlushed:]):
+        (WebCore::SourceBufferPrivateAVFObjC::rendererWasAutomaticallyFlushed):
+
+2021-04-29  Jean-Yves Avenard  <[email protected]>
         https://bugs.webkit.org/show_bug.cgi?id=225183
         rdar://77251937
 

Modified: trunk/Source/WebCore/PAL/ChangeLog (276827 => 276828)


--- trunk/Source/WebCore/PAL/ChangeLog	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/PAL/ChangeLog	2021-04-30 02:04:29 UTC (rev 276828)
@@ -1,3 +1,13 @@
+2021-04-29  Jean-Yves Avenard  <[email protected]>
+
+        Adopt AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification
+        https://bugs.webkit.org/show_bug.cgi?id=225170
+
+        Reviewed by Eric Carlson.
+
+        * pal/cocoa/AVFoundationSoftLink.h: Add AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification and its related key
+        * pal/cocoa/AVFoundationSoftLink.mm:
+
 2021-04-26  Alex Christensen  <[email protected]>
 
         Add missing SPI declarations

Modified: trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h (276827 => 276828)


--- trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.h	2021-04-30 02:04:29 UTC (rev 276828)
@@ -148,6 +148,11 @@
 SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey, NSString*)
 #define AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey PAL::get_AVFoundation_AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey()
 
+SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification, NSString*)
+#define AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification PAL::get_AVFoundation_AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification()
+SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVSampleBufferAudioRendererFlushTimeKey, NSString*)
+#define AVSampleBufferAudioRendererFlushTimeKey PAL::get_AVFoundation_AVSampleBufferAudioRendererFlushTimeKey()
+
 SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVMediaCharacteristicContainsOnlyForcedSubtitles, NSString *)
 #define AVMediaCharacteristicContainsOnlyForcedSubtitles PAL::get_AVFoundation_AVMediaCharacteristicContainsOnlyForcedSubtitles()
 SOFT_LINK_CONSTANT_FOR_HEADER(PAL, AVFoundation, AVMediaCharacteristicLegible, NSString *)

Modified: trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm (276827 => 276828)


--- trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/PAL/pal/cocoa/AVFoundationSoftLink.mm	2021-04-30 02:04:29 UTC (rev 276828)
@@ -170,6 +170,8 @@
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVPlayerItemLegibleOutputTextStylingResolutionSourceAndRulesOnly, NSString *, PAL_EXPORT)
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVSampleBufferDisplayLayerFailedToDecodeNotification, NSString*, PAL_EXPORT)
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey, NSString*, PAL_EXPORT)
+SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification, NSString*, PAL_EXPORT)
+SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVSampleBufferAudioRendererFlushTimeKey, NSString*, PAL_EXPORT)
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVStreamDataParserContentKeyRequestProtocolVersionsKey, NSString *, PAL_EXPORT)
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVStreamSessionContentProtectionSessionIdentifierChangedNotification, NSString *, PAL_EXPORT)
 SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, AVFoundation, AVStreamingKeyDeliveryContentKeyType, NSString *, PAL_EXPORT)

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm (276827 => 276828)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2021-04-30 02:04:29 UTC (rev 276828)
@@ -44,6 +44,7 @@
 #import "WebCoreDecompressionSession.h"
 #import <AVFoundation/AVAsset.h>
 #import <AVFoundation/AVTime.h>
+#import <CoreMedia/CMTime.h>
 #import <QuartzCore/CALayer.h>
 #import <objc_runtime.h>
 #import <pal/avfoundation/MediaTimeAVFoundation.h>

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h (276827 => 276828)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h	2021-04-30 02:04:29 UTC (rev 276828)
@@ -113,6 +113,7 @@
     void registerForErrorNotifications(SourceBufferPrivateAVFObjCErrorClient*);
     void unregisterForErrorNotifications(SourceBufferPrivateAVFObjCErrorClient*);
     void layerDidReceiveError(AVSampleBufferDisplayLayer *, NSError *);
+    void rendererWasAutomaticallyFlushed(AVSampleBufferAudioRenderer *, const CMTime&);
     void outputObscuredDueToInsufficientExternalProtectionChanged(bool);
     ALLOW_NEW_API_WITHOUT_GUARDS_BEGIN
     void rendererDidReceiveError(AVSampleBufferAudioRenderer *, NSError *);

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (276827 => 276828)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2021-04-30 01:42:20 UTC (rev 276827)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2021-04-30 02:04:29 UTC (rev 276828)
@@ -169,6 +169,7 @@
 
     _renderers.append(renderer);
     [renderer addObserver:self forKeyPath:@"error" options:NSKeyValueObservingOptionNew context:nullptr];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioRendererWasAutomaticallyFlushed:) name:AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification object:renderer];
 }
 
 ALLOW_NEW_API_WITHOUT_GUARDS_BEGIN
@@ -179,6 +180,8 @@
     ASSERT(_renderers.contains(renderer));
 
     [renderer removeObserver:self forKeyPath:@"error"];
+    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVSampleBufferAudioRendererWasFlushedAutomaticallyNotification object:renderer];
+
     _renderers.remove(_renderers.find(renderer));
 }
 
@@ -239,6 +242,18 @@
             parent->layerDidReceiveError(layer.get(), error.get());
     });
 }
+
+- (void)audioRendererWasAutomaticallyFlushed:(NSNotification*)note
+{
+    RetainPtr<AVSampleBufferAudioRenderer> renderer = (AVSampleBufferAudioRenderer *)[note object];
+    if (!_renderers.contains(renderer.get()))
+        return;
+
+    callOnMainThread([parent = _parent, renderer = WTFMove(renderer), flushTime = [[[note userInfo] valueForKey:AVSampleBufferAudioRendererFlushTimeKey] CMTimeValue]] {
+        if (parent)
+            parent->rendererWasAutomaticallyFlushed(renderer.get(), flushTime);
+    });
+}
 @end
 
 namespace WebCore {
@@ -944,6 +959,24 @@
         m_client->sourceBufferPrivateDidReceiveRenderingError(errorCode);
 }
 
+void SourceBufferPrivateAVFObjC::rendererWasAutomaticallyFlushed(AVSampleBufferAudioRenderer *renderer, const CMTime& time)
+{
+    auto mediaTime = toMediaTime(time);
+    ERROR_LOG(LOGIDENTIFIER, mediaTime);
+    AtomString trackId;
+    for (auto& pair : m_audioRenderers) {
+        if (pair.value.get() == renderer) {
+            trackId = String::number(pair.key);
+            break;
+        }
+    }
+    if (trackId.isEmpty()) {
+        ERROR_LOG(LOGIDENTIFIER, "Couldn't find track attached to Audio Renderer.");
+        return;
+    }
+    reenqueSamples(trackId);
+}
+
 void SourceBufferPrivateAVFObjC::outputObscuredDueToInsufficientExternalProtectionChanged(bool obscured)
 {
 #if ENABLE(ENCRYPTED_MEDIA) && HAVE(AVCONTENTKEYSESSION)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to