Skip to content

Commit

Permalink
frame buffer size checks added, just in case.
Browse files Browse the repository at this point in the history
Also it will be compatible with SDK checks
  • Loading branch information
IGitGotIt committed Jan 9, 2024
1 parent 83f0b24 commit 61e4eb7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ void updateTextures(Frame frame) {
int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1;

ByteBuffer bb = frame.getBuffer();
bb.clear();
//check if buffer data is correctly sized.
if (bb.remaining() != frame.getYplaneSize() + frame.getUVplaneSize() * 2) {
textureWidth = 0;
textureHeight = 0;
return;
}

bb.position(0);
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1);

Expand All @@ -234,11 +244,11 @@ void updateTextures(Frame frame) {

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[1]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());

GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[2]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ void updateTextures(Frame frame) {
int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1;

ByteBuffer bb = frame.getBuffer();
bb.clear();
//check if buffer data is correctly sized.
if (bb.remaining() != frame.getYplaneSize() + frame.getUVplaneSize() * 2) {
textureWidth = 0;
textureHeight = 0;
return;
}
bb.position(0);
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1);

Expand All @@ -234,11 +243,11 @@ void updateTextures(Frame frame) {

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[1]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());

GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[2]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,23 @@ void GlTexSubImage2D(int width, int height, int stride,
}
}
}

void updateTextures(Frame frame) {
int width = frame.getWidth();
int height = frame.getHeight();
int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1;

ByteBuffer bb = frame.getBuffer();
bb.clear();
//check if buffer data is correctly sized.
if (bb.remaining() != frame.getYplaneSize() + frame.getUVplaneSize() * 2) {
textureWidth = 0;
textureHeight = 0;
return;
}

bb.position(0);
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1);

Expand All @@ -230,11 +240,11 @@ void updateTextures(Frame frame) {

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[1]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());

GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[2]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ void updateTextures(Frame frame) {
int half_width = (width + 1) >> 1;
int half_height = (height + 1) >> 1;

ByteBuffer bb = frame.getBuffer();
bb.clear();
//check if buffer data is correctly sized.
if (bb.remaining() != frame.getYplaneSize() + frame.getUVplaneSize() * 2) {
textureWidth = 0;
textureHeight = 0;
return;
}

bb.position(0);
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1);

Expand All @@ -230,11 +240,11 @@ void updateTextures(Frame frame) {

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[1]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getUplane());

GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[2]);
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
GlTexSubImage2D(half_width, half_height, frame.getUvStride(), frame.getVplane());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ void main(void) {
val half_width = width + 1 shr 1
val half_height = height + 1 shr 1

val bb = frame.buffer
// If we are reusing this frame, make sure we reset position and
// limit
bb.clear()
if (bb.remaining() != frame.getYplaneSize() + frame.getUVplaneSize() * 2) {
textureWidth = 0
textureHeight = 0
return
}

bb.position(0)
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1)
GLES20.glPixelStorei(GLES20.GL_PACK_ALIGNMENT, 1)

Expand Down

0 comments on commit 61e4eb7

Please sign in to comment.