summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/ffmpeg/libavcodec/g2meet.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/ffmpeg/libavcodec/g2meet.c')
-rw-r--r--chromium/third_party/ffmpeg/libavcodec/g2meet.c174
1 files changed, 109 insertions, 65 deletions
diff --git a/chromium/third_party/ffmpeg/libavcodec/g2meet.c b/chromium/third_party/ffmpeg/libavcodec/g2meet.c
index 8f8e88047a4..700eb338c41 100644
--- a/chromium/third_party/ffmpeg/libavcodec/g2meet.c
+++ b/chromium/third_party/ffmpeg/libavcodec/g2meet.c
@@ -24,6 +24,7 @@
* Go2Webinar decoder
*/
+#include <inttypes.h>
#include <zlib.h>
#include "libavutil/intreadwrite.h"
@@ -35,7 +36,7 @@
#include "mjpeg.h"
enum ChunkType {
- FRAME_INFO = 0xC8,
+ DISPLAY_INFO = 0xC8,
TILE_DATA,
CURSOR_POS,
CURSOR_SHAPE,
@@ -198,8 +199,8 @@ static int jpg_decode_block(JPGContext *c, GetBitContext *gb,
return AVERROR_INVALIDDATA;
if (dc)
dc = get_xbits(gb, dc);
- dc = dc * qmat[0] + c->prev_dc[plane];
- block[0] = dc;
+ dc = dc * qmat[0] + c->prev_dc[plane];
+ block[0] = dc;
c->prev_dc[plane] = dc;
pos = 0;
@@ -214,8 +215,8 @@ static int jpg_decode_block(JPGContext *c, GetBitContext *gb,
if (val) {
int nbits = val;
- val = get_xbits(gb, nbits);
- val *= qmat[ff_zigzag_direct[pos]];
+ val = get_xbits(gb, nbits);
+ val *= qmat[ff_zigzag_direct[pos]];
block[c->scantable.permutated[pos]] = val;
}
}
@@ -253,19 +254,25 @@ static int jpg_decode_data(JPGContext *c, int width, int height,
mb_h = (height + 15) >> 4;
if (!num_mbs)
- num_mbs = mb_w * mb_h;
+ num_mbs = mb_w * mb_h * 4;
for (i = 0; i < 3; i++)
c->prev_dc[i] = 1024;
bx = by = 0;
+ c->dsp.clear_blocks(c->block[0]);
for (mb_y = 0; mb_y < mb_h; mb_y++) {
for (mb_x = 0; mb_x < mb_w; mb_x++) {
- if (mask && !mask[mb_x]) {
+ if (mask && !mask[mb_x * 2] && !mask[mb_x * 2 + 1] &&
+ !mask[mb_x * 2 + mask_stride] &&
+ !mask[mb_x * 2 + 1 + mask_stride]) {
bx += 16;
continue;
}
for (j = 0; j < 2; j++) {
for (i = 0; i < 2; i++) {
+ if (mask && !mask[mb_x * 2 + i + j * mask_stride])
+ continue;
+ num_mbs--;
if ((ret = jpg_decode_block(c, &gb, 0,
c->block[i + j * 2])) != 0)
return ret;
@@ -290,14 +297,14 @@ static int jpg_decode_data(JPGContext *c, int width, int height,
}
}
- if (!--num_mbs)
+ if (!num_mbs)
return 0;
bx += 16;
}
bx = 0;
by += 16;
if (mask)
- mask += mask_stride;
+ mask += mask_stride * 2;
}
return 0;
@@ -353,7 +360,7 @@ static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
width = FFMIN(c->width - tile_x * c->tile_width, c->tile_width);
height = FFMIN(c->height - tile_y * c->tile_height, c->tile_height);
- hdr = *src++;
+ hdr = *src++;
sub_type = hdr >> 5;
if (sub_type == 0) {
int j;
@@ -375,19 +382,21 @@ static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
npal = *src++ + 1;
if (src_end - src < npal * 3)
return AVERROR_INVALIDDATA;
- memcpy(pal, src, npal * 3); src += npal * 3;
+ memcpy(pal, src, npal * 3);
+ src += npal * 3;
if (sub_type != 2) {
for (i = 0; i < npal; i++) {
if (!memcmp(pal + i * 3, transp, 3)) {
- tidx = i;
- break;
+ tidx = i;
+ break;
}
}
}
if (src_end - src < 2)
return 0;
- zsize = (src[0] << 8) | src[1]; src += 2;
+ zsize = (src[0] << 8) | src[1];
+ src += 2;
if (src_end - src < zsize + (sub_type != 2))
return AVERROR_INVALIDDATA;
@@ -405,7 +414,7 @@ static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
nblocks = *src++ + 1;
cblocks = 0;
- bstride = FFALIGN(width, 16) >> 4;
+ bstride = FFALIGN(width, 16) >> 3;
// blocks are coded LSB and we need normal bitreader for JPEG data
bits = 0;
for (i = 0; i < (FFALIGN(height, 16) >> 4); i++) {
@@ -422,14 +431,17 @@ static int kempf_decode_tile(G2MContext *c, int tile_x, int tile_y,
cblocks += coded;
if (cblocks > nblocks)
return AVERROR_INVALIDDATA;
- c->kempf_flags[j + i * bstride] = coded;
+ c->kempf_flags[j * 2 + i * 2 * bstride] =
+ c->kempf_flags[j * 2 + 1 + i * 2 * bstride] =
+ c->kempf_flags[j * 2 + (i * 2 + 1) * bstride] =
+ c->kempf_flags[j * 2 + 1 + (i * 2 + 1) * bstride] = coded;
}
}
memset(c->jpeg_tile, 0, c->tile_stride * height);
jpg_decode_data(&c->jc, width, height, src, src_end - src,
c->jpeg_tile, c->tile_stride,
- c->kempf_flags, bstride, nblocks, 0);
+ c->kempf_flags, bstride, nblocks * 4, 0);
kempf_restore_buf(c->kempf_buf, dlen, dst, c->framebuf_stride,
c->jpeg_tile, c->tile_stride,
@@ -482,30 +494,30 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
uint32_t cursor_hot_x, cursor_hot_y;
int cursor_fmt, err;
- cur_size = bytestream2_get_be32(gb);
- cursor_w = bytestream2_get_byte(gb);
- cursor_h = bytestream2_get_byte(gb);
- cursor_hot_x = bytestream2_get_byte(gb);
- cursor_hot_y = bytestream2_get_byte(gb);
- cursor_fmt = bytestream2_get_byte(gb);
+ cur_size = bytestream2_get_be32(gb);
+ cursor_w = bytestream2_get_byte(gb);
+ cursor_h = bytestream2_get_byte(gb);
+ cursor_hot_x = bytestream2_get_byte(gb);
+ cursor_hot_y = bytestream2_get_byte(gb);
+ cursor_fmt = bytestream2_get_byte(gb);
cursor_stride = FFALIGN(cursor_w, cursor_fmt==1 ? 32 : 1) * 4;
if (cursor_w < 1 || cursor_w > 256 ||
cursor_h < 1 || cursor_h > 256) {
- av_log(avctx, AV_LOG_ERROR, "Invalid cursor dimensions %dx%d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor dimensions %"PRIu32"x%"PRIu32"\n",
cursor_w, cursor_h);
return AVERROR_INVALIDDATA;
}
if (cursor_hot_x > cursor_w || cursor_hot_y > cursor_h) {
- av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %d,%d\n",
+ av_log(avctx, AV_LOG_WARNING, "Invalid hotspot position %"PRIu32",%"PRIu32"\n",
cursor_hot_x, cursor_hot_y);
cursor_hot_x = FFMIN(cursor_hot_x, cursor_w - 1);
cursor_hot_y = FFMIN(cursor_hot_y, cursor_h - 1);
}
if (cur_size - 9 > bytestream2_get_bytes_left(gb) ||
c->cursor_w * c->cursor_h / 4 > cur_size) {
- av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %d/%d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %"PRIu32"/%u\n",
cur_size, bytestream2_get_bytes_left(gb));
return AVERROR_INVALIDDATA;
}
@@ -535,7 +547,7 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
bits = bytestream2_get_be32(gb);
for (k = 0; k < 32; k++) {
dst[0] = !!(bits & 0x80000000);
- dst += 4;
+ dst += 4;
bits <<= 1;
}
}
@@ -549,18 +561,24 @@ static int g2m_load_cursor(AVCodecContext *avctx, G2MContext *c,
int mask_bit = !!(bits & 0x80000000);
switch (dst[0] * 2 + mask_bit) {
case 0:
- dst[0] = 0xFF; dst[1] = 0x00;
- dst[2] = 0x00; dst[3] = 0x00;
+ dst[0] = 0xFF;
+ dst[1] = 0x00;
+ dst[2] = 0x00;
+ dst[3] = 0x00;
break;
case 1:
- dst[0] = 0xFF; dst[1] = 0xFF;
- dst[2] = 0xFF; dst[3] = 0xFF;
+ dst[0] = 0xFF;
+ dst[1] = 0xFF;
+ dst[2] = 0xFF;
+ dst[3] = 0xFF;
break;
default:
- dst[0] = 0x00; dst[1] = 0x00;
- dst[2] = 0x00; dst[3] = 0x00;
+ dst[0] = 0x00;
+ dst[1] = 0x00;
+ dst[2] = 0x00;
+ dst[3] = 0x00;
}
- dst += 4;
+ dst += 4;
bits <<= 1;
}
}
@@ -645,8 +663,8 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
GetByteContext bc, tbc;
int magic;
int got_header = 0;
- uint32_t chunk_size;
- int chunk_type;
+ uint32_t chunk_size, r_mask, g_mask, b_mask;
+ int chunk_type, chunk_start;
int i;
int ret;
@@ -672,18 +690,20 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
}
while (bytestream2_get_bytes_left(&bc) > 5) {
- chunk_size = bytestream2_get_le32(&bc) - 1;
- chunk_type = bytestream2_get_byte(&bc);
+ chunk_size = bytestream2_get_le32(&bc) - 1;
+ chunk_type = bytestream2_get_byte(&bc);
+ chunk_start = bytestream2_tell(&bc);
if (chunk_size > bytestream2_get_bytes_left(&bc)) {
- av_log(avctx, AV_LOG_ERROR, "Invalid chunk size %d type %02X\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid chunk size %"PRIu32" type %02X\n",
chunk_size, chunk_type);
break;
}
switch (chunk_type) {
- case FRAME_INFO:
+ case DISPLAY_INFO:
+ got_header =
c->got_header = 0;
if (chunk_size < 21) {
- av_log(avctx, AV_LOG_ERROR, "Invalid frame info size %d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid display info size %"PRIu32"\n",
chunk_size);
break;
}
@@ -697,14 +717,18 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
ret = AVERROR_INVALIDDATA;
goto header_fail;
}
- if (c->width != avctx->width || c->height != avctx->height)
- ff_set_dimensions(avctx, c->width, c->height);
+ if (c->width != avctx->width || c->height != avctx->height) {
+ ret = ff_set_dimensions(avctx, c->width, c->height);
+ if (ret < 0)
+ goto header_fail;
+ }
c->compression = bytestream2_get_be32(&bc);
if (c->compression != 2 && c->compression != 3) {
av_log(avctx, AV_LOG_ERROR,
"Unknown compression method %d\n",
c->compression);
- return AVERROR_PATCHWELCOME;
+ ret = AVERROR_PATCHWELCOME;
+ goto header_fail;
}
c->tile_width = bytestream2_get_be32(&bc);
c->tile_height = bytestream2_get_be32(&bc);
@@ -718,9 +742,30 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
}
c->tiles_x = (c->width + c->tile_width - 1) / c->tile_width;
c->tiles_y = (c->height + c->tile_height - 1) / c->tile_height;
- c->bpp = bytestream2_get_byte(&bc);
- chunk_size -= 21;
- bytestream2_skip(&bc, chunk_size);
+ c->bpp = bytestream2_get_byte(&bc);
+ if (c->bpp == 32) {
+ if (bytestream2_get_bytes_left(&bc) < 16 ||
+ (chunk_size - 21) < 16) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Display info: missing bitmasks!\n");
+ ret = AVERROR_INVALIDDATA;
+ goto header_fail;
+ }
+ r_mask = bytestream2_get_be32(&bc);
+ g_mask = bytestream2_get_be32(&bc);
+ b_mask = bytestream2_get_be32(&bc);
+ if (r_mask != 0xFF0000 || g_mask != 0xFF00 || b_mask != 0xFF) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Invalid or unsupported bitmasks: R=%"PRIX32", G=%"PRIX32", B=%"PRIX32"\n",
+ r_mask, g_mask, b_mask);
+ ret = AVERROR_PATCHWELCOME;
+ goto header_fail;
+ }
+ } else {
+ avpriv_request_sample(avctx, "bpp=%d", c->bpp);
+ ret = AVERROR_PATCHWELCOME;
+ goto header_fail;
+ }
if (g2m_init_buffers(c)) {
ret = AVERROR(ENOMEM);
goto header_fail;
@@ -730,12 +775,11 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
case TILE_DATA:
if (!c->tiles_x || !c->tiles_y) {
av_log(avctx, AV_LOG_WARNING,
- "No frame header - skipping tile\n");
- bytestream2_skip(&bc, bytestream2_get_bytes_left(&bc));
+ "No display info - skipping tile\n");
break;
}
if (chunk_size < 2) {
- av_log(avctx, AV_LOG_ERROR, "Invalid tile data size %d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid tile data size %"PRIu32"\n",
chunk_size);
break;
}
@@ -747,7 +791,6 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
c->tile_x, c->tile_y, c->tiles_x, c->tiles_y);
break;
}
- chunk_size -= 2;
ret = 0;
switch (c->compression) {
case COMPR_EPIC_J_B:
@@ -757,44 +800,42 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
case COMPR_KEMPF_J_B:
ret = kempf_decode_tile(c, c->tile_x, c->tile_y,
buf + bytestream2_tell(&bc),
- chunk_size);
+ chunk_size - 2);
break;
}
if (ret && c->framebuf)
av_log(avctx, AV_LOG_ERROR, "Error decoding tile %d,%d\n",
c->tile_x, c->tile_y);
- bytestream2_skip(&bc, chunk_size);
break;
case CURSOR_POS:
if (chunk_size < 5) {
- av_log(avctx, AV_LOG_ERROR, "Invalid cursor pos size %d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor pos size %"PRIu32"\n",
chunk_size);
break;
}
c->cursor_x = bytestream2_get_be16(&bc);
c->cursor_y = bytestream2_get_be16(&bc);
- bytestream2_skip(&bc, chunk_size - 4);
break;
case CURSOR_SHAPE:
if (chunk_size < 8) {
- av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %d\n",
+ av_log(avctx, AV_LOG_ERROR, "Invalid cursor data size %"PRIu32"\n",
chunk_size);
break;
}
bytestream2_init(&tbc, buf + bytestream2_tell(&bc),
chunk_size - 4);
g2m_load_cursor(avctx, c, &tbc);
- bytestream2_skip(&bc, chunk_size);
break;
case CHUNK_CC:
case CHUNK_CD:
- bytestream2_skip(&bc, chunk_size);
break;
default:
- av_log(avctx, AV_LOG_WARNING, "Skipping chunk type %02X\n",
+ av_log(avctx, AV_LOG_WARNING, "Skipping chunk type %02d\n",
chunk_type);
- bytestream2_skip(&bc, chunk_size);
}
+
+ /* navigate to next chunk */
+ bytestream2_skip(&bc, chunk_start + chunk_size - bytestream2_tell(&bc));
}
if (got_header)
c->got_header = 1;
@@ -808,7 +849,7 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
for (i = 0; i < avctx->height; i++)
memcpy(pic->data[0] + i * pic->linesize[0],
- c->framebuf + i * c->framebuf_stride,
+ c->framebuf + i * c->framebuf_stride,
c->width * 3);
g2m_paint_cursor(c, pic->data[0], pic->linesize[0]);
@@ -816,15 +857,18 @@ static int g2m_decode_frame(AVCodecContext *avctx, void *data,
}
return buf_size;
+
header_fail:
- c->width = c->height = 0;
- c->tiles_x = c->tiles_y = 0;
+ c->width =
+ c->height = 0;
+ c->tiles_x =
+ c->tiles_y = 0;
return ret;
}
static av_cold int g2m_decode_init(AVCodecContext *avctx)
{
- G2MContext * const c = avctx->priv_data;
+ G2MContext *const c = avctx->priv_data;
int ret;
if ((ret = jpg_init(avctx, &c->jc)) != 0) {
@@ -840,7 +884,7 @@ static av_cold int g2m_decode_init(AVCodecContext *avctx)
static av_cold int g2m_decode_end(AVCodecContext *avctx)
{
- G2MContext * const c = avctx->priv_data;
+ G2MContext *const c = avctx->priv_data;
jpg_free_context(&c->jc);