Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[iOS] Transcode videos selected from UIImagePickerController
https://bugs.webkit.org/show_bug.cgi?id=230639 rdar://79665678 Reviewed by Tim Horton. Source/WebCore: * en.lproj/Localizable.strings: Add a localizable string for the message displayed while transcoding video. Source/WebCore/PAL: Add AVFoundation API needed to transcode video. * pal/cocoa/AVFoundationSoftLink.h: * pal/cocoa/AVFoundationSoftLink.mm: Source/WebKit: File inputs on iOS allow users to choose images/videos from the system photo picker, using UIImagePickerController. In single selection mode, UIImagePickerController transcodes the selected video to H.264. However, in multiple selection mode, video is not transcoded and is left in its original format. Today, videos on most iOS devices are encoded with HEVC by default. However, some sites, such as Twitter, only accept H.264 encoded video. Thus, the current video upload behavior is problematic, as users may be unable to upload video. Unfortunately, the photo picking functionality of UIImagePickerController is deprecated. The best solution would be to adopt PHPickerViewController, the replacement API, which performs transcoding when retrieving selected items (regardless of single/multiple selection). However, PHPickerViewController currently lacks other functionality that WebKit requires, preventing adoption. Consequently, the short term solution is to transcode the videos in WebKit, ensuring H.264 encoded video is always provided to sites. See below for implementation details. * Platform/spi/ios/PhotosUISPI.h: Added. * UIProcess/ios/forms/WKFileUploadPanel.mm: (-[_WKFileUploadItem setFileURL:]): Add a setter to update the file URL. Called after transcoding a _WKFileUploadItem. (-[WKFileUploadMediaTranscoder initWithItems:videoCount:completionHandler:]): Introduce WKFileUploadMediaTranscoder to manage transcoding of videos and the display of progress UI. Transcoding is performed serially (one video at a time), but occurs off the main thread. (-[WKFileUploadMediaTranscoder start]): Begin transcoding. Run a timer to update the progress UI, as AVAssetExportSession does not provide progress updates on its own. The progress UI is implemented using PUActivityProgressController, to match system Photos UI. (-[WKFileUploadMediaTranscoder _processItemAtIndex:]): Transcode a single video, using AVAssetExportSession. If transcoding fails for any reason, the original video is used as a fallback. Transcoding can also be cancelled using the progress UI, in which case no more videos are processed. (-[WKFileUploadMediaTranscoder _finishedProcessing]): (-[WKFileUploadMediaTranscoder _dismissProgress]): (-[WKFileUploadMediaTranscoder _updateProgress:]): (-[WKFileUploadMediaTranscoder _temporaryDirectoryCreateIfNecessary]): (-[WKFileUploadPanel _chooseMediaItems:]): Refactor the common aspects of single/multiple media selection into a single method. (-[WKFileUploadPanel imagePickerController:didFinishPickingMediaWithInfo:]): (-[WKFileUploadPanel imagePickerController:didFinishPickingMultipleMediaWithInfo:]): (-[WKFileUploadPanel _processMediaInfoDictionaries:successBlock:failureBlock:]): (-[WKFileUploadPanel _processMediaInfoDictionaries:atIndex:processedResults:successBlock:failureBlock:]): (-[WKFileUploadPanel _uploadItemFromMediaInfo:successBlock:failureBlock:]): Remove redundant platform conditional. (-[WKFileUploadPanel _uploadMediaItemsTranscodingVideo:]): If any videos were selected, transcode them prior to uploading. * WebKit.xcodeproj/project.pbxproj: Canonical link: https://commits.webkit.org/242548@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283592 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
9 changed files
with
404 additions
and
38 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) 2021 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. | ||
*/ | ||
|
||
#if USE(APPLE_INTERNAL_SDK) | ||
|
||
#import <PhotosUI/PUActivityProgressController.h> | ||
|
||
#else | ||
|
||
#import "UIKitSPI.h" | ||
|
||
@interface PUActivityProgressController : NSObject | ||
|
||
@property (nonatomic, copy) NSString *title; | ||
|
||
@property (nonatomic, copy) void (^cancellationHandler)(void); | ||
|
||
@property (nonatomic, readonly) BOOL isCancelled; | ||
|
||
- (void)setFractionCompleted:(double)fractionCompleted; | ||
|
||
- (void)showAnimated:(BOOL)animated allowDelay:(BOOL)allowDelay; | ||
- (void)hideAnimated:(BOOL)animated allowDelay:(BOOL)allowDelay; | ||
|
||
@end | ||
|
||
#endif // USE(APPLE_INTERNAL_SDK) |
Oops, something went wrong.