diff --git a/SGPlayer/Classes/Core/SGDescription/SGVideoDescriptor.m b/SGPlayer/Classes/Core/SGDescription/SGVideoDescriptor.m index a0e13c1b..75c67379 100644 --- a/SGPlayer/Classes/Core/SGDescription/SGVideoDescriptor.m +++ b/SGPlayer/Classes/Core/SGDescription/SGVideoDescriptor.m @@ -83,12 +83,11 @@ - (SGRational)presentationSize aspectRatio = av_make_q(1, 1); } aspectRatio = av_mul_q(aspectRatio, av_make_q(width, height)); - if (av_q2d(aspectRatio) >= 1) { - width = av_rescale(height, aspectRatio.num, aspectRatio.den) & ~1; - } else { - height = av_rescale(width, aspectRatio.den, aspectRatio.num) & ~1; - } - return (SGRational){width, height}; + SGRational size1 = {width, av_rescale(width, aspectRatio.den, aspectRatio.num) & ~1}; + SGRational size2 = {av_rescale(height, aspectRatio.num, aspectRatio.den) & ~1, height}; + int64_t pixels1 = size1.num * size1.den; + int64_t pixels2 = size2.num * size2.den; + return (pixels1 > pixels2) ? size1 : size2; } - (BOOL)isEqualToDescriptor:(SGVideoDescriptor *)descriptor diff --git a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m index aefffe24..ba89f939 100644 --- a/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m +++ b/SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m @@ -343,9 +343,10 @@ - (void)drawInMTKView:(MTKView *)view } [self->_lock lock]; SGVideoFrame *frame = self->_currentFrame; - NSUInteger width = frame.descriptor.width; - NSUInteger height = frame.descriptor.height; - if (!frame || width == 0 || height == 0) { + SGRational presentationSize = frame.descriptor.presentationSize; + if (!frame || + presentationSize.num == 0 || + presentationSize.den == 0) { [self->_lock unlock]; return; } @@ -379,8 +380,11 @@ - (void)drawInMTKView:(MTKView *)view if (rotate && (rotate % 90) == 0) { float radians = GLKMathDegreesToRadians(-rotate); baseMatrix = GLKMatrix4RotateZ(baseMatrix, radians); - width = frame.descriptor.width * ABS(cos(radians)) + frame.descriptor.height * ABS(sin(radians)); - height = frame.descriptor.width * ABS(sin(radians)) + frame.descriptor.height * ABS(cos(radians)); + SGRational size = { + presentationSize.num * ABS(cos(radians)) + presentationSize.den * ABS(sin(radians)), + presentationSize.num * ABS(sin(radians)) + presentationSize.den * ABS(cos(radians)), + }; + presentationSize = size; } NSArray> *textures = nil; if (frame.pixelBuffer) { @@ -403,7 +407,7 @@ - (void)drawInMTKView:(MTKView *)view if (drawableSize.width == 0 || drawableSize.height == 0) { return; } - MTLSize textureSize = MTLSizeMake(frame.descriptor.presentationSize.num, frame.descriptor.presentationSize.den, 0); + MTLSize textureSize = MTLSizeMake(presentationSize.num, presentationSize.den, 0); MTLSize layerSize = MTLSizeMake(drawable.texture.width, drawable.texture.height, 0); switch (displayMode) { case SGDisplayModePlane: {