Changeset 246611 in webkit
- Timestamp:
- Jun 19, 2019 2:33:35 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r246604 r246611 1 2019-06-19 Jer Noble <jer.noble@apple.com> 2 3 iOS 12.2 Drawing portrait video to canvas is sideways 4 https://bugs.webkit.org/show_bug.cgi?id=196772 5 <rdar://problem/49781802> 6 7 Reviewed by Eric Carlson. 8 9 * media/content/no-rotation.mp4: 10 * media/media-source/only-bcp47-language-tags-accepted-as-valid-expected.txt: 11 * media/video-orientation-canvas-expected.html: Added. 12 * media/video-orientation-canvas.html: Added. 13 * media/video-test.js: 14 (waitFor): 15 1 16 2019-06-19 Alicia Boya García <aboya@igalia.com> 2 17 -
trunk/LayoutTests/media/media-source/only-bcp47-language-tags-accepted-as-valid-expected.txt
r231817 r246611 1 CONSOLE MESSAGE: line 22 1: The language 'a' is not a valid BCP 47 language tag.1 CONSOLE MESSAGE: line 222: The language 'a' is not a valid BCP 47 language tag. 2 2 CONSOLE MESSAGE: line 106: The language 'a' is not a valid BCP 47 language tag. 3 CONSOLE MESSAGE: line 22 1: The language 'a' is not a valid BCP 47 language tag.4 CONSOLE MESSAGE: line 22 1: The language '1' is not a valid BCP 47 language tag.3 CONSOLE MESSAGE: line 222: The language 'a' is not a valid BCP 47 language tag. 4 CONSOLE MESSAGE: line 222: The language '1' is not a valid BCP 47 language tag. 5 5 CONSOLE MESSAGE: line 106: The language '1' is not a valid BCP 47 language tag. 6 CONSOLE MESSAGE: line 22 1: The language '1' is not a valid BCP 47 language tag.7 CONSOLE MESSAGE: line 22 1: The language 'ab-abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij' is not a valid BCP 47 language tag.6 CONSOLE MESSAGE: line 222: The language '1' is not a valid BCP 47 language tag. 7 CONSOLE MESSAGE: line 222: The language 'ab-abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij' is not a valid BCP 47 language tag. 8 8 CONSOLE MESSAGE: line 106: The language 'ab-abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij' is not a valid BCP 47 language tag. 9 CONSOLE MESSAGE: line 22 1: The language 'ab-abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij' is not a valid BCP 47 language tag.10 CONSOLE MESSAGE: line 22 1: The language '1a' is not a valid BCP 47 language tag.9 CONSOLE MESSAGE: line 222: The language 'ab-abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij' is not a valid BCP 47 language tag. 10 CONSOLE MESSAGE: line 222: The language '1a' is not a valid BCP 47 language tag. 11 11 CONSOLE MESSAGE: line 106: The language '1a' is not a valid BCP 47 language tag. 12 CONSOLE MESSAGE: line 22 1: The language '1a' is not a valid BCP 47 language tag.13 CONSOLE MESSAGE: line 22 1: The language '-a' is not a valid BCP 47 language tag.12 CONSOLE MESSAGE: line 222: The language '1a' is not a valid BCP 47 language tag. 13 CONSOLE MESSAGE: line 222: The language '-a' is not a valid BCP 47 language tag. 14 14 CONSOLE MESSAGE: line 106: The language '-a' is not a valid BCP 47 language tag. 15 CONSOLE MESSAGE: line 22 1: The language '-a' is not a valid BCP 47 language tag.16 CONSOLE MESSAGE: line 22 1: The language 'a-' is not a valid BCP 47 language tag.15 CONSOLE MESSAGE: line 222: The language '-a' is not a valid BCP 47 language tag. 16 CONSOLE MESSAGE: line 222: The language 'a-' is not a valid BCP 47 language tag. 17 17 CONSOLE MESSAGE: line 106: The language 'a-' is not a valid BCP 47 language tag. 18 CONSOLE MESSAGE: line 22 1: The language 'a-' is not a valid BCP 47 language tag.19 CONSOLE MESSAGE: line 22 1: The language 'a1' is not a valid BCP 47 language tag.18 CONSOLE MESSAGE: line 222: The language 'a-' is not a valid BCP 47 language tag. 19 CONSOLE MESSAGE: line 222: The language 'a1' is not a valid BCP 47 language tag. 20 20 CONSOLE MESSAGE: line 106: The language 'a1' is not a valid BCP 47 language tag. 21 CONSOLE MESSAGE: line 22 1: The language 'a1' is not a valid BCP 47 language tag.22 CONSOLE MESSAGE: line 22 1: The language 'aa1' is not a valid BCP 47 language tag.21 CONSOLE MESSAGE: line 222: The language 'a1' is not a valid BCP 47 language tag. 22 CONSOLE MESSAGE: line 222: The language 'aa1' is not a valid BCP 47 language tag. 23 23 CONSOLE MESSAGE: line 106: The language 'aa1' is not a valid BCP 47 language tag. 24 CONSOLE MESSAGE: line 22 1: The language 'aa1' is not a valid BCP 47 language tag.25 CONSOLE MESSAGE: line 22 1: The language 'aaaa' is not a valid BCP 47 language tag.24 CONSOLE MESSAGE: line 222: The language 'aa1' is not a valid BCP 47 language tag. 25 CONSOLE MESSAGE: line 222: The language 'aaaa' is not a valid BCP 47 language tag. 26 26 CONSOLE MESSAGE: line 106: The language 'aaaa' is not a valid BCP 47 language tag. 27 CONSOLE MESSAGE: line 22 1: The language 'aaaa' is not a valid BCP 47 language tag.28 CONSOLE MESSAGE: line 22 1: The language 'aaa1' is not a valid BCP 47 language tag.27 CONSOLE MESSAGE: line 222: The language 'aaaa' is not a valid BCP 47 language tag. 28 CONSOLE MESSAGE: line 222: The language 'aaa1' is not a valid BCP 47 language tag. 29 29 CONSOLE MESSAGE: line 106: The language 'aaa1' is not a valid BCP 47 language tag. 30 CONSOLE MESSAGE: line 22 1: The language 'aaa1' is not a valid BCP 47 language tag.31 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char space' is not a valid BCP 47 language tag.30 CONSOLE MESSAGE: line 222: The language 'aaa1' is not a valid BCP 47 language tag. 31 CONSOLE MESSAGE: line 222: The language 'inv-alid-char space' is not a valid BCP 47 language tag. 32 32 CONSOLE MESSAGE: line 106: The language 'inv-alid-char space' is not a valid BCP 47 language tag. 33 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char space' is not a valid BCP 47 language tag.34 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char–longDash' is not a valid BCP 47 language tag.33 CONSOLE MESSAGE: line 222: The language 'inv-alid-char space' is not a valid BCP 47 language tag. 34 CONSOLE MESSAGE: line 222: The language 'inv-alid-char–longDash' is not a valid BCP 47 language tag. 35 35 CONSOLE MESSAGE: line 106: The language 'inv-alid-char–longDash' is not a valid BCP 47 language tag. 36 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char–longDash' is not a valid BCP 47 language tag.37 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-Pålska' is not a valid BCP 47 language tag.36 CONSOLE MESSAGE: line 222: The language 'inv-alid-char–longDash' is not a valid BCP 47 language tag. 37 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-Pålska' is not a valid BCP 47 language tag. 38 38 CONSOLE MESSAGE: line 106: The language 'inv-alid-char-Pålska' is not a valid BCP 47 language tag. 39 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-Pålska' is not a valid BCP 47 language tag.40 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-*' is not a valid BCP 47 language tag.39 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-Pålska' is not a valid BCP 47 language tag. 40 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-*' is not a valid BCP 47 language tag. 41 41 CONSOLE MESSAGE: line 106: The language 'inv-alid-char-*' is not a valid BCP 47 language tag. 42 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-*' is not a valid BCP 47 language tag.43 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-' is not a valid BCP 47 language tag.42 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-*' is not a valid BCP 47 language tag. 43 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-' is not a valid BCP 47 language tag. 44 44 CONSOLE MESSAGE: line 106: The language 'inv-alid-char-' is not a valid BCP 47 language tag. 45 CONSOLE MESSAGE: line 22 1: The language 'inv-alid-char-' is not a valid BCP 47 language tag.45 CONSOLE MESSAGE: line 222: The language 'inv-alid-char-' is not a valid BCP 47 language tag. 46 46 Test that only BCP47 language tags are accepted as valid but still reflected. 47 47 -
trunk/LayoutTests/media/video-test.js
r236531 r246611 187 187 } 188 188 189 function waitFor(element, type ) {189 function waitFor(element, type, silent) { 190 190 return new Promise(resolve => { 191 191 element.addEventListener(type, event => { 192 consoleWrite(`EVENT(${event.type})`); 192 if (!silent) 193 consoleWrite(`EVENT(${event.type})`); 193 194 resolve(event); 194 195 }, { once: true }); -
trunk/Source/WebCore/ChangeLog
r246596 r246611 1 2019-06-19 Jer Noble <jer.noble@apple.com> 2 3 iOS 12.2 Drawing portrait video to canvas is sideways 4 https://bugs.webkit.org/show_bug.cgi?id=196772 5 <rdar://problem/49781802> 6 7 Reviewed by Eric Carlson. 8 9 Test: media/video-orientation-canvas.html 10 11 Move rotation code into its own ImageRotationSessionVT class for re-use across 12 all existing classes with rotation operations. Should slightly increase performance 13 for painting rotated media files, as the rotation only occurs once per frame, rather 14 than once per drawing operation. 15 16 * WebCore.xcodeproj/project.pbxproj: 17 * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h: 18 (WebCore::ImageDecoderAVFObjC::RotationProperties::isIdentity const): Deleted. 19 * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm: 20 (WebCore::ImageDecoderAVFObjC::readTrackMetadata): 21 (WebCore::ImageDecoderAVFObjC::storeSampleBuffer): 22 (WebCore::ImageDecoderAVFObjC::setTrack): 23 (WebCore::transformToRotationProperties): Deleted. 24 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: 25 * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: 26 (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): 27 (WebCore::MediaPlayerPrivateAVFoundationObjC::updateLastPixelBuffer): 28 (WebCore::MediaPlayerPrivateAVFoundationObjC::paintWithVideoOutput): 29 * platform/graphics/cv/ImageRotationSessionVT.h: Added. 30 (WebCore::ImageRotationSessionVT::RotationProperties::isIdentity const): 31 (WebCore::ImageRotationSessionVT::rotationProperties const): 32 (WebCore::ImageRotationSessionVT::rotatedSize): 33 * platform/graphics/cv/ImageRotationSessionVT.mm: Added. 34 (WebCore::transformToRotationProperties): 35 (WebCore::ImageRotationSessionVT::ImageRotationSessionVT): 36 (WebCore::ImageRotationSessionVT::rotate): 37 * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp: 38 * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h: 39 * platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm: 40 (WebCore::rotationToAngle): 41 (WebCore::RealtimeOutgoingVideoSourceCocoa::rotatePixelBuffer): 42 (WebCore::computeRotatedWidthAndHeight): Deleted. 43 1 44 2019-06-19 Adrian Perez de Castro <aperez@igalia.com> 2 45 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r246554 r246611 4027 4027 CD225C0B1C46FBF400140761 /* WebCoreNSURLSession.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD225C091C46FBF400140761 /* WebCoreNSURLSession.mm */; }; 4028 4028 CD225C0C1C46FBF400140761 /* WebCoreNSURLSession.h in Headers */ = {isa = PBXBuildFile; fileRef = CD225C0A1C46FBF400140761 /* WebCoreNSURLSession.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4029 CD27AE5022A9868700947FF9 /* ImageRotationSessionVT.h in Headers */ = {isa = PBXBuildFile; fileRef = CD27AE4E22A9868700947FF9 /* ImageRotationSessionVT.h */; }; 4030 CD27AE5122A9868700947FF9 /* ImageRotationSessionVT.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD27AE4F22A9868700947FF9 /* ImageRotationSessionVT.mm */; }; 4029 4031 CD2F4A2418D89F700063746D /* AudioHardwareListener.h in Headers */ = {isa = PBXBuildFile; fileRef = CD2F4A2218D89F700063746D /* AudioHardwareListener.h */; settings = {ATTRIBUTES = (Private, ); }; }; 4030 4032 CD2F4A2818D8A3490063746D /* AudioHardwareListenerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = CD2F4A2618D8A3490063746D /* AudioHardwareListenerMac.h */; }; … … 13512 13514 CD225C091C46FBF400140761 /* WebCoreNSURLSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSURLSession.mm; sourceTree = "<group>"; }; 13513 13515 CD225C0A1C46FBF400140761 /* WebCoreNSURLSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreNSURLSession.h; sourceTree = "<group>"; }; 13516 CD27AE4E22A9868700947FF9 /* ImageRotationSessionVT.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageRotationSessionVT.h; sourceTree = "<group>"; }; 13517 CD27AE4F22A9868700947FF9 /* ImageRotationSessionVT.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ImageRotationSessionVT.mm; sourceTree = "<group>"; }; 13514 13518 CD27F6E014575C1B0078207D /* MediaController.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = MediaController.idl; sourceTree = "<group>"; }; 13515 13519 CD27F6E2145767580078207D /* JSMediaController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMediaController.cpp; sourceTree = "<group>"; }; … … 25670 25674 isa = PBXGroup; 25671 25675 children = ( 25676 CD27AE4E22A9868700947FF9 /* ImageRotationSessionVT.h */, 25677 CD27AE4F22A9868700947FF9 /* ImageRotationSessionVT.mm */, 25672 25678 0746D30C2146EA38003DDF84 /* ImageTransferSessionVT.h */, 25673 25679 0746D30A2146EA37003DDF84 /* ImageTransferSessionVT.mm */, … … 29509 29515 B51A2F3F17D7D3AE0072517A /* ImageQualityController.h in Headers */, 29510 29516 49291E4B134172C800E753DE /* ImageRenderingMode.h in Headers */, 29517 CD27AE5022A9868700947FF9 /* ImageRotationSessionVT.h in Headers */, 29511 29518 7C193BC11F5E0EED0088F3E6 /* ImageSmoothingQuality.h in Headers */, 29512 29519 5546757B1FD212A9003B10B0 /* ImageSource.h in Headers */, … … 32763 32770 1AC900C31943C0FC008625B5 /* HTTPHeaderNames.cpp in Sources */, 32764 32771 CD19FEAF1F574B6D000C42FB /* ImageDecoderAVFObjC.mm in Sources */, 32772 CD27AE5122A9868700947FF9 /* ImageRotationSessionVT.mm in Sources */, 32765 32773 BE961C5418AD338500D07DC5 /* InbandDataTextTrack.cpp in Sources */, 32766 32774 BE16C59217CFE17200852C04 /* InbandGenericTextTrack.cpp in Sources */, -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h
r239636 r246611 39 39 OBJC_CLASS WebCoreSharedBufferResourceLoaderDelegate; 40 40 typedef struct opaqueCMSampleBuffer* CMSampleBufferRef; 41 typedef struct OpaqueVTImageRotationSession* VTImageRotationSessionRef;42 typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef;43 41 44 42 namespace WTF { … … 50 48 class ContentType; 51 49 class ImageDecoderAVFObjCSample; 50 class ImageRotationSessionVT; 52 51 class PixelBufferConformerCV; 53 52 class WebCoreDecompressionSession; … … 91 90 void clearFrameBufferCache(size_t) final; 92 91 93 struct RotationProperties {94 bool flipX { false };95 bool flipY { false };96 unsigned angle { 0 };97 98 bool isIdentity() const { return !flipX && !flipY && !angle; }99 };100 101 92 private: 102 93 ImageDecoderAVFObjC(SharedBuffer&, const String& mimeType, AlphaOption, GammaAndColorProfileOption); … … 117 108 RetainPtr<AVAssetTrack> m_track; 118 109 RetainPtr<WebCoreSharedBufferResourceLoaderDelegate> m_loader; 119 RetainPtr<VTImageRotationSessionRef> m_rotationSession; 120 RetainPtr<CVPixelBufferPoolRef> m_rotationPool; 110 std::unique_ptr<ImageRotationSessionVT> m_imageRotationSession; 121 111 Ref<WebCoreDecompressionSession> m_decompressionSession; 122 112 WTF::Function<void(EncodedDataStatus)> m_encodedDataStatusChangedCallback; … … 127 117 bool m_isAllDataReceived { false }; 128 118 Optional<IntSize> m_size; 129 Optional<RotationProperties> m_rotation;130 119 }; 131 120 -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm
r244980 r246611 35 35 #import "FloatRect.h" 36 36 #import "FloatSize.h" 37 #import "ImageRotationSessionVT.h" 37 38 #import "Logging.h" 38 39 #import "MIMETypeRegistry.h" … … 234 235 } 235 236 236 static ImageDecoderAVFObjC::RotationProperties transformToRotationProperties(AffineTransform inTransform)237 {238 ImageDecoderAVFObjC::RotationProperties rotation;239 if (inTransform.isIdentity())240 return rotation;241 242 AffineTransform::DecomposedType decomposed { };243 if (!inTransform.decompose(decomposed))244 return rotation;245 246 rotation.flipY = WTF::areEssentiallyEqual(decomposed.scaleX, -1.);247 rotation.flipX = WTF::areEssentiallyEqual(decomposed.scaleY, -1.);248 auto degrees = rad2deg(decomposed.angle);249 while (degrees < 0)250 degrees += 360;251 252 // Only support rotation in multiples of 90º:253 if (WTF::areEssentiallyEqual(fmod(degrees, 90.), 0.))254 rotation.angle = clampToUnsigned(degrees);255 256 return rotation;257 }258 259 237 class ImageDecoderAVFObjCSample : public MediaSampleAVFObjC { 260 238 public: … … 423 401 void ImageDecoderAVFObjC::readTrackMetadata() 424 402 { 425 if (!m_rotation) 426 m_rotation = transformToRotationProperties(CGAffineTransformConcat(m_asset.get().preferredTransform, m_track.get().preferredTransform)); 427 428 if (!m_size) { 429 auto size = FloatSize(m_track.get().naturalSize); 430 auto angle = m_rotation.value().angle; 431 if (angle == 90 || angle == 270) 432 size = size.transposedSize(); 433 434 m_size = expandedIntSize(size); 435 } 403 AffineTransform finalTransform = CGAffineTransformConcat(m_asset.get().preferredTransform, m_track.get().preferredTransform); 404 auto size = expandedIntSize(FloatSize(m_track.get().naturalSize)); 405 if (finalTransform.isIdentity()) { 406 m_size = size; 407 m_imageRotationSession = nullptr; 408 return; 409 } 410 411 if (!m_imageRotationSession 412 || !m_imageRotationSession->transform() 413 || m_imageRotationSession->transform().value() != finalTransform 414 || m_imageRotationSession->size() != size) 415 m_imageRotationSession = std::make_unique<ImageRotationSessionVT>(WTFMove(finalTransform), size, kCVPixelFormatType_32BGRA, ImageRotationSessionVT::IsCGImageCompatible::Yes); 416 417 m_size = expandedIntSize(m_imageRotationSession->rotatedSize()); 436 418 } 437 419 … … 447 429 auto iter = m_sampleData.presentationOrder().findSampleWithPresentationTime(presentationTime); 448 430 449 if (m_rotation && !m_rotation.value().isIdentity()) { 450 auto& rotation = m_rotation.value(); 451 if (!m_rotationSession) { 452 VTImageRotationSessionRef rawRotationSession = nullptr; 453 VTImageRotationSessionCreate(kCFAllocatorDefault, rotation.angle, &rawRotationSession); 454 m_rotationSession = rawRotationSession; 455 VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_EnableHighSpeedTransfer, kCFBooleanTrue); 456 457 if (rotation.flipY) 458 VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipVerticalOrientation, kCFBooleanTrue); 459 if (rotation.flipX) 460 VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipHorizontalOrientation, kCFBooleanTrue); 461 } 462 463 if (!m_rotationPool) { 464 auto pixelAttributes = @{ 465 (__bridge NSString *)kCVPixelBufferWidthKey: @(m_size.value().width()), 466 (__bridge NSString *)kCVPixelBufferHeightKey: @(m_size.value().height()), 467 (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA), 468 (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @YES, 469 }; 470 CVPixelBufferPoolRef rawPool = nullptr; 471 CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); 472 m_rotationPool = adoptCF(rawPool); 473 } 474 475 CVPixelBufferRef rawRotatedBuffer = nullptr; 476 CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer); 477 auto status = VTImageRotationSessionTransferImage(m_rotationSession.get(), pixelBuffer.get(), rawRotatedBuffer); 478 if (status == noErr) 479 pixelBuffer = adoptCF(rawRotatedBuffer); 480 } 431 if (m_imageRotationSession) 432 pixelBuffer = m_imageRotationSession->rotate(pixelBuffer.get()); 481 433 482 434 CGImageRef rawImage = nullptr; … … 507 459 m_sampleData.clear(); 508 460 m_size.reset(); 509 m_rotation.reset();510 461 m_cursor = m_sampleData.decodeOrder().end(); 511 m_ rotationSession = nullptr;462 m_imageRotationSession = nullptr; 512 463 513 464 [track loadValuesAsynchronouslyForKeys:@[@"naturalSize", @"preferredTransform"] completionHandler:[protectedThis = makeRefPtr(this)] () mutable { -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
r245868 r246611 59 59 class CDMInstanceFairPlayStreamingAVFObjC; 60 60 class CDMSessionAVFoundationObjC; 61 class ImageRotationSessionVT; 61 62 class InbandMetadataTextTrackPrivateAVF; 62 63 class MediaSelectionGroupAVFObjC; … … 326 327 327 328 void setShouldDisableSleep(bool) override; 329 void updateRotationSession(); 328 330 329 331 Optional<VideoPlaybackQualityMetrics> videoPlaybackQualityMetrics() final; … … 361 363 RetainPtr<CGImageRef> m_lastImage; 362 364 BinarySemaphore m_videoOutputSemaphore; 365 std::unique_ptr<ImageRotationSessionVT> m_imageRotationSession; 363 366 std::unique_ptr<VideoTextureCopierCV> m_videoTextureCopier; 364 367 #endif -
trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
r246490 r246611 44 44 #import "GraphicsContext3D.h" 45 45 #import "GraphicsContextCG.h" 46 #import "ImageRotationSessionVT.h" 46 47 #import "InbandMetadataTextTrackPrivateAVF.h" 47 48 #import "InbandTextTrackPrivateAVFObjC.h" … … 1864 1865 } 1865 1866 1867 void MediaPlayerPrivateAVFoundationObjC::updateRotationSession() 1868 { 1869 AffineTransform finalTransform = m_avAsset.get().preferredTransform; 1870 FloatSize naturalSize; 1871 if (auto* firstEnabledVideoTrack = firstEnabledTrack([m_avAsset.get() tracksWithMediaCharacteristic:AVMediaCharacteristicVisual])) { 1872 naturalSize = FloatSize(firstEnabledVideoTrack.naturalSize); 1873 finalTransform *= firstEnabledVideoTrack.preferredTransform; 1874 } 1875 1876 if (finalTransform.isIdentity()) { 1877 m_imageRotationSession = nullptr; 1878 return; 1879 } 1880 1881 if (m_imageRotationSession 1882 && m_imageRotationSession->transform() 1883 && m_imageRotationSession->transform().value() == finalTransform 1884 && m_imageRotationSession->size() == naturalSize) 1885 return; 1886 1887 m_imageRotationSession = std::make_unique<ImageRotationSessionVT>(WTFMove(finalTransform), naturalSize, kCVPixelFormatType_32BGRA, ImageRotationSessionVT::IsCGImageCompatible::Yes); 1888 } 1889 1866 1890 #if ENABLE(VIDEO_TRACK) 1867 1891 … … 2054 2078 return; 2055 2079 2080 updateRotationSession(); 2056 2081 setNaturalSize(m_cachedPresentationSize); 2057 2082 } … … 2141 2166 2142 2167 m_lastPixelBuffer = adoptCF([m_videoOutput.get() copyPixelBufferForItemTime:currentTime itemTimeForDisplay:nil]); 2168 2169 if (m_imageRotationSession) 2170 m_lastPixelBuffer = m_imageRotationSession->rotate(m_lastPixelBuffer.get()); 2171 2143 2172 m_lastImage = nullptr; 2144 2173 return true; … … 2207 2236 INFO_LOG(LOGIDENTIFIER); 2208 2237 2209 GraphicsContextStateSaver stateSaver(context);2210 2238 FloatRect imageRect(0, 0, CGImageGetWidth(m_lastImage.get()), CGImageGetHeight(m_lastImage.get())); 2211 AffineTransform videoTransform = [firstEnabledVideoTrack preferredTransform]; 2212 FloatRect transformedOutputRect = videoTransform.inverse().valueOr(AffineTransform()).mapRect(outputRect); 2213 2214 context.concatCTM(videoTransform); 2215 context.drawNativeImage(m_lastImage.get(), imageRect.size(), transformedOutputRect, imageRect); 2239 context.drawNativeImage(m_lastImage.get(), imageRect.size(), outputRect, imageRect); 2216 2240 2217 2241 // If we have created an AVAssetImageGenerator in the past due to m_videoOutput not having an available -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.cpp
r240120 r246611 29 29 #if USE(LIBWEBRTC) 30 30 31 #include "ImageRotationSessionVT.h" 31 32 #include "Logging.h" 32 33 #include "RealtimeIncomingVideoSourceCocoa.h" -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.h
r245033 r246611 32 32 #include <webrtc/api/video/video_rotation.h> 33 33 34 typedef struct OpaqueVTImageRotationSession* VTImageRotationSessionRef; 35 typedef struct __CVPixelBufferPool* CVPixelBufferPoolRef; 34 namespace WebCore { 36 35 37 namespace WebCore { 36 class ImageRotationSessionVT; 38 37 39 38 class RealtimeOutgoingVideoSourceCocoa final : public RealtimeOutgoingVideoSource { … … 53 52 54 53 std::unique_ptr<PixelBufferConformerCV> m_pixelBufferConformer; 55 RetainPtr<VTImageRotationSessionRef> m_rotationSession; 56 RetainPtr<CVPixelBufferPoolRef> m_rotationPool; 54 std::unique_ptr<ImageRotationSessionVT> m_rotationSession; 57 55 webrtc::VideoRotation m_currentRotationSessionAngle { webrtc::kVideoRotation_0 }; 58 56 size_t m_rotatedWidth { 0 }; -
trunk/Source/WebCore/platform/mediastream/mac/RealtimeOutgoingVideoSourceCocoa.mm
r245033 r246611 29 29 #if USE(LIBWEBRTC) 30 30 31 #import "AffineTransform.h" 32 #import "ImageRotationSessionVT.h" 31 33 #import "Logging.h" 32 34 #import "MediaSample.h" … … 50 52 } 51 53 52 static inline void computeRotatedWidthAndHeight(CVPixelBufferRef pixelBuffer, webrtc::VideoRotation rotation, size_t& width, size_t& height)54 static inline unsigned rotationToAngle(webrtc::VideoRotation rotation) 53 55 { 54 56 switch (rotation) { 55 57 case webrtc::kVideoRotation_0: 58 return 0; 59 case webrtc::kVideoRotation_90: 60 return 90; 56 61 case webrtc::kVideoRotation_180: 57 width = CVPixelBufferGetWidth(pixelBuffer); 58 height = CVPixelBufferGetHeight(pixelBuffer); 59 return; 60 case webrtc::kVideoRotation_90: 62 return 180; 61 63 case webrtc::kVideoRotation_270: 62 width = CVPixelBufferGetHeight(pixelBuffer); 63 height = CVPixelBufferGetWidth(pixelBuffer); 64 return; 64 return 270; 65 65 } 66 66 } … … 73 73 74 74 if (!m_rotationSession || rotation != m_currentRotationSessionAngle) { 75 VTImageRotationSessionRef rawRotationSession = nullptr; 76 auto status = VTImageRotationSessionCreate(kCFAllocatorDefault, rotation, &rawRotationSession); 77 if (status != noErr) { 78 ERROR_LOG(LOGIDENTIFIER, "Failed creating a rotation session with error ", status); 79 return nullptr; 80 } 81 82 m_rotationSession = adoptCF(rawRotationSession); 83 m_currentRotationSessionAngle = rotation; 84 85 VTImageRotationSessionSetProperty(rawRotationSession, kVTImageRotationPropertyKey_EnableHighSpeedTransfer, kCFBooleanTrue); 75 IntSize size = { (int)CVPixelBufferGetWidth(pixelBuffer) , (int)CVPixelBufferGetHeight(pixelBuffer) }; 76 AffineTransform transform; 77 transform.rotate(rotationToAngle(rotation)); 78 m_rotationSession = std::make_unique<ImageRotationSessionVT>(WTFMove(transform), size, CVPixelBufferGetPixelFormatType(pixelBuffer), ImageRotationSessionVT::IsCGImageCompatible::No); 86 79 } 87 80 88 size_t rotatedWidth, rotatedHeight; 89 computeRotatedWidthAndHeight(pixelBuffer, rotation, rotatedWidth, rotatedHeight); 90 auto format = CVPixelBufferGetPixelFormatType(pixelBuffer); 91 if (!m_rotationPool || rotatedWidth != m_rotatedWidth || rotatedHeight != m_rotatedHeight || format != m_rotatedFormat) { 92 auto pixelAttributes = @{ 93 (__bridge NSString *)kCVPixelBufferWidthKey: @(rotatedWidth), 94 (__bridge NSString *)kCVPixelBufferHeightKey: @(rotatedHeight), 95 (__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(format), 96 (__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @NO, 97 }; 98 99 CVPixelBufferPoolRef pool = nullptr; 100 auto status = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &pool); 101 102 if (status != kCVReturnSuccess) { 103 ERROR_LOG(LOGIDENTIFIER, "Failed creating a pixel buffer pool with error ", status); 104 return nullptr; 105 } 106 m_rotationPool = adoptCF(pool); 107 108 m_rotatedWidth = rotatedWidth; 109 m_rotatedHeight = rotatedHeight; 110 m_rotatedFormat = format; 111 } 112 113 CVPixelBufferRef rawRotatedBuffer = nullptr; 114 auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer); 115 116 if (status != kCVReturnSuccess) { 117 ERROR_LOG(LOGIDENTIFIER, "Failed creating a pixel buffer with error ", status); 118 return nullptr; 119 } 120 RetainPtr<CVPixelBufferRef> rotatedBuffer = adoptCF(rawRotatedBuffer); 121 122 status = VTImageRotationSessionTransferImage(m_rotationSession.get(), pixelBuffer, rotatedBuffer.get()); 123 124 if (status != noErr) { 125 ERROR_LOG(LOGIDENTIFIER, "Failed rotating with error ", status, " for rotation ", m_currentRotation); 126 return nullptr; 127 } 128 return rotatedBuffer; 81 return m_rotationSession->rotate(pixelBuffer); 129 82 } 130 83
Note: See TracChangeset
for help on using the changeset viewer.