Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[Cocoa] Use AVAssetWriterDelegate to implement MediaRecorder
https://bugs.webkit.org/show_bug.cgi?id=206582 Reviewed by Eric Carlson. Source/WebCore: AVAssetWriterDelegate allows to grab recorded data whenever wanted. This delegate requires passing compressed samples to AVAssetWriter. Implement video encoding and audio encoding in dedicated classes and use these classes before adding buffers to AVAssetWriter. Since AVAssetWriterDelegate is Apple SDK only, keep the existing file based implementation as a fallback. Covered by existing tests. * platform/mediarecorder/cocoa/AudioSampleBufferCompressor.h: * platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm: (WebCore::AudioSampleBufferCompressor::create): (WebCore::AudioSampleBufferCompressor::AudioSampleBufferCompressor): (WebCore::AudioSampleBufferCompressor::~AudioSampleBufferCompressor): (WebCore::AudioSampleBufferCompressor::initialize): (WebCore::AudioSampleBufferCompressor::finish): (WebCore::AudioSampleBufferCompressor::audioConverterComplexInputDataProc): (WebCore::AudioSampleBufferCompressor::initAudioConverterForSourceFormatDescription): (WebCore::AudioSampleBufferCompressor::computeBufferSizeForAudioFormat): (WebCore::AudioSampleBufferCompressor::attachPrimingTrimsIfNeeded): (WebCore::AudioSampleBufferCompressor::gradualDecoderRefreshCount): (WebCore::AudioSampleBufferCompressor::sampleBufferWithNumPackets): (WebCore::AudioSampleBufferCompressor::processSampleBuffersUntilLowWaterTime): (WebCore::AudioSampleBufferCompressor::provideSourceDataNumOutputPackets): (WebCore::AudioSampleBufferCompressor::processSampleBuffer): (WebCore::AudioSampleBufferCompressor::addSampleBuffer): (WebCore::AudioSampleBufferCompressor::getOutputSampleBuffer): (WebCore::AudioSampleBufferCompressor::takeOutputSampleBuffer): * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h: * platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm: (WebCore::MediaRecorderPrivateWriter::create): (WebCore::MediaRecorderPrivateWriter::MediaRecorderPrivateWriter): (WebCore::MediaRecorderPrivateWriter::initialize): (WebCore::MediaRecorderPrivateWriter::processNewCompressedVideoSampleBuffers): (WebCore::MediaRecorderPrivateWriter::processNewCompressedAudioSampleBuffers): (WebCore::MediaRecorderPrivateWriter::appendCompressedAudioSampleBuffer): (WebCore::MediaRecorderPrivateWriter::appendCompressedVideoSampleBuffer): (WebCore::MediaRecorderPrivateWriter::appendVideoSampleBuffer): (WebCore::MediaRecorderPrivateWriter::appendAudioSampleBuffer): (WebCore::MediaRecorderPrivateWriter::stopRecording): * platform/mediarecorder/cocoa/VideoSampleBufferCompressor.h: * platform/mediarecorder/cocoa/VideoSampleBufferCompressor.mm: (WebCore::VideoSampleBufferCompressor::create): (WebCore::VideoSampleBufferCompressor::VideoSampleBufferCompressor): (WebCore::VideoSampleBufferCompressor::~VideoSampleBufferCompressor): (WebCore::VideoSampleBufferCompressor::initialize): (WebCore::VideoSampleBufferCompressor::finish): (WebCore::VideoSampleBufferCompressor::videoCompressionCallback): (WebCore::VideoSampleBufferCompressor::initCompressionSession): (WebCore::VideoSampleBufferCompressor::processSampleBuffer): (WebCore::VideoSampleBufferCompressor::addSampleBuffer): (WebCore::VideoSampleBufferCompressor::getOutputSampleBuffer): (WebCore::VideoSampleBufferCompressor::takeOutputSampleBuffer): Source/WebCore/PAL: Add soft link macros for VideoToolbox and AudioToolbox. * PAL.xcodeproj/project.pbxproj: * pal/cf/AudioToolboxSoftLink.cpp: Added. * pal/cf/AudioToolboxSoftLink.h: Added. * pal/cf/CoreMediaSoftLink.cpp: * pal/cf/CoreMediaSoftLink.h: * pal/cf/VideoToolboxSoftLink.cpp: Added. * pal/cf/VideoToolboxSoftLink.h: Added. Source/WebKit: * GPUProcess/webrtc/RemoteMediaRecorder.cpp: (WebKit::RemoteMediaRecorder::create): Use new constructor. LayoutTests: * http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable-gpuprocess.html: Remove web audio generation since there seems to be some unstability in web audio -> stream -> media recorder. which should be fixed as follow-up specific patches. Canonical link: https://commits.webkit.org/220010@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255424 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
1,933 additions
and 255 deletions.
- +11 −0 LayoutTests/ChangeLog
- +0 −10 LayoutTests/http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable-gpuprocess.html
- +59 −0 Source/WebCore/ChangeLog
- +17 −0 Source/WebCore/PAL/ChangeLog
- +16 −0 Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
- +41 −0 Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.cpp
- +43 −0 Source/WebCore/PAL/pal/cf/AudioToolboxSoftLink.h
- +5 −0 Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp
- +9 −0 Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h
- +40 −0 Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.cpp
- +42 −0 Source/WebCore/PAL/pal/cf/VideoToolboxSoftLink.h
- +14 −0 Source/WebCore/WebCore.xcodeproj/project.pbxproj
- +1 −0 Source/WebCore/platform/graphics/cv/ImageTransferSessionVT.mm
- +9 −1 Source/WebCore/platform/mediarecorder/MediaRecorderPrivateAVFImpl.cpp
- +91 −0 Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.h
- +498 −0 Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm
- +67 −11 Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.h
- +338 −233 Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoa.mm
- +383 −0 Source/WebCore/platform/mediarecorder/cocoa/MediaRecorderPrivateWriterCocoaFileBased.mm
- +71 −0 Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.h
- +167 −0 Source/WebCore/platform/mediarecorder/cocoa/VideoSampleBufferCompressor.mm
- +11 −0 Source/WebKit/ChangeLog
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -56,17 +56,7 @@ | ||
} | ||
|
||
async_test(t => { | ||
const video = createVideoStream(); | ||
const recorder = new MediaRecorder(video); | ||
let mode = 0; | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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) |
Oops, something went wrong.