Unreviewed, rolling out r255910, r255970, and r255972.
authorryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Feb 2020 20:01:27 +0000 (20:01 +0000)
committerryanhaddad@apple.com <ryanhaddad@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Feb 2020 20:01:27 +0000 (20:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207345

Broke internal builds (Requested by ryanhaddad on #webkit).

Reverted changesets:

"[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
https://bugs.webkit.org/show_bug.cgi?id=206582
https://trac.webkit.org/changeset/255910

"[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
https://bugs.webkit.org/show_bug.cgi?id=206582
https://trac.webkit.org/changeset/255970

"[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
https://bugs.webkit.org/show_bug.cgi?id=206582
https://trac.webkit.org/changeset/255972

Patch by Commit Queue <commit-queue@webkit.org> on 2020-02-06

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

38 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable-gpuprocess.html
LayoutTests/platform/mac/TestExpectations
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformHave.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediarecorder/MediaRecorderProvider.cpp
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.cpp [deleted file]
Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.h [deleted file]
Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp
Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h
Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp [deleted file]
Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h [deleted file]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp
Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.h
Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.h [deleted file]
Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm [deleted file]
Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h
Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm
Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.h [deleted file]
Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.mm [deleted file]
Source/WebKit/ChangeLog
Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp
Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.cpp
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.h
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorder.messages.in
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorderManager.cpp
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorderManager.h
Source/WebKit/GPUProcess/webrtc/RemoteMediaRecorderManager.messages.in
Source/WebKit/GPUProcess/webrtc/RemoteSampleBufferDisplayLayerManager.h
Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.cpp
Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderPrivate.h
Source/WebKit/WebProcess/GPU/webrtc/MediaRecorderProvider.cpp

index 54315c6..b5d58eb 100644 (file)
@@ -1,3 +1,24 @@
+2020-02-06  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r255910, r255970, and r255972.
+        https://bugs.webkit.org/show_bug.cgi?id=207345
+
+        Broke internal builds (Requested by ryanhaddad on #webkit).
+
+        Reverted changesets:
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255910
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255970
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255972
+
 2020-02-06  Ali Juma  <ajuma@chromium.org>
 
         Crash in RenderTableCol::willBeRemovedFromTree()
index 03541a2..ec66d7c 100644 (file)
@@ -3332,10 +3332,7 @@ webgl/1.0.3/conformance/textures/copy-tex-image-2d-formats.html [ Skip ]
 webgl/1.0.3/conformance/canvas/rapid-resizing.html [ Skip ]
 webgl/1.0.3/conformance/extensions/webgl-draw-buffers.html [ Skip ]
 
-# Not supported by default
-http/wpt/mediarecorder [ Skip ]
-imported/w3c/web-platform-tests/mediacapture-record [ Skip ]
-fast/history/page-cache-media-recorder.html [ Skip ]
+webkit.org/b/197673 http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable.html [ Pass Failure Timeout ]
 
 # To aid transition to ANGLE backend for WebGL, skip all of WebGL 2 tests for now. 
 # Re-enable as each chunk of tests are verified with ANGLE backend.
index 8801486..33306de 100644 (file)
     }
 
     async_test(t => {
+        const ac = new AudioContext();
+        const osc = ac.createOscillator();
+        const dest = ac.createMediaStreamDestination();
+        const audio = dest.stream;
+        osc.connect(dest);
+
         const video = createVideoStream();
+        assert_equals(video.getAudioTracks().length, 0, "video mediastream starts with no audio track");
+        assert_equals(audio.getAudioTracks().length, 1, "audio mediastream starts with one audio track");
+        video.addTrack(audio.getAudioTracks()[0]);
+        assert_equals(video.getAudioTracks().length, 1, "video mediastream starts with one audio track");
         const recorder = new MediaRecorder(video);
         let mode = 0;
 
index 46b30f7..592a7ba 100644 (file)
@@ -1828,10 +1828,6 @@ webkit.org/b/195635 scrollingcoordinator/mac/multiple-fixed.html [ Pass Timeout
 [ Catalina+ ] fast/text/design-system-ui-15.html [ Pass ]
 [ Catalina+ ] fast/text/design-system-ui-16.html [ Pass ]
 
-[ Catalina+ ] http/wpt/mediarecorder [ Pass Failure ] 
-[ Catalina+ ] imported/w3c/web-platform-tests/mediacapture-record [ Pass Failure ]
-[ Catalina+ ] fast/history/page-cache-media-recorder.html [ Pass Failure ]
-
 webkit.org/b/200128 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-video-element/video_timeupdate_on_seek.html [ Timeout Pass ]
 
 # rdar://55405851 ([ macOS ] Layout tests webgpu/*-triangle-strip.html are flaky failures. (201827))
index 3a75f82..b7f9e4a 100644 (file)
@@ -1,3 +1,24 @@
+2020-02-06  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r255910, r255970, and r255972.
+        https://bugs.webkit.org/show_bug.cgi?id=207345
+
+        Broke internal builds (Requested by ryanhaddad on #webkit).
+
+        Reverted changesets:
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255910
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255970
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255972
+
 2020-02-06  Ryan Haddad  <ryanhaddad@apple.com>
 
         [Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder
index f7b5100..175b6f5 100644 (file)
 #define HAVE_OS_SIGNPOST 1
 #endif
 
-#if (PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500 ) && (defined __has_include && __has_include(<AVFoundation/AVAssetWriter_Private.h>))
-#define HAVE_AVASSETWRITERDELEGATE 1
-#endif
-
 #if PLATFORM(IOS_FAMILY) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
 #define HAVE_SYSTEM_FONT_STYLE_TITLE_0 1
 #define HAVE_SYSTEM_FONT_STYLE_TITLE_4 1
index db48052..0ea5c05 100644 (file)
@@ -1,3 +1,24 @@
+2020-02-06  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r255910, r255970, and r255972.
+        https://bugs.webkit.org/show_bug.cgi?id=207345
+
+        Broke internal builds (Requested by ryanhaddad on #webkit).
+
+        Reverted changesets:
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255910
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255970
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255972
+
 2020-02-06  Ali Juma  <ajuma@chromium.org>
 
         Crash in RenderTableCol::willBeRemovedFromTree()
index f54df71..fcb097e 100644 (file)
@@ -34,12 +34,7 @@ namespace WebCore {
 
 std::unique_ptr<MediaRecorderPrivate> MediaRecorderProvider::createMediaRecorderPrivate(const MediaStreamPrivate& stream)
 {
-#if HAVE(AVASSETWRITERDELEGATE)
     return MediaRecorderPrivateAVFImpl::create(stream);
-#else
-    UNUSED_PARAM(stream);
-    return nullptr;
-#endif
 }
 
 }
index c9e5b4e..a4bf80f 100644 (file)
@@ -1,3 +1,24 @@
+2020-02-06  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r255910, r255970, and r255972.
+        https://bugs.webkit.org/show_bug.cgi?id=207345
+
+        Broke internal builds (Requested by ryanhaddad on #webkit).
+
+        Reverted changesets:
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255910
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255970
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255972
+
 2020-02-06  youenn fablet  <youenn@apple.com>
 
         [Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder
index c281b92..38d7fa9 100644 (file)
                2E1342CC215AA10A007199D2 /* UIKitSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E1342CA215AA10A007199D2 /* UIKitSoftLink.h */; };
                2E1342CD215AA10A007199D2 /* UIKitSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E1342CB215AA10A007199D2 /* UIKitSoftLink.mm */; };
                31308B1420A21705003FB929 /* SystemPreviewSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 31308B1320A21705003FB929 /* SystemPreviewSPI.h */; };
-               416E995323DAE6BE00E871CB /* AudioToolboxSoftLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 416E995123DAE6BD00E871CB /* AudioToolboxSoftLink.cpp */; };
-               416E995423DAE6BE00E871CB /* AudioToolboxSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E995223DAE6BE00E871CB /* AudioToolboxSoftLink.h */; };
-               416E995723DAEFF800E871CB /* VideoToolboxSoftLink.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 416E995523DAEFF700E871CB /* VideoToolboxSoftLink.cpp */; };
-               416E995823DAEFF800E871CB /* VideoToolboxSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 416E995623DAEFF700E871CB /* VideoToolboxSoftLink.h */; };
                442956CD218A72DF0080DB54 /* RevealSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 442956CC218A72DE0080DB54 /* RevealSPI.h */; };
                4450FC9F21F5F602004DFA56 /* QuickLookSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4450FC9D21F5F602004DFA56 /* QuickLookSoftLink.mm */; };
                4450FCA021F5F602004DFA56 /* QuickLookSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */; };
                2E1342CB215AA10A007199D2 /* UIKitSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIKitSoftLink.mm; sourceTree = "<group>"; };
                31308B1320A21705003FB929 /* SystemPreviewSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SystemPreviewSPI.h; sourceTree = "<group>"; };
                37119A7820CCB5FF002C6DC9 /* WebKitTargetConditionals.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitTargetConditionals.xcconfig; sourceTree = "<group>"; };
-               416E995123DAE6BD00E871CB /* AudioToolboxSoftLink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AudioToolboxSoftLink.cpp; sourceTree = "<group>"; };
-               416E995223DAE6BE00E871CB /* AudioToolboxSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioToolboxSoftLink.h; sourceTree = "<group>"; };
-               416E995523DAEFF700E871CB /* VideoToolboxSoftLink.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VideoToolboxSoftLink.cpp; sourceTree = "<group>"; };
-               416E995623DAEFF700E871CB /* VideoToolboxSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoToolboxSoftLink.h; sourceTree = "<group>"; };
                442956CC218A72DE0080DB54 /* RevealSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RevealSPI.h; sourceTree = "<group>"; };
                4450FC9D21F5F602004DFA56 /* QuickLookSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuickLookSoftLink.mm; sourceTree = "<group>"; };
                4450FC9E21F5F602004DFA56 /* QuickLookSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookSoftLink.h; sourceTree = "<group>"; };
                0CF99CA51F73841C007EE793 /* cf */ = {
                        isa = PBXGroup;
                        children = (
-                               416E995123DAE6BD00E871CB /* AudioToolboxSoftLink.cpp */,
-                               416E995223DAE6BE00E871CB /* AudioToolboxSoftLink.h */,
                                0CF99CA61F738436007EE793 /* CoreMediaSoftLink.cpp */,
                                0CF99CA71F738437007EE793 /* CoreMediaSoftLink.h */,
-                               416E995523DAEFF700E871CB /* VideoToolboxSoftLink.cpp */,
-                               416E995623DAEFF700E871CB /* VideoToolboxSoftLink.h */,
                        );
                        path = cf;
                        sourceTree = "<group>";
                        files = (
                                57FD318B22B35989008D0E8B /* AppSSOSoftLink.h in Headers */,
                                576CA9D622B854AB0030143C /* AppSSOSPI.h in Headers */,
-                               416E995423DAE6BE00E871CB /* AudioToolboxSoftLink.h in Headers */,
                                2D02E93C2056FAA700A13797 /* AudioToolboxSPI.h in Headers */,
                                572A107822B456F500F410C8 /* AuthKitSPI.h in Headers */,
                                077E87B2226A460300A2AFF0 /* AVFoundationSoftLink.h in Headers */,
                                2E1342CC215AA10A007199D2 /* UIKitSoftLink.h in Headers */,
                                0C5AF9221F43A4C7002EAC02 /* UIKitSPI.h in Headers */,
                                0C2DA1471F3BEB4900DBC317 /* URLFormattingSPI.h in Headers */,
-                               416E995823DAEFF800E871CB /* VideoToolboxSoftLink.h in Headers */,
                                0C2DA1591F3BEB4900DBC317 /* WebFilterEvaluatorSPI.h in Headers */,
                                A10826F91F576292004772AC /* WebPanel.h in Headers */,
                        );
                        buildActionMask = 2147483647;
                        files = (
                                57FD318A22B3593E008D0E8B /* AppSSOSoftLink.mm in Sources */,
-                               416E995323DAE6BE00E871CB /* AudioToolboxSoftLink.cpp in Sources */,
                                077E87B1226A460200A2AFF0 /* AVFoundationSoftLink.mm in Sources */,
                                0C5FFF0F1F78D9DA009EFF1A /* ClockCM.mm in Sources */,
                                0CF99CA81F738437007EE793 /* CoreMediaSoftLink.cpp in Sources */,
                                A3AB6E571F3D1DDB009C14B1 /* SystemSleepListener.cpp in Sources */,
                                A3AB6E651F3D217F009C14B1 /* SystemSleepListenerMac.mm in Sources */,
                                2E1342CD215AA10A007199D2 /* UIKitSoftLink.mm in Sources */,
-                               416E995723DAEFF800E871CB /* VideoToolboxSoftLink.cpp in Sources */,
                                A10826FA1F576292004772AC /* WebPanel.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.cpp b/Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.cpp
deleted file mode 100644 (file)
index 1cf5505..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if USE(AVFOUNDATION)
-
-#include <AudioToolbox/AudioConverter.h>
-#include <AudioToolbox/AudioFormat.h>
-
-#include <wtf/SoftLinking.h>
-
-SOFT_LINK_FRAMEWORK_FOR_SOURCE(PAL, AudioToolbox)
-
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, AudioToolbox, AudioFormatGetProperty, OSStatus, (AudioFormatPropertyID inPropertyID, UInt32 inSpecifierSize, const void* inSpecifier, UInt32* ioPropertyDataSize, void* outPropertyData), (inPropertyID, inSpecifierSize, inSpecifier, ioPropertyDataSize, outPropertyData))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, AudioToolbox, AudioConverterNew, OSStatus, (const AudioStreamBasicDescription* inSourceFormat, const AudioStreamBasicDescription* inDestinationFormat, AudioConverterRef* outAudioConverter), (inSourceFormat, inDestinationFormat, outAudioConverter))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, AudioToolbox, AudioConverterSetProperty, OSStatus, (AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32 inPropertyDataSize, const void* inPropertyData), (inAudioConverter, inPropertyID, inPropertyDataSize, inPropertyData))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, AudioToolbox, AudioConverterGetProperty, OSStatus, (AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32* ioPropertyDataSize, void* outPropertyData), (inAudioConverter, inPropertyID, ioPropertyDataSize, outPropertyData))
-
-#endif // USE(AVFOUNDATION)
diff --git a/Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.h b/Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.h
deleted file mode 100644 (file)
index 0731187..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if USE(AVFOUNDATION)
-
-#include <wtf/SoftLinking.h>
-
-SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, AudioToolbox)
-
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, AudioToolbox, AudioConverterGetProperty, OSStatus, (AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32* ioPropertyDataSize, void* outPropertyData), (inAudioConverter, inPropertyID, ioPropertyDataSize, outPropertyData))
-#define AudioConverterGetProperty softLink_AudioToolbox_AudioConverterGetProperty
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, AudioToolbox, AudioConverterNew, OSStatus, (const AudioStreamBasicDescription* inSourceFormat, const AudioStreamBasicDescription* inDestinationFormat, AudioConverterRef* outAudioConverter), (inSourceFormat, inDestinationFormat, outAudioConverter))
-#define AudioConverterNew softLink_AudioToolbox_AudioConverterNew
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, AudioToolbox, AudioConverterSetProperty, OSStatus, (AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32 inPropertyDataSize, const void* inPropertyData), (inAudioConverter, inPropertyID, inPropertyDataSize, inPropertyData))
-#define AudioConverterSetProperty softLink_AudioToolbox_AudioConverterSetProperty
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, AudioToolbox, AudioFormatGetProperty, OSStatus, (AudioFormatPropertyID inPropertyID, UInt32 inSpecifierSize, const void* inSpecifier, UInt32* ioPropertyDataSize, void* outPropertyData), (inPropertyID, inSpecifierSize, inSpecifier, ioPropertyDataSize, outPropertyData))
-#define AudioFormatGetProperty softLink_AudioToolbox_AudioFormatGetProperty
-
-
-#endif // USE(AVFOUNDATION)
index fa22cec..2b82313 100644 (file)
@@ -46,7 +46,6 @@ SOFT_LINK_FRAMEWORK_FOR_SOURCE(PAL, CoreMedia)
 
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBlockBufferCopyDataBytes, OSStatus, (CMBlockBufferRef theSourceBuffer, size_t offsetToData, size_t dataLength, void* destination), (theSourceBuffer, offsetToData, dataLength, destination))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBlockBufferGetDataLength, size_t, (CMBlockBufferRef theBuffer), (theBuffer))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBlockBufferReplaceDataBytes, OSStatus, (const void* sourceBytes, CMBlockBufferRef destinationBuffer, size_t offsetIntoDestination, size_t dataLength), (sourceBytes, destinationBuffer, offsetIntoDestination, dataLength))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMFormatDescriptionGetExtensions, CFDictionaryRef, (CMFormatDescriptionRef desc), (desc))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMSampleBufferGetTypeID, CFTypeID, (void), ())
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMSampleBufferGetDataBuffer, CMBlockBufferRef, (CMSampleBufferRef sbuf), (sbuf))
@@ -134,11 +133,9 @@ SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueDequeueAndRetain, CMB
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueEnqueue, OSStatus, (CMBufferQueueRef queue, CMBufferRef buffer), (queue, buffer))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueIsEmpty, Boolean, (CMBufferQueueRef queue), (queue))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueGetBufferCount, CMItemCount, (CMBufferQueueRef queue), (queue))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueGetCallbacksForUnsortedSampleBuffers, const CMBufferCallbacks *, (), ())
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueGetFirstPresentationTimeStamp, CMTime, (CMBufferQueueRef queue), (queue))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueGetEndPresentationTimeStamp, CMTime, (CMBufferQueueRef queue), (queue))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueInstallTriggerWithIntegerThreshold, OSStatus, (CMBufferQueueRef queue, CMBufferQueueTriggerCallback triggerCallback, void* triggerRefcon, CMBufferQueueTriggerCondition triggerCondition, CMItemCount triggerThreshold, CMBufferQueueTriggerToken* triggerTokenOut), (queue, triggerCallback, triggerRefcon, triggerCondition, triggerThreshold, triggerTokenOut))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMBufferQueueMarkEndOfData, OSStatus, (CMBufferQueueRef queue), (queue))
 
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleAttachmentKey_DoNotDisplay, CFStringRef)
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleAttachmentKey_NotSync, CFStringRef)
@@ -152,9 +149,6 @@ SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleBufferAttachmentKey_Sampl
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleAttachmentKey_DisplayImmediately, CFStringRef)
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleAttachmentKey_IsDependedOnByOthers, CFStringRef)
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleBufferConsumerNotification_BufferConsumed, CFStringRef)
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleBufferAttachmentKey_EndsPreviousSampleDuration, CFStringRef)
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMSampleBufferAttachmentKey_GradualDecoderRefresh, CFStringRef)
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, get_CoreMedia_kCMSampleBufferAttachmentKey_TrimDurationAtStart, CFStringRef)
 
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMTimebaseNotification_EffectiveRateChanged, CFStringRef)
 SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, CoreMedia, kCMTimebaseNotification_TimeJumped, CFStringRef)
@@ -169,9 +163,6 @@ SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMAudioSampleBufferCreateWithPacke
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMSampleBufferSetDataBufferFromAudioBufferList, OSStatus, (CMSampleBufferRef sbuf, CFAllocatorRef bbufStructAllocator, CFAllocatorRef bbufMemoryAllocator, uint32_t flags, const AudioBufferList *bufferList), (sbuf, bbufStructAllocator, bbufMemoryAllocator, flags, bufferList))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMSampleBufferSetDataReady, OSStatus, (CMSampleBufferRef sbuf), (sbuf))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMAudioFormatDescriptionCreate, OSStatus, (CFAllocatorRef allocator, const AudioStreamBasicDescription* asbd, size_t layoutSize, const AudioChannelLayout* layout, size_t magicCookieSize, const void* magicCookie, CFDictionaryRef extensions, CMAudioFormatDescriptionRef* outDesc), (allocator, asbd, layoutSize, layout, magicCookieSize, magicCookie, extensions, outDesc))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMAudioFormatDescriptionGetMagicCookie, const void*, (CMAudioFormatDescriptionRef desc, size_t* sizeOut), (desc, sizeOut))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMAudioFormatDescriptionGetRichestDecodableFormat, const AudioFormatListItem *, (CMAudioFormatDescriptionRef desc), (desc))
-
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMClockGetHostTimeClock, CMClockRef, (void), ())
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMClockGetTime, CMTime, (CMClockRef clock), (clock))
 SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, CoreMedia, CMSampleBufferCallForEachSample, OSStatus, (CMSampleBufferRef sbuf, OSStatus (* CMSAMPLEBUFFERCALL_NOESCAPE callback)( CMSampleBufferRef sampleBuffer, CMItemCount index, void *refcon), void *refcon), (sbuf, callback, refcon))
index 83ff4d6..268d167 100644 (file)
@@ -49,8 +49,6 @@ SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBlockBufferCopyDataBytes, OSStat
 #define CMBlockBufferCopyDataBytes softLink_CoreMedia_CMBlockBufferCopyDataBytes
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBlockBufferGetDataLength, size_t, (CMBlockBufferRef theBuffer), (theBuffer))
 #define CMBlockBufferGetDataLength softLink_CoreMedia_CMBlockBufferGetDataLength
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBlockBufferReplaceDataBytes, OSStatus, (const void* sourceBytes, CMBlockBufferRef destinationBuffer, size_t offsetIntoDestination, size_t dataLength), (sourceBytes, destinationBuffer, offsetIntoDestination, dataLength))
-#define CMBlockBufferReplaceDataBytes softLink_CoreMedia_CMBlockBufferReplaceDataBytes
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMFormatDescriptionGetExtensions, CFDictionaryRef, (CMFormatDescriptionRef desc), (desc))
 #define CMFormatDescriptionGetExtensions softLink_CoreMedia_CMFormatDescriptionGetExtensions
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMSampleBufferGetTypeID, CFTypeID, (void), ())
@@ -225,14 +223,10 @@ SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueGetBufferCount, CMIte
 #define CMBufferQueueGetBufferCount softLink_CoreMedia_CMBufferQueueGetBufferCount
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueGetFirstPresentationTimeStamp, CMTime, (CMBufferQueueRef queue), (queue))
 #define CMBufferQueueGetFirstPresentationTimeStamp softLink_CoreMedia_CMBufferQueueGetFirstPresentationTimeStamp
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueGetCallbacksForUnsortedSampleBuffers, const CMBufferCallbacks *, (), ())
-#define CMBufferQueueGetCallbacksForUnsortedSampleBuffers softLink_CoreMedia_CMBufferQueueGetCallbacksForUnsortedSampleBuffers
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueGetEndPresentationTimeStamp, CMTime, (CMBufferQueueRef queue), (queue))
 #define CMBufferQueueGetEndPresentationTimeStamp softLink_CoreMedia_CMBufferQueueGetEndPresentationTimeStamp
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueInstallTriggerWithIntegerThreshold, OSStatus, (CMBufferQueueRef queue, CMBufferQueueTriggerCallback triggerCallback, void* triggerRefcon, CMBufferQueueTriggerCondition triggerCondition, CMItemCount triggerThreshold, CMBufferQueueTriggerToken* triggerTokenOut), (queue, triggerCallback, triggerRefcon, triggerCondition, triggerThreshold, triggerTokenOut))
 #define CMBufferQueueInstallTriggerWithIntegerThreshold softLink_CoreMedia_CMBufferQueueInstallTriggerWithIntegerThreshold
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBufferQueueMarkEndOfData, OSStatus, (CMBufferQueueRef queue), (queue))
-#define CMBufferQueueMarkEndOfData softLink_CoreMedia_CMBufferQueueMarkEndOfData
 
 SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, kCMSampleAttachmentKey_DoNotDisplay, CFStringRef)
 #define kCMSampleAttachmentKey_DoNotDisplay get_CoreMedia_kCMSampleAttachmentKey_DoNotDisplay()
@@ -262,15 +256,6 @@ SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, kCMTimebaseNotification_TimeJumped
 #define kCMTimebaseNotification_TimeJumped get_CoreMedia_kCMTimebaseNotification_TimeJumped()
 SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, kCMSampleBufferConsumerNotification_BufferConsumed, CFStringRef)
 #define kCMSampleBufferConsumerNotification_BufferConsumed get_CoreMedia_kCMSampleBufferConsumerNotification_BufferConsumed()
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, kCMSampleBufferAttachmentKey_EndsPreviousSampleDuration, CFStringRef)
-#define kCMSampleBufferAttachmentKey_EndsPreviousSampleDuration get_CoreMedia_kCMSampleBufferAttachmentKey_EndsPreviousSampleDuration()
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, kCMSampleBufferAttachmentKey_GradualDecoderRefresh, CFStringRef)
-#define kCMSampleBufferAttachmentKey_GradualDecoderRefresh get_CoreMedia_kCMSampleBufferAttachmentKey_GradualDecoderRefresh()
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, CoreMedia, get_CoreMedia_kCMSampleBufferAttachmentKey_TrimDurationAtStart, CFStringRef)
-#define get_CoreMedia_kCMSampleBufferAttachmentKey_TrimDurationAtStart get_CoreMedia_kCMSampleBufferAttachmentKey_TrimDurationAtStart()
-
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMAudioFormatDescriptionGetMagicCookie, const void*, (CMAudioFormatDescriptionRef desc, size_t* sizeOut), (desc, sizeOut))
-#define CMAudioFormatDescriptionGetMagicCookie softLink_CoreMedia_CMAudioFormatDescriptionGetMagicCookie
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMAudioFormatDescriptionGetStreamBasicDescription, const AudioStreamBasicDescription *, (CMAudioFormatDescriptionRef desc), (desc))
 #define CMAudioFormatDescriptionGetStreamBasicDescription softLink_CoreMedia_CMAudioFormatDescriptionGetStreamBasicDescription
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMBlockBufferCreateWithMemoryBlock, OSStatus, (CFAllocatorRef structureAllocator, void* memoryBlock, size_t blockLength, CFAllocatorRef blockAllocator, const CMBlockBufferCustomBlockSource* customBlockSource, size_t offsetToData, size_t dataLength, CMBlockBufferFlags flags, CMBlockBufferRef* blockBufferOut), (structureAllocator, memoryBlock, blockLength, blockAllocator, customBlockSource, offsetToData, dataLength, flags, blockBufferOut))
@@ -279,8 +264,6 @@ SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMSampleBufferGetAudioBufferListWi
 #define CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer softLink_CoreMedia_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMSampleBufferGetNumSamples, CMItemCount, (CMSampleBufferRef sbuf), (sbuf))
 #define CMSampleBufferGetNumSamples softLink_CoreMedia_CMSampleBufferGetNumSamples
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMAudioFormatDescriptionGetRichestDecodableFormat, const AudioFormatListItem *, (CMAudioFormatDescriptionRef desc), (desc))
-#define CMAudioFormatDescriptionGetRichestDecodableFormat softLink_CoreMedia_CMAudioFormatDescriptionGetRichestDecodableFormat
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMSampleBufferCopySampleBufferForRange, OSStatus, (CFAllocatorRef allocator, CMSampleBufferRef sbuf, CFRange sampleRange, CMSampleBufferRef* sBufOut), (allocator, sbuf, sampleRange, sBufOut))
 #define CMSampleBufferCopySampleBufferForRange softLink_CoreMedia_CMSampleBufferCopySampleBufferForRange
 SOFT_LINK_FUNCTION_FOR_HEADER(PAL, CoreMedia, CMSampleBufferGetSampleSizeArray, OSStatus, (CMSampleBufferRef sbuf, CMItemCount sizeArrayEntries, size_t* sizeArrayOut, CMItemCount* sizeArrayEntriesNeededOut), (sbuf, sizeArrayEntries, sizeArrayOut, sizeArrayEntriesNeededOut))
diff --git a/Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp b/Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp
deleted file mode 100644 (file)
index 2dba376..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if USE(AVFOUNDATION)
-
-#import <VideoToolbox/VTCompressionSession.h>
-
-#include <wtf/SoftLinking.h>
-
-SOFT_LINK_FRAMEWORK_FOR_SOURCE(PAL, VideoToolbox)
-
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, VideoToolbox, kVTCompressionPropertyKey_ExpectedFrameRate, CFStringRef)
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, VideoToolbox, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, CFStringRef)
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, VideoToolbox, kVTCompressionPropertyKey_RealTime, CFStringRef)
-
-SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, VideoToolbox, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, CFStringRef)
-
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, VideoToolbox, VTCompressionSessionCreate, OSStatus, (CFAllocatorRef allocator, int32_t width, int32_t height, CMVideoCodecType codecType, CFDictionaryRef encoderSpecification, CFDictionaryRef sourceImageBufferAttributes, CFAllocatorRef compressedDataAllocator, VTCompressionOutputCallback outputCallback, void* outputCallbackRefCon, VTCompressionSessionRef* compressionSessionOut), (allocator, width, height, codecType, encoderSpecification, sourceImageBufferAttributes, compressedDataAllocator, outputCallback, outputCallbackRefCon, compressionSessionOut))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, VideoToolbox, VTCompressionSessionCompleteFrames, OSStatus, (VTCompressionSessionRef session, CMTime completeUntilPresentationTimeStamp), (session, completeUntilPresentationTimeStamp))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, VideoToolbox, VTCompressionSessionEncodeFrame, OSStatus, (VTCompressionSessionRef session, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime duration, CFDictionaryRef frameProperties, void* sourceFrameRefcon, VTEncodeInfoFlags* infoFlagsOut), (session, imageBuffer, presentationTimeStamp, duration, frameProperties, sourceFrameRefcon, infoFlagsOut))
-SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, VideoToolbox, VTCompressionSessionPrepareToEncodeFrames, OSStatus, (VTCompressionSessionRef session), (session))
-
-#endif // USE(AVFOUNDATION)
diff --git a/Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h b/Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h
deleted file mode 100644 (file)
index da9fe51..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if USE(AVFOUNDATION)
-
-#include <wtf/SoftLinking.h>
-
-SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, VideoToolbox)
-
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, VideoToolbox, kVTCompressionPropertyKey_ExpectedFrameRate, CFStringRef)
-#define kVTCompressionPropertyKey_ExpectedFrameRate get_VideoToolbox_kVTCompressionPropertyKey_ExpectedFrameRate()
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, VideoToolbox, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, CFStringRef)
-#define kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration get_VideoToolbox_kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration()
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, VideoToolbox, kVTCompressionPropertyKey_RealTime, CFStringRef)
-#define kVTCompressionPropertyKey_RealTime get_VideoToolbox_kVTCompressionPropertyKey_RealTime()
-
-SOFT_LINK_CONSTANT_FOR_HEADER(PAL, VideoToolbox, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, CFStringRef)
-#define kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder get_VideoToolbox_kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder()
-
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, VideoToolbox, VTCompressionSessionCreate, OSStatus, (CFAllocatorRef allocator, int32_t width, int32_t height, CMVideoCodecType codecType, CFDictionaryRef encoderSpecification, CFDictionaryRef sourceImageBufferAttributes, CFAllocatorRef compressedDataAllocator, VTCompressionOutputCallback outputCallback, void* outputCallbackRefCon, VTCompressionSessionRef* compressionSessionOut), (allocator, width, height, codecType, encoderSpecification, sourceImageBufferAttributes, compressedDataAllocator, outputCallback, outputCallbackRefCon, compressionSessionOut))
-#define VTCompressionSessionCreate softLink_VideoToolbox_VTCompressionSessionCreate
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, VideoToolbox, VTCompressionSessionCompleteFrames, OSStatus, (VTCompressionSessionRef session, CMTime completeUntilPresentationTimeStamp), (session, completeUntilPresentationTimeStamp))
-#define VTCompressionSessionCompleteFrames softLink_VideoToolbox_VTCompressionSessionCompleteFrames
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, VideoToolbox, VTCompressionSessionEncodeFrame, OSStatus, (VTCompressionSessionRef session, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime duration, CFDictionaryRef frameProperties, void* sourceFrameRefcon, VTEncodeInfoFlags* infoFlagsOut), (session, imageBuffer, presentationTimeStamp, duration, frameProperties, sourceFrameRefcon, infoFlagsOut))
-#define VTCompressionSessionEncodeFrame softLink_VideoToolbox_VTCompressionSessionEncodeFrame
-SOFT_LINK_FUNCTION_FOR_HEADER(PAL, VideoToolbox, VTCompressionSessionPrepareToEncodeFrames, OSStatus, (VTCompressionSessionRef session), (session))
-#define VTCompressionSessionPrepareToEncodeFrames softLink_VideoToolbox_VTCompressionSessionPrepareToEncodeFrames
-
-#endif // USE(AVFOUNDATION)
index e55d3a8..febf05e 100644 (file)
                416E6FE81BBD12DF000A6053 /* WritableStreamInternalsBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E6FE91BBD12E5000A6043 /* ReadableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764D8 /* ReadableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416E6FE91BBD12E5000A6053 /* WritableStreamBuiltins.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               416F799023D750CF00829FC1 /* AudioSampleBufferCompressor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 416F798F23D750CB00829FC1 /* AudioSampleBufferCompressor.mm */; };
                417253AB1354BBBC00360F2A /* MediaControlElements.h in Headers */ = {isa = PBXBuildFile; fileRef = 417253A91354BBBC00360F2A /* MediaControlElements.h */; };
                417612AF1E3A994000C3D81D /* LibWebRTCMediaEndpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417612AB1E3A993B00C3D81D /* LibWebRTCMediaEndpoint.cpp */; };
                417612B01E3A994000C3D81D /* LibWebRTCMediaEndpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 417612AC1E3A993B00C3D81D /* LibWebRTCMediaEndpoint.h */; };
                41B8776223DE1045003638B8 /* RealtimeMediaSourceIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B8776023DE1042003638B8 /* RealtimeMediaSourceIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41BF204922BA7BE80004F812 /* RealtimeVideoSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF204022B947160004F812 /* RealtimeVideoSource.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               41CD6F8C23D6E82100B16421 /* VideoSampleBufferCompressor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 41CD6F8B23D6E81D00B16421 /* VideoSampleBufferCompressor.mm */; };
                41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41D129CE1F3D0EF600D15E47 /* WorkerGlobalScopeCaches.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FB278D1F34C28200795487 /* WorkerGlobalScopeCaches.h */; };
                41D129D01F3D0F0500D15E47 /* CacheQueryOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FB279B1F34CEF000795487 /* CacheQueryOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                416D759F20C6441300D02D2C /* NetworkLoadInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkLoadInformation.h; sourceTree = "<group>"; };
                416E0B37209BC3C2004A95D9 /* FetchIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchIdentifier.h; sourceTree = "<group>"; };
                416E29A5102FA962007FC14E /* WorkerReportingProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerReportingProxy.h; sourceTree = "<group>"; };
-               416F798D23D750CA00829FC1 /* AudioSampleBufferCompressor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioSampleBufferCompressor.h; sourceTree = "<group>"; };
-               416F798F23D750CB00829FC1 /* AudioSampleBufferCompressor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AudioSampleBufferCompressor.mm; sourceTree = "<group>"; };
                4170A2E91D8C0CC000318452 /* JSDOMWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMWrapper.cpp; sourceTree = "<group>"; };
                417253A81354BBBC00360F2A /* MediaControlElements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControlElements.cpp; sourceTree = "<group>"; };
                417253A91354BBBC00360F2A /* MediaControlElements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControlElements.h; sourceTree = "<group>"; };
                41C7E1051E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CanvasCaptureMediaStreamTrack.cpp; sourceTree = "<group>"; };
                41C7E1061E6A54360027B4DE /* CanvasCaptureMediaStreamTrack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CanvasCaptureMediaStreamTrack.h; sourceTree = "<group>"; };
                41C7E1081E6AA37C0027B4DE /* CanvasCaptureMediaStreamTrack.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CanvasCaptureMediaStreamTrack.idl; sourceTree = "<group>"; };
-               41CD6F8923D6E81C00B16421 /* VideoSampleBufferCompressor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VideoSampleBufferCompressor.h; sourceTree = "<group>"; };
-               41CD6F8B23D6E81D00B16421 /* VideoSampleBufferCompressor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoSampleBufferCompressor.mm; sourceTree = "<group>"; };
                41CF8BE41D46222000707DC9 /* FetchBodyConsumer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchBodyConsumer.cpp; sourceTree = "<group>"; };
                41CF8BE51D46222000707DC9 /* FetchBodyConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchBodyConsumer.h; sourceTree = "<group>"; };
                41D015C80F4B5C71004A662F /* ContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentType.h; sourceTree = "<group>"; };
                4D3C05D421AF480900F2890A /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
-                               416F798D23D750CA00829FC1 /* AudioSampleBufferCompressor.h */,
-                               416F798F23D750CB00829FC1 /* AudioSampleBufferCompressor.mm */,
                                4D73F94C218C4A87003A3ED6 /* MediaRecorderPrivateWriterCocoa.h */,
                                4D73F94D218C4A87003A3ED6 /* MediaRecorderPrivateWriterCocoa.mm */,
-                               41CD6F8923D6E81C00B16421 /* VideoSampleBufferCompressor.h */,
-                               41CD6F8B23D6E81D00B16421 /* VideoSampleBufferCompressor.mm */,
                        );
                        path = cocoa;
                        sourceTree = "<group>";
                                A9787CB41F5F5C6600C551C6 /* AccessibilityMediaObject.cpp in Sources */,
                                CD0EEE0E14743F39003EAFA2 /* AudioDestinationIOS.cpp in Sources */,
                                CD5596911475B678001D0BD0 /* AudioFileReaderIOS.cpp in Sources */,
-                               416F799023D750CF00829FC1 /* AudioSampleBufferCompressor.mm in Sources */,
                                CDA79827170A279100D45C55 /* AudioSessionIOS.mm in Sources */,
                                CD8A7BBB197735FE00CBD643 /* AudioSourceProviderAVFObjC.mm in Sources */,
                                BE88E0D81715D2A200658D98 /* AudioTrack.cpp in Sources */,
                                7C73FB07191EF417007DE061 /* UserMessageHandlersNamespace.cpp in Sources */,
                                3FBC4AF3189881560046EE38 /* VideoFullscreenInterfaceAVKit.mm in Sources */,
                                52D5A18F1C54592300DE34A3 /* VideoFullscreenLayerManagerObjC.mm in Sources */,
-                               41CD6F8C23D6E82100B16421 /* VideoSampleBufferCompressor.mm in Sources */,
                                BE88E0DE1715D2A200658D98 /* VideoTrack.cpp in Sources */,
                                BE88E0E11715D2A200658D98 /* VideoTrackList.cpp in Sources */,
                                CD336F6717FA0AC600DDDCD0 /* VideoTrackPrivateAVFObjC.cpp in Sources */,
index f1f6804..73f1d0a 100644 (file)
 #include "config.h"
 #include "MediaRecorderPrivateAVFImpl.h"
 
-#if ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if ENABLE(MEDIA_STREAM)
 
 #include "AudioStreamDescription.h"
-#include "MediaRecorderPrivateWriterCocoa.h"
 #include "MediaSample.h"
 #include "MediaStreamPrivate.h"
 #include "SharedBuffer.h"
@@ -69,14 +68,7 @@ std::unique_ptr<MediaRecorderPrivateAVFImpl> MediaRecorderPrivateAVFImpl::create
             break;
         }
     }
-
-    int width = 0, height = 0;
-    if (videoTrack) {
-        auto& settings = videoTrack->settings();
-        width = settings.width();
-        height = settings.height();
-    }
-    auto writer = MediaRecorderPrivateWriter::create(!!audioTrack, width, height);
+    auto writer = MediaRecorderPrivateWriter::create(audioTrack, videoTrack);
     if (!writer)
         return nullptr;
 
@@ -127,4 +119,4 @@ const String& MediaRecorderPrivateAVFImpl::mimeType()
 
 } // namespace WebCore
 
-#endif // ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // ENABLE(MEDIA_STREAM)
index 34e2a96..0cf0df3 100644 (file)
@@ -24,7 +24,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if ENABLE(MEDIA_STREAM)
 
 #include "MediaRecorderPrivate.h"
 #include "MediaRecorderPrivateWriterCocoa.h"
@@ -56,4 +56,4 @@ private:
 
 } // namespace WebCore
 
-#endif // ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.h b/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.h
deleted file mode 100644 (file)
index 147bf81..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-#import <CoreMedia/CoreMedia.h>
-
-typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-typedef struct OpaqueAudioConverter* AudioConverterRef;
-
-namespace WebCore {
-
-class AudioSampleBufferCompressor {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    static std::unique_ptr<AudioSampleBufferCompressor> create(CMBufferQueueTriggerCallback, void* callbackObject);
-    ~AudioSampleBufferCompressor();
-
-    void finish();
-    void addSampleBuffer(CMSampleBufferRef);
-    CMSampleBufferRef getOutputSampleBuffer();
-    RetainPtr<CMSampleBufferRef> takeOutputSampleBuffer();
-
-private:
-    AudioSampleBufferCompressor();
-    bool initialize(CMBufferQueueTriggerCallback, void* callbackObject);
-
-    static OSStatus audioConverterComplexInputDataProc(AudioConverterRef, UInt32*, AudioBufferList*, AudioStreamPacketDescription**, void*);
-
-    void processSampleBuffer(CMSampleBufferRef);
-    bool initAudioConverterForSourceFormatDescription(CMFormatDescriptionRef, AudioFormatID);
-    size_t computeBufferSizeForAudioFormat(AudioStreamBasicDescription, UInt32, Float32);
-    void attachPrimingTrimsIfNeeded(CMSampleBufferRef);
-    RetainPtr<NSNumber> gradualDecoderRefreshCount();
-    CMSampleBufferRef sampleBufferWithNumPackets(UInt32 numPackets, AudioBufferList);
-    void processSampleBuffersUntilLowWaterTime(CMTime);
-    OSStatus provideSourceDataNumOutputPackets(UInt32*, AudioBufferList*, AudioStreamPacketDescription**);
-
-    RetainPtr<CMBufferQueueRef> m_outputBufferQueue;
-    RetainPtr<CMBufferQueueRef> m_inputBufferQueue;
-    dispatch_queue_t m_serialDispatchQueue;
-    CMTime m_lowWaterTime;
-    bool m_isEncoding { false };
-
-    RetainPtr<AudioConverterRef> m_converter;
-    AudioStreamBasicDescription m_sourceFormat;
-    AudioStreamBasicDescription m_destinationFormat;
-    RetainPtr<CMFormatDescriptionRef> m_destinationFormatDescription;
-    RetainPtr<NSNumber> m_gdrCountNum;
-    UInt32 m_maxOutputPacketSize;
-    Vector<AudioStreamPacketDescription> m_destinationPacketDescriptions;
-
-    CMTime m_currentNativePresentationTimeStamp;
-    CMTime m_currentOutputPresentationTimeStamp;
-    CMTime m_remainingPrimeDuration;
-
-    Vector<char> m_sourceBuffer;
-    Vector<char> m_destinationBuffer;
-
-    RetainPtr<CMBlockBufferRef> m_sampleBlockBuffer;
-    size_t m_sampleBlockBufferSize;
-    size_t m_currentOffsetInSampleBlockBuffer;
-    AudioFormatID m_outputCodecType;
-};
-
-}
-
-#endif // ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm b/Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm
deleted file mode 100644 (file)
index 3b15120..0000000
+++ /dev/null
@@ -1,498 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "AudioSampleBufferCompressor.h"
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-#include "Logging.h"
-#include <AudioToolbox/AudioCodec.h>
-#include <AudioToolbox/AudioConverter.h>
-#include <AudioToolbox/AudioFormat.h>
-#include <Foundation/Foundation.h>
-
-#import <pal/cf/AudioToolboxSoftLink.h>
-
-#define LOW_WATER_TIME_IN_SECONDS 0.1
-
-using namespace PAL;
-
-namespace WebCore {
-
-std::unique_ptr<AudioSampleBufferCompressor> AudioSampleBufferCompressor::create(CMBufferQueueTriggerCallback callback, void* callbackObject)
-{
-    auto compressor = std::unique_ptr<AudioSampleBufferCompressor>(new AudioSampleBufferCompressor());
-    if (!compressor->initialize(callback, callbackObject))
-        return nullptr;
-    return compressor;
-}
-
-AudioSampleBufferCompressor::AudioSampleBufferCompressor()
-    : m_serialDispatchQueue { dispatch_queue_create("com.apple.AudioSampleBufferCompressor", DISPATCH_QUEUE_SERIAL) }
-    , m_lowWaterTime { CMTimeMakeWithSeconds(LOW_WATER_TIME_IN_SECONDS, 1000) }
-    , m_outputCodecType { kAudioFormatMPEG4AAC }
-{
-}
-
-AudioSampleBufferCompressor::~AudioSampleBufferCompressor()
-{
-    if (m_serialDispatchQueue)
-        dispatch_release(m_serialDispatchQueue);
-}
-
-bool AudioSampleBufferCompressor::initialize(CMBufferQueueTriggerCallback callback, void* callbackObject)
-{
-    CMBufferQueueRef inputBufferQueue;
-    if (auto error = CMBufferQueueCreate(kCFAllocatorDefault, 0, CMBufferQueueGetCallbacksForUnsortedSampleBuffers(), &inputBufferQueue)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBufferQueueCreate for m_inputBufferQueue failed with %d", error);
-        return false;
-    }
-    m_inputBufferQueue = adoptCF(inputBufferQueue);
-
-    CMBufferQueueRef outputBufferQueue;
-    if (auto error = CMBufferQueueCreate(kCFAllocatorDefault, 0, CMBufferQueueGetCallbacksForUnsortedSampleBuffers(), &outputBufferQueue)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBufferQueueCreate for m_outputBufferQueue failed with %d", error);
-        return false;
-    }
-    m_outputBufferQueue = adoptCF(outputBufferQueue);
-    CMBufferQueueInstallTrigger(m_outputBufferQueue.get(), callback, callbackObject, kCMBufferQueueTrigger_WhenDataBecomesReady, kCMTimeZero, NULL);
-
-    m_isEncoding = true;
-    return true;
-}
-
-void AudioSampleBufferCompressor::finish()
-{
-    dispatch_sync(m_serialDispatchQueue, ^{
-        processSampleBuffersUntilLowWaterTime(kCMTimeInvalid);
-        auto error = CMBufferQueueMarkEndOfData(m_outputBufferQueue.get());
-        RELEASE_LOG_ERROR_IF(error, MediaStream, "AudioSampleBufferCompressor CMBufferQueueMarkEndOfData failed %d", error);
-        m_isEncoding = false;
-    });
-}
-
-bool AudioSampleBufferCompressor::initAudioConverterForSourceFormatDescription(CMFormatDescriptionRef formatDescription, AudioFormatID outputFormatID)
-{
-    const auto *audioFormatListItem = CMAudioFormatDescriptionGetRichestDecodableFormat(formatDescription);
-    m_sourceFormat = audioFormatListItem->mASBD;
-
-    memset(&m_destinationFormat, 0, sizeof(AudioStreamBasicDescription));
-    m_destinationFormat.mFormatID = outputFormatID;
-    m_destinationFormat.mSampleRate = m_sourceFormat.mSampleRate;
-    m_destinationFormat.mChannelsPerFrame = m_sourceFormat.mChannelsPerFrame;
-
-    UInt32 size = sizeof(m_destinationFormat);
-    if (auto error = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &m_destinationFormat)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor AudioFormatGetProperty failed with %d", error);
-        return false;
-    }
-
-    AudioConverterRef converter;
-    if (auto error = AudioConverterNew(&m_sourceFormat, &m_destinationFormat, &converter)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor AudioConverterNew failed with %d", error);
-        return false;
-    }
-    m_converter = adoptCF(converter);
-
-    size_t cookieSize = 0;
-    const void *cookie = CMAudioFormatDescriptionGetMagicCookie(formatDescription, &cookieSize);
-    if (cookieSize) {
-        if (auto error = AudioConverterSetProperty(m_converter.get(), kAudioConverterDecompressionMagicCookie, (UInt32)cookieSize, cookie)) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor setting kAudioConverterDecompressionMagicCookie failed with %d", error);
-            return false;
-        }
-    }
-
-    size = sizeof(m_sourceFormat);
-    if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioConverterCurrentInputStreamDescription, &size, &m_sourceFormat)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioConverterCurrentInputStreamDescription failed with %d", error);
-        return false;
-    }
-
-    if (!m_sourceFormat.mBytesPerPacket) {
-        RELEASE_LOG_ERROR(MediaStream, "mBytesPerPacket should not be zero");
-        return false;
-    }
-
-    size = sizeof(m_destinationFormat);
-    if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioConverterCurrentOutputStreamDescription, &size, &m_destinationFormat)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioConverterCurrentOutputStreamDescription failed with %d", error);
-        return false;
-    }
-
-    if (m_destinationFormat.mFormatID == kAudioFormatMPEG4AAC) {
-        // FIXME: Set outputBitRate according MediaRecorderOptions.audioBitsPerSecond.
-        UInt32 outputBitRate = 64000;
-        if (m_destinationFormat.mSampleRate >= 44100)
-            outputBitRate = 192000;
-        else if (m_destinationFormat.mSampleRate < 22000)
-            outputBitRate = 32000;
-
-        size = sizeof(outputBitRate);
-        if (auto error = AudioConverterSetProperty(m_converter.get(), kAudioConverterEncodeBitRate, size, &outputBitRate)) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor setting kAudioConverterEncodeBitRate failed with %d", error);
-            return false;
-        }
-    }
-
-    if (!m_destinationFormat.mBytesPerPacket) {
-        // If the destination format is VBR, we need to get max size per packet from the converter.
-        size = sizeof(m_maxOutputPacketSize);
-
-        if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioConverterPropertyMaximumOutputPacketSize, &size, &m_maxOutputPacketSize)) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioConverterPropertyMaximumOutputPacketSize failed with %d", error);
-            return false;
-        }
-    }
-
-    m_destinationBuffer.reserveCapacity(computeBufferSizeForAudioFormat(m_destinationFormat, m_maxOutputPacketSize, LOW_WATER_TIME_IN_SECONDS));
-    if (!m_destinationFormat.mBytesPerPacket)
-        m_destinationPacketDescriptions.reserveCapacity(m_destinationBuffer.capacity() / m_maxOutputPacketSize);
-
-    return true;
-}
-
-size_t AudioSampleBufferCompressor::computeBufferSizeForAudioFormat(AudioStreamBasicDescription format, UInt32 maxOutputPacketSize, Float32 duration)
-{
-    UInt32 numPackets = (format.mSampleRate * duration) / format.mFramesPerPacket;
-    UInt32 outputPacketSize = format.mBytesPerPacket ? format.mBytesPerPacket : maxOutputPacketSize;
-    UInt32 bufferSize = numPackets * outputPacketSize;
-
-    return bufferSize;
-}
-
-void AudioSampleBufferCompressor::attachPrimingTrimsIfNeeded(CMSampleBufferRef buffer)
-{
-    if (CMTIME_IS_INVALID(m_remainingPrimeDuration)) {
-        AudioConverterPrimeInfo primeInfo { 0, 0 };
-        UInt32 size = sizeof(primeInfo);
-
-        if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioConverterPrimeInfo, &size, &primeInfo)) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioConverterPrimeInfo failed with %d", error);
-            return;
-        }
-
-        m_remainingPrimeDuration = CMTimeMake(primeInfo.leadingFrames, m_destinationFormat.mSampleRate);
-    }
-
-    if (CMTIME_COMPARE_INLINE(kCMTimeZero, <, m_remainingPrimeDuration)) {
-        CMTime sampleDuration = CMSampleBufferGetDuration(buffer);
-        CMTime trimDuration = CMTimeMinimum(sampleDuration, m_remainingPrimeDuration);
-        CFDictionaryRef trimAtStartDict = CMTimeCopyAsDictionary(trimDuration, kCFAllocatorDefault);
-        CMSetAttachment(buffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, trimAtStartDict, kCMAttachmentMode_ShouldPropagate);
-        CFRelease(trimAtStartDict);
-        m_remainingPrimeDuration = CMTimeSubtract(m_remainingPrimeDuration, trimDuration);
-    }
-}
-
-RetainPtr<NSNumber> AudioSampleBufferCompressor::gradualDecoderRefreshCount()
-{
-    UInt32 delaySize = sizeof(uint32_t);
-    uint32_t originalDelayMode = 0;
-    if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioCodecPropertyDelayMode, &delaySize, &originalDelayMode)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioCodecPropertyDelayMode failed with %d", error);
-        return nil;
-    }
-
-    uint32_t optimalDelayMode = kAudioCodecDelayMode_Optimal;
-    if (auto error = AudioConverterSetProperty(m_converter.get(), kAudioCodecPropertyDelayMode, delaySize, &optimalDelayMode)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor setting kAudioCodecPropertyDelayMode failed with %d", error);
-        return nil;
-    }
-
-    UInt32 primeSize = sizeof(AudioCodecPrimeInfo);
-    AudioCodecPrimeInfo primeInfo { 0, 0 };
-    if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioCodecPropertyPrimeInfo, &primeSize, &primeInfo)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioCodecPropertyPrimeInfo failed with %d", error);
-        return nil;
-    }
-
-    if (auto error = AudioConverterSetProperty(m_converter.get(), kAudioCodecPropertyDelayMode, delaySize, &originalDelayMode)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor setting kAudioCodecPropertyDelayMode failed with %d", error);
-        return nil;
-    }
-    return adoptNS([NSNumber numberWithInt:(primeInfo.leadingFrames / m_destinationFormat.mFramesPerPacket)]);
-}
-
-CMSampleBufferRef AudioSampleBufferCompressor::sampleBufferWithNumPackets(UInt32 numPackets, AudioBufferList fillBufferList)
-{
-    Vector<char> cookie;
-    if (!m_destinationFormatDescription) {
-        UInt32 cookieSize = 0;
-
-        auto error = AudioConverterGetPropertyInfo(m_converter.get(), kAudioConverterCompressionMagicCookie, &cookieSize, NULL);
-        if ((error == noErr) && !!cookieSize) {
-            cookie.reserveCapacity(cookieSize);
-
-            if (auto error = AudioConverterGetProperty(m_converter.get(), kAudioConverterCompressionMagicCookie, &cookieSize, cookie.data())) {
-                RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor getting kAudioConverterCompressionMagicCookie failed with %d", error);
-                return nil;
-            }
-        }
-
-        CMFormatDescriptionRef destinationFormatDescription;
-        if (auto error = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, &m_destinationFormat, 0, NULL, cookieSize, cookie.data(), NULL, &destinationFormatDescription)) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMAudioFormatDescriptionCreate failed with %d", error);
-            return nil;
-        }
-        m_destinationFormatDescription = adoptCF(destinationFormatDescription);
-        m_gdrCountNum = gradualDecoderRefreshCount();
-    }
-
-    char *data = static_cast<char*>(fillBufferList.mBuffers[0].mData);
-    size_t dataSize = fillBufferList.mBuffers[0].mDataByteSize;
-
-    CMBlockBufferRef blockBuffer;
-    if (auto error = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault, NULL, dataSize, kCFAllocatorDefault, NULL, 0, dataSize, kCMBlockBufferAssureMemoryNowFlag, &blockBuffer)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBlockBufferCreateWithMemoryBlock failed with %d", error);
-        return nil;
-    }
-    auto buffer = adoptCF(blockBuffer);
-
-    if (auto error = CMBlockBufferReplaceDataBytes(data, buffer.get(), 0, dataSize)) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBlockBufferReplaceDataBytes failed with %d", error);
-        return nil;
-    }
-
-    CMSampleBufferRef sampleBuffer;
-    auto error = CMAudioSampleBufferCreateWithPacketDescriptions(kCFAllocatorDefault, buffer.get(), true, NULL, NULL, m_destinationFormatDescription.get(), numPackets, m_currentNativePresentationTimeStamp, m_destinationPacketDescriptions.data(), &sampleBuffer);
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMAudioSampleBufferCreateWithPacketDescriptions failed with %d", error);
-        return nil;
-    }
-
-    if ([m_gdrCountNum intValue])
-        CMSetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_GradualDecoderRefresh, (__bridge CFTypeRef)m_gdrCountNum.get(), kCMAttachmentMode_ShouldPropagate);
-
-    return sampleBuffer;
-}
-
-OSStatus AudioSampleBufferCompressor::audioConverterComplexInputDataProc(AudioConverterRef, UInt32 *numOutputPacketsPtr, AudioBufferList *bufferList, AudioStreamPacketDescription **packetDescriptionOut, void *audioSampleBufferCompressor)
-{
-    auto *compressor = static_cast<AudioSampleBufferCompressor*>(audioSampleBufferCompressor);
-    return compressor->provideSourceDataNumOutputPackets(numOutputPacketsPtr, bufferList, packetDescriptionOut);
-}
-
-OSStatus AudioSampleBufferCompressor::provideSourceDataNumOutputPackets(UInt32* numOutputPacketsPtr, AudioBufferList* audioBufferList, AudioStreamPacketDescription** packetDescriptionOut)
-{
-    if (packetDescriptionOut)
-        *packetDescriptionOut = NULL;
-
-    const UInt32 numPacketsToCopy = *numOutputPacketsPtr;
-    size_t numBytesToCopy = (numPacketsToCopy * m_sourceFormat.mBytesPerPacket);
-
-    if (audioBufferList->mNumberBuffers == 1) {
-        size_t currentOffsetInSourceBuffer = 0;
-
-        m_sourceBuffer.reserveCapacity(numBytesToCopy);
-
-        while (numBytesToCopy) {
-            if (m_sampleBlockBufferSize <= m_currentOffsetInSampleBlockBuffer) {
-                if (m_sampleBlockBuffer) {
-                    m_sampleBlockBuffer = nullptr;
-                    m_sampleBlockBufferSize = 0;
-                }
-
-                if (CMBufferQueueIsEmpty(m_inputBufferQueue.get()))
-                    break;
-
-                auto sampleBuffer = adoptCF((CMSampleBufferRef)(const_cast<void*>(CMBufferQueueDequeueAndRetain(m_inputBufferQueue.get()))));
-                m_sampleBlockBuffer = adoptCF((CMBlockBufferRef)(const_cast<void*>(CFRetain(CMSampleBufferGetDataBuffer(sampleBuffer.get())))));
-                if (!m_sampleBlockBuffer) {
-                    RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMSampleBufferGetDataBuffer failed");
-                    m_sampleBlockBufferSize = 0;
-                    m_currentOffsetInSampleBlockBuffer = 0;
-                    continue;
-                }
-                m_sampleBlockBufferSize = CMBlockBufferGetDataLength(m_sampleBlockBuffer.get());
-                m_currentOffsetInSampleBlockBuffer = 0;
-            }
-
-            if (m_sampleBlockBuffer) {
-                size_t numBytesToCopyFromSampleBbuf = std::min(numBytesToCopy, (m_sampleBlockBufferSize - m_currentOffsetInSampleBlockBuffer));
-                if (auto error = CMBlockBufferCopyDataBytes(m_sampleBlockBuffer.get(), m_currentOffsetInSampleBlockBuffer, numBytesToCopyFromSampleBbuf, (m_sourceBuffer.data() + currentOffsetInSourceBuffer))) {
-                    RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBlockBufferCopyDataBytes failed with %d", error);
-                    return error;
-                }
-                numBytesToCopy -= numBytesToCopyFromSampleBbuf;
-                currentOffsetInSourceBuffer += numBytesToCopyFromSampleBbuf;
-                m_currentOffsetInSampleBlockBuffer += numBytesToCopyFromSampleBbuf;
-            }
-        }
-        audioBufferList->mBuffers[0].mData = m_sourceBuffer.data();
-        audioBufferList->mBuffers[0].mDataByteSize = currentOffsetInSourceBuffer;
-        audioBufferList->mBuffers[0].mNumberChannels = m_sourceFormat.mChannelsPerFrame;
-
-        *numOutputPacketsPtr = (audioBufferList->mBuffers[0].mDataByteSize / m_sourceFormat.mBytesPerPacket);
-        return noErr;
-    }
-
-    ASSERT(audioBufferList->mNumberBuffers == 2);
-
-    // FIXME: Support interleaved data by uninterleaving m_sourceBuffer if needed.
-    ASSERT(m_sourceFormat.mFormatFlags & kAudioFormatFlagIsNonInterleaved);
-
-    m_sourceBuffer.reserveCapacity(2 * numBytesToCopy);
-    auto* firstChannel = m_sourceBuffer.data();
-    auto* secondChannel = m_sourceBuffer.data() + numBytesToCopy;
-
-    size_t currentOffsetInSourceBuffer = 0;
-    while (numBytesToCopy) {
-        if (m_sampleBlockBufferSize <= m_currentOffsetInSampleBlockBuffer) {
-            if (m_sampleBlockBuffer) {
-                m_sampleBlockBuffer = nullptr;
-                m_sampleBlockBufferSize = 0;
-            }
-
-            if (CMBufferQueueIsEmpty(m_inputBufferQueue.get()))
-                break;
-
-            auto sampleBuffer = adoptCF((CMSampleBufferRef)(const_cast<void*>(CMBufferQueueDequeueAndRetain(m_inputBufferQueue.get()))));
-            m_sampleBlockBuffer = adoptCF((CMBlockBufferRef)(const_cast<void*>(CFRetain(CMSampleBufferGetDataBuffer(sampleBuffer.get())))));
-            if (!m_sampleBlockBuffer) {
-                RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMSampleBufferGetDataBuffer failed");
-                m_sampleBlockBufferSize = 0;
-                m_currentOffsetInSampleBlockBuffer = 0;
-                continue;
-            }
-            m_sampleBlockBufferSize = CMBlockBufferGetDataLength(m_sampleBlockBuffer.get()) / 2;
-            m_currentOffsetInSampleBlockBuffer = 0;
-        }
-
-        if (m_sampleBlockBuffer) {
-            size_t numBytesToCopyFromSampleBbuf = std::min(numBytesToCopy, (m_sampleBlockBufferSize - m_currentOffsetInSampleBlockBuffer));
-            if (auto error = CMBlockBufferCopyDataBytes(m_sampleBlockBuffer.get(), m_currentOffsetInSampleBlockBuffer, numBytesToCopyFromSampleBbuf, (firstChannel + currentOffsetInSourceBuffer))) {
-                RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBlockBufferCopyDataBytes first channel failed with %d", error);
-                return error;
-            }
-            if (auto error = CMBlockBufferCopyDataBytes(m_sampleBlockBuffer.get(), m_currentOffsetInSampleBlockBuffer + m_sampleBlockBufferSize, numBytesToCopyFromSampleBbuf, (secondChannel + currentOffsetInSourceBuffer))) {
-                RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBlockBufferCopyDataBytes second channel failed with %d", error);
-                return error;
-            }
-            numBytesToCopy -= numBytesToCopyFromSampleBbuf;
-            currentOffsetInSourceBuffer += numBytesToCopyFromSampleBbuf;
-            m_currentOffsetInSampleBlockBuffer += numBytesToCopyFromSampleBbuf;
-        }
-    }
-
-    audioBufferList->mBuffers[0].mData = firstChannel;
-    audioBufferList->mBuffers[0].mDataByteSize = currentOffsetInSourceBuffer;
-    audioBufferList->mBuffers[0].mNumberChannels = 1;
-
-    audioBufferList->mBuffers[1].mData = secondChannel;
-    audioBufferList->mBuffers[1].mDataByteSize = currentOffsetInSourceBuffer;
-    audioBufferList->mBuffers[1].mNumberChannels = 1;
-
-    *numOutputPacketsPtr = (audioBufferList->mBuffers[0].mDataByteSize / m_sourceFormat.mBytesPerPacket);
-    return noErr;
-}
-
-void AudioSampleBufferCompressor::processSampleBuffersUntilLowWaterTime(CMTime lowWaterTime)
-{
-    if (!m_converter) {
-        auto buffer = (CMSampleBufferRef)(const_cast<void*>(CMBufferQueueGetHead(m_inputBufferQueue.get())));
-        ASSERT(buffer);
-
-        m_currentNativePresentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(buffer);
-        m_currentOutputPresentationTimeStamp = CMSampleBufferGetOutputPresentationTimeStamp(buffer);
-
-        auto formatDescription = CMSampleBufferGetFormatDescription(buffer);
-        if (!initAudioConverterForSourceFormatDescription(formatDescription, m_outputCodecType))
-            return;
-    }
-
-    while (CMTIME_IS_INVALID(lowWaterTime) || CMTIME_COMPARE_INLINE(lowWaterTime, <, CMBufferQueueGetDuration(m_inputBufferQueue.get()))) {
-        AudioBufferList fillBufferList;
-
-        fillBufferList.mNumberBuffers = 1;
-        fillBufferList.mBuffers[0].mNumberChannels = m_destinationFormat.mChannelsPerFrame;
-        fillBufferList.mBuffers[0].mDataByteSize = (UInt32)m_destinationBuffer.capacity();
-        fillBufferList.mBuffers[0].mData = m_destinationBuffer.data();
-
-        UInt32 outputPacketSize = m_destinationFormat.mBytesPerPacket ? m_destinationFormat.mBytesPerPacket : m_maxOutputPacketSize;
-        UInt32 numOutputPackets = (UInt32)m_destinationBuffer.capacity() / outputPacketSize;
-
-        auto error = AudioConverterFillComplexBuffer(m_converter.get(), audioConverterComplexInputDataProc, this, &numOutputPackets, &fillBufferList, m_destinationPacketDescriptions.data());
-        if (error) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor AudioConverterFillComplexBuffer failed with %d", error);
-            return;
-        }
-
-        if (!numOutputPackets)
-            break;
-
-        auto buffer = sampleBufferWithNumPackets(numOutputPackets, fillBufferList);
-
-        attachPrimingTrimsIfNeeded(buffer);
-
-        error = CMSampleBufferSetOutputPresentationTimeStamp(buffer, m_currentOutputPresentationTimeStamp);
-        if (error) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMSampleBufferSetOutputPresentationTimeStamp failed with %d", error);
-            return;
-        }
-
-        CMTime nativeDuration = CMSampleBufferGetDuration(buffer);
-        m_currentNativePresentationTimeStamp = CMTimeAdd(m_currentNativePresentationTimeStamp, nativeDuration);
-
-        CMTime outputDuration = CMSampleBufferGetOutputDuration(buffer);
-        m_currentOutputPresentationTimeStamp = CMTimeAdd(m_currentOutputPresentationTimeStamp, outputDuration);
-
-        error = CMBufferQueueEnqueue(m_outputBufferQueue.get(), buffer);
-        if (error) {
-            RELEASE_LOG_ERROR(MediaStream, "AudioSampleBufferCompressor CMBufferQueueEnqueue failed with %d", error);
-            return;
-        }
-    }
-}
-
-void AudioSampleBufferCompressor::processSampleBuffer(CMSampleBufferRef buffer)
-{
-    auto error = CMBufferQueueEnqueue(m_inputBufferQueue.get(), buffer);
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "AudioSampleBufferCompressor CMBufferQueueEnqueue failed with %d", error);
-
-    processSampleBuffersUntilLowWaterTime(m_lowWaterTime);
-}
-
-void AudioSampleBufferCompressor::addSampleBuffer(CMSampleBufferRef buffer)
-{
-    dispatch_sync(m_serialDispatchQueue, ^{
-        if (m_isEncoding)
-            processSampleBuffer(buffer);
-    });
-}
-
-CMSampleBufferRef AudioSampleBufferCompressor::getOutputSampleBuffer()
-{
-    return (CMSampleBufferRef)(const_cast<void*>(CMBufferQueueGetHead(m_outputBufferQueue.get())));
-}
-
-RetainPtr<CMSampleBufferRef> AudioSampleBufferCompressor::takeOutputSampleBuffer()
-{
-    return adoptCF((CMSampleBufferRef)(const_cast<void*>(CMBufferQueueDequeueAndRetain(m_outputBufferQueue.get()))));
-}
-
-}
-
-#endif // ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
index 0518608..b147ca2 100644 (file)
@@ -24,9 +24,7 @@
 
 #pragma once
 
-#if ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
-
-#include "AudioStreamDescription.h"
+#if ENABLE(MEDIA_STREAM)
 
 #include "SharedBuffer.h"
 #include <wtf/CompletionHandler.h>
 #include <wtf/WeakPtr.h>
 #include <wtf/threads/BinarySemaphore.h>
 
-#include <CoreAudio/CoreAudioTypes.h>
-#include <CoreMedia/CMTime.h>
-
 typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-typedef const struct opaqueCMFormatDescription* CMFormatDescriptionRef;
-typedef struct opaqueCMBufferQueueTriggerToken *CMBufferQueueTriggerToken;
 
 OBJC_CLASS AVAssetWriter;
 OBJC_CLASS AVAssetWriterInput;
-OBJC_CLASS WebAVAssetWriterDelegate;
 
 namespace WTF {
 class MediaTime;
@@ -54,72 +46,51 @@ class MediaTime;
 
 namespace WebCore {
 
-class AudioSampleBufferCompressor;
 class AudioStreamDescription;
 class MediaStreamTrackPrivate;
 class PlatformAudioData;
-class VideoSampleBufferCompressor;
 
-class WEBCORE_EXPORT MediaRecorderPrivateWriter : public ThreadSafeRefCounted<MediaRecorderPrivateWriter, WTF::DestructionThread::Main>, public CanMakeWeakPtr<MediaRecorderPrivateWriter, WeakPtrFactoryInitialization::Eager> {
+class WEBCORE_EXPORT MediaRecorderPrivateWriter : public ThreadSafeRefCounted<MediaRecorderPrivateWriter, WTF::DestructionThread::Main>, public CanMakeWeakPtr<MediaRecorderPrivateWriter> {
 public:
+    static RefPtr<MediaRecorderPrivateWriter> create(const MediaStreamTrackPrivate* audioTrack, const MediaStreamTrackPrivate* videoTrack);
     static RefPtr<MediaRecorderPrivateWriter> create(bool hasAudio, int width, int height);
     ~MediaRecorderPrivateWriter();
-
+    
+    bool setupWriter();
+    bool setVideoInput(int width, int height);
+    bool setAudioInput();
     void appendVideoSampleBuffer(CMSampleBufferRef);
     void appendAudioSampleBuffer(const PlatformAudioData&, const AudioStreamDescription&, const WTF::MediaTime&, size_t);
     void stopRecording();
     void fetchData(CompletionHandler<void(RefPtr<SharedBuffer>&&)>&&);
 
-    void appendData(const char*, size_t);
-    void appendData(Ref<SharedBuffer>&&);
-
 private:
-    MediaRecorderPrivateWriter(bool hasAudio, bool hasVideo);
+    MediaRecorderPrivateWriter(RetainPtr<AVAssetWriter>&&, String&& path);
     void clear();
 
-    bool initialize();
-
-    static void compressedVideoOutputBufferCallback(void*, CMBufferQueueTriggerToken);
-    static void compressedAudioOutputBufferCallback(void*, CMBufferQueueTriggerToken);
-
-    void startAssetWriter();
-    void appendCompressedSampleBuffers();
-
-    bool appendCompressedAudioSampleBuffer();
-    bool appendCompressedVideoSampleBuffer();
-
-    void processNewCompressedAudioSampleBuffers();
-    void processNewCompressedVideoSampleBuffers();
-
-    void flushCompressedSampleBuffers(CompletionHandler<void()>&&);
-    void appendEndOfVideoSampleDurationIfNeeded(CompletionHandler<void()>&&);
-
+    RetainPtr<AVAssetWriter> m_writer;
+    RetainPtr<AVAssetWriterInput> m_videoInput;
+    RetainPtr<AVAssetWriterInput> m_audioInput;
+
+    String m_path;
+    Lock m_videoLock;
+    Lock m_audioLock;
+    BinarySemaphore m_finishWritingSemaphore;
+    BinarySemaphore m_finishWritingAudioSemaphore;
+    BinarySemaphore m_finishWritingVideoSemaphore;
     bool m_hasStartedWriting { false };
     bool m_isStopped { false };
-
-    RetainPtr<AVAssetWriter> m_writer;
+    bool m_isFirstAudioSample { true };
+    dispatch_queue_t m_audioPullQueue;
+    dispatch_queue_t m_videoPullQueue;
+    Deque<RetainPtr<CMSampleBufferRef>> m_videoBufferPool;
+    Deque<RetainPtr<CMSampleBufferRef>> m_audioBufferPool;
 
     bool m_isStopping { false };
     RefPtr<SharedBuffer> m_data;
     CompletionHandler<void(RefPtr<SharedBuffer>&&)> m_fetchDataCompletionHandler;
-
-    bool m_hasAudio;
-    bool m_hasVideo;
-
-    RetainPtr<CMFormatDescriptionRef> m_audioFormatDescription;
-    std::unique_ptr<AudioSampleBufferCompressor> m_audioCompressor;
-    RetainPtr<AVAssetWriterInput> m_audioAssetWriterInput;
-
-    RetainPtr<CMFormatDescriptionRef> m_videoFormatDescription;
-    std::unique_ptr<VideoSampleBufferCompressor> m_videoCompressor;
-    RetainPtr<AVAssetWriterInput> m_videoAssetWriterInput;
-    CMTime m_lastVideoPresentationTime;
-    CMTime m_lastVideoDecodingTime;
-    bool m_hasEncodedVideoSamples { false };
-
-    RetainPtr<WebAVAssetWriterDelegate> m_writerDelegate;
 };
 
 } // namespace WebCore
 
-#endif // ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // ENABLE(MEDIA_STREAM)
index ec3bb6e..23354f4 100644 (file)
 #include "config.h"
 #include "MediaRecorderPrivateWriterCocoa.h"
 
-#if ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
 
-#include "AudioSampleBufferCompressor.h"
 #include "AudioStreamDescription.h"
 #include "Logging.h"
 #include "MediaStreamTrackPrivate.h"
-#include "VideoSampleBufferCompressor.h"
 #include "WebAudioBufferList.h"
 #include <AVFoundation/AVAssetWriter.h>
 #include <AVFoundation/AVAssetWriterInput.h>
-#include <AVFoundation/AVAssetWriter_Private.h>
-#include <pal/avfoundation/MediaTimeAVFoundation.h>
 #include <pal/cf/CoreMediaSoftLink.h>
-#include <wtf/BlockPtr.h>
 #include <wtf/CompletionHandler.h>
 #include <wtf/FileSystem.h>
-#include <wtf/cf/TypeCastsCF.h>
 
 #import <pal/cocoa/AVFoundationSoftLink.h>
 
-@interface WebAVAssetWriterDelegate : NSObject <AVAssetWriterDelegate> {
-    WeakPtr<WebCore::MediaRecorderPrivateWriter> m_writer;
-}
-
-- (instancetype)initWithWriter:(WebCore::MediaRecorderPrivateWriter*)writer;
-- (void)close;
+#undef AVEncoderBitRateKey
+#define AVEncoderBitRateKey getAVEncoderBitRateKeyWithFallback()
+#undef AVFormatIDKey
+#define AVFormatIDKey getAVFormatIDKeyWithFallback()
+#undef AVNumberOfChannelsKey
+#define AVNumberOfChannelsKey getAVNumberOfChannelsKeyWithFallback()
+#undef AVSampleRateKey
+#define AVSampleRateKey getAVSampleRateKeyWithFallback()
 
-@end
+namespace WebCore {
 
-@implementation WebAVAssetWriterDelegate {
-};
+using namespace PAL;
 
-- (instancetype)initWithWriter:(WebCore::MediaRecorderPrivateWriter*)writer
+static NSString *getAVFormatIDKeyWithFallback()
 {
-    ASSERT(isMainThread());
-    self = [super init];
-    if (self)
-        self->m_writer = makeWeakPtr(writer);
+    if (PAL::canLoad_AVFoundation_AVFormatIDKey())
+        return PAL::get_AVFoundation_AVFormatIDKey();
 
-    return self;
+    RELEASE_LOG_ERROR(Media, "Failed to load AVFormatIDKey");
+    return @"AVFormatIDKey";
 }
 
-- (void)assetWriter:(AVAssetWriter *)assetWriter didProduceFragmentedHeaderData:(NSData *)fragmentedHeaderData
+static NSString *getAVNumberOfChannelsKeyWithFallback()
 {
-    UNUSED_PARAM(assetWriter);
-    if (!isMainThread()) {
-        if (auto size = [fragmentedHeaderData length]) {
-            callOnMainThread([protectedSelf = RetainPtr<WebAVAssetWriterDelegate>(self), buffer = WebCore::SharedBuffer::create(static_cast<const char*>([fragmentedHeaderData bytes]), size)]() mutable {
-                if (protectedSelf->m_writer)
-                    protectedSelf->m_writer->appendData(WTFMove(buffer));
-            });
-        }
-        return;
-    }
+    if (PAL::canLoad_AVFoundation_AVNumberOfChannelsKey())
+        return PAL::get_AVFoundation_AVNumberOfChannelsKey();
 
-    if (m_writer)
-        m_writer->appendData(static_cast<const char*>([fragmentedHeaderData bytes]), [fragmentedHeaderData length]);
+    RELEASE_LOG_ERROR(Media, "Failed to load AVNumberOfChannelsKey");
+    return @"AVNumberOfChannelsKey";
 }
 
-- (void)assetWriter:(AVAssetWriter *)assetWriter didProduceFragmentedMediaData:(NSData *)fragmentedMediaData fragmentedMediaDataReport:(AVFragmentedMediaDataReport *)fragmentedMediaDataReport
+static NSString *getAVSampleRateKeyWithFallback()
 {
-    UNUSED_PARAM(assetWriter);
-    UNUSED_PARAM(fragmentedMediaDataReport);
-    if (!isMainThread()) {
-        if (auto size = [fragmentedMediaData length]) {
-            callOnMainThread([protectedSelf = RetainPtr<WebAVAssetWriterDelegate>(self), buffer = WebCore::SharedBuffer::create(static_cast<const char*>([fragmentedMediaData bytes]), size)]() mutable {
-                if (protectedSelf->m_writer)
-                    protectedSelf->m_writer->appendData(WTFMove(buffer));
-            });
-        }
-        return;
-    }
+    if (PAL::canLoad_AVFoundation_AVSampleRateKey())
+        return PAL::get_AVFoundation_AVSampleRateKey();
 
-    if (m_writer)
-        m_writer->appendData(static_cast<const char*>([fragmentedMediaData bytes]), [fragmentedMediaData length]);
-}
-
-- (void)close
-{
-    m_writer = nullptr;
-}
-
-@end
-
-namespace WebCore {
-
-using namespace PAL;
-
-RefPtr<MediaRecorderPrivateWriter> MediaRecorderPrivateWriter::create(bool hasAudio, int width, int height)
-{
-    auto writer = adoptRef(*new MediaRecorderPrivateWriter(hasAudio, width && height));
-    if (!writer->initialize())
-        return nullptr;
-    return writer;
+    RELEASE_LOG_ERROR(Media, "Failed to load AVSampleRateKey");
+    return @"AVSampleRateKey";
 }
 
-void MediaRecorderPrivateWriter::compressedVideoOutputBufferCallback(void *mediaRecorderPrivateWriter, CMBufferQueueTriggerToken)
+static NSString *getAVEncoderBitRateKeyWithFallback()
 {
-    auto *writer = static_cast<MediaRecorderPrivateWriter*>(mediaRecorderPrivateWriter);
-    writer->processNewCompressedVideoSampleBuffers();
-}
+    if (PAL::canLoad_AVFoundation_AVEncoderBitRateKey())
+        return PAL::get_AVFoundation_AVEncoderBitRateKey();
 
-void MediaRecorderPrivateWriter::compressedAudioOutputBufferCallback(void *mediaRecorderPrivateWriter, CMBufferQueueTriggerToken)
-{
-    auto *writer = static_cast<MediaRecorderPrivateWriter*>(mediaRecorderPrivateWriter);
-    writer->processNewCompressedAudioSampleBuffers();
+    RELEASE_LOG_ERROR(Media, "Failed to load AVEncoderBitRateKey");
+    return @"AVEncoderBitRateKey";
 }
 
-MediaRecorderPrivateWriter::MediaRecorderPrivateWriter(bool hasAudio, bool hasVideo)
-    : m_hasAudio(hasAudio)
-    , m_hasVideo(hasVideo)
+RefPtr<MediaRecorderPrivateWriter> MediaRecorderPrivateWriter::create(const MediaStreamTrackPrivate* audioTrack, const MediaStreamTrackPrivate* videoTrack)
 {
+    int width = 0, height = 0;
+    if (videoTrack) {
+        auto& settings = videoTrack->settings();
+        width = settings.width();
+        height = settings.height();
+    }
+    return create(!!audioTrack, width, height);
 }
 
-MediaRecorderPrivateWriter::~MediaRecorderPrivateWriter()
+RefPtr<MediaRecorderPrivateWriter> MediaRecorderPrivateWriter::create(bool hasAudio, int width, int height)
 {
-    clear();
-}
+    NSString *directory = FileSystem::createTemporaryDirectory(@"videos");
+    NSString *filename = [NSString stringWithFormat:@"/%lld.mp4", CMClockGetTime(CMClockGetHostTimeClock()).value];
+    NSString *path = [directory stringByAppendingString:filename];
 
-bool MediaRecorderPrivateWriter::initialize()
-{
+    NSURL *outputURL = [NSURL fileURLWithPath:path];
+    String filePath = [path UTF8String];
     NSError *error = nil;
-    m_writer = adoptNS([PAL::allocAVAssetWriterInstance() initWithFileType:AVFileTypeMPEG4 error:&error]);
+    auto avAssetWriter = adoptNS([PAL::allocAVAssetWriterInstance() initWithURL:outputURL fileType:AVFileTypeMPEG4 error:&error]);
     if (error) {
         RELEASE_LOG_ERROR(MediaStream, "create AVAssetWriter instance failed with error code %ld", (long)error.code);
-        return false;
+        return nullptr;
     }
 
-    m_writerDelegate = adoptNS([[WebAVAssetWriterDelegate alloc] initWithWriter: this]);
-    [m_writer.get() setDelegate:m_writerDelegate.get()];
+    auto writer = adoptRef(*new MediaRecorderPrivateWriter(WTFMove(avAssetWriter), WTFMove(filePath)));
 
-    if (m_hasAudio) {
-        m_audioCompressor = AudioSampleBufferCompressor::create(compressedAudioOutputBufferCallback, this);
-        if (!m_audioCompressor)
-            return false;
-    }
-    if (m_hasVideo) {
-        m_videoCompressor = VideoSampleBufferCompressor::create(kCMVideoCodecType_H264, compressedVideoOutputBufferCallback, this);
-        if (!m_videoCompressor)
-            return false;
+    if (hasAudio && !writer->setAudioInput())
+        return nullptr;
+
+    if (width && height) {
+        if (!writer->setVideoInput(width, height))
+            return nullptr;
     }
-    return true;
+
+    return WTFMove(writer);
 }
 
-void MediaRecorderPrivateWriter::processNewCompressedVideoSampleBuffers()
+MediaRecorderPrivateWriter::MediaRecorderPrivateWriter(RetainPtr<AVAssetWriter>&& avAssetWriter, String&& filePath)
+    : m_writer(WTFMove(avAssetWriter))
+    , m_path(WTFMove(filePath))
 {
-    ASSERT(m_hasVideo);
-    if (!m_videoFormatDescription) {
-        m_videoFormatDescription = CMSampleBufferGetFormatDescription(m_videoCompressor->getOutputSampleBuffer());
-        callOnMainThread([weakThis = makeWeakPtr(this), this] {
-            if (!weakThis)
-                return;
-
-            if (m_hasAudio && !m_audioFormatDescription)
-                return;
-
-            startAssetWriter();
-        });
-    }
-    if (!m_hasStartedWriting)
-        return;
-    appendCompressedSampleBuffers();
 }
 
-void MediaRecorderPrivateWriter::processNewCompressedAudioSampleBuffers()
+MediaRecorderPrivateWriter::~MediaRecorderPrivateWriter()
 {
-    ASSERT(m_hasAudio);
-    if (!m_audioFormatDescription) {
-        m_audioFormatDescription = CMSampleBufferGetFormatDescription(m_audioCompressor->getOutputSampleBuffer());
-        callOnMainThread([weakThis = makeWeakPtr(this), this] {
-            if (!weakThis)
-                return;
-            
-            if (m_hasVideo && !m_videoFormatDescription)
-                return;
-
-            startAssetWriter();
-        });
-    }
-    if (!m_hasStartedWriting)
-        return;
-    appendCompressedSampleBuffers();
+    clear();
 }
 
-void MediaRecorderPrivateWriter::startAssetWriter()
+void MediaRecorderPrivateWriter::clear()
 {
-    if (m_hasVideo) {
-        m_videoAssetWriterInput = adoptNS([PAL::allocAVAssetWriterInputInstance() initWithMediaType:AVMediaTypeVideo outputSettings:nil sourceFormatHint:m_videoFormatDescription.get()]);
-        [m_videoAssetWriterInput setExpectsMediaDataInRealTime:true];
-        if (![m_writer.get() canAddInput:m_videoAssetWriterInput.get()]) {
-            RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter::startAssetWriter failed canAddInput for video");
-            return;
-        }
-        [m_writer.get() addInput:m_videoAssetWriterInput.get()];
+    if (m_videoInput) {
+        m_videoInput.clear();
+        dispatch_release(m_videoPullQueue);
     }
-    
-    if (m_hasAudio) {
-        m_audioAssetWriterInput = adoptNS([PAL::allocAVAssetWriterInputInstance() initWithMediaType:AVMediaTypeAudio outputSettings:nil sourceFormatHint:m_audioFormatDescription.get()]);
-        [m_audioAssetWriterInput setExpectsMediaDataInRealTime:true];
-        if (![m_writer.get() canAddInput:m_audioAssetWriterInput.get()]) {
-            RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter::startAssetWriter failed canAddInput for audio");
-            return;
-        }
-        [m_writer.get() addInput:m_audioAssetWriterInput.get()];
+    if (m_audioInput) {
+        m_audioInput.clear();
+        dispatch_release(m_audioPullQueue);
     }
-    
-    if (![m_writer.get() startWriting]) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter::startAssetWriter failed startWriting");
-        return;
-    }
-
-    [m_writer.get() startSessionAtSourceTime:kCMTimeZero];
-
-    appendCompressedSampleBuffers();
+    if (m_writer)
+        m_writer.clear();
 
-    m_hasStartedWriting = true;
+    m_data = nullptr;
+    if (auto completionHandler = WTFMove(m_fetchDataCompletionHandler))
+        completionHandler(nullptr);
 }
 
-bool MediaRecorderPrivateWriter::appendCompressedAudioSampleBuffer()
+bool MediaRecorderPrivateWriter::setVideoInput(int width, int height)
 {
-    if (!m_audioCompressor)
-        return false;
-
-    if (![m_audioAssetWriterInput isReadyForMoreMediaData])
-        return false;
-
-    auto buffer = m_audioCompressor->takeOutputSampleBuffer();
-    if (!buffer)
+    ASSERT(!m_videoInput);
+    
+    NSDictionary *compressionProperties = @{
+        AVVideoAverageBitRateKey : [NSNumber numberWithInt:width * height * 12],
+        AVVideoExpectedSourceFrameRateKey : @(30),
+        AVVideoMaxKeyFrameIntervalKey : @(120),
+        AVVideoProfileLevelKey : AVVideoProfileLevelH264MainAutoLevel
+    };
+
+    NSDictionary *videoSettings = @{
+        AVVideoCodecKey: AVVideoCodecH264,
+        AVVideoWidthKey: [NSNumber numberWithInt:width],
+        AVVideoHeightKey: [NSNumber numberWithInt:height],
+        AVVideoCompressionPropertiesKey: compressionProperties
+    };
+    
+    m_videoInput = adoptNS([PAL::allocAVAssetWriterInputInstance() initWithMediaType:AVMediaTypeVideo outputSettings:videoSettings sourceFormatHint:nil]);
+    [m_videoInput setExpectsMediaDataInRealTime:true];
+    
+    if (![m_writer canAddInput:m_videoInput.get()]) {
+        m_videoInput = nullptr;
+        RELEASE_LOG_ERROR(MediaStream, "the video input is not allowed to add to the AVAssetWriter");
         return false;
-
-    [m_audioAssetWriterInput.get() appendSampleBuffer:buffer.get()];
+    }
+    [m_writer addInput:m_videoInput.get()];
+    m_videoPullQueue = dispatch_queue_create("WebCoreVideoRecordingPullBufferQueue", DISPATCH_QUEUE_SERIAL);
     return true;
 }
 
-bool MediaRecorderPrivateWriter::appendCompressedVideoSampleBuffer()
+bool MediaRecorderPrivateWriter::setAudioInput()
 {
-    if (!m_videoCompressor)
-        return false;
+    ASSERT(!m_audioInput);
 
-    if (![m_videoAssetWriterInput isReadyForMoreMediaData])
-        return false;
+    NSDictionary *audioSettings = @{
+        AVEncoderBitRateKey : @(28000),
+        AVFormatIDKey : @(kAudioFormatMPEG4AAC),
+        AVNumberOfChannelsKey : @(1),
+        AVSampleRateKey : @(22050)
+    };
 
-    auto buffer = m_videoCompressor->takeOutputSampleBuffer();
-    if (!buffer)
+    m_audioInput = adoptNS([PAL::allocAVAssetWriterInputInstance() initWithMediaType:AVMediaTypeAudio outputSettings:audioSettings sourceFormatHint:nil]);
+    [m_audioInput setExpectsMediaDataInRealTime:true];
+    
+    if (![m_writer canAddInput:m_audioInput.get()]) {
+        m_audioInput = nullptr;
+        RELEASE_LOG_ERROR(MediaStream, "the audio input is not allowed to add to the AVAssetWriter");
         return false;
-
-    m_lastVideoPresentationTime = CMSampleBufferGetPresentationTimeStamp(buffer.get());
-    m_lastVideoDecodingTime = CMSampleBufferGetDecodeTimeStamp(buffer.get());
-    m_hasEncodedVideoSamples = true;
-
-    [m_videoAssetWriterInput.get() appendSampleBuffer:buffer.get()];
-    return true;
-}
-
-void MediaRecorderPrivateWriter::appendCompressedSampleBuffers()
-{
-    while (appendCompressedVideoSampleBuffer() || appendCompressedAudioSampleBuffer()) { };
-}
-
-static inline void appendEndsPreviousSampleDurationMarker(AVAssetWriterInput *assetWriterInput, CMTime presentationTimeStamp, CMTime decodingTimeStamp)
-{
-    CMSampleTimingInfo timingInfo = { kCMTimeInvalid, presentationTimeStamp, decodingTimeStamp};
-
-    CMSampleBufferRef buffer = NULL;
-    auto error = CMSampleBufferCreate(kCFAllocatorDefault, NULL, true, NULL, NULL, NULL, 0, 1, &timingInfo, 0, NULL, &buffer);
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter appendEndsPreviousSampleDurationMarker failed CMSampleBufferCreate with %d", error);
-        return;
-    }
-    auto sampleBuffer = adoptCF(buffer);
-
-    CMSetAttachment(sampleBuffer.get(), kCMSampleBufferAttachmentKey_EndsPreviousSampleDuration, kCFBooleanTrue, kCMAttachmentMode_ShouldPropagate);
-    if (![assetWriterInput appendSampleBuffer:sampleBuffer.get()])
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter appendSampleBuffer to writer input failed");
-}
-
-void MediaRecorderPrivateWriter::appendEndOfVideoSampleDurationIfNeeded(CompletionHandler<void()>&& completionHandler)
-{
-    if (!m_hasEncodedVideoSamples) {
-        completionHandler();
-        return;
     }
-    if ([m_videoAssetWriterInput isReadyForMoreMediaData]) {
-        appendEndsPreviousSampleDurationMarker(m_videoAssetWriterInput.get(), m_lastVideoPresentationTime, m_lastVideoDecodingTime);
-        completionHandler();
-        return;
-    }
-
-    auto block = makeBlockPtr([this, weakThis = makeWeakPtr(this), completionHandler = WTFMove(completionHandler)]() mutable {
-        if (weakThis) {
-            appendEndsPreviousSampleDurationMarker(m_videoAssetWriterInput.get(), m_lastVideoPresentationTime, m_lastVideoDecodingTime);
-            [m_videoAssetWriterInput markAsFinished];
-        }
-        completionHandler();
-    });
-    [m_videoAssetWriterInput requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:block.get()];
-}
-
-void MediaRecorderPrivateWriter::flushCompressedSampleBuffers(CompletionHandler<void()>&& completionHandler)
-{
-    appendCompressedSampleBuffers();
-    appendEndOfVideoSampleDurationIfNeeded(WTFMove(completionHandler));
-}
-
-void MediaRecorderPrivateWriter::clear()
-{
-    if (m_writer)
-        m_writer.clear();
-
-    m_data = nullptr;
-    if (auto completionHandler = WTFMove(m_fetchDataCompletionHandler))
-        completionHandler(nullptr);
+    [m_writer addInput:m_audioInput.get()];
+    m_audioPullQueue = dispatch_queue_create("WebCoreAudioRecordingPullBufferQueue", DISPATCH_QUEUE_SERIAL);
+    return true;
 }
 
-
 static inline RetainPtr<CMSampleBufferRef> copySampleBufferWithCurrentTimeStamp(CMSampleBufferRef originalBuffer)
 {
     CMTime startTime = CMClockGetTime(CMClockGetHostTimeClock());
     CMItemCount count = 0;
     CMSampleBufferGetSampleTimingInfoArray(originalBuffer, 0, nil, &count);
-
+    
     Vector<CMSampleTimingInfo> timeInfo(count);
     CMSampleBufferGetSampleTimingInfoArray(originalBuffer, count, timeInfo.data(), &count);
-
-    for (auto i = 0; i < count; i++) {
+    
+    for (CMItemCount i = 0; i < count; i++) {
         timeInfo[i].decodeTimeStamp = kCMTimeInvalid;
         timeInfo[i].presentationTimeStamp = startTime;
     }
-
+    
     CMSampleBufferRef newBuffer = nullptr;
-    if (auto error = CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, originalBuffer, count, timeInfo.data(), &newBuffer)) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter CMSampleBufferCreateCopyWithNewTiming failed with %d", error);
+    auto error = CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, originalBuffer, count, timeInfo.data(), &newBuffer);
+    if (error)
         return nullptr;
-    }
     return adoptCF(newBuffer);
 }
 
 void MediaRecorderPrivateWriter::appendVideoSampleBuffer(CMSampleBufferRef sampleBuffer)
 {
-    // FIXME: We should not set the timestamps if they are already set.
-    if (auto bufferWithCurrentTime = copySampleBufferWithCurrentTimeStamp(sampleBuffer))
-        m_videoCompressor->addSampleBuffer(bufferWithCurrentTime.get());
+    ASSERT(m_videoInput);
+    if (m_isStopped)
+        return;
+
+    if (!m_hasStartedWriting) {
+        if (![m_writer startWriting]) {
+            m_isStopped = true;
+            RELEASE_LOG_ERROR(MediaStream, "create AVAssetWriter instance failed with error code %ld", (long)[m_writer error]);
+            return;
+        }
+        [m_writer startSessionAtSourceTime:CMClockGetTime(CMClockGetHostTimeClock())];
+        m_hasStartedWriting = true;
+        RefPtr<MediaRecorderPrivateWriter> protectedThis = this;
+        [m_videoInput requestMediaDataWhenReadyOnQueue:m_videoPullQueue usingBlock:[this, protectedThis = WTFMove(protectedThis)] {
+            do {
+                if (![m_videoInput isReadyForMoreMediaData])
+                    break;
+                auto locker = holdLock(m_videoLock);
+                if (m_videoBufferPool.isEmpty())
+                    break;
+                auto buffer = m_videoBufferPool.takeFirst();
+                locker.unlockEarly();
+                if (![m_videoInput appendSampleBuffer:buffer.get()])
+                    break;
+            } while (true);
+            if (m_isStopped && m_videoBufferPool.isEmpty()) {
+                [m_videoInput markAsFinished];
+                m_finishWritingVideoSemaphore.signal();
+            }
+        }];
+        return;
+    }
+    auto bufferWithCurrentTime = copySampleBufferWithCurrentTimeStamp(sampleBuffer);
+    if (!bufferWithCurrentTime)
+        return;
+
+    auto locker = holdLock(m_videoLock);
+    m_videoBufferPool.append(WTFMove(bufferWithCurrentTime));
 }
 
 static inline RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(const AudioStreamDescription& description)
@@ -375,39 +280,68 @@ static inline RetainPtr<CMFormatDescriptionRef> createAudioFormatDescription(con
     auto basicDescription = WTF::get<const AudioStreamBasicDescription*>(description.platformDescription().description);
     CMFormatDescriptionRef format = nullptr;
     auto error = CMAudioFormatDescriptionCreate(kCFAllocatorDefault, basicDescription, 0, NULL, 0, NULL, NULL, &format);
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter CMAudioFormatDescriptionCreate failed with %d", error);
+    if (error)
         return nullptr;
-    }
     return adoptCF(format);
 }
 
-static inline RetainPtr<CMSampleBufferRef> createAudioSampleBuffer(const PlatformAudioData& data, const AudioStreamDescription& description, const WTF::MediaTime& time, size_t sampleCount)
+static inline RetainPtr<CMSampleBufferRef> createAudioSampleBufferWithPacketDescriptions(CMFormatDescriptionRef format, size_t sampleCount)
 {
-    auto format = createAudioFormatDescription(description);
-    if (!format)
-        return nullptr;
-
+    CMTime startTime = CMClockGetTime(CMClockGetHostTimeClock());
     CMSampleBufferRef sampleBuffer = nullptr;
-    auto error = CMAudioSampleBufferCreateWithPacketDescriptions(kCFAllocatorDefault, NULL, false, NULL, NULL, format.get(), sampleCount, toCMTime(time), NULL, &sampleBuffer);
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter createAudioSampleBufferWithPacketDescriptions failed with %d", error);
+    auto error = CMAudioSampleBufferCreateWithPacketDescriptions(kCFAllocatorDefault, NULL, false, NULL, NULL, format, sampleCount, startTime, NULL, &sampleBuffer);
+    if (error)
         return nullptr;
-    }
-    auto buffer = adoptCF(sampleBuffer);
-
-    error = CMSampleBufferSetDataBufferFromAudioBufferList(buffer.get(), kCFAllocatorDefault, kCFAllocatorDefault, 0, downcast<WebAudioBufferList>(data).list());
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "MediaRecorderPrivateWriter CMSampleBufferSetDataBufferFromAudioBufferList failed with %d", error);
-        return nullptr;
-    }
-    return buffer;
+    return adoptCF(sampleBuffer);
 }
 
-void MediaRecorderPrivateWriter::appendAudioSampleBuffer(const PlatformAudioData& data, const AudioStreamDescription& description, const WTF::MediaTime& time, size_t sampleCount)
+void MediaRecorderPrivateWriter::appendAudioSampleBuffer(const PlatformAudioData& data, const AudioStreamDescription& description, const WTF::MediaTime&, size_t sampleCount)
 {
-    if (auto sampleBuffer = createAudioSampleBuffer(data, description, time, sampleCount))
-        m_audioCompressor->addSampleBuffer(sampleBuffer.get());
+    ASSERT(m_audioInput);
+    if ((!m_hasStartedWriting && m_videoInput) || m_isStopped)
+        return;
+    auto format = createAudioFormatDescription(description);
+    if (!format)
+        return;
+    if (m_isFirstAudioSample) {
+        if (!m_videoInput) {
+            // audio-only recording.
+            if (![m_writer startWriting]) {
+                m_isStopped = true;
+                return;
+            }
+            [m_writer startSessionAtSourceTime:CMClockGetTime(CMClockGetHostTimeClock())];
+            m_hasStartedWriting = true;
+        }
+        m_isFirstAudioSample = false;
+        RefPtr<MediaRecorderPrivateWriter> protectedThis = this;
+        [m_audioInput requestMediaDataWhenReadyOnQueue:m_audioPullQueue usingBlock:[this, protectedThis = WTFMove(protectedThis)] {
+            do {
+                if (![m_audioInput isReadyForMoreMediaData])
+                    break;
+                auto locker = holdLock(m_audioLock);
+                if (m_audioBufferPool.isEmpty())
+                    break;
+                auto buffer = m_audioBufferPool.takeFirst();
+                locker.unlockEarly();
+                [m_audioInput appendSampleBuffer:buffer.get()];
+            } while (true);
+            if (m_isStopped && m_audioBufferPool.isEmpty()) {
+                [m_audioInput markAsFinished];
+                m_finishWritingAudioSemaphore.signal();
+            }
+        }];
+    }
+
+    auto sampleBuffer = createAudioSampleBufferWithPacketDescriptions(format.get(), sampleCount);
+    if (!sampleBuffer)
+        return;
+    auto error = CMSampleBufferSetDataBufferFromAudioBufferList(sampleBuffer.get(), kCFAllocatorDefault, kCFAllocatorDefault, 0, downcast<WebAudioBufferList>(data).list());
+    if (error)
+        return;
+
+    auto locker = holdLock(m_audioLock);
+    m_audioBufferPool.append(WTFMove(sampleBuffer));
 }
 
 void MediaRecorderPrivateWriter::stopRecording()
@@ -416,40 +350,35 @@ void MediaRecorderPrivateWriter::stopRecording()
         return;
 
     m_isStopped = true;
-
-    if (m_videoCompressor)
-        m_videoCompressor->finish();
-    if (m_audioCompressor)
-        m_audioCompressor->finish();
-
     if (!m_hasStartedWriting)
         return;
     ASSERT([m_writer status] == AVAssetWriterStatusWriting);
+    if (m_videoInput)
+        m_finishWritingVideoSemaphore.wait();
+
+    if (m_audioInput)
+        m_finishWritingAudioSemaphore.wait();
 
     m_isStopping = true;
+    [m_writer finishWritingWithCompletionHandler:[this, weakPtr = makeWeakPtr(*this)]() mutable {
+        callOnMainThread([this, weakPtr = WTFMove(weakPtr), buffer = SharedBuffer::createWithContentsOfFile(m_path)]() mutable {
+            if (!weakPtr)
+                return;
 
-    flushCompressedSampleBuffers([this, weakThis = makeWeakPtr(this)]() mutable {
-        if (!weakThis)
-            return;
+            m_isStopping = false;
+            if (m_fetchDataCompletionHandler)
+                m_fetchDataCompletionHandler(WTFMove(buffer));
+            else
+                m_data = WTFMove(buffer);
 
-        [m_writer flush];
-        [m_writer finishWritingWithCompletionHandler:[this, weakThis = WTFMove(weakThis)]() mutable {
-            callOnMainThread([this, weakThis = WTFMove(weakThis)]() mutable {
-                if (!weakThis)
-                    return;
-
-                m_isStopping = false;
-                if (m_fetchDataCompletionHandler) {
-                    auto buffer = WTFMove(m_data);
-                    m_fetchDataCompletionHandler(WTFMove(buffer));
-                }
-
-                m_isStopped = false;
-                m_hasStartedWriting = false;
-                clear();
-            });
-        }];
-    });
+            m_isStopped = false;
+            m_hasStartedWriting = false;
+            m_isFirstAudioSample = true;
+            clear();
+        });
+        m_finishWritingSemaphore.signal();
+    }];
+    m_finishWritingSemaphore.wait();
 }
 
 void MediaRecorderPrivateWriter::fetchData(CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& completionHandler)
@@ -463,24 +392,6 @@ void MediaRecorderPrivateWriter::fetchData(CompletionHandler<void(RefPtr<SharedB
     completionHandler(WTFMove(buffer));
 }
 
-void MediaRecorderPrivateWriter::appendData(const char* data, size_t size)
-{
-    if (!m_data) {
-        m_data = SharedBuffer::create(data, size);
-        return;
-    }
-    m_data->append(data, size);
-}
-
-void MediaRecorderPrivateWriter::appendData(Ref<SharedBuffer>&& buffer)
-{
-    if (!m_data) {
-        m_data = WTFMove(buffer);
-        return;
-    }
-    m_data->append(WTFMove(buffer));
-}
-
 } // namespace WebCore
 
-#endif // ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.h b/Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.h
deleted file mode 100644 (file)
index 5e42893..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-#include <CoreMedia/CoreMedia.h>
-#include <VideoToolbox/VTErrors.h>
-
-typedef struct opaqueCMSampleBuffer *CMSampleBufferRef;
-typedef struct OpaqueVTCompressionSession *VTCompressionSessionRef;
-
-namespace WebCore {
-
-class VideoSampleBufferCompressor {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    static std::unique_ptr<VideoSampleBufferCompressor> create(CMVideoCodecType, CMBufferQueueTriggerCallback, void* callbackObject);
-    ~VideoSampleBufferCompressor();
-
-    void finish();
-    void addSampleBuffer(CMSampleBufferRef);
-    CMSampleBufferRef getOutputSampleBuffer();
-    RetainPtr<CMSampleBufferRef> takeOutputSampleBuffer();
-
-private:
-    explicit VideoSampleBufferCompressor(CMVideoCodecType);
-
-    bool initialize(CMBufferQueueTriggerCallback, void* callbackObject);
-
-    void processSampleBuffer(CMSampleBufferRef);
-    bool initCompressionSession(CMVideoFormatDescriptionRef);
-
-    static void videoCompressionCallback(void *refCon, void*, OSStatus, VTEncodeInfoFlags, CMSampleBufferRef);
-
-    dispatch_queue_t m_serialDispatchQueue;
-    RetainPtr<CMBufferQueueRef> m_outputBufferQueue;
-    RetainPtr<VTCompressionSessionRef> m_vtSession;
-
-    bool m_isEncoding { false };
-
-    CMVideoCodecType m_outputCodecType;
-    float m_maxKeyFrameIntervalDuration { 2.0 };
-    unsigned m_expectedFrameRate { 30 };
-};
-
-}
-
-#endif
diff --git a/Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.mm b/Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.mm
deleted file mode 100644 (file)
index b08fe43..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "VideoSampleBufferCompressor.h"
-
-#if ENABLE(MEDIA_STREAM) && USE(AVFOUNDATION)
-
-#import "Logging.h"
-#import <CoreMedia/CoreMedia.h>
-#import <Foundation/Foundation.h>
-#import <VideoToolbox/VTCompressionSession.h>
-#import <wtf/SoftLinking.h>
-
-#import <pal/cf/VideoToolboxSoftLink.h>
-
-using namespace PAL;
-
-namespace WebCore {
-
-std::unique_ptr<VideoSampleBufferCompressor> VideoSampleBufferCompressor::create(CMVideoCodecType outputCodecType, CMBufferQueueTriggerCallback callback, void* callbackObject)
-{
-    auto compressor = std::unique_ptr<VideoSampleBufferCompressor>(new VideoSampleBufferCompressor(outputCodecType));
-    if (!compressor->initialize(callback, callbackObject))
-        return nullptr;
-    return compressor;
-}
-
-VideoSampleBufferCompressor::VideoSampleBufferCompressor(CMVideoCodecType outputCodecType)
-    : m_serialDispatchQueue { dispatch_queue_create("com.apple.VideoSampleBufferCompressor", DISPATCH_QUEUE_SERIAL) }
-    , m_outputCodecType { outputCodecType }
-{
-}
-
-VideoSampleBufferCompressor::~VideoSampleBufferCompressor()
-{
-    if (m_serialDispatchQueue)
-        dispatch_release(m_serialDispatchQueue);
-}
-
-bool VideoSampleBufferCompressor::initialize(CMBufferQueueTriggerCallback callback, void* callbackObject)
-{
-    CMBufferQueueRef outputBufferQueue;
-    if (auto error = CMBufferQueueCreate(kCFAllocatorDefault, 0, CMBufferQueueGetCallbacksForUnsortedSampleBuffers(), &outputBufferQueue)) {
-        RELEASE_LOG_ERROR(MediaStream, "VideoSampleBufferCompressor unable to create buffer queue %d", error);
-        return false;
-    }
-    m_outputBufferQueue = outputBufferQueue;
-    CMBufferQueueInstallTrigger(m_outputBufferQueue.get(), callback, callbackObject, kCMBufferQueueTrigger_WhenDataBecomesReady, kCMTimeZero, NULL);
-
-    m_isEncoding = true;
-    return true;
-}
-
-void VideoSampleBufferCompressor::finish()
-{
-    dispatch_sync(m_serialDispatchQueue, ^{
-        auto error = VTCompressionSessionCompleteFrames(m_vtSession.get(), kCMTimeInvalid);
-        RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTCompressionSessionCompleteFrames failed with %d", error);
-
-        error = CMBufferQueueMarkEndOfData(m_outputBufferQueue.get());
-        RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor CMBufferQueueMarkEndOfData failed with %d", error);
-
-        m_isEncoding = false;
-    });
-}
-
-void VideoSampleBufferCompressor::videoCompressionCallback(void *refCon, void*, OSStatus status, VTEncodeInfoFlags, CMSampleBufferRef buffer)
-{
-    RELEASE_LOG_ERROR_IF(status, MediaStream, "VideoSampleBufferCompressor videoCompressionCallback status is %d", status);
-    if (status != noErr)
-        return;
-
-    VideoSampleBufferCompressor *compressor = static_cast<VideoSampleBufferCompressor*>(refCon);
-
-    auto error = CMBufferQueueEnqueue(compressor->m_outputBufferQueue.get(), buffer);
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor CMBufferQueueEnqueue failed with %d", error);
-}
-
-bool VideoSampleBufferCompressor::initCompressionSession(CMVideoFormatDescriptionRef formatDescription)
-{
-    CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
-#if PLATFORM(IOS)
-    NSDictionary *encoderSpecifications = nil;
-#else
-    NSDictionary *encoderSpecifications = @{(__bridge NSString *)kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder:@YES};
-#endif
-
-    VTCompressionSessionRef vtSession;
-    auto error = VTCompressionSessionCreate(kCFAllocatorDefault, dimensions.width, dimensions.height, m_outputCodecType, (__bridge CFDictionaryRef)encoderSpecifications, NULL, NULL, videoCompressionCallback, this, &vtSession);
-    if (error) {
-        RELEASE_LOG_ERROR(MediaStream, "VideoSampleBufferCompressor VTCompressionSessionCreate failed with %d", error);
-        return NO;
-    }
-    m_vtSession = adoptCF(vtSession);
-
-    error = VTSessionSetProperty(m_vtSession.get(), kVTCompressionPropertyKey_RealTime, kCFBooleanTrue);
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTSessionSetProperty kVTCompressionPropertyKey_RealTime failed with %d", error);
-    error = VTSessionSetProperty(m_vtSession.get(), kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, (__bridge CFTypeRef)@(m_maxKeyFrameIntervalDuration));
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTSessionSetProperty kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration failed with %d", error);
-    error = VTSessionSetProperty(m_vtSession.get(), kVTCompressionPropertyKey_ExpectedFrameRate, (__bridge CFTypeRef)@(m_expectedFrameRate));
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTSessionSetProperty kVTCompressionPropertyKey_ExpectedFrameRate failed with %d", error);
-
-    // FIXME: Set video compression rate.
-    error = VTCompressionSessionPrepareToEncodeFrames(m_vtSession.get());
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTCompressionSessionPrepareToEncodeFrames failed with %d", error);
-
-    return YES;
-}
-
-void VideoSampleBufferCompressor::processSampleBuffer(CMSampleBufferRef buffer)
-{
-    if (!m_vtSession) {
-        if (!initCompressionSession(CMSampleBufferGetFormatDescription(buffer)))
-            return;
-    }
-
-    auto imageBuffer = CMSampleBufferGetImageBuffer(buffer);
-    auto presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(buffer);
-    auto duration = CMSampleBufferGetDuration(buffer);
-    auto error = VTCompressionSessionEncodeFrame(m_vtSession.get(), imageBuffer, presentationTimeStamp, duration, NULL, this, NULL);
-    RELEASE_LOG_ERROR_IF(error, MediaStream, "VideoSampleBufferCompressor VTCompressionSessionEncodeFrame failed with %d", error);
-}
-
-void VideoSampleBufferCompressor::addSampleBuffer(CMSampleBufferRef buffer)
-{
-    dispatch_sync(m_serialDispatchQueue, ^{
-        if (!m_isEncoding)
-            return;
-
-        processSampleBuffer(buffer);
-    });
-}
-
-CMSampleBufferRef VideoSampleBufferCompressor::getOutputSampleBuffer()
-{
-    return (CMSampleBufferRef)(const_cast<void*>(CMBufferQueueGetHead(m_outputBufferQueue.get())));
-}
-
-RetainPtr<CMSampleBufferRef> VideoSampleBufferCompressor::takeOutputSampleBuffer()
-{
-    return adoptCF((CMSampleBufferRef)(const_cast<void*>(CMBufferQueueDequeueAndRetain(m_outputBufferQueue.get()))));
-}
-
-}
-#endif
index 536726a..11a8de7 100644 (file)
@@ -1,3 +1,24 @@
+2020-02-06  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r255910, r255970, and r255972.
+        https://bugs.webkit.org/show_bug.cgi?id=207345
+
+        Broke internal builds (Requested by ryanhaddad on #webkit).
+
+        Reverted changesets:
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255910
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255970
+
+        "[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder"
+        https://bugs.webkit.org/show_bug.cgi?id=206582
+        https://trac.webkit.org/changeset/255972
+
 2020-02-06  Patrick Griffis  <pgriffis@igalia.com>
 
         [GTK][WPE] Re-add flatpak sandbox support
index f310f48..a6cee54 100644 (file)
@@ -149,7 +149,6 @@ UserMediaCaptureManagerProxy& GPUConnectionToWebProcess::userMediaCaptureManager
     return *m_userMediaCaptureManagerProxy;
 }
 
-#if HAVE(AVASSETWRITERDELEGATE)
 RemoteMediaRecorderManager& GPUConnectionToWebProcess::mediaRecorderManager()
 {
     if (!m_remoteMediaRecorderManager)
@@ -157,7 +156,6 @@ RemoteMediaRecorderManager& GPUConnectionToWebProcess::mediaRecorderManager()
 
     return *m_remoteMediaRecorderManager;
 }
-#endif
 
 #if ENABLE(VIDEO_TRACK)
 RemoteAudioMediaStreamTrackRendererManager& GPUConnectionToWebProcess::audioTrackRendererManager()
@@ -176,7 +174,7 @@ RemoteSampleBufferDisplayLayerManager& GPUConnectionToWebProcess::sampleBufferDi
     return *m_sampleBufferDisplayLayerManager;
 }
 #endif
-#endif //  PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
+#endif
 
 #if PLATFORM(COCOA) && USE(LIBWEBRTC)
 LibWebRTCCodecsProxy& GPUConnectionToWebProcess::libWebRTCCodecsProxy()
@@ -205,7 +203,6 @@ void GPUConnectionToWebProcess::didReceiveMessage(IPC::Connection& connection, I
         userMediaCaptureManagerProxy().didReceiveMessageFromGPUProcess(connection, decoder);
         return;
     }
-#if HAVE(AVASSETWRITERDELEGATE)
     if (decoder.messageReceiverName() == Messages::RemoteMediaRecorderManager::messageReceiverName()) {
         mediaRecorderManager().didReceiveMessageFromWebProcess(connection, decoder);
         return;
@@ -214,7 +211,6 @@ void GPUConnectionToWebProcess::didReceiveMessage(IPC::Connection& connection, I
         mediaRecorderManager().didReceiveRemoteMediaRecorderMessage(connection, decoder);
         return;
     }
-#endif // HAVE(AVASSETWRITERDELEGATE)
 #if PLATFORM(COCOA) && ENABLE(VIDEO_TRACK)
     if (decoder.messageReceiverName() == Messages::RemoteAudioMediaStreamTrackRendererManager::messageReceiverName()) {
         audioTrackRendererManager().didReceiveMessageFromWebProcess(connection, decoder);
@@ -232,8 +228,8 @@ void GPUConnectionToWebProcess::didReceiveMessage(IPC::Connection& connection, I
         sampleBufferDisplayLayerManager().didReceiveLayerMessage(connection, decoder);
         return;
     }
-#endif // PLATFORM(COCOA) && ENABLE(VIDEO_TRACK)
-#endif // ENABLE(MEDIA_STREAM)
+#endif
+#endif
 #if PLATFORM(COCOA) && USE(LIBWEBRTC)
     if (decoder.messageReceiverName() == Messages::LibWebRTCCodecsProxy::messageReceiverName()) {
         libWebRTCCodecsProxy().didReceiveMessageFromWebProcess(connection, decoder);
index 78663bc..2b9bd1f 100644 (file)
@@ -79,9 +79,7 @@ private:
 #endif
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     UserMediaCaptureManagerProxy& userMediaCaptureManagerProxy();
-#if HAVE(AVASSETWRITERDELEGATE)
     RemoteMediaRecorderManager& mediaRecorderManager();
-#endif
 #if ENABLE(VIDEO_TRACK)
     RemoteAudioMediaStreamTrackRendererManager& audioTrackRendererManager();
     RemoteSampleBufferDisplayLayerManager& sampleBufferDisplayLayerManager();
@@ -104,9 +102,7 @@ private:
     PAL::SessionID m_sessionID;
 #if PLATFORM(COCOA) && ENABLE(MEDIA_STREAM)
     std::unique_ptr<UserMediaCaptureManagerProxy> m_userMediaCaptureManagerProxy;
-#if HAVE(AVASSETWRITERDELEGATE)
     std::unique_ptr<RemoteMediaRecorderManager> m_remoteMediaRecorderManager;
-#endif
 #if ENABLE(VIDEO_TRACK)
     std::unique_ptr<RemoteAudioMediaStreamTrackRendererManager> m_audioTrackRendererManager;
     std::unique_ptr<RemoteSampleBufferDisplayLayerManager> m_sampleBufferDisplayLayerManager;
index 568c280..cb24ddb 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "RemoteMediaRecorder.h"
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "SharedRingBufferStorage.h"
 #include <WebCore/CARingBuffer.h>
@@ -136,4 +136,4 @@ void RemoteMediaRecorder::stopRecording()
 
 }
 
-#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif
index a83da30..ff5a829 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "MediaRecorderIdentifier.h"
 #include "MessageReceiver.h"
@@ -82,4 +82,4 @@ private:
 
 }
 
-#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif
index ce32b70..54ba64d 100644 (file)
@@ -21,7 +21,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 messages -> RemoteMediaRecorder NotRefCounted {
     AudioSamplesStorageChanged(WebKit::SharedMemory::Handle storageHandle, WebCore::CAAudioStreamDescription description, uint64_t numberOfFrames)
index 019e4b8..370cd9b 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "RemoteMediaRecorderManager.h"
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "DataReference.h"
 #include "Decoder.h"
index ab801bc..5471bbd 100644 (file)
@@ -27,7 +27,7 @@
 
 #pragma once
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "MediaRecorderIdentifier.h"
 #include "MessageReceiver.h"
index c518410..387a413 100644 (file)
@@ -21,7 +21,7 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 # THE POSSIBILITY OF SUCH DAMAGE.
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 messages -> RemoteMediaRecorderManager NotRefCounted {
     CreateRecorder(WebKit::MediaRecorderIdentifier id, bool hasAudio, int width, int height) -> (Optional<WebCore::ExceptionData> creationError) Async
index e38c5d6..9f9b30c 100644 (file)
@@ -30,7 +30,6 @@
 #include "MessageReceiver.h"
 #include "RemoteSampleBufferDisplayLayerManagerMessagesReplies.h"
 #include "SampleBufferDisplayLayerIdentifier.h"
-#include <WebCore/IntSize.h>
 #include <wtf/HashMap.h>
 
 namespace IPC {
index 67e3ee6..dd40919 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "MediaRecorderPrivate.h"
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "GPUProcessConnection.h"
 #include "RemoteMediaRecorderManagerMessages.h"
@@ -146,4 +146,4 @@ void MediaRecorderPrivate::stopRecording()
 
 }
 
-#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
index d80fcd7..6d9fabe 100644 (file)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#if PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
 #include "MediaRecorderIdentifier.h"
 #include "SharedRingBufferStorage.h"
@@ -73,5 +73,5 @@ private:
 
 }
 
-#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM) && HAVE(AVASSETWRITERDELEGATE)
+#endif // PLATFORM(COCOA) && ENABLE(GPU_PROCESS) && ENABLE(MEDIA_STREAM)
 
index d959c92..bce774a 100644 (file)
@@ -37,7 +37,7 @@ namespace WebKit {
 
 std::unique_ptr<WebCore::MediaRecorderPrivate> MediaRecorderProvider::createMediaRecorderPrivate(const MediaStreamPrivate& stream)
 {
-#if ENABLE(GPU_PROCESS) && HAVE(AVASSETWRITERDELEGATE)
+#if ENABLE(GPU_PROCESS)
     if (m_useGPUProcess)
         return makeUnique<MediaRecorderPrivate>(stream);
 #endif