1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  vmdav: convert to bytestream2
  FATE: add a test for the join filter
  FATE: add a test for the volume filter

Conflicts:
	libavcodec/vmdav.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer
2013-03-28 15:02:49 +01:00
2 changed files with 81 additions and 91 deletions

View File

@@ -48,6 +48,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "bytestream.h"
#define VMD_HEADER_SIZE 0x330 #define VMD_HEADER_SIZE 0x330
#define PALETTE_COUNT 256 #define PALETTE_COUNT 256
@@ -77,8 +78,6 @@ typedef struct VmdVideoContext {
static void lz_unpack(const unsigned char *src, int src_len, static void lz_unpack(const unsigned char *src, int src_len,
unsigned char *dest, int dest_len) unsigned char *dest, int dest_len)
{ {
const unsigned char *s;
const unsigned char *s_end;
unsigned char *d; unsigned char *d;
unsigned char *d_end; unsigned char *d_end;
unsigned char queue[QUEUE_SIZE]; unsigned char queue[QUEUE_SIZE];
@@ -89,19 +88,17 @@ static void lz_unpack(const unsigned char *src, int src_len,
unsigned int speclen; unsigned int speclen;
unsigned char tag; unsigned char tag;
unsigned int i, j; unsigned int i, j;
GetByteContext gb;
s = src; bytestream2_init(&gb, src, src_len);
s_end = src + src_len;
d = dest; d = dest;
d_end = d + dest_len; d_end = d + dest_len;
dataleft = bytestream2_get_le32(&gb);
if (s_end - s < 8)
return;
dataleft = AV_RL32(s);
s += 4;
memset(queue, 0x20, QUEUE_SIZE); memset(queue, 0x20, QUEUE_SIZE);
if (AV_RL32(s) == 0x56781234) { if (bytestream2_get_bytes_left(&gb) < 4)
s += 4; return;
if (bytestream2_peek_le32(&gb) == 0x56781234) {
bytestream2_get_le32(&gb);
qpos = 0x111; qpos = 0x111;
speclen = 0xF + 3; speclen = 0xF + 3;
} else { } else {
@@ -109,13 +106,13 @@ static void lz_unpack(const unsigned char *src, int src_len,
speclen = 100; /* no speclen */ speclen = 100; /* no speclen */
} }
while (s_end - s > 0 && dataleft > 0) { while (dataleft > 0 && bytestream2_get_bytes_left(&gb) > 0) {
tag = *s++; tag = bytestream2_get_byteu(&gb);
if ((tag == 0xFF) && (dataleft > 8)) { if ((tag == 0xFF) && (dataleft > 8)) {
if (d_end - d < 8 || s_end - s < 8) if (d_end - d < 8 || bytestream2_get_bytes_left(&gb) < 8)
return; return;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
queue[qpos++] = *d++ = *s++; queue[qpos++] = *d++ = bytestream2_get_byteu(&gb);
qpos &= QUEUE_MASK; qpos &= QUEUE_MASK;
} }
dataleft -= 8; dataleft -= 8;
@@ -124,21 +121,17 @@ static void lz_unpack(const unsigned char *src, int src_len,
if (dataleft == 0) if (dataleft == 0)
break; break;
if (tag & 0x01) { if (tag & 0x01) {
if (d_end - d < 1 || s_end - s < 1) if (d_end - d < 1 || bytestream2_get_bytes_left(&gb) < 1)
return; return;
queue[qpos++] = *d++ = *s++; queue[qpos++] = *d++ = bytestream2_get_byte(&gb);
qpos &= QUEUE_MASK; qpos &= QUEUE_MASK;
dataleft--; dataleft--;
} else { } else {
if (s_end - s < 2) chainofs = bytestream2_get_byte(&gb);
return; chainofs |= ((bytestream2_peek_byte(&gb) & 0xF0) << 4);
chainofs = *s++; chainlen = (bytestream2_get_byte(&gb) & 0x0F) + 3;
chainofs |= ((*s & 0xF0) << 4);
chainlen = (*s++ & 0x0F) + 3;
if (chainlen == speclen) { if (chainlen == speclen) {
if (s_end - s < 1) chainlen = bytestream2_get_byte(&gb) + 0xF + 3;
return;
chainlen = *s++ + 0xF + 3;
} }
if (d_end - d < chainlen) if (d_end - d < chainlen)
return; return;
@@ -154,51 +147,47 @@ static void lz_unpack(const unsigned char *src, int src_len,
} }
} }
} }
static int rle_unpack(const unsigned char *src, unsigned char *dest,
static int rle_unpack(const unsigned char *src, int src_len, int src_count, int src_count, int src_size, int dest_len)
unsigned char *dest, int dest_len)
{ {
const unsigned char *ps;
const unsigned char *ps_end;
unsigned char *pd; unsigned char *pd;
int i, l; int i, l;
unsigned char *dest_end = dest + dest_len; unsigned char *dest_end = dest + dest_len;
GetByteContext gb;
ps = src; bytestream2_init(&gb, src, src_size);
ps_end = src + src_len;
pd = dest; pd = dest;
if (src_count & 1) { if (src_count & 1) {
if (ps_end - ps < 1) if (bytestream2_get_bytes_left(&gb) < 1)
return 0; return 0;
*pd++ = *ps++; *pd++ = bytestream2_get_byteu(&gb);
} }
src_count >>= 1; src_count >>= 1;
i = 0; i = 0;
do { do {
if (ps_end - ps < 1) if (bytestream2_get_bytes_left(&gb) < 1)
break; break;
l = *ps++; l = bytestream2_get_byteu(&gb);
if (l & 0x80) { if (l & 0x80) {
l = (l & 0x7F) * 2; l = (l & 0x7F) * 2;
if (dest_end - pd < l || ps_end - ps < l) if (dest_end - pd < l || bytestream2_get_bytes_left(&gb) < l)
return ps - src; return bytestream2_tell(&gb);
memcpy(pd, ps, l); bytestream2_get_buffer(&gb, pd, l);
ps += l;
pd += l; pd += l;
} else { } else {
if (dest_end - pd < i || ps_end - ps < 2) if (dest_end - pd < i || bytestream2_get_bytes_left(&gb) < 2)
return ps - src; return bytestream2_tell(&gb);
for (i = 0; i < l; i++) { for (i = 0; i < l; i++) {
*pd++ = ps[0]; *pd++ = bytestream2_get_byteu(&gb);
*pd++ = ps[1]; *pd++ = bytestream2_get_byteu(&gb);
} }
ps += 2; bytestream2_skip(&gb, 2);
} }
i += l; i += l;
} while (i < src_count); } while (i < src_count);
return ps - src; return bytestream2_tell(&gb);
} }
static void vmd_decode(VmdVideoContext *s, AVFrame *frame) static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
@@ -207,12 +196,8 @@ static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
unsigned int *palette32; unsigned int *palette32;
unsigned char r, g, b; unsigned char r, g, b;
/* point to the start of the encoded data */ GetByteContext gb;
const unsigned char *p = s->buf + 16;
const unsigned char *p_end = s->buf + s->size;
const unsigned char *pb;
const unsigned char *pb_end;
unsigned char meth; unsigned char meth;
unsigned char *dp; /* pointer to current frame */ unsigned char *dp; /* pointer to current frame */
unsigned char *pp; /* pointer to previous frame */ unsigned char *pp; /* pointer to previous frame */
@@ -257,29 +242,31 @@ static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
} }
/* check if there is a new palette */ /* check if there is a new palette */
bytestream2_init(&gb, s->buf + 16, s->size - 16);
if (s->buf[15] & 0x02) { if (s->buf[15] & 0x02) {
if (p_end - p < 2 + 3 * PALETTE_COUNT) bytestream2_skip(&gb, 2);
return;
p += 2;
palette32 = (unsigned int *)s->palette; palette32 = (unsigned int *)s->palette;
if (bytestream2_get_bytes_left(&gb) >= PALETTE_COUNT * 3) {
for (i = 0; i < PALETTE_COUNT; i++) { for (i = 0; i < PALETTE_COUNT; i++) {
r = *p++ * 4; r = bytestream2_get_byteu(&gb) * 4;
g = *p++ * 4; g = bytestream2_get_byteu(&gb) * 4;
b = *p++ * 4; b = bytestream2_get_byteu(&gb) * 4;
palette32[i] = 0xFFU << 24 | r << 16 | g << 8 | b; palette32[i] = 0xFFU << 24 | (r << 16) | (g << 8) | (b);
palette32[i] |= palette32[i] >> 6 & 0x30303; palette32[i] |= palette32[i] >> 6 & 0x30303;
} }
} }
if (p < p_end) { }
if (s->size > 0) {
/* originally UnpackFrame in VAG's code */ /* originally UnpackFrame in VAG's code */
pb = p; bytestream2_init(&gb, gb.buffer, s->buf + s->size - gb.buffer);
pb_end = p_end; if (bytestream2_get_bytes_left(&gb) < 1)
meth = *pb++; return;
meth = bytestream2_get_byteu(&gb);
if (meth & 0x80) { if (meth & 0x80) {
lz_unpack(pb, p_end - pb, s->unpack_buffer, s->unpack_buffer_size); lz_unpack(gb.buffer, bytestream2_get_bytes_left(&gb),
s->unpack_buffer, s->unpack_buffer_size);
meth &= 0x7F; meth &= 0x7F;
pb = s->unpack_buffer; bytestream2_init(&gb, s->unpack_buffer, s->unpack_buffer_size);
pb_end = s->unpack_buffer + s->unpack_buffer_size;
} }
dp = &frame->data[0][frame_y * frame->linesize[0] + frame_x]; dp = &frame->data[0][frame_y * frame->linesize[0] + frame_x];
@@ -289,15 +276,12 @@ static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
for (i = 0; i < frame_height; i++) { for (i = 0; i < frame_height; i++) {
ofs = 0; ofs = 0;
do { do {
if (pb_end - pb < 1) len = bytestream2_get_byte(&gb);
return;
len = *pb++;
if (len & 0x80) { if (len & 0x80) {
len = (len & 0x7F) + 1; len = (len & 0x7F) + 1;
if (ofs + len > frame_width || pb_end - pb < len) if (ofs + len > frame_width || bytestream2_get_bytes_left(&gb) < len)
return; return;
memcpy(&dp[ofs], pb, len); bytestream2_get_buffer(&gb, &dp[ofs], len);
pb += len;
ofs += len; ofs += len;
} else { } else {
/* interframe pixel copy */ /* interframe pixel copy */
@@ -319,10 +303,7 @@ static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
case 2: case 2:
for (i = 0; i < frame_height; i++) { for (i = 0; i < frame_height; i++) {
if (pb_end -pb < frame_width) bytestream2_get_buffer(&gb, dp, frame_width);
return;
memcpy(dp, pb, frame_width);
pb += frame_width;
dp += frame->linesize[0]; dp += frame->linesize[0];
pp += s->prev_frame.linesize[0]; pp += s->prev_frame.linesize[0];
} }
@@ -332,22 +313,16 @@ static void vmd_decode(VmdVideoContext *s, AVFrame *frame)
for (i = 0; i < frame_height; i++) { for (i = 0; i < frame_height; i++) {
ofs = 0; ofs = 0;
do { do {
if (pb_end - pb < 1) len = bytestream2_get_byte(&gb);
return;
len = *pb++;
if (len & 0x80) { if (len & 0x80) {
len = (len & 0x7F) + 1; len = (len & 0x7F) + 1;
if (pb_end - pb < 1) if (bytestream2_get_byte(&gb) == 0xFF)
return; len = rle_unpack(gb.buffer, &dp[ofs],
if (*pb++ == 0xFF) len, bytestream2_get_bytes_left(&gb),
len = rle_unpack(pb, pb_end - pb, len, &dp[ofs], frame_width - ofs); frame_width - ofs);
else { else
if (pb_end - pb < len) bytestream2_get_buffer(&gb, &dp[ofs], len);
return; bytestream2_skip(&gb, len);
memcpy(&dp[ofs], pb, len);
}
pb += len;
ofs += len;
} else { } else {
/* interframe pixel copy */ /* interframe pixel copy */
if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])

View File

@@ -69,6 +69,14 @@ fate-filter-gradfun: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf gradfun
FATE_FILTER_VSYNTH-$(CONFIG_HQDN3D_FILTER) += fate-filter-hqdn3d FATE_FILTER_VSYNTH-$(CONFIG_HQDN3D_FILTER) += fate-filter-hqdn3d
fate-filter-hqdn3d: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf hqdn3d fate-filter-hqdn3d: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf hqdn3d
FATE_FILTER-$(call FILTERDEMDECENCMUX, JOIN, WAV, PCM_S16LE, PCM_S16LE, PCM_S16LE) += fate-filter-join
fate-filter-join: SRC1 = $(TARGET_PATH)/tests/data/asynth-44100-2.wav
fate-filter-join: SRC2 = $(TARGET_PATH)/tests/data/asynth-44100-3.wav
fate-filter-join: tests/data/asynth-44100-2.wav tests/data/asynth-44100-3.wav
fate-filter-join: CMD = md5 -i $(SRC1) -i $(SRC2) -filter_complex join=channel_layout=5 -f s16le
fate-filter-join: CMP = oneline
fate-filter-join: REF = 38fa1b18b0c46d77df6f17bfc4f078dd
FATE_FILTER_VSYNTH-$(CONFIG_NEGATE_FILTER) += fate-filter-negate FATE_FILTER_VSYNTH-$(CONFIG_NEGATE_FILTER) += fate-filter-negate
fate-filter-negate: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf negate fate-filter-negate: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf negate
@@ -84,6 +92,13 @@ fate-filter-transpose: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf transpose
FATE_FILTER_VSYNTH-$(CONFIG_UNSHARP_FILTER) += fate-filter-unsharp FATE_FILTER_VSYNTH-$(CONFIG_UNSHARP_FILTER) += fate-filter-unsharp
fate-filter-unsharp: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf unsharp fate-filter-unsharp: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf unsharp
FATE_FILTER-$(call FILTERDEMDECENCMUX, VOLUME, WAV, PCM_S16LE, PCM_S16LE, PCM_S16LE) += fate-filter-volume
fate-filter-volume: SRC = $(TARGET_PATH)/tests/data/asynth-44100-2.wav
fate-filter-volume: tests/data/asynth-44100-2.wav
fate-filter-volume: CMD = md5 -i $(SRC) -af volume=precision=fixed:volume=0.5 -f s16le
fate-filter-volume: CMP = oneline
fate-filter-volume: REF = 4d6ba75ef3e32d305d066b9bc771d6f4
FATE_YADIF += fate-filter-yadif-mode0 FATE_YADIF += fate-filter-yadif-mode0
fate-filter-yadif-mode0: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vframes 30 -vf yadif=0 fate-filter-yadif-mode0: CMD = framecrc -flags bitexact -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -vframes 30 -vf yadif=0