Skip to content

Commit

Permalink
SGVideoRenderer: Presentation size.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Nov 7, 2019
1 parent 4f8da84 commit 7e5b11d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
11 changes: 5 additions & 6 deletions SGPlayer/Classes/Core/SGDescription/SGVideoDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions SGPlayer/Classes/Core/SGRenderer/SGVideoRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<id<MTLTexture>> *textures = nil;
if (frame.pixelBuffer) {
Expand All @@ -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: {
Expand Down

0 comments on commit 7e5b11d

Please sign in to comment.