|
Lines 59-79
static ImageRotationSessionVT::RotationProperties transformToRotationProperties(
a/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm_sec1
|
| 59 |
return rotation; |
59 |
return rotation; |
| 60 |
} |
60 |
} |
| 61 |
|
61 |
|
| 62 |
ImageRotationSessionVT::ImageRotationSessionVT(AffineTransform&& transform, FloatSize size, OSType pixelFormat, IsCGImageCompatible cvImageCompatibility) |
62 |
ImageRotationSessionVT::ImageRotationSessionVT(AffineTransform&& transform, FloatSize size, IsCGImageCompatible isCGImageCompatible) |
| 63 |
: ImageRotationSessionVT(transformToRotationProperties(transform), size, pixelFormat, cvImageCompatibility) |
63 |
: ImageRotationSessionVT(transformToRotationProperties(transform), size, isCGImageCompatible) |
| 64 |
{ |
64 |
{ |
| 65 |
m_transform = WTFMove(transform); |
65 |
m_transform = WTFMove(transform); |
| 66 |
} |
66 |
} |
| 67 |
|
67 |
|
| 68 |
ImageRotationSessionVT::ImageRotationSessionVT(const RotationProperties& rotation, FloatSize size, OSType pixelFormat, IsCGImageCompatible cvImageCompatibility) |
68 |
ImageRotationSessionVT::ImageRotationSessionVT(const RotationProperties& rotation, FloatSize size, IsCGImageCompatible isCGImageCompatible) |
| 69 |
{ |
69 |
{ |
| 70 |
initialize(rotation, size, pixelFormat, cvImageCompatibility); |
70 |
initialize(rotation, size, isCGImageCompatible); |
| 71 |
} |
71 |
} |
| 72 |
|
72 |
|
| 73 |
void ImageRotationSessionVT::initialize(const RotationProperties& rotation, FloatSize size, OSType pixelFormat, IsCGImageCompatible cvImageCompatibility) |
73 |
void ImageRotationSessionVT::initialize(const RotationProperties& rotation, FloatSize size, IsCGImageCompatible isCGImageCompatible) |
| 74 |
{ |
74 |
{ |
| 75 |
m_rotationProperties = rotation; |
75 |
m_rotationProperties = rotation; |
| 76 |
m_size = size; |
76 |
m_size = size; |
|
|
77 |
m_isCGImageCompatible = isCGImageCompatible; |
| 77 |
|
78 |
|
| 78 |
if (m_rotationProperties.angle == 90 || m_rotationProperties.angle == 270) |
79 |
if (m_rotationProperties.angle == 90 || m_rotationProperties.angle == 270) |
| 79 |
size = size.transposedSize(); |
80 |
size = size.transposedSize(); |
|
Lines 89-114
void ImageRotationSessionVT::initialize(const RotationProperties& rotation, Floa
a/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm_sec2
|
| 89 |
VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipVerticalOrientation, kCFBooleanTrue); |
90 |
VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipVerticalOrientation, kCFBooleanTrue); |
| 90 |
if (m_rotationProperties.flipX) |
91 |
if (m_rotationProperties.flipX) |
| 91 |
VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipHorizontalOrientation, kCFBooleanTrue); |
92 |
VTImageRotationSessionSetProperty(m_rotationSession.get(), kVTImageRotationPropertyKey_FlipHorizontalOrientation, kCFBooleanTrue); |
| 92 |
|
|
|
| 93 |
auto pixelAttributes = @{ |
| 94 |
(__bridge NSString *)kCVPixelBufferWidthKey: @(m_rotatedSize.width()), |
| 95 |
(__bridge NSString *)kCVPixelBufferHeightKey: @(m_rotatedSize.height()), |
| 96 |
(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(pixelFormat), |
| 97 |
(__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: (cvImageCompatibility == IsCGImageCompatible::Yes ? @YES : @NO), |
| 98 |
#if PLATFORM(IOS_SIMULATOR) || PLATFORM(MAC) |
| 99 |
(__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ } |
| 100 |
#endif |
| 101 |
}; |
| 102 |
CVPixelBufferPoolRef rawPool = nullptr; |
| 103 |
if (auto err = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); err != noErr) |
| 104 |
RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer pool with error %d", err); |
| 105 |
m_rotationPool = adoptCF(rawPool); |
| 106 |
} |
93 |
} |
| 107 |
|
94 |
|
| 108 |
RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(CVPixelBufferRef pixelBuffer) |
95 |
RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(CVPixelBufferRef pixelBuffer) |
| 109 |
{ |
96 |
{ |
| 110 |
RetainPtr<CVPixelBufferRef> result; |
97 |
auto pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer); |
|
|
98 |
if (pixelFormat != m_pixelFormat || !m_rotationPool) { |
| 99 |
m_pixelFormat = pixelFormat; |
| 100 |
auto pixelAttributes = @{ |
| 101 |
(__bridge NSString *)kCVPixelBufferWidthKey: @(m_rotatedSize.width()), |
| 102 |
(__bridge NSString *)kCVPixelBufferHeightKey: @(m_rotatedSize.height()), |
| 103 |
(__bridge NSString *)kCVPixelBufferPixelFormatTypeKey: @(m_pixelFormat), |
| 104 |
(__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: (m_isCGImageCompatible == IsCGImageCompatible::Yes ? @YES : @NO), |
| 105 |
#if PLATFORM(IOS_SIMULATOR) || PLATFORM(MAC) |
| 106 |
(__bridge NSString *)kCVPixelBufferIOSurfacePropertiesKey : @{ } |
| 107 |
#endif |
| 108 |
}; |
| 109 |
|
| 110 |
CVPixelBufferPoolRef rawPool = nullptr; |
| 111 |
if (auto err = CVPixelBufferPoolCreate(kCFAllocatorDefault, nullptr, (__bridge CFDictionaryRef)pixelAttributes, &rawPool); err != noErr) { |
| 112 |
RELEASE_LOG_ERROR(WebRTC, "ImageRotationSessionVT failed creating buffer pool with error %d", err); |
| 113 |
return nullptr; |
| 114 |
} |
| 111 |
|
115 |
|
|
|
116 |
m_rotationPool = adoptCF(rawPool); |
| 117 |
} |
| 118 |
|
| 119 |
RetainPtr<CVPixelBufferRef> result; |
| 112 |
CVPixelBufferRef rawRotatedBuffer = nullptr; |
120 |
CVPixelBufferRef rawRotatedBuffer = nullptr; |
| 113 |
auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer); |
121 |
auto status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, m_rotationPool.get(), &rawRotatedBuffer); |
| 114 |
if (status != kCVReturnSuccess) { |
122 |
if (status != kCVReturnSuccess) { |
|
Lines 126-141
RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(CVPixelBufferRef pixe
a/Source/WebCore/platform/graphics/cv/ImageRotationSessionVT.mm_sec3
|
| 126 |
return result; |
134 |
return result; |
| 127 |
} |
135 |
} |
| 128 |
|
136 |
|
| 129 |
RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(MediaSample& sample, const RotationProperties& rotation, IsCGImageCompatible cvImageCompatibility) |
137 |
RetainPtr<CVPixelBufferRef> ImageRotationSessionVT::rotate(MediaSample& sample, const RotationProperties& rotation, IsCGImageCompatible cgImageCompatible) |
| 130 |
{ |
138 |
{ |
| 131 |
auto pixelBuffer = static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(sample.platformSample().sample.cmSampleBuffer)); |
139 |
auto pixelBuffer = static_cast<CVPixelBufferRef>(PAL::CMSampleBufferGetImageBuffer(sample.platformSample().sample.cmSampleBuffer)); |
| 132 |
ASSERT(pixelBuffer); |
140 |
ASSERT(pixelBuffer); |
| 133 |
if (!pixelBuffer) |
141 |
if (!pixelBuffer) |
| 134 |
return nullptr; |
142 |
return nullptr; |
| 135 |
|
143 |
|
|
|
144 |
m_pixelFormat = CVPixelBufferGetPixelFormatType(pixelBuffer); |
| 136 |
IntSize size { (int)CVPixelBufferGetWidth(pixelBuffer), (int)CVPixelBufferGetHeight(pixelBuffer) }; |
145 |
IntSize size { (int)CVPixelBufferGetWidth(pixelBuffer), (int)CVPixelBufferGetHeight(pixelBuffer) }; |
| 137 |
if (rotation != m_rotationProperties || m_size != size) |
146 |
if (rotation != m_rotationProperties || m_size != size) |
| 138 |
initialize(rotation, size, CVPixelBufferGetPixelFormatType(pixelBuffer), cvImageCompatibility); |
147 |
initialize(rotation, size, cgImageCompatible); |
| 139 |
|
148 |
|
| 140 |
return rotate(pixelBuffer); |
149 |
return rotate(pixelBuffer); |
| 141 |
} |
150 |
} |