Commit a9d7c8e1 authored by Anthony Léonard's avatar Anthony Léonard Committed by Kateryna Kostiuk

fix possible segfault when reading video frames

Height and width contained in Video::Frame structure are now used to
determine the size of a frame instead of the possibly incorrect
Renderer::size() values. This prevent some segfault when hardware
acceleration for decoding is used with certain size of picture.

Change-Id: I22e928eb0b9a0889d0b4ff861bb93dfba16d1bc6
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 66a050cc
......@@ -465,15 +465,13 @@
-(void) renderer: (Video::Renderer*)renderer renderFrameForDistantView:(CallView*) view
{
QSize res = renderer->size();
auto frame_ptr = renderer->currentFrame();
if (!frame_ptr.ptr)
return;
CallLayer* callLayer = (CallLayer*) view.layer;
[callLayer setCurrentFrame:std::move(frame_ptr) ofSize:res];
[callLayer setCurrentFrame:std::move(frame_ptr)];
[callLayer setVideoRunning:YES];
}
......
......@@ -25,6 +25,6 @@
@property BOOL videoRunning;
- (void) setCurrentFrame:(Video::Frame)framePtr ofSize:(QSize)frameSize;
- (void) setCurrentFrame:(Video::Frame)framePtr;
@end
......@@ -57,7 +57,6 @@ GLuint tex, vbo, vShader, fShader, sProg, vao;
// Last frame data and attributes
Video::Frame currentFrame;
QSize currentFrameSize;
BOOL currentFrameDisplayed;
NSLock* currentFrameLk;
......@@ -166,16 +165,17 @@ NSLock* currentFrameLk;
[currentFrameLk lock];
if(!currentFrameDisplayed) {
if(currentFrame.ptr)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, currentFrameSize.width(), currentFrameSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, currentFrame.ptr);
if(currentFrame.ptr) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, currentFrame.width, currentFrame.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, currentFrame.ptr);
}
currentFrameDisplayed = YES;
}
// To ensure that we will not divide by zero
if (!currentFrameSize.isEmpty()) {
if (currentFrame.ptr && currentFrame.width && currentFrame.height) {
// Compute scaling factor to keep the original aspect ratio of the video
CGSize viewSize = self.frame.size;
float viewRatio = viewSize.width/viewSize.height;
float frameRatio = ((float)currentFrameSize.width())/((float)currentFrameSize.height());
float frameRatio = ((float)currentFrame.width)/((float)currentFrame.height);
float ratio = viewRatio * (1/frameRatio);
GLint inScalingUniform = glGetUniformLocation(sProg, "in_Scaling");
......@@ -194,11 +194,10 @@ NSLock* currentFrameLk;
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
- (void) setCurrentFrame:(Video::Frame)framePtr ofSize:(QSize)frameSize
- (void) setCurrentFrame:(Video::Frame)framePtr
{
[currentFrameLk lock];
currentFrame = std::move(framePtr);
currentFrameSize = frameSize;
currentFrameDisplayed = NO;
[currentFrameLk unlock];
}
......
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