[FFmpeg-devel] [PATCH] Fraps fix
Roine Gustafsson
roine
Sun Feb 24 04:13:48 CET 2008
Fraps sometimes glitches with current SVN because symbols with zero
count is not added to the huffman tree despite Kostya's stern
warning: <http://wiki.multimedia.cx/index.php?title=Fraps>
It seems VP6 and Fraps differ in this regard (both share the huffman
tree build code)
None of the current Fraps samples on mplayerhq seem to exhibit this
bug; here is a sample that does: <http://www.mediafire.com/?e4dqezhxcm2>
Suggested patch attached. This correctly plays the broken one, all
Fraps samples on mplayerhq and all VP6 samples that worked before.
/Roine
Index: libavcodec/huffman.c
===================================================================
--- libavcodec/huffman.c (revision 12184)
+++ libavcodec/huffman.c (working copy)
@@ -28,12 +28,14 @@
#define HNODE -1
-static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t
*xlat, Node *nodes, int node, uint32_t pfx, int pl, int *pos)
+static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t
*xlat,
+ Node *nodes, int node, uint32_t pfx, int pl,
+ int *pos, int include_zero_count)
{
int s;
s = nodes[node].sym;
- if(s != HNODE || !nodes[node].count){
+ if(s != HNODE || (!include_zero_count && !nodes[node].count)){
bits[*pos] = pfx;
lens[*pos] = pl;
xlat[*pos] = s;
@@ -41,20 +43,20 @@
}else{
pfx <<= 1;
pl++;
- get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx,
pl, pos);
+ get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx,
pl, pos, include_zero_count);
pfx |= 1;
- get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0+1,
pfx, pl, pos);
+ get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0+1,
pfx, pl, pos, include_zero_count);
}
}
-static int build_huff_tree(VLC *vlc, Node *nodes, int head)
+static int build_huff_tree(VLC *vlc, Node *nodes, int head, int
include_zero_count)
{
uint32_t bits[256];
int16_t lens[256];
uint8_t xlat[256];
int pos = 0;
- get_tree_codes(bits, lens, xlat, nodes, head, 0, 0, &pos);
+ get_tree_codes(bits, lens, xlat, nodes, head, 0, 0, &pos,
include_zero_count);
return init_vlc_sparse(vlc, 9, pos, lens, 2, 2, bits, 4, 4,
xlat, 1, 1, 0);
}
@@ -62,9 +64,11 @@
/**
* nodes size must be 2*nb_codes
* first nb_codes nodes.count must be set
+ * @param include_zero_count boolean; set to include zero symbol counts
*/
int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
- Node *nodes, huff_cmp_t cmp, int hnode_first)
+ Node *nodes, huff_cmp_t cmp, int hnode_first,
+ int include_zero_count)
{
int i, j;
int cur_node;
@@ -97,7 +101,7 @@
}
cur_node++;
}
- if(build_huff_tree(vlc, nodes, nb_codes*2-2) < 0){
+ if(build_huff_tree(vlc, nodes, nb_codes*2-2, include_zero_count)
< 0){
av_log(avctx, AV_LOG_ERROR, "Error building tree\n");
return -1;
}
Index: libavcodec/huffman.h
===================================================================
--- libavcodec/huffman.h (revision 12184)
+++ libavcodec/huffman.h (working copy)
@@ -34,6 +34,7 @@
typedef int (*huff_cmp_t)(const void *va, const void *vb);
int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
- Node *nodes, huff_cmp_t cmp, int hnode_first);
+ Node *nodes, huff_cmp_t cmp, int hnode_first,
+ int include_zero_count);
#endif /* FFMPEG_HUFFMAN_H */
Index: libavcodec/fraps.c
===================================================================
--- libavcodec/fraps.c (revision 12184)
+++ libavcodec/fraps.c (working copy)
@@ -94,7 +94,7 @@
for(i = 0; i < 256; i++)
nodes[i].count = bytestream_get_le32(&src);
size -= 1024;
- if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, 0)
< 0)
+ if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, 0,
1) < 0)
return -1;
/* we have built Huffman table and are ready to decode plane */
Index: libavcodec/vp6.c
===================================================================
--- libavcodec/vp6.c (revision 12184)
+++ libavcodec/vp6.c (working copy)
@@ -225,7 +225,7 @@
}
/* then build the huffman tree accodring to probabilities */
- ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, 1);
+ ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, 1, 0);
}
static void vp6_parse_coeff_models(vp56_context_t *s)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fraps.patch
Type: application/octet-stream
Size: 4035 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080224/dbeafbe2/attachment.obj>
More information about the ffmpeg-devel
mailing list