Commit faa73bf2 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

video: rotation for hardware decoded frame

Change-Id: I43a9a78efd73374362af408cfa8edef491fd3786
parent c3f9967c
...@@ -43,4 +43,6 @@ struct AVFrame; ...@@ -43,4 +43,6 @@ struct AVFrame;
+ (AVFrame*)configureFrame:(AVFrame*)frame + (AVFrame*)configureFrame:(AVFrame*)frame
fromImageBuffer: (CVImageBufferRef)image fromImageBuffer: (CVImageBufferRef)image
angle:(int)angle; angle:(int)angle;
+(UIImageOrientation)uimageOrientationFromRotation:(double)rotation;
+(CGImagePropertyOrientation)ciimageOrientationFromRotation:(double)rotation;
@end @end
...@@ -109,9 +109,59 @@ extern "C" { ...@@ -109,9 +109,59 @@ extern "C" {
return vector; return vector;
} }
+(UIImageOrientation)uimageOrientationFromRotation:(double)rotation {
UIImageOrientation orientation = UIImageOrientationUp;
switch ((int)rotation) {
case 0:
orientation = UIImageOrientationUp;
break;
case 90:
orientation = UIImageOrientationLeft;
break;
case -90:
orientation = UIImageOrientationRight;
break;
case -180:
orientation = UIImageOrientationDown;
break;
}
return orientation;
}
+(CGImagePropertyOrientation)ciimageOrientationFromRotation:(double)rotation {
CGImagePropertyOrientation orientation = kCGImagePropertyOrientationUp;
switch ((int)rotation) {
case 0:
orientation = kCGImagePropertyOrientationUp;
break;
case 90:
orientation = kCGImagePropertyOrientationLeft;
break;
case -90:
orientation = kCGImagePropertyOrientationRight;
break;
case -180:
orientation = kCGImagePropertyOrientationDown;
break;
}
return orientation;
}
+ (UIImage*)convertHardwareDecodedFrameToImage:(const AVFrame*)frame { + (UIImage*)convertHardwareDecodedFrameToImage:(const AVFrame*)frame {
if ((CVPixelBufferRef)frame->data[3]) { if ((CVPixelBufferRef)frame->data[3]) {
CIImage *image = [CIImage imageWithCVPixelBuffer: (CVPixelBufferRef)frame->data[3]]; CIImage *image = [CIImage imageWithCVPixelBuffer: (CVPixelBufferRef)frame->data[3]];
if (auto matrix = av_frame_get_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX)) {
const int32_t* data = reinterpret_cast<int32_t*>(matrix->data);
auto rotation = av_display_rotation_get(data);
auto uiImageOrientation = [Utils uimageOrientationFromRotation:rotation];
auto ciImageOrientation = [Utils ciimageOrientationFromRotation:rotation];
if (@available(iOS 11.0, *)) {
image = [image imageByApplyingCGOrientation: ciImageOrientation];
} else if (@available(iOS 10.0, *)) {
image = [image imageByApplyingOrientation:static_cast<int>(ciImageOrientation)];
}
UIImage * imageUI = [UIImage imageWithCIImage:image scale:1 orientation: uiImageOrientation];
return imageUI;
}
UIImage * imageUI = [UIImage imageWithCIImage:image]; UIImage * imageUI = [UIImage imageWithCIImage:image];
return imageUI; return imageUI;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment